Jun 08 2009

A Simple Java Program

Category: Javaadmin @ 12:43 pm

Writing the First Java Program

/*
This is a simple Java Program.
Call this file “Example.java”
*/
 
class Example {
 
	public static void main(String args[]){
		System.out.println("This is a simple Java program.");
	}
}

Compiling the Program

To Compile the Example program, execute the compiler, javac, specifying the name of source file as showed below,

Let’s assume that source file is located at D:\>java\Example.java

Go to Command prompt & type: at D:\>java\javac Example.java

The javac compiler creates a file called Example.class that contains bytecode version of the program, That can Be executed by Java virtual Machine.

To actually run the program you must use java application launcher, called “java”.
To do so in command prompt Type,
D:\>java\java Example

When the program run, the following output is displayed:
” This is a simple Java program. “

Tags: ,