0 ratings0% found this document useful (0 votes) 37 views9 pagesIntroduction To Java-Java Buzzwords-Min
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Chapter 1: The wemer
Bell
C44 was invented by Bjarne Stroustray angilase
Laboratories in Murray Hill, New Jersey, $4 roustrup initially called the new I i.
*C with Classes.” However, in 1983, the name wie changed to C#t. C#+ extend
by adding object-oriented features, Because C4 ig built tupon the foundation of
jt includes all of C’s features, attributes, and benefits, This ig a crucial reason for .
success of C++-a8 a language, The invention of C44 was not an attemipt to create 4
ad
completely new programming language. Instead, it was an enhancement to an alreacy
highly successful one.
P in 1979, while he was working a
The Stage Is Set for Java
By the end of the 1980s and the early 1990s, object-oriented programming using C++
took hold. Indeed, for a brief moment it seemed as if programmers had finally found ,
the perfect language. Because C++ blended the high efficiency and stylistic elements o
Cwith the object-oriented paradigm, it was a language that could be used to create a
wide range of programs. However, just as in the past, forces were brewing that would,
once again, drive computer language evolution forward. Within a few years, the World
Wide Web and the Internet would reach critical mass. This event would precipitate
another revolution in programming.
TJ The Creation of Java _
Java was conceived by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and
Mike Sheridan at Sun Microsystems, Inc. in 1991. It took 18 months to develop the first
working version. This language was initially called “Oak” but was renamed “Java”
{in 1995. Between the initial implementation of Oak in the fall of 1992 and the public
announcement of Java in the spring of 1995, many more people contributed to the design
and evolution of the language. Bill Joy, Arthur van Hoff, Jonathan Payne, Frank Yellin,
and Tim Lindholm were key contributors to the maturing of the original prototype.
Somewhat surprisingly, the original impetus for Java was not the Internet! Instead,
the primary motivation was the need for a platform-independent (that is, architecture-
neutral) language that could be used to create software to be embedded in various
consumer electronic devices, such as microwave ovens and remote controls. As you
can probably guess, many different types of CPUs are used as controllers, The trouble
with C and C++ (and most other languages) is that they are designed to be compiled
for a specific target. Although it is possible to compile a C++ program for just about
any type of CPU, to do so requires a full C++ compiler targeted for that CPU. The
Problem is that compilers are expensive and time-consuming to create. An easier—
and more cost-efficient—solution was needed. In an attempt to find such a solution,
ling and others began work on a portable, platform-independent language that
“ould be used to produce code that would run ona variety of CPUs under differing
‘avironments. This effort ultimately led to the creation of Java.
Scanned with CamScannerJava™ 2: The Complete Reference
details of Java were being worked out, a second, and
factor was emerging that would play a crucial role
in the future of Java. This second force was, of course, the World Wide Web. Had
the Web not taken shape at about the same time that Java was being implemented,
Java might have remained a useful but obscure language for programming consumer
electronics. However, with the emergence of the World Wide Web, Java was propelled
fo the forefront of computer language design, because the Web, too, demanded
portable programs.
Most programmers learn early in their careers that portable programs are as
elusive as they are desirable. While the quest for a way to create efficient, portable
(platform-independent) programs is nearly as old as the discipline of programming
itself, it had taken a back seat to other, more pressing problems. Further, because much
of the computer world had divided itself into the three competing camps of Intel,
Macintosh, and UNIX, most programmers stayed within their fortified boundaries,
and the urgent need for portable ‘code was reduced. However, with the advent of the
Internet and the Web, the old problem of portability returned with a vengeance. After
all, the Internet consists of a diverse, distributed universe populated with many types
of computers, operating systems, and CPUs. Even though many types of platforms
are attached to the Internet, users would like them all to be able to run the same
program. What was once an irritating but low-priority problem had become a
team that the problems
About the time that the
ultimately more important,
high-profile necessity.
By 1993, it became obvious to members of the Java design
of portability frequently encountered when creating code for embedded controllers
are also found when attempting to create code for the Internet. In fact, the same problem
that Java was initially designed to solve on a small scale could also be applied to the
Internet on a large scale. This realization caused the focus of Java to switch from
consumer electronics to Internet programming. So, while the desire for an architecture-
neutral programming language provided the initial spark, the Internet ultimately led to
Java's large-scale success.
As mentioned earlier, Java derives much of its character from C and C++. This is
by intent. The Java designers knew that using the familiar syntax of C and echoing
the object-oriented features of C++ would make their language appealing to the
legions of experienced C/C++ programmers. In addition to the surface similarities,
Java shares some of the other attributes that helped make C and C++ successful. First,
ie ae ie res ine refined by real, working programmers. It is a language
eer tae experiences of the people who devised it. Thus, Java is also
Beeler tse ii ao poond i dave i cohesive and logically consistent. Third,
prpsraanier hull oa teol Ie ae ais vy the Internet environment, Java gives you, the
poorly, your programs a oe ae ere well, your programs reflect it. If you program
Cane eo eee eee ut differently, Java is not a language with
professional programmers.
Scanned with CamScanner| ie TE
Chapter t: The Genesis of 144 &
cause of the similarities betwee,
Sen the “Internet v one Java and C44, itis tempting to think of Java 38
has signific racl Neerentee ever todo . e mistake. Jav4
bas significant practi al and philosophical differences While ie tact oe
infuenced by C+ itis not an enhanced version of rs Fo xa te janie nather
upysandly nor dovenwardly compatible with Crs, Ofcourse the similarities with C#++
aresignificant,and if You area Crt progamacet 00, the edmnilaritie
1 e other point: ‘ammer, then ill feel right a with
Java, One other point: Java was not designed to epLuee Cd ebues designe fo
solve a certain set of problems. C++ was desi; 7
Both will coexist for many years to come, esigned to solve a different set of problems.
As mentioned at the start of this chapter,
reasons: to adapt to changes in environment and to implement advances in the art
of programming. The environmental change that promp ted Java was the need for
platform-independent programs destined for distribution on the Internet. However,
Java also embodies changes in the way that people approach the writing Sf progian.
Specifically, Java enhances and refines the object-oriented paradigm used by C+.
Thus, Java is not a language that exists in isolation. Rather, itis part of anongoing =
process begun many years ago. This fact alone is enough to ensure Java a place in
computer language history. Java is to Internet programming what C was to systems
programming: a revolutionary force that changed the world.
computer languages evolve for two
The C# Connection
The reach and power of Java continues to be felt in the world of computer language
development. Many of its innovative features, constructs, and concepts have become
part of the baseline for any new language. The success of Java is simply too important
to ignore.
Perhaps the most important example of Java's influence is C#. Recently created by
Microsoft to support the NET Framework, C# is closely related to Java. For example,
both share the same general C++-style syntax, support distributed programming, and
utilize the same object model. There are, of course, differences between Java and C#,
but the overalll “look and feel” of these languages is very similar. This “cross-pollination”
from Java to Ci is the strongest testimonial to date that Java redefined the way we
think about and use a computer language.
| Why Java Is Important to the Internet
The Internet helped catapult Java to the forefront of programming, and Java, in turn,
has had a profound effect on the Internet. The reason for this is quite simple: Java
expands the universe of objects that can move about freely in cyberspace. In a network,
two very broad categories of objects are transmitted between the server and your
personal computer: passive information and dynamic, active programs. For example,
,
Scanned with CamScanneroe 2: The Complete Reference
when you read your e-mail, you are viewing passive data, Even when you download a
program, the program’s code is still only passive data until you execute it. However,
second type of object can be transmitted to your computer: a dynamic, self-executing
program. Such a program is an active ageni on the client computer, yet is initiated by
the server, For example, a progtam might be provided by the server to display properly
the data that the server is sending,
As desirable as dynamic, networked Programs are, they also present serious
problems in the areas of security and portability, Priot to Java, cyberspace was
effectively closed to half the entities that now live there, As you will see, Java addresses
those concerns and, by doing so, has opened the door to an exciting new form of
program: the applet,
Java Applets and Applications
ava. can be used to create two types of programs: applications and applets. An
application is a program that runs on your com der the operating system of that
gomputer. That is, an application created by Java is more ot less like one created using C
C++. When used to create applications, Java is not much different from any other
computer language. Rather, it is Java’s ability to create applets that makes it important.
An applet is an application designed to be transmitted over the Internet and executed by *
‘“GJava-compatible Web browser. An applet is actually a tiny Java program, dynamically
downk across the twork, just ideo clip. The
important difference is that an applet is an intelligent program, not just an animation or
media file, In other-words, an applet is a-progtam that-can-react touserinputand
dynamically change—not just run the same animation or sound over and ov
As exciting as applets are, they would be nothing more than wishful thinking if
Java were not able to address the two fundamental problems associated with them:
- Before continuing, let’s define what these two terms mean
security and portability
relative to the Internet,
Security
As you are likely aware, every time that you download a “normal” program, you
are risking a viral infection. Prior to Java, most users did not download executable
programs frequently, and those who did scanned them for viruses prior to execution.
Even so, most users still worried about the possibility of infecting their systems with
a virus. In addition to viruses, another type of malicious program exists that must be
guarded against. This type of program can gather private information, such as sel
card numbers, bank account balances, and passwords, by searching the contents o
your computer's local file system. Java answers both of these concerns by providing
Fi " ication and your computer.
a “firewall” between a networked application an‘
n you use a Java-compatible Web browser, you can. safely download, va oa
malicious intent. Java achieves this protect
pplets without fear of viral infection o1 3 . a
7 confining a Java program fo the Java execution 5
Scanned with CamScanner"aa a
Chapter i: The Genesis of 12¥# = ,
access to other parts of the coy et. (You will soe ed shortly.)
ie aia plate eit see how this is accomplished s
i Confidence thy will be done and that
no security will be breached is considers to bathversale
pect of Java. 5
PeEtoulavs
portability
As discussed earlier, many types of computers and operating systems are in use
throughout the world—and many are connected to the Internet. For programs to
be dynamically downloaded to all the Various types of platforms connected to the
Internet, some cnerating portable executable code Ts RAETEA- As you will
soon See, the same mechanism that helps on
, fi sure security also helps create portability.
Indeed, Java's solution to these two problems is both elegant and efficient.
Tet
S
é
ae
Java’s Magic: The Bytecode
The key that allows Java to solve both the security and the portability problems just
leScribed is that the output of a Java co
mpiler is not executable code. Rather, itis
Aytecode. Bylecode is a highly optimized set of instructions designed to be executed
by the Java run-time system,
which is called the Java Virtual Machine (JVM). That is, -
in its standar:
form, the 1S.an interpreter for bytecode This may come as a bit of
a surprise. AS you Know, C++ is compiled to exec
‘utable code. In fact, most modern.
languages are designed to be compiled, not interpreted—mostly because of
performance concerns. However, the fact that a Java program is executed by the .
JVM helps solve the major problems associated with downloading programs over
the Internet. Here is why.
Translating a Java program into bytecode helps makes it much easier to run a potable.
piogram ina wide variety of environments.The reason is straightforward: only the
JVM needs to be implemented for each platform. Once the run-time package exists
fora given system, any Java program can run’on. it. Remember, although the details
of the JVM will differ from platform to platform, all interpret the same Java bytecode.
Ifa Java program were compiled to native’ code, then different versions of the same
Program would have to exist for each type of CPU connected to the Internet. This is,
of course, not a feasible solution. Thus, the interpretation of byteco
fo create truly portable programs. ;
The fact that a Java program is interpreted also helps to make it secure. Because the
£xecution of every Java program is under the control of the JVM, the JVM can contain
the program and prevent it from generating side effects outside Of the system. As you
will see, safety is also enhanced by certain restrictions that exist in the Java language.
len a program is interpreted, it generally runs substantially slower than it would
7un if compiled to executable code. However, with Java, the differential between the
tWois not so great. The use of bytecode enables the Java run-time system to execute +
29grams much faster than you might expect. a
de is the easiest way
Scanned with CamScannerJava™ 2: The Complete Reference
as designed for interpretation, there is technically nothing about
fly compilation of bytecode into native code. Along these 7
lines, Sun supplies its Just In Time (IT) compiler for bytecode, which is included in
the Java 2 release. When the JIT compiler is part of the JVM, it compiles bytecode into
executable code in real time, on a piece-by-piece, demand basis. It is important to
understand that it is not possible to compile an entire Java program into executable
code all at once, because Java performs various run-time checks that can be done only
at run time. Instead, the JIT compiles code as it is needed, during execution. However,
the just-in-time approach still yields a significant performance boost. Even when
dynamic compilation is applied to bytecode, the portability and safety features still
apply, because the run-time system (which performs the compilation) still is in. charge
of the execution environment. Whether your Java program is actually interpreted in the
traditional way or compiled on-the-fly, its functionality is the same.
|
seeecentrennennererntnneeemennit 7
Although Java
Java that prevents on-the~
The Java Buzzwords
No discussion of the genesis of Java is complete without a look at the Java buzzwords. ,
Although the fundamental forces that necessitated the invention of Java are portability
and security, other factors also played an important role in molding the final form of
the language. The key considerations were summed up by the Java team in the
following list of buzzwords: *
H Simple
@ Secure
& Portable
‘BL Object-oriented ;
B Robust eta
@ Multithreaded
@ Architeture-neutral
Bi Interpreted
™@ High perfcrmance
B Distributed
@ Dynamic.
Two of, these buzzwords have already been discussed: secure and portable.
examine what each of the others implies.
Scanned with CamScannerva
Chapter 1; The Genesis of Ja
7 learn and use
Assuming thal you have some pr eT ‘ou will not find
ava hard to master. If you already understand the hasie eoncepts of object-oriented
programming, learning Java will be even easier, Best of all, if you are an experienced
(Cr+ programmer, moving to Java will require very little effort. Because Java inherits 7
the C/C++ syntax and many of the object-oriented features of C++, most programmers”
fttle trouble learning Java. Also, i More confusing concepts from C++
are either left out of Java or implémented ina cleaner, more approachable manner.
Beyond its similarities with C/C++, Java has another attribute that makes it easy
tolearn: it makes an effort not to have surprising features. In Java, there are a small
number of clearly defined ways to accomplish a given task.
Object-Oriented L
Although influenced by its predecessors, Java was not designed to be source-code .
compatible with any other language. This allowed the Java team the freedom to design ©
witha blank slate. One outcome of this was a clean, usable, pragmatic approach to
objects. Borrowing liberally from many seminal cbject-software environments of the
last few decades, Java manages to strike a balance between the purist’s “everything is
an object” paradigm and the pragmatist’s “stay out of my way” model. The object
model in Java is simple and easy to extend, while simple types, such as integers, are
kept as high-performance nonobjects.
Robust —
The multiplatformed environment of the Web places extraordinary demands on a
program, because the program must execute reliably in a variety of systems. Thus, the *
ability to create robust programs was given a high priority in the design of Java. To
‘gain reliability, Java restricts you in a few key areas, to force you to tind your Mistakes
carly peng development. Atthe same time, Java frees you from having to worry™”*
about many of the most common causes of programming errors. Because Java is a
strictly Typed language, ILchecks your code at compile time. However, it also checks
our code at run time. In fact, many hard-o-track-down bugs that often turn up in
RaeoTeprotaceran-time situations are simply impossible to create in Java.
Knowing that what you have written will behave in a predictable way under diverse
conditions is a key feature of Java. i
To better understand how Java is robust, consider two of the main reasons for
Program failure: memory management mistakes and mishandled exceptional
conditions (tatierarene oes} Memory management can be a difficult, tedious
——_——— ee
Scanned with CamScannerJava™ 2: The Complete Reference
task in traditional programming environments. For example, in C/C++, the
programmer must manually allocate and free all dynamic memory. This sometimes
leads to problems, because programmers will either forget to free memory that has
been previously allocated or, worse, try to free soine memory that another part of =~
their code is still using, Java virtually eliminates these problems by managing UNOTY
allocation and deallocation for you 1 dit stain!
Because Java provides garbage collection for Exception le not
‘aditional cavironments often arise in situations suchas di not 4
Yound,” and they must be managed with clumsy and hard-to-read constructs. Java
FaIps inthis aes by providing objrt-orgnted exception handling, Ina wel-S
Java program, all run-time errors can—and should—be managed by your program.
Multithreaded
b ava was designed to meet the real-world requirement of creating interactive,
ee Sid pronsti. To accomptSh tis Java suppors mUITGRIN Program "8,
wl to write programs that do many things simultaneously, The Java
in-time system comes With an elegant yet sophisticated solution For multiprocess
synchronization that enables you to construct smoothly running interactive systems.
Java’s easy-to-use approach to multithreading allows you to think about the specific
behavior of your program, not the multitasking subsystem.
Architecture-Neutral
Accentral issue for the Java desi
‘of the main problems facigg programmers is that no guarantee exists that if you write
a program today, 1
“Twill run tomorrow—even on the same machine. Operating system
sources Can ine
tion. The Java designers made several hard. decisions in the
| Java language and the Java Virtu: i mpt to. Hs 5 n. Their
| “goal was “write once; run anywhere, any time, forever.” To a great estent. this goal
| ‘was accomplished.
‘ers was that of code longevity and portability. One
‘upgrades, processor upgrades, and chafiges in core sy
romake a program mal
Interpreted and High Performance : :
| ‘As described earlier, Java enables the creation of cross-platform programs by compiling
j into an intermediate representation called Java bytecode. This code can be interpreted
on any system that provides a Java Virtual Machine. Most previous attempts at cross-
+ platform solutions have done so at the expense of performance, Other interpreted
} systems, such as BASIC, Tel, and PERL, suffer from almost insurmountable performance
\ deficits, Java, however, was designed to perform well orrvery low-power CPUs. As
explained earlier, while it is true that Java was engineered for interpretation;the Java
bytecode was carefully designed so that it would be easy to translate directly into native
machine code for very high performance by using a just-in-time compiler. Java run-time
systems that provide this feature lose none of the benefits of the platform-independent
code, “High-performance cross-platform” is no longer an oxymoron.
—|
Scanned with CamScanner: va
Chapter 1: The Genesis Hs
pistributed eae
Java is designed for the distributed environment of the Internet, because it handles .
TCP/IP protocols. In fact, accessing a resource using a URL is not much different
from accessing a file. The original version of Java (Oak) included features for intra-
address-space messaging. This allowed objects on two different computers to execute
procedures remotely. Java revived these interfaces in a package called Remole Method —
Ingocatiot (RMI). This feature brings an unparalleled level of abstraction to client/
server programming.
Dynamic
Java programs carry with them substantial amounts of run-time type information that
is used to verify and resolve accesses to objects at run time. This makes it possible to
dynamically link code in a safe and expedient manner. This is crucial to the robustness
of the applet environment, in which small fragments of bytecode may be dynamically
updated on a running system.
|] The Continuing Revolution
‘The initial release of Java was nothing short of revolutionary, but it did not mark the
end of Java's era of rapid innovation. Unlike most other software systems that usually
settle into a pattern of small, incremental improvements, Java continued to evolve at
an explosive pace. Soon after the release of Java 1.0, the designers of Java had already
created Java 1.1. The features added by Java 1.1 were more significant and substantial
than the increase in the minor revision number would have you think. Java 1.1 added
many new library elements, redefined the way events are handled by applets, and
reconfigured many features of the 1.0 library. It also deprecated (rendered obsolete)
several features originally defined by Java 1.0. Thus, Java 1.1 both added andy = _
subtracted attributes from its original specification. nk
The next major release of Java was Java 2. Java 2 was a watershed event, marking
the beginning of the “modern age” of this rapidly evolving language! The first release
of Java 2 carried the version number 1.2. It may seem odd that the first release of Java 2
used the 1.2 version number. The reason is that it originally referred to the version of
the Java libraries, but it was generalized to refer to the entire release, itself. Java 2
added support for a number of new features, such as Swing and the Collections
framework, and it enhanced the Java Virtual Machine and various programming tools.
Java 2 also contained a few deprecations, The most important affected the Thread class
in which the methods suspend( ), resume( ), and stop() were deprecated,
The next release of Java was Java 2, version 1.3. This version of Java was the first
Major upgrade to the original Java 2 release. For the most part it added to existing
functionality and “tightened up” the development environment. In general, programs
Written for version 1.2 and those written for version 1.3 are source-code compatible.
Although version 1.3 contained a smaller set of changes than the preceding three major
Teleases, it was nevertheless important.
Scanned with CamScanner