27-12-2012, 01:53 PM
JavaTM Programming Language
1JavaTM Programming.pdf (Size: 2.39 MB / Downloads: 68)
Introduction
What is Java?
he term Java refers to more than just a computer language like C or Pascal. Java
encompasses several distinct components:
A high-level language – Java is an object-oriented language whose source code at
a glance looks very similar to C and C++ but is unique in many ways.
Java bytecode – A compiler transforms the Java language source code to files of
binary instructions and data called bytecode that run in the Java Virtual Machine.
Java Virtual Machine (JVM) – A JVM program takes bytecode as input and
interprets the instructions just as if it were a physical processor executing machine
code. Sun Microsystems owns the Java trademark (see the next section on the history
of Java) and provides a set of programming tools and class libraries in bundles called
Java Software Development Kits (SDKs). The tools include javac, which compiles
Java source code into bytecode, and java, the executable program that creates a JVM
that executes the bytecode. Sun provides SDKs for Windows, Linux, and Solaris.
Other vendors provide SDKs for their own platforms (IBM AIX and Apple Mac OS
X, for example). Sun also provides a runtime bundle with just the JVM and a few
tools for users who want to run Java programs on their machines but have no intention
of creating Java programs. This runtime bundle is called the Java Runtime
Environment (JRE).
In hope of making Java a widely used standard, Sun placed minimal restrictions on
Java and gave substantial control of the development of the language over to a
broadly based Java community organization (see Section 1.4 “Java: open or closed?”).
So as long as other implementations obey the official Java specifications, any or all of
the Java components can be replaced by non-Sun components. For example, just as
compilers for different languages can create machine code for the same processor,
there are programs for compiling source code written in other languages, such as
Pascal and C, into Java bytecode. There are even Java bytecode assembler programs.
Many JVMs have been written by independent sources.
History of Java
During 1990, James Gosling, Bill Joy and others at Sun Microsystems began
developing a language called Oak. They primarily intended it as a language for
microprocessors embedded in consumer devices such as cable set-top boxes, VCRs,
and handheld computers (now known as personal data assistants or PDAs). To serve
these goals, Oak needed the following features:
platform independence, since it must run on devices from multiple manufacturers
extreme reliability (can’t expect consumers to reboot their VCRs!)
compactness, since embedded processors typically have limited memory
They also wanted a next-generation language that built on the strengths and avoided
the weaknesses of earlier languages. Such features would help the new language
provide more rapid software development and faster debugging.
By 1993 the interactiveTVand PDAmarkets had failed to take off, but internet and
web activity began its upward zoom. So Sun shifted the target market to internet
applications and changed the name of the project to Java. The portability of Java made
it ideal for the Web, and in 1995 Sun’s HotJava browser appeared. Written in Java in
only a few months, it illustrated the power of applets – programs that run within a
browser – and the ability of Java to accelerate program development. Riding atop the
tidal wave of interest and publicity in the Internet, Java quickly gained widespread
recognition (some would say hype), and expectations grew for it to become the
dominant software for browsers and perhaps even for desktop programs. However, the
early versions of Java did not possess the breadth and depth of capabilities needed for
desktop applications. For example, the graphics in Java 1.0 appeared crude and
clumsy compared with the graphics features available in software written in C and
other languages and targeted at a single operating system.
Versions of Java
Since its introduction, Sun has released new versions of the Java core language with
significant enhancements about every two years or so. Until recently, Sun denoted the
versions with a 1.x number, where x reached up to 4. (Less drastic releases with bug
fixes were indicated with a third number as in 1.4.2.) The next version, however, will
be called Java 5.0. Furthermore, Sun has split its development kits into so-called
editions, each aimed towards a platform with different capabilities. Here we try to
clarify all of this.
Standard Edition
Below is a time line for the different versions of the Standard Edition (SE) of Java,
which offers the core language libraries (called packages in Java) and is aimed at
desktop platforms.We include a sampling of the new features that came with each
release.
Other editions
Embedded processor systems, such as cell phones and PDAs, typically offer very
limited resources as compared to desktop PCs. This means small amounts of RAM
and very little disk space or non-volatile memory. It also usually means small, lowresolution
displays, if any at all. So Sun offers slimmed-down versions of Java for
such applications. Until recently this involved three separate bundles of Java 1.1-
based packages, organized according to the size of the platform. Java Card is
intended for extremely limited Java for systems with only 16 KB non-volatile
memory and 512 bytes volatile. The Embedded Java and Personal Java bundles are
intended for systems with memory resources in the 512 KB and 2 MB ranges,
respectively. To provide a more unified structure to programming for small platforms,
Sun has replaced Embedded Java and Personal Java (but not JavaCard) with the Java
2 Micro Edition (J2ME). The developer chooses from different subsets of the
packages to suit the capacity of a given system. At the other extreme are high-end
platforms, often involving multiple processors, that carry out large-scale computing
tasks such as online stores, interactions with massive databases, etc. With the Java 2
Platform came a separate set of libraries called the Java 2 Enterprise Edition (J2EE)
with enhanced resources targeted at these types of applications. Built around the same
core as Standard Edition packages, it provides an additional array of tools for building
these so called middleware products.
Naming conventions
We note that the naming and version numbering scheme in Java can be rather
confusing. As we see from the time line above, the original Java release included the
Java Development Kit (JDK) and was referred to as either Java 1.0 or JDK 1.0. Then
came JDK 1.1 with a number of significant changes. The name Java 2 first appeared
with what would have been JDK 1.2. At that time the JDK moniker was dropped in
favor of SDK (for Software Development Kit). Thus the official name of the first Java
2 development kit was something like Java 2 Platform Standard Edition (J2SE) SDK
Version 1.2. Versions 1.3 and 1.4 continued the same naming/numbering scheme.
Java – open or closed?
Java is not a true open language but not quite a proprietary one either. All the core
language components – compiler, virtual machines, core language class packages, and
many other tools – are free from Sun. Furthermore, Sun makes detailed specifications
and source code openly available for the core language. Another company can legally
create a so-called clean room compiler and/or a Java Virtual Machine as long as it
follows the detailed publicly available specifications and agrees to the trademark and
licensing terms. Microsoft, for example, created its own version 1.1 JVM for the
Internet Explorer browser. See the Web Course for a listing of other independent Java
compilers and virtual machines. Sun, other companies, and independent programmers
participate in the Java Community Process (JCP) organization whose charter is “to
develop and revise Java technology specifications, reference implementations, and
technology compatibility kits.” Proposals for newAPIs, classes, and other changes to
the language now follow a formal process in the JCP to achieve acceptance
Java shortcomings for technical programming
Several features of Java that make it a powerful and highly secure language, such as
array limit checking and the absence of direct memory pointers, can also slow it
down, especially for large-scale intensive mathematical calculations. Furthermore, the
interpretation of bytecode that makes Java programs so easily portable can cause a big
reduction in performance as compared to running a program in local machine code.
This was a particular problem in the early days of Java, and its slow performance led
many who experimented with Java to drop it.
Fortunately, more sophisticated JVMs have greatly improved Java performance. So
called Just-in-Time compilers, for example, convert bytecode to local machine code
on the fly. This is especially effective for repetitive sections of code. During the first
pass through a loop the code is interpreted and converted to native code so that in
subsequent passes the code will run at full native speeds.
Another approach involves adaptive interpretation, such as in Sun’s Hotspot, in which
the JVM dynamically determines where performance in a program is slow and then
optimizes that section in local machine code. Such an approach can actually lead to
faster performance than C/C++ programs in some cases.