0% found this document useful (0 votes)
43 views6 pages

What Is Java?: NEW Term

The document introduces Java programming and discusses Java's history and capabilities. It describes how Java was created at Sun Microsystems to be portable across devices and platforms. It also explains that Java applets can be embedded in web pages and used to create interactive content, and that the Java language can be used to create full applications as well. The document notes that Java development tools are currently in beta form.

Uploaded by

Manoj Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views6 pages

What Is Java?: NEW Term

The document introduces Java programming and discusses Java's history and capabilities. It describes how Java was created at Sun Microsystems to be portable across devices and platforms. It also explains that Java applets can be embedded in web pages and used to create interactive content, and that the Java language can be used to create full applications as well. The document notes that Java development tools are currently in beta form.

Uploaded by

Manoj Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

S

DAY
F
R
W
T
M

1 An Introduction to Java Programming

Hello and welcome to Teach Yourself Java in 21 Days! Starting today and for the next three weeks
you’ll learn all about the Java language and how to use it to create applets, as well as how to create
stand-alone Java applications that you can use for just about anything.

NEW An applet is a dynamic and interactive program that can run inside a Web page displayed
TERM by a Java-capable browser such as HotJava or Netscape 2.0.
The HotJava browser is a World Wide Web browser used to view Web pages, follow links, and
submit forms. It can also download and play applets on the reader’s system.
That’s the overall goal for the next three weeks. Today, the goals are somewhat more modest,
and you’ll learn about the following:
What exactly Java and HotJava are, and their current status
Why you should learn Java—its various features and advantages over other program-
ming languages
Getting started programming in Java—what you’ll need in terms of software and
background, as well as some basic terminology
How to create your first Java programs—to close this day, you’ll create both a simple
Java application and a simple Java applet!

What Is Java?
Java is an object-oriented programming language developed by Sun Microsystems, a company
best known for its high-end Unix workstations. Modeled after C++, the Java language was
designed to be small, simple, and portable across platforms and operating systems, both at the
source and at the binary level (more about this later).
Java is often mentioned in the same breath as HotJava, a World Wide Web browser from Sun
like Netscape or Mosaic (see Figure 1.1). What makes HotJava different from most other
browsers is that, in addition to all its basic Web features, it can also download and play applets
on the reader’s system. Applets appear in a Web page much in the same way as images do, but
unlike images, applets are dynamic and interactive. Applets can be used to create animations,
figures, or areas that can respond to input from the reader, games, or other interactive effects on
the same Web pages among the text and graphics.
Although HotJava was the first World Wide Web browser to be able to play Java applets, Java
support is rapidly becoming available in other browsers. Netscape 2.0 provides support for Java
applets, and other browser developers have also announced support for Java in forthcoming
products.

4
abcd

et
g
Le ar nin
Sa ms.n

Ce nte r
Figure 1.1.
The HotJava browser.
1

To create an applet, you write it in the Java language, compile it using a Java compiler, and refer
to that applet in your HTML Web pages. You put the resulting HTML and Java files on a Web
site much in the same way that you make ordinary HTML and image files available. Then, when
someone using the HotJava browser (or other Java-aware browser) views your page with the
embedded applet, that browser downloads the applet to the local system and executes it, and
then the reader can view and interact with your applet in all its glory (readers using other
browsers won’t see anything). You’ll learn more about how applets, browsers, and the World
Wide Web work together further on in this book.
The important thing to understand about Java is that you can do so much more with it besides
create applets. Java was written as a full-fledged programming language in which you can
accomplish the same sorts of tasks and solve the same sorts of problems that you can in other
programming languages, such as C or C++. HotJava itself, including all the networking, display,
and user interface elements, is written in Java.

5
S
S

DAY
F
R
W
T
M

1 An Introduction to Java Programming

Java’s Past, Present, and Future


The Java language was developed at Sun Microsystems in 1991 as part of a research project to
develop software for consumer electronics devices—television sets, VCRs, toasters, and the
other sorts of machines you can buy at any department store. Java’s goals at that time were to
be small, fast, efficient, and easily portable to a wide range of hardware devices. It is those same
goals that made Java an ideal language for distributing executable programs via the World Wide
Web, and also a general-purpose programming language for developing programs that are easily
usable and portable across different platforms.
The Java language was used in several projects within Sun, but did not get very much commercial
attention until it was paired with HotJava. HotJava was written in 1994 in a matter of months,
both as a vehicle for downloading and running applets and also as an example of the sort of
complex application that can be written in Java.
At the time this book is being written, Sun has released the beta version of the Java Developer’s
Kit (JDK), which includes tools for developing Java applets and applications on Sun systems
running Solaris 2.3 or higher for Windows NT and for Windows 95. By the time you read this,
support for Java development may have appeared on other platforms, either from Sun or from
third-party companies.
Note that because the JDK is currently in beta, it is still subject to change between now and when
it is officially released. Applets and applications you write using the JDK and using the examples
in this book may require some changes to work with future versions of the JDK. However,
because the Java language has been around for several years and has been used for several projects,
the language itself is quite stable and robust and most likely will not change excessively. Keep
this beta status in mind as you read through this book and as you develop your own Java
programs.
Support for playing Java programs is a little more confusing at the moment. Sun’s HotJava is
not currently included with the Beta JDK; the only available version of HotJava is an older alpha
version, and, tragically, applets written for the alpha version of Java do not work with the beta
JDK, and vice versa. By the time you read this, Sun may have released a newer version of HotJava
which will enable you to view applets.
The JDK does include an application called appletviewer that allows you to test your Java applets
as you write them. If an applet works in the appletviewer, it should work with any Java-capable
browser. You’ll learn more about applet viewer later today.
What’s in store for the future? In addition to the final Java release from Sun, other companies
have announced support for Java in their own World Wide Web browsers. Netscape Commu-
nications Corporation has already incorporated Java capabilities into the 2.0 version of their very
popular Netscape Navigator Web browser—pages with embedded Java applets can be viewed
and played with Netscape. With support for Java available in as popular a browser as Netscape,

6
abcd

et
g
Le ar nin
Sa ms.n

Ce nte r
tools to help develop Java applications (debuggers, development environments, and so on) most
likely will be rapidly available as well.
1
Why Learn Java?
At the moment, probably the most compelling reason to learn Java—and probably the reason
you bought this book—is that HotJava applets are written in Java. Even if that were not the case,
Java as a language has significant advantages over other languages and other programming
environments that make it suitable for just about any programming task. This section describes
some of those advantages.

Java Is Platform-Independent
Platform independence is one of the most significant advantages that Java has over other
programming languages, particularly for systems that need to work on many different platforms.
Java is platform-independent at both the source and the binary level.
NEW Platform-independence is a program’s capability of moving easily from one computer
TERM system to another.
At the source level, Java’s primitive data types have consistent sizes across all development
platforms. Java’s foundation class libraries make it easy to write code that can be moved from
platform to platform without the need to rewrite it to work with that platform.
Platform-independence doesn’t stop at the source level, however. Java binary files are also
platform-independent and can run on multiple problems without the need to recompile the
source. How does this work? Java binary files are actually in a form called bytecodes.

NEW Bytecodes are a set of instructions that looks a lot like some machine codes, but that is not
TERM specific to any one processor.
Normally, when you compile a program written in C or in most other languages, the compiler
translates your program into machine codes or processor instructions. Those instructions are
specific to the processor your computer is running—so, for example, if you compile your code
on a Pentium system, the resulting program will run only on other Pentium systems. If you want
to use the same program on another system, you have to go back to your original source, get a
compiler for that system, and recompile your code. Figure 1.2 shows the result of this system:
multiple executable programs for multiple systems.
Things are different when you write code in Java. The Java development environment has two
parts: a Java compiler and a Java interpreter. The Java compiler takes your Java program and
instead of generating machine codes from your source files, it generates bytecodes.

7
S
S

DAY
F
R
W
T
M

1 An Introduction to Java Programming

Binary File
Figure 1.2. (Pentium)
Traditional compiled
programs.

Your Code
Compiler (Pentium) Binary File
(PowerPC)

Compiler (PowerPC) Binary File


(SPARC)

Compiler (SPARC)

To run a Java program, you run a program called a bytecode interpreter, which in turn executes
your Java program (see Figure 1.3). You can either run the interpreter by itself, or—for applets—
there is a bytecode interpreter built into HotJava and other Java-capable browsers that runs the
applet for you.

Figure 1.3.
Window

Java programs.

Java Interpreter
Java Bytecode (Pentium)
Java Code Java Compiler (Platform- Window
(Pentium) Independent)

Java Compiler
(PowerPC) Java Interpreter
(PowerPC)
Window

Java Compiler
(SPARC)

Java Interpreter
(SPARC)

8
abcd

et
g
Le ar nin
Sa ms.n

Ce nte r
Why go through all the trouble of adding this extra layer of the bytecode interpreter? Having
your Java programs in bytecode form means that instead of being specific to any one system, your
programs can be run on any platform and any operating or window system as long as the Java 1
interpreter is available. This capability of a single binary file to be executable across platforms
is crucial to what enables applets to work, because the World Wide Web itself is also platform-
independent. Just as HTML files can be read on any platform, so applets can be executed on any
platform that is a Java-capable browser.
The disadvantage of using bytecodes is in execution speed. Because system-specific programs
run directly on the hardware for which they are compiled, they run significantly faster than Java
bytecodes, which must be processed by the interpreter. For many Java programs, the speed may
not be an issue. If you write programs that require more execution speed than the Java interpreter
can provide, you have several solutions available to you, including being able to link native code
into your Java program or using tools to convert your Java bytecodes into native code. Note that
by using any of these solutions, you lose the portability that Java bytecodes provide. You’ll learn
about each of these mechanisms on Day 20.

Java Is Object-Oriented
To some, object-oriented programming (OOP) technique is merely a way of organizing
programs, and it can be accomplished using any language. Working with a real object-oriented
language and programming environment, however, enables you to take full advantage of object-
oriented methodology and its capabilities of creating flexible, modular programs and reusing
code.
Many of Java’s object-oriented concepts are inherited from C++, the language on which it is
based, but it borrows many concepts from other object-oriented languages as well. Like most
object-oriented programming languages, Java includes a set of class libraries that provide basic
data types, system input and output capabilities, and other utility functions. These basic classes
are part of the Java development kit, which also has classes to support networking, common
Internet protocols, and user interface toolkit functions. Because these class libraries are written
in Java, they are portable across platforms as all Java applications are.
You’ll learn more about object-oriented programming and Java tomorrow.

Java Is Easy to Learn


In addition to its portability and object-orientation, one of Java’s initial design goals was to be
small and simple, and therefore easier to write, easier to compile, easier to debug, and, best of
all, easy to learn. Keeping the language small also makes it more robust because there are fewer
chances for programmers to make difficult-to-find mistakes. Despite its size and simple design,
however, Java still has a great deal of power and flexibility.

You might also like