Class 1, Part 2 |
Intro to Java 30-IT-396 |
|
Your First Java Program:
Practice
with the Bare Bones
-
Using NetBeans or a text editor of your
choice, type or copy-paste the following:
// Define the class. No package for this simple application.
public class HelloWorld {
// The public static void main method for running from a
command
line
// String args[] is a String array that contains the command
line arguments.
public static void main(String args[]) {
// Define a variable called message, put some default
text
in it.
String message = "Hello world, this is Java I!";
// Print that to the output window
System.out.println(message);
// Close the method.
}
// Close the class.
}
- If you used NetBeans or a similar IDE...
- Under the Filesystems tab in the upper left, look for the file
you created.
- Right-click on that file and choose 'Execute'. That
command will save and compile your file, and then attempt to run it.
- If compilation fails, the program will not execute.
Instead, it will display the compilation errors at the output window
toward the bottom of your screen.
- If you used a text editor...
- Save the file as HelloWorld.java
- Go to a command prompt. How?
- Go to the directory where you saved HelloWorld.java, and type
javac HelloWorld.java
- Then, type Java HelloWorld
- If all works well, it should print out a welcome message.
If not,
let me know.
A closer look

Created by: Brandan
Jones
December 17, 2001
Updated September 28, 2004