java examples for beginners

Example 1: basic java coding

public class AddTwoNumbers {

   public static void main(String[] args) {
        
      int num1 = 5, num2 = 15, sum;
      sum = num1 + num2;

      System.out.println("Sum of these numbers: "+sum);
   }
}

Example 2: java tutorial for beginners

public class MyFirstJavaProgram {

   /* This is my first java program.
    * This will print 'Hello World' as the output
    */

   public static void main(String []args) {
      System.out.println("Hello World"); // prints Hello World
   }
}

Example 3: java coding for beginners

= Output: 10
+= Output: 20
-= Output: 10
*= Output: 200
/= Output: 10
%= Output: 0

Example 4: java example

class Anupam
{
  public static void main(String...args)
  {
    System.out.println("HI this is Anupam Guin ");
  }
}