Aqua Phoenix
     >>  Lectures >>  Java 1  
 

Navigator
   
 
       
   

1.4 Hello World

Following tradition, the first program we will write is as simple as printing out "Hello World" on the command line. This will give us an idea of the basic framework of a Java program:

HelloWorld.javaThis code can be produced in any text editor. To compile it, we use the following command in a terminal:

javac HelloWorld.java
This will produce a corresponding class file with Java byte code, named HelloWorld.class. The byte code can be run using the JVM by calling the following command:

java HelloWorld
Note that there is no need to specify the .class extension. In fact, specifying it would return an error. The following is the output in the terminal:

$ java HelloWorld
Hello World!
$
The basic parts of this example code include:
  • A class definition: public class HelloWorld { ... }
  • One method: public static void main(String[] args) { ... }