CHAPTER 1 ■ WRITING YOUR FIRST JAVA PROGRAM
■ Note That said, some code bases actually have a number of main methods. They exist so that classes can be
tested individually. Strictly speaking, each one starts a separate Java program, even though the people working on
them might think of them as just parts of the larger program. For our purposes, just remember that a Java
program must have a main method.
The class that contains the main method .determines the name of the program. The name of the
program is the name of that class. For example, the program we write later in this chapter is called Hello
because the class that holds its main method is named Hello. (Of course, the marketing department can
call it anything, but it's the Hello program to Java and Java developers.) This naming arrangement
happens because of the way Java programs are started: The Java runtime engine requires the name of a
class that contains a main method.
■ Note The file that holds a Java class must have exactly the same name as the Java class. For example, the
Hello class must be stored in a file named Hello.java. If the file were named hello.java, it wouldn't work. A
lowercase h is not an uppercase H, and the Java compiler won’t recognize that hello.java contains the Hello
class.
To create a class with a main method for your first program, follow these steps:
- Right-click the Hello project in the Eclipse Package Explorer, choose NNew,
and then choose CClass. The New Java Class window displays, as shown in
Figure 1-4.