Вы находитесь на странице: 1из 5

talking about Java. plays information as a scrolling text.

within a company because fewer people


ng force for this The repaint method is embedded in a are accessing the information. On the
Java’s simplicity thread that updates the value of the x- intranet, information can be shared
ntial power. Java is coordinates. This invokes the paint without any concem for the platform or
ng language, and a method for displaying the scrolling text: geographic location.
intranet and the World With proper
le Web (WWW). Java is a Write On pul7lic vold paint(Graphics g) access privi-
one platform and Run on Many plat- leges, one can
forms (WORM) language. For net- I update the
work-friendly, platform-independent information in
applications, Java (originally Oak, see The scrolling text is dynamically real time. This makes the latest informa-
box) is an object-oriented programming updated showing current activity (time tion ‘‘current; across the Internet. It’s
language. Java source code is compiled or stock prices) of the day (Fig. 1). done by making the web site accessible
into a virtual machine code or bytecode. Intranets are internal organizational from any platform. Using telecommuni-
This makes the Java platform indepen- networks set up to connect manage- cation, or other dedicated communica-
dent. It can be placed on a web site, and ment. They connect computers to peo- tions lines anywhere in the world, one
executed on the client side on a PC- ple, people to people, and people to can access the intranet or web site and
Intel, Mac-Motorola or UNIX- information. Information found on the treat it “as the Network” on the Internet.
Solaris machine without recompiling. intranet is protected, proprietary, pri-
Sun Microsystems formally vate and security-sensitive for develop- 3ava and HTMC
announced Java in May 1995. Java is ment activity and dynamically updated. Java applets are designed to be run
the first language that has built-in capa- Jaya makes intranets practical in the through a web browser. In the Hyper-
bilities for networking applications, in academic and business environment. Text Markup Language (HTML) file
particular, creating dynamic web pages. Intranets are embedded in the Intemet. associated with the applet bytecode, the
Java programs that run on the Internet Intranets support two objectives: 1) minimum requirements needing defini-
web pages are called applets. These increased information sharing within tions are code, width and height for the
applets are easily incorporated into certain boundaries, and 2) cost effective applet display window.
Web pages. These applets are executed management. This is done by storing The applets can be parameterized so
1
from homepages on remote web sites. information on a server on the Internet. that the user can personalize them for his
Java programs run interpretively on the Common protocols are used to link or her own use. There are additional use-
client side. computers to provide clientkerver com- ful attributes depending on the nature of
Java reduces development costs and munication over the Internet. An the applel. The full list of attributes
speeds up the learning curve. Tradition- intranet uses the same common proto- include: align, alt, archive, codebase,
al client-server development tools- cols for communication, but it is limited hspace, vspace and name. In addition,
such as Delphi, Power-Builder and to a select group of people or a compa- param is used to customize the applets
Visual Basic-are losing ground to ny. A group of people may have similar which require commandline input.
Java as a result. By year-end of 1996, skills and be working on the related Codebase is required when the.html file
Java had moved ahead in use of both C parts of a problem. The collaborating and.class f i e are in different directories.
and C++ and these application develop- people can access the current copy of The name attribute is useful when an
ment tools. documents simultaneously. However, applet references another applet via the -
the communication channels may be getApplet() method (see Box A pg 34). 8
different. The speed of access is better Note: There should be no confusion @
3ava, lnternet, Intranets
and the WWW
Information found on the Internet is
usually public domain, commercial for
production and static in context. Java
can be incorporated in WWW pages
and can be executed without modifica-
tion as you connect to the web site.
Java’s design is based on the concept of
sharing information across the net-
works, not hiding information.
Today, it is not practical to produce
full-blown network applications
because of the low communication
bandwidth. For the time being, Java is
used to add functionality to network
applications. Applets included in
WWW pages introduce new levels of
multimedia functionality through the
use of text, graphics, images and audio.
For example, a tickertape applet dis-

AUGUSTKEPTEMBER 1998
between the Java language and The html file, usually
the Java script. The Java script is denoted by the same name,
different in syntax and semantics is hello.htm1 and contains
from the Java language. The Java Fig. I Scrolling text with dynamically updating the current date what is shown in Box C.
script is Netscape's interpreted Now the applet can be
language for programming the Web viewed by using the appletviewer com-
pages. The two languages have different Hello There in Applet Window mmd, appletviewer hello.htm1. The result
objectives. The Java script is a common wblh*.mst&wbn IE; of t h s command are shown in Figs. 3 and
gateway interface (CGI) scripting lan- Fig. 2 Applet window and status bar 4.
guage. The Java language is an applica- display output of hello applet
tiodapplet programming language. Classes
However, there are plans to make the Java composed of at least one class. All Java Java programming is based on class.
script more like the Java language. applets are classes and inherit (all prop- Every Java program has at least one
erties and methods) from the Applet class. In Object Oriented Programmmg,
3ave-progratming class. A Java applet can be stored as a thiz focus is on the encapsulation of data
text file using any editor. types and the operations on the data. A
language The name of the Java source file has class embodies this concept. Java class-
The Java language is both a conven- the extension Java. For example, the es promote code reuse.
tional and rapid prototyping language. hello applet file is stored as Java is simplified by the fact that most
By definition, Java is a simple, object- hello.java. It is compiled by using of the useable code is available in Java
oriented, distributed, interpreted, robust, the Java compiler with a javac com- packages called libraries. Classes are
secure, platform independent, portable, mand. It creates a new file with the grouped by categories into the packages.
high-performance, multi-threaded and name hello.class in the same fold- Oine strength of Java is the Applicalion
dynamic language. (Think of a buzz- er as the hellojava file. Then the browser Programming Interface (API) that pro-
word, you will find it here.) Java is also uses the hello.html file in Box B. motes reusability and raves programmers
called an architecture neutral or platform Now the applet is viewed by using a from reinventing efficiently tested code.
independent or multi platform language. Java enabled browser or by an appletview- The hierarchy for a particular package
If you use a web browser, you are a er command. Thus, the minimal program refers to all the classes in the package
de facto Java user. Java enables development environment consists of an according to their inheritance. Object Ori-
browsers, Netscape or Internet Explor- editor for creating a source code, a javac ented Programming (OOP) prevents
er, to automatically download Java compiler for compiling and an appletview- duplication of effort in reinventing class-
applets across the network. It then runs er interpreterfor executing it. es every time the user needs them. OOP
them on the local machine relieving the simplifies maintenance by pushing the
remote CPU (central processing unit) details as far as possible from the user to
of this duty. the super classes. Java classes enforce
object orientation through information
A com- hiding and extensibility.
p l e t e In Java, some methods are automati-
example of cally invoked for the programmer such as
an applet is init, start, paint, stop and destroy. In an
the hello applet, the init method is executed fist.
program When init (which does the initializing) is
which dis- completely finished, it is followed by the
vsgclce -- [vex
plays a start method, other methods are invoked
simple on an as-needed basis.
message on A final class contains static final data
the screen members which can be used by any
is shown class. A final class is never extended. In
in Fig. 2. a class, static members are called class
Java programs also can be true con- Java allows the user to display an applet members. They expand the scope of the
ventional standalone applications. In fact, response at any of the three places on variable values to all objects of the class
applets are bytecode instead of text source the screen depending on the nature of arid are referenced by using the class
code. There are things one program can the program's output. This example name or object name. The static vari-
do the others cannot including U 0 and changes the default font to a 24-point ables are shared by each instance/object
Socket connections on the network. This Times Roman typeface that is bolded. of the class. An example of a class
is entirely for security reasons. Most Java This program is stored as hello.java. It which comes with the language is the
programs, however, are applets due to the is compiled by using a Java compiler Math class which has static members PI
popular acceptance and success of the with the command javac and E, the well known mathematical
World Wide Web. (Remember, Java pro- h e l l o . java. numbers. The Math class does not need
grams that run on the Intemet web pages It creates a new file hello.class. to be imported. These symbols are used
are called applets.) diirectly as Math.PI and Math.E. The
Java shares language structures with method Math.Random() returns a ran-
other languages. Every Java program is dom number in (0, 1).

34 IEEE POTENTIALS
it is implemented. That is, the user needs
to know only the interface and the para- objects. Java anticiapates that
meter list. This way the user cannot inad- A garbage collector (GC) frees memory something could go wrong, it encapsulate
vertently change anything in the method that is no longer needed by the objects. such statements in a try block. If some-
code. The methods that provide this An object is marked for the garbage col- thing fails in the try block, an exception
information are called interface func- lector by setting it to null. The GC runs object is generated. The catch statement
tions. What’s more, the developer can periodically to check for objects no verifies the type of exception. The excep-
replace the implemented code with opti- longer needed. The programmer has no tion is handled in the block of statements
mized code without affecting the user. control over Java GC. The Java immedliately following the catch state-
Information hiding is also accom- garbage collector is asynchronous, ment. However, the programmer may
plished by prefixing an access type to thus, it may not collect garbage as soon decide not do anything in response to the
the data members, methods and classes. as the object is dead. This frees the exception if he or she wants.
The access types are public-for uni- programmer from allocating and
versal access by everyone; private-for de-allocating the memory. Memory
access of members by the defining class management is left to the Java runtime
only (i.e., the owner); protected-for environment. However, GC gives the
only the subclasses and classes within object a chance to clean up after itself Java has built-in capabilities of
the package. A class cannot be declared by calling first the finalize method. Graphics, Graphical User Interfaces
private because then it defeats its own Even if the program has a direct call to (GUIs), Concurrency via multiple
purpose. It cannot be instantiated or the finalize method, GC will still call it threads and Networking via Sockets and
extended. Java class extensibility is before freeing its resources. Uniform Resource Locators (URLs).
achieved through inheritance, abstrac- Graphics and animation axe the salient
tion and overloading. A class can be features of Java. Graphics is one of the
public, abstract, interface or final. How- key classes of Java. Graphical User
ever, it is a good practice to keep all A multidimensional array is an array
data members private or protected. of arrays stored in row major order. In
general, a two dimensional array is a
brtrqction rectangular array of order m x n. Java
Abstract classes promote encapsula- mays are an exception to this rule. Java
tion of features common to several allows unbalanced multidimensional
classes. An abstract method is one arrays, a two dimensional array may Fig. 4 Applet display on standard out-
whose interface appears in the super have rows of different lengths. put device for the hello applet
class and its implementation appears in
a subclass. An abstract method must Interface in Java runs without change in
always be subclassed where it may be Defensive programming saves time Windows, UNIX, and Mac-three dif-
implemented. A final method is never when something goes wrong. Without a ferent GUI environments. This allows
overridden in any subclass. debug environment, the programmer the Java programmer to create multime-
If a class has one or more abstract inserts print statements and then dia applets by integrating text, graphics,
methods, it is an abstract class. An removes them after debugging for the images,,animation and sound.
abstract class must be declared by prefix- production version. The irony is that As ,a result, Java applets are useful for
ing a keyword abstract. An abstract class when one removes all the print com- user interaction via interaction devices
prevents instantiation and promotes sub- ments, one inadvertently introduces and user interface via GUI widgets. Java
classing. An interface is a conceptual additional errors. Now when one detects supports interaction with the keyboard
model. It is the next level of abstraction another bug after one has removed all and the mouse devices. Java supports GUI
to abstract class. A Java interface is an comments, one has to redo all the work with labels, text fields, text areas, buttons,
abstract class in which each method is just undone. Runtime errors may be checkboxes, radio-buttons, pop-up menus
abstract, each data member is final and anticipated and handled easily by using and List for interaction with the users. The
static. Thus, an interface is equivalent to an exception handling mechanism. following example figure has a label, an
a class, but is not a “class.” Exception handling leads to safe and updatable textfield and a button to activate
error-free programming. Java builds data updating and hide widgets. With a
qrbsge collection exception handling in most methods and very simple program, the 3-D view is gen-
Java provides a constructor to build enforces its use on the part of the devel- erated in Fig. 5 (pg 36). The code segment

AUGUSTEEPTEMBER 1998 35
:ry easily handled by using the
keyword “synchronize d. ’’
There are several other help
methods: sleep, yield, wait,
notify, suspend, resume and
riority which make program-
;concurrency much easier.

for generating it is just above Fig. 5. designed to be used


All display/drawing in Java is done on the Internet, it
through the Graphics object. This comes loaded with
object provides many methods for networking libraries
drawing on the screen, e.g. we have such as Transmission
already seen one method drawString0. Control Protocol/
The most common use of the Graphics Internet Proto’col
object is through the paint function. The (TCP/IP) networking
paint method is overridden in an applet. and used
Fig. 5 The output generated by varying the sizes and col-
When the browser invokes the paint on the Internet. such
ors of characters. as HyperText Trans-
function, it sends the applets’ graphics
context to it dependent on the local sys- same time. MultiThreading is the process fer Protocol (HTTP) and File Transfer
tem. To make the graphics environment of executing two or more threads at the Protocol (FIT). It is very easy to provide
portable across multiple platforms, it same time. Unlike other languages, Java network applications through applets.
uses the environment of the machine on provides a built-in library for multitasking Thus, the concept of an applet also fits
which the Java applet is executed. There rather than a separate layer of software to well with a distributed software model.
are many other graphics objects such as implement parallelism such as PVM (Par- Since Java is endowed with built-in net-
Frame, Panel and Canvas for organizing allel Virtual Machine) or MPI (Message working libraries, it adds to the functiond-
the widgets. Passing Interface). Even though the client ity of traditional HTML and CGI scnpts.
Web pages are enhanced by incorpo- may be a uniprocessor, Java simulates The good thing is that you do not have to
rating images in the applet window. concurrent processing via threads giving depend on the server administrator to ]pro-
Java supports two formats for image the illusion of multitasking. Creating and vide services to run CGI type applications.
display: Joint Photographers Expert using threads is very easy in Java. This is an extremely useful feature.
Group (JPEG) and Graphics Inter- Java allows us to create threads in It is very easy to connect to olher
change Format (GIF). It does not sup- two ways. The common way to create a web sites. To communicate on the Inter-
port other formats including Tagged thread class is by extending the Thread net, one only needs to know the loca-
Image File Format (TIFF), Portable class. The Thread class implements tion’s URL. AppletContext object is the
Network Graphics (PNG) and Picture run() method. The thread subclass inher- web browser which runs the applet. The
Format (PICT). Java has a built-in its and overrides the run() method for Applet class has a method, getApplet-
uncompress utility. That is, the image is concurrent processing. The other equally Context(), which returns the Applet-
automatically decompressed without common way is to implement the Context object. In Java, one can connect
your knowledge. Downloading and dis- Runnable interface in the applet class to other sites with a single line of code.
playing an image is as easy as display- and override the run() method. In either
ing a text string. case, a thread overrides the run() method P i
Besides text, graphics and images, for specific processing. There are many other things in Java
Java provides the ability to include audio In concurrent programming, there are which are useful for the programmer
to create truly multimedia applets. Playing deadlock problems. These problems are and enterprise computing. These
sounds within Java is quite simple. Java
supports only the Next/Sun audio (AU)
sound format, popularized on the UNlX
Machines. Other formats such as WAV (a
Microsoft DOS and Windows sound for-
mat) must be converted to the AU format.
(There are public domain utilities for for-
mat conversion such as Goldwave.)

H1t iThrecrdting
60&6MPPe?Wy
A thread is a specific task or a set of
instructions executed by the applet at any
given time. There are times when more
than one task must be executed at the

36 IEEE POTENTIALS
include pitfalls in the Java language at while teaching the Winter 1997 Csc301 * Gosling James, Frank Yellin, The
both the compile level and the run level. class of very enthusiastic students who Java Application Programming Inter-
For instance, there are several inconsis- were really motivated to learn the sub- face, Window Toolkit and Applets, Vol.
tencies in the language. These may be ject. It is enjoyable to have such stu- 2, Addison Wesley, 1996.
confusing to the programmer. dents. The author thanks the reviewers a Harold, Rusty Elliot, Java Devel-
a) To create an instance of date for substantial improvement in the pre- oper’s Resource, Prentice Hall, 1997.
1901/01/01 new Date(1901,00,01) is sentation of this article. * Laffra, Chris, Advanced Java,
used because the months begin at zero. Prentice Hall, 1997.
b) To get the size of an object: ‘Read more about it
1. activecount() is used for a thread. Within a year of emergence, there about the author
2. countItems()is used for a choice list. were 163 published Java books with Chaman L. Sabharwal is Professor of
3.1ength() is used for a file. 161 Java books in the works for a total Computer Science at the University of
4. size() is used for a vector. of 324 English language Java books. Missouri-Rolla, Graduate Engineering
Also, important issues involve the Another 228 foreign language books Center at St. Louis, Missouri. He has been
second wave of Java development kits, make a total of 552 books worldwide Professor of Mathematics at St. Louis Uni-
Client/Server applications, Database <http://lightyear.ncsa.uiuc.edu/--srp/java versity and Lead Engineer and Senior Spe-
applications including Remote Method /j avabooks.html>. cialist at McDonnel Douglas Corporation.
Invocation ( M I ) and Common Object 1 Andreeson Marc, Netscape Com- He developed an object-oriented software
Request Broker Architecture (CORBA) munications Corporation, The Red Her- Engineering Methology for the IRM pro-
which have not been mentioned due to ring, October 1996. ject for McDonnell Douglas Corporation.
space limitations. * Chen Mark C., Steven W. Griffith, He designed and implemented an automat-
This article provides only snippets and F. Iasi, 1001 Java Programming ed symbolic kinematics solver for robot
of some programs. All the complete Tips, Jams Press, 1997. arm, algorithms for Parametric Triangular
programs illustrate the language con- 4 Deitel H. M. and P. J. Deitel, Juv a Blending Patches, reparameterization of
cepts through programmed fully func- How to Program, Prentice Hall, 1997. Parametric Curve String Structures, com-
tional exercises. These are available Eskow, Dennis, NetReadyAdvisor, putationally intensive algorithms for curve
from the author at <http://www.umr. Winter 1997. and surface modeling. He has published in
edu/-chaman>. * Gosling James, Frank Yellin, The various confernce proceedings and journals
Java Application Programming Inter- including S i M l Journul on Applied Math-
Acknowledgments face, Core Packages, Vol. 1, Addison ematics, Computer Aided Geometric
The author developed this paper Wesley, 1996. Design, and Pattern Recognition Journal.

Discounts on conferences,
workshops and tutorials. RFICs
Discounts on leading Wireless components
and systems
technical publications.
Just $10/year for the MTT Digital microwave
Transactions. systems

Free MlT-S newsletter.


8 Solid-state devices
Micromachined devices
Graduate fellowships. Millimeter-wave compo-
We are everything from basic researchers
nents and systems
Student paper contest. through applied engineers working on RF, Fiber and
Microwave and Millimeter-Wave Technologies. We integrated optics
Attend local, national and
international MlT spon- are over 9500 members strong and have over 90 Field theory
sored meetings. local chapters. We publish leading technicaljour- Superconductivity
Meet colleagues nals and sponsor preeminent technical meet- Measurement techniques
and learn! ings. Join us!

Вам также может понравиться