|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 2 of 5
Is Fred one application or two applications? The answer depends on your perspective. Normally, an application consists of a single
class with a main() method. As you've seen, you run the application by specifying java and the name of the class that contains main(). However, you might find yourself placing a main() method in other classes (for debugging purposes). To prevent confusion for anyone using your program, either remove all main() methods except the main() method that starts the application, or identify the class file containing the official main() method before deploying the application.
In addition to java, the Java 2 SDK includes a javaw program that you can use to run applications. That program is almost identical to java, except that javaw does not display a command window when running an application (unless you run the application through a Windows batch file,
which automatically opens a command window). For example, suppose your class file called GUIDemo is stored in the c:\jdk1.4\projects directory (assuming Windows). You decide to create a Windows shortcut for running that program, and choose the following
command line: java -cp c:\jdk1.4\projects GUIDemo. (The -cp option tells java where to find a class file called GUIDemo.class.) When you select the shortcut, a command window pops up along with GUIDemo's GUI window. However, if you change java to javaw, you won't see the command window.
Now that you've had a chance to play with applications, let's take a look at the second category of Java programs -- applets.
An applet is an application that runs in the context of a Web browser that controls the applet. Because a rectangular area of the Webpage displays an applet's output, applets are described as being embedded in Webpages. Furthermore, by calling certain methods -- which we'll shortly investigate -- the browser manages an applet's life cycle.
An applet's class files download automatically to a user's machine when the user surfs to a Webpage containing the applet. Once downloaded, the browser's virtual machine or the Java Plug-in software executes those class files. (See Resources for an article that explores Java Plug-in.)
Imagine a malicious person creating an applet that deletes files, wastes reams of printer paper, steals passwords or other sensitive information, and so on. An applet with unrestricted access to a user's machine could perform all of those misdeeds. For that reason, applets can only execute limited functions. For example, an applet cannot perform any file-related activities.
Sun has established a specific (and involved) procedure for turning restricted applets into unrestricted applets. However, unrestricted applets can only run under the user's permission. (We will explore that subject in a future article.) To be an applet, one -- and only one -- of the applet's classes must conform to the following pattern:
public class class_name extends java.applet.Applet
{
}
The required public keyword gives the Web browser access to the applet. The extends keyword indicates the object-oriented programming concept of inheritance and suggests that the class_name class inherits applet capabilities from a class called Applet (located in the java.applet package -- an organizational mechanism for classes and class files -- to be explored in a future article).