Java Reference
In-Depth Information
JAVA PROGRAM STRUCTURE
Let's summarize how a Java program is structured:
• A Java program always consists of one or more classes.
• You put the program code for each class in a separate file, and you must give each file the same
name as that of the class that is defined within it.
• A Java source file name must have the extension .java .
Thus your file containing the class Hat is called Hat.java , and your file containing the class Base-
ballPlayer must have the file name BaseballPlayer.java .
NOTE You see in Chapter 5 that a class definition can be nested inside another class. This
meansthata .java filecancontainthedefinitions formorethanoneclasstype.Thefilename
in such cases is the same as the name of the outer class.
A typical program consists of several files, as Figure 1-8 illustrates.
FIGURE 1-8
The program in Figure 1-8 clearly majors on apparel, with four of the five classes representing clothing.
Each source file contains a class definition, and all of the files that go to make up the program are stored
in the same directory. The source files for your program contain all the code that you wrote, but this is not
everything that is ultimately included in the program. There is also code from the Java standard class lib-
rary , so let's take a peek at what that can do.
Java's Class Library
A library in Java is a collection of classes — usually providing related facilities — that you can use in your
programs. The Java class library provides you with a whole range of goodies, some of which are essential
for your programs to work at all, and some of which make writing your Java programs easier. To say that
the standard class library covers a lot of ground would be something of an understatement, so I won't be
going into it in detail here, and this topic certainly does not cover it all — you would probably risk a hernia
lifting a book that did. However, you learn how to apply many of the most commonly used facilities the Java
libraries provide throughout the topic.
 
 
Search WWH ::




Custom Search