Java Reference
In-Depth Information
download the current documentation set and install it following the directions avail-
able at http://java.sun.com .Ifyou use a third-party SDK, the documentation
should be available from the same source as the SDK itself.
The following two sections give an example of a simple applet and a simple
application program. These illustrate the basics for creating such programs and
provide some initial experience with the SDK programming tools. The general
workings of the code should be readily apparent so we wait until later chapters
to discuss the exact meaning and function of the various language keywords and
structures.
1.8.2 First application
Standalone programs in Java are referred to as applications. As mentioned pre-
viously, Figure 1.2 shows the steps needed to create and run an application. The
code for the standard “Hello World” application that prints a string to the console
is shown here:
public class HelloWorldApp
{
public static void main (String[] args)
{
System.out.println ("Hello World!");
}
}
Put this code into a file called HelloWorldApp.java .(AJava file name must
match exactly the class name, including the capitalization; this is true for all
platforms.) Compile the application as follows:
> javac HelloWorldApp.java
This creates the class file HelloWorldApp.class . Use the java command
to run the program:
> java HelloWorldApp
This produces the output
Hello World!
in the console window.
 
Search WWH ::




Custom Search