Java Reference
In-Depth Information
Note that Java is case-sensitive. You can't enter public with a capital P — if you do, the program won't
compile. This applet just displays a message when you run it. The mechanics of how the message gets dis-
played are irrelevant here — the example is just to illustrate how an applet goes into an HTML page. If you
compile this code and save the previous HTML page specification in the file MyFirstApplet.html in the
same directory as the Java applet .class file, you can run the applet using appletviewer from the JDK
with the command:
appletviewer MyFirstApplet.html
This displays the window shown in Figure 1-2 :
FIGURE 1-2
Because the height and width of the window for the applet are specified in pixels, the physical dimensions
of the appletviewer window depend on the resolution and size of your monitor.
OBJECT-ORIENTED PROGRAMMING IN JAVA
As I said at the beginning of this chapter, Java is an object-oriented language. When you use a programming
language that is not object-oriented, you must express the solution to every problem essentially in terms of
numbers and characters — the basic kinds of data that you can manipulate in the language. In an object-
oriented language like Java, things are different. Of course, you still have numbers and characters to work
with — these are referred to as the primitive data types — but you can define other kinds of entities that are
relevant to your particular problem. You solve your problem in terms of the entities or objects that occur in
the context of the problem. This not only affects how a program is structured, but also the terms in which
the solution to your problem is expressed.
If your problem concerns baseball players, your Java program is likely to have BaseballPlayer objects
in it; if you are producing a program dealing with fruit production in California, it may well have objects
that are Oranges in it. Apart from seeming to be an inherently sensible approach to constructing programs,
object-oriented programs are usually easier to understand.
In Java almost everything is an object. If you haven't delved into object-oriented programming before, or
maybe because you have, you may feel this is a bit daunting. But fear not. Objects in Java are particularly
easy. So easy, in fact, that you are going to start out by understanding some of the ideas behind Java objects
right now. In that way you can be on the right track from the outset.
 
 
Search WWH ::




Custom Search