CHAPTER 1 ■ WRITING YOUR FIRST JAVA PROGRAM
- In the PPackage field, type whatever you like for the package, but remember to
use a name you can remember and keep it separate from your other projects. A
package is a way to group classes together. For small projects, you don't need
them. Large projects would be impossible to manage without them, though.
We'll cover classes in the next chapterIn the NName field, type Hello. This is the
name of your class. - Check the checkbox that gives you a main method (public static void main
(String args[])). When you're done, you should have a class similar to the
one in Listing 1-1.
Remember that Java is case-sensitive. “Hello” is not the same as “hello”
to Java.
Listing 1-1: Preliminary Hello class
package com.bryantcs.examples.hello;
public class Hello {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
- Remove the comments. We don't need a comment (the lines that start with /
and end with / and the line that starts with //), and we're about to fill in that
autogenerated stub. - Within the main method, type:
System.out.println(“Hello, World!”);
Your class should now look similar to Listing 1-2.
Listing 1-2: Basic Hello program
package com.bryantcs.examples.hello;
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}