Java Reference
In-Depth Information
Java Applications
Every Java application contains a class that defines a method called main() . The name of this class is
the name that you use as the argument to the Java interpreter when you run the application. You can
call the class whatever you want, but the method which is executed first in an application is always
called main() . When you run your Java application the method main() will typically cause methods
belonging to other classes to be executed, but the simplest possible Java application program consists of
one class containing just the method main() . As we shall see below, the main() method has a
particular fixed form, and if it is not of the required form, it will not be recognized by the Java
interpreter as the method where execution starts.
We'll see how this works by taking a look at just such a Java program. You need to enter the program
code using your favorite plain text editor, or if you have a Java development system with an editor, you
can enter the code for the example using that. When you have entered the code, save the file with the
same name as that used for the class and the extension .java . For this example the file name will be
OurFirstProgram.java . The code for the program is:
The program consists of a definition for a class we have called OurFirstProgram . The class definition
only contains one method, the method main() . The first line of the definition for the method main()
is always of the form:
public static void main(String[] args)
The code for the method appears between the pair of curly braces. Our version of the method has only
one executable statement:
System.out.println("Krakatoa, EAST of Java??");
So what does this statement do? Let's work through it from left to right:
Search WWH ::




Custom Search