Java Reference
In-Depth Information
Chapter
16
Applications and Applets
OBJECTIVES
• See how to make a set of classes into a Java application.
• See how to make an application into an executable file.
• See how to write an applet and put it on an html page.
INTRODUCTION
There are two ways to make a set of Java classes into a unit that can be used else-
where. The first is to build an
application
, which generally resides on your com-
puter and can be executed when you want. The second is to build an
applet
, which
can be called when a browser loads an html page.
16.1
Java applications
A
Java application
is a bunch of classes (in
.java
files) in which (at least) one
class has a method
main
of the following form:
/**
Called by system to start execution of the Java application
*/
public static void
main(String[] args) { … }
The system calls method
main
to start execution of the program. The param-
eter, a
String
array, can contain information that the application uses when exe-
cution starts. The parameter is rarely used, and we will not discuss it further. So
if you do not know about arrays, it does not matter.
In DrJava, there is no need for this method
main
because any static method
in a compiled class, as well as any instance method of an accessible folder, can
be called in the Interactions pane. But in other IDEs, method
main
is necessary,
and you may have to tell the IDE which class contains method
main
. Each IDE
has a different way to do this.
Activity
1-2.1
Search WWH ::
Custom Search