Java Reference
In-Depth Information
You will follow these three steps:
1. Enter the program.
2. Compile the program.
3. Run the program.
Entering the Program
The programs shown in this topic are available from McGraw-Hill Education's website:
www.oraclepressbooks.com . However, if you want to enter the programs by hand, you are
free to do so. In this case, you must enter the program into your computer using a text ed-
itor, not a word processor. Word processors typically store format information along with
text. This format information will confuse the Java compiler. If you are using a Windows
platform, you can use WordPad or any other programming editor that you like.
For most computer languages, the name of the file that holds the source code to a pro-
gram is arbitrary. However, this is not the case with Java. The first thing that you must learn
about Java is that the name you give to a source file is very important . For this example,
the name of the source file should be Example.java . Let's see why.
In Java, a source file is officially called a compilation unit . It is a text file that contains
(among other things) one or more class definitions. (For now, we will be using source files
that contain only one class.) The Java compiler requires that a source file use the .java fi-
lename extension. As you can see by looking at the program, the name of the class defined
by the program is also Example . This is not a coincidence. In Java, all code must reside
inside a class. By convention, the name of the main class should match the name of the file
that holds the program. You should also make sure that the capitalization of the filename
matches the class name. The reason for this is that Java is case sensitive. At this point, the
Search WWH ::




Custom Search