JAVA , Yet Another Language ?
by Tracey Au-Yeung
20th May 1997
Introduction
Java computing is a worldwide phenomenon, a language
for network programming that was developed by Sun Microsystems under the
guidance of James Gosling and Bill Joy. It is already in widespread use
for creating fun and interesting animated Web pages. Java language and
environment are rich enough to support entirely new kinds of applications,
like dynamically extensible browsers. It is designed to be a machine independent
programming language that is both safe enough to traverse networks and
powerful enough to replace native executable code. The increasing importance
of networks is placing new demands on existing tools, and fueling the demand
for a rapidly growing list of completely new kinds of application.
With Java, we can have a fast, portable and secure
software that works on any platform and plays with any applications; dynamic
applications that take advantage of a connected world, capable of accessing
disparate and distributed information sources; a truly distributed software
that can be extended and upgraded; an intelligent applications that can
roam the Net for us, ferreting out information and serving as electronic
emissaries.
A Little bit of Java's History
Sun Microsystems patriarch, James Gosling, is
the one who will be remembered as the father of Java. In the eighties,
Gosling had designed the Sun's NeWS window system, which briefly contended
with the X Window System for control of the UNIX graphic user interface
desktop (GUI). However, NeWS was lost out to X, because Sun kept it proprietary
and didn't publish the source code.
In the failure of NeWS, Gosling has learnt that
the power of integrating expressive language with a network-aware windowing
GUI, and the Internet programming community will refuse to accept proprietary
standards, no matter how good they may be.
In 1992, the Sun subsidiary, FirstPerson team
worked on developing software for information appliances. The goal was
to enable the transfer of information and real-time applications over cheap
infrared and packet-based networks. Memory and bandwidth limitations dictated
small and efficient code. The nature of the applications also demanded
they to be safe and robust. Gosling and his teammates began programming in
C++, but they soon found that it is too complex, unwieldy and insecure
for the task, so they start from scratch again !
Then, Sun shifted FirstPerson's efforts to interactive
TV (ITV), and the programming language for the ITV set-top boxes was Oak.
Oak is elegance and able to provide safe interactivity, but it could not
reduce the lost cause of ITV.
In 1993, the explosion of interest in Internet,
and the World Wide Web (WWW) presented a new opportunity. Oak was small,
robust, architecture independent, and object oriented. These are just the
requirements for a universal, network programming language. Sun quickly
changed focus, and with a little retooling, Oak became Java.
The Java Language
Java is a curious mixture of C++ and Smalltalk.
It has the syntax of C++, making it easy to learn. It has improved on C++
in some of the important areas, because C++ proved to be inadequated for
certain tasks, those language features which make C++ unsafe and hard to
read are removed to make Java, which include #define, typedef, multiple
inheritance, operator overloading, enum, unions, structs, pointer arithmetic,
global variables, standalone functions, friend functions and non-virtual
functions. Like Smalltalk, Java has garbage collection, a feature that
frees the programmer from explicitly allocating and de-allocating memory,
It runs on a Smalltalk-style virtual machine, software built into your
web browser which executes the same standard compiled Java bytecodes no
matter what type of computer you have .
In Java, the basic builing blocks are the
Java Applet and Application.
Java also has a number of features that make it
safer, these include true arrays with bounds checking, garbage collection,
councrrency, interfaces and packages. There is no need to explicitly allocate
or free memory in Java.
-
Garbage collection - It is used to remove
objects that are no longer needed. The garbage collector is usually a low
priority thread; it counts references to the objects periodically, when
all references to an object are gone, it is no longer accessible, the garbage
collection mechanism reclaims it and returns the space to the available
pool of resources.
-
Reference - Java does not use pointers, instead
it uses references, which is an abstract identifier for an object. A reference
tags a particular object with a name in the Java virtual machine (JVM),
so that the programmer may refer to it. The exact way of how the JVM implements
references at the level of machine code is completely hidden from the programmer.
Also it is VM dependent, so other schemes are possible, while Sun's VM
uses handles and Microsoft's does use pointers.
-
Interface - Java doesn't support multiple
inheritance. Therefore interfaces are used instead, which are unique to
the language, and played a role similar to that of multiple inheritance
in other object-oriented languages. An interface is essentially a special
kind of class, contain methods and variables, but completely abstract.
Declare interfaces for each additional class you want to inherit from,
and implement those interfaces in your subclass.
-
Multi thread - It is similar to multi-processing,
with multi-threading all execution contexts share the same memory, this
makes sharing data between threads simpler than sharing data between processes.
Thread provide synchronous execution. The advantages of using multi-threading
is the apparent in graphical user interfaces and in applets, severs and
simulations.
-
Packages - It is used for managing namespaces;
it can thought of as a container for related classes and interfaces, and
the Java standard library was divided into packages.
-
Exception handling - It used as error management;
an exception, likes an interrupt during the execution of a program. Java
uses exceptions to provide error handling capabilities for its programs.
When an error occurs with a Java method, it creates an exception object
and hands it to the run-time system.
Finally Java was designed to make it a lot easier
to write bugfree code. Shipping C code has, on average , one bug per 55
lines of code. About half of these bugs are related to memory allocation
and deallocation. Thus Java has a number of features to make bugs less
common.
-
strong typing
-
no unsafe constructs
-
the language is small ,easy to become fluent
-
the language is easy to read and write
-
no undefined or architecture dependent constructs
General Features of Java
Language
-
Portable - Java was designed to be cross-platform
in source form, also in compiled binary form. Since this is impossible
across processor architectures, Java is compiled to an intermediate bytecode
which is interpreted by the Java interpreter. Thus, to port Java programs
to a new platform all that is needed is a port of the interpreter and a
few native code libraries. So the Java program can run on any machine that
has the Java interpreter, because of this feature, Java is used on network
computing.
-
Robust - The Java code is well behaved, and
the need for solid applications that will not bring down a system when
a user stumbles across a home page with a small animation.
-
Secure and reliable - Java uses both compile-time
and run-time checking to ensure reliablity. The Java environment protects
the client against both intentional and unintentional attacks; also against
any viruses and worms when the applications are download and run. Also,
by removing the pointers from the memory management model, many common
program errors are eliminated. Java programs cannot access arbitrary addresses
in memory.
-
Object-oriented - It allows inheritance and
reuse of code both in static and dynamic fashion.
-
High performance - It supports several high
performance features such as multi-threading, just-in-time compiling, and
native code usage.
-
Easy - It is similar to C and C++, and is
one of the easiest language to write.
Virtual Machine
Java Virtual Machine (JVM) is an abstract computer
that runs compiled Java programs. It generally implemented in software
on top of a "real" hardware platform and operating system. All Java programs
are compiled for the JVM, and the compiled Java program will run on the
platform which was implemented by the JVM. JVM
is small when implemented in software, therefore, it can fit in as many
places as possible, places like TV sets, cell phones, and personal computers.
JVM provides a layer of abstraction between the
compiled Java program and the underlying hardware platform and operating
system, so the compiled Java programs run on the JVM, which is independent
of whatever may be underneath a particular JVM implementation. Therefore,
programs written in Java will run everywhere.
Java program are compiled from the java source
into a form called Java bytecode, also called J-code. The compiled bytecode
is executed by a Java run-time interpreter,
so it is like a machine language of the JVM. The run-time system performs
all the normal activities of a real processor, but is does so in a safe,
virtual environment.
The Java compiler reads Java language source (.java)
files, translates the source into Java bytecodes, and places the bytecodes
into class (.class) files.
To the JVM, a stream of bytecodes is a sequence
of instructions. Each instruction consists of opcode and operand. The opcode
tells the JVM what action to take. If the JVM requires more information
to perform the action than just the opcode, the required information immediately
follows the opcode as operands.
All of this has proved that Java code is implicitly
portable. The same Java application can run on any platform that provides
a Java run-time environment. You don't have to produce alternate versions
of your application for different platforms, and you never have to distribute
source code to end users.
For World Wide Web
Java is the latest, flashiest object-oriented
language. It has taken the software world by storm due to its close ties
with the Internet and Web browsers. It is designed as a portable, safe
network programming language that can run on any web-enabled computer
via that computer's Web browser. As such, it offers great promise as
the standard Internet and Intranet programming language.
The development of the WWW started later than
Java, but the advantage of Java to the web is that it provides a secure,
cross-platform way for code to be executed. Java also provides several
features to existing web sites to simplify the editing,
like graphics and data type; it also improved on the loading to the server
and make more user interaction.
Is there any alternatives ?
Microsoft's ActiveX, since Microsoft operating
systems and applications are used in most desktop computers and a large
percentage of servers, however, it is not a cross-platform solution, so
applications developed using ActiveX eliminate all non Microsoft users
from the consumer base.
Sun's JavaBeans component APIs for Java,
represents a complete multi-platform solution. By developing to JavaBeans
specifications, your code runs on every operating system and also within
any application environment. JavaBeans actually provides interoperability
with ActiveX, OpenDoc, and LiveConnect.
Sun's JavaScript is a compact, object-based
scripting programming language for developing clinent and server Internet
application. It is quite different
from Java.
Platform
Just as Sun said "Write Once, Run Anywhere."
is the ideal task for the Java platform, it saves developers time, saves
their companies the expense of multiple ports and traditional distribution
methods. The Java Platform bridges many varieties of hardware and system
software with a common language.
Different platform will have a different architecture,
for example, UNIX, Window and Macintosh are all different platform. Therefore,
if we write a program in one of the platform, it may have problems if it
runs on the other.
From platform to platform, we may have different
conventions for line termination in a text file, different size of fonts,
different size of screen, different number of colour available, this can
lead to a illegal display or operation. Therefore, it is important
to have a common language that can run on all platforms.
The number of Java platform is ever increasing;
with the rapid expansion of the network computing, it is essential to have
a portable network programming language and cross-platform. A cross platform
architecture, need portability, produce the same result on any platform,
fulfill its function on any platform, therefore portability is dependent
on the functionality of a particular program.
Java development tools are being rapidly deployed,
and are available from such major software companies as IBM, Microsoft;
and Sun has made a Java development kit available for Sparc and X86 Solaris,
Windows NT for Intel, Windows 95, MacOS 7.5 on PowerMacs and 68030 (25
MHz and faster) and 68040 Macx.
"We have a solid asset in this thing called
Windows, so how do we invest and further that platform and still respond
to the cross-platform needs that make Java and the network computer so
popular? That is what we have to figure out." said one source at Microsoft.
And Microsoft is rewriting a key windows technology, its Distributed COM
(Component Object Model) transport, in Java, to extend its reach to make
it multiplatform.
We can see the importance of making the language
portable to allow cross-platform application.
Real World Applications
Java has been adopted faster than any other software
technology, most developers are now written in Java, and most companies
are using Java applications to create competitive advantages, increase
revenues, and cut costs. Java computing model helps businesses solve some
of the most pressing challenges they currently face: building corporate
intranets, complexity of the computing environment, high administration
and support costs, product incompatibilities, long product development
cycles, and end-user frustration. It enables business to complement their
traditional architectures with new Java capabilities.
In 1996, Sun introduced Java Enterprise Computing,
it is an end-to-end, secure network computing solution based on distributed
Java applications and low-cost Java network devices. Recently, Sun has
announced that the formation of the Java Financial Objects XChange (JFOX),
an organization of top financial houses and computer companies aimed at
promoting the use of Java applications in financial transactions and banking.
JavaBeans component architecture may be used as the foundation for major
financial transaction applications for functions such as trading, consumer
banking, risk management and insurance-claims processing.
Conclusion
Java is a easy to use, fast, portable and secure
programming language, which is most suitable for networking computing,
it is not only used for creating animated web pages, but also helping the
real world business to make money.
Reference
1. PowerPC Microprocessor Common Hardware Reference
Platform
by Morgan Kaufmann
2. Towards A Java Compiler
by Ying Xiong
3. Exploring Java
by Niemeyer & Peck
4.
JavaSoft Home Page
5.
Gamelan
6.
Club Java: sponsored by Virutal Rendezvous
7.
What is Object-Oriented Software ?
8.
Java World - IDG's magazine for the Java Community
9.
JavaScript Authoring Guide