The procedure to create and run a standalone program, called
an application in Java, goes as follows for a program that
simply prints "Hello
World!"
to the command console:
Step 1: Use an editor to enger the following code for
the HelloWoldApp
program:
HelloWorldApp
Application |
public
class HelloWorldApp
{
public static void main(String arg[])
{
System.out.println("Hello
World!");
}
}
|
Save this code code in a file called HelloWorldApp.java
Step 2: Compile the application with the command line*:
> javac HelloWorldApp.java
This creates the class file (with the bytecode output):
Step 3: Use the java
command to run the program:
> java HelloWorldApp
Hello World!
The output is printed after the command line.
We will discuss in coming chapters the structure of the program,
the class
keyword, and other elements of a Java program.
* On the Java
Tools page, see the note
on the javac
-target option.
Latest update: Oct. 10, 2004
|