web analytics

Java Getting Started

All applications in java begin with a class name, and that class must match the filename. Now let’s create our fist java program. Name of class will be FirstJavaProgram and name of file will FirstJavaProgram.java. We can do it in any text editor like notepad or an IDE like Netbeans. It will contain a main method which will print “Hello Word” on screen.

class FirstJavaProgram {

public static void main(String args[]){

System.out.println("Hello World");

}

}

Save the file as FirstJavaProgram.java
Open terminal, point it to directory where you have saved the above java file and type following command:
javac FirstJavaProgram.java
above command will compile the java file and create an new file named FirstJavaProgram.class. Now let’s run this file by type following command on termial:
java FirstJavaProgram.class
the above command will print the string “Hello World” on screen and will be terminated.