Contents / Previous / Next


Java Application

Java Applications are standalone programs that execute independently of a browser.

They are interpreted by the Java interpreter, thus running on the Java Virtual Machine.

The main Method is the entry point of every Java application.
Every Java application must contain a main method whose signature looks like this:

public static void main(String[] args)

Example. The HelloWorldApplication class implements an application that writes "Hello World!" to the standard output:

class HelloWorldApplication 
{
    public static void main(String[] args) 
    {
        System.out.println("Hello World!");
    }
}
The main method controls the flow of the program, allocates whatever resources are needed, and runs any other methods that provide the functionality for the application.


Compiling and Running a Java Application

Java classes are stored one class per file. File-name and class-name must be identical.
Use the Java compiler javac to compile the "HelloWorldApplication" (stored in the file "HelloWorldApplication.java"):
 javac HelloWorldApplication.java
The output is the file "HelloWorldApplication.class" containing the Java byte code of the application.

Then you run the application with the Java interpreter, specifying the name of the class file (without the .class extension):

 java HelloWorldApplication
The interpreter invokes the main method defined within that class.