Writing My First Java Program
Writing My First Java Program
This section provides a tutorial example on how to write, compile, and execute the first Java program with JDK 1.7.
Java, First, Program
Writing My First Java Program
This section provides a tutorial example on how to write, compile, and execute the first Java program with JDK 1.7.
When JDK is installed on your machine, it provides two commands for you to compile and run Java programs.
Let's try these commands with a very simple Java program.
First use NotePad to enter the following Java program into a file called Hello.java:
class Hello {
public static void main(String[] a) {
System.out.println("Hello world!");
}
}
Then compile this program in a command window with the "javac" command:
C:\herong>"\Program Files\java\jdk1.7.0_03\bin\javac.exe" Hello.java
To execute the program, use the java command:
C:\herong>"\Program Files\java\jdk1.7.0_03\bin\java.exe" Hello Hello world!
Congratulations, you have successfully entered, compiled and executed your first Java program.
Last update: 2012.