First Java Program

Consider below program

Program : Abc.java

class Abc
{

public static void main(String args[])

{

System.out.println(“Hello Amol”);

}

}

This is a simple java program to print “Hello Amol”.  This program is saved as Abc.java. The java program must be saved with .java extension and the file name should be its class name.

To compile this program on command prompt type javac programName.java (here javac Abc.java) and to run Java program name (Here java Abc)

but this will work only if you are in the same directory on command prompt where the program is. if the program is in another directory then you will have to give full path of the program while compliling.

e.g. javac D:/amol/java/Abc.java

let us see one more simple program for addition of 2 numbers in java

class pqr
{

public static void main(String[] args)
{
int a=10;
int b=20;
int c=0;
System.out.println("Addition of a and b" );

c=a+b;
System.out.println("The answer is :" + c );
}

}