Part I: Introducing Java
|
Chapter 1. IntroductionWelcome to Java. This chapter begins by explaining what Java is and describing some of the features that distinguish it from other programming languages. Next, it outlines the structure of this book, with special emphasis on what is new in Java 5.0. Finally, as a quick tutorial introduction to the language, it walks you through a simple Java program you can type, compile, and run. |
1.1. What Is Java?
In discussing Java, it is important to distinguish between the Java programming language, the Java Virtual Machine, and the Java platform. The Java programming language is the language in which Java applications, applets, servlets, and
The Java platform is distinct from both the Java language and Java VM. The Java platform is the predefined set of Java classes that exist on every Java installation; these classes are available for use by all Java programs. The Java platform is also sometimes referred to as the Java runtime environment or the
The Java programming language is a state-of-the-art, object-oriented language that has a syntax similar to that of C. The language designers strove to make the Java language powerful, but, at the same time, they tried to avoid the overly complex features that have bogged down other object-oriented languages like C++. By keeping the language simple, the designers also made it easier for programmers to write robust, bug-free code. As a result of its elegant design and
Java 5.0, the latest version of the Java language,
[1]
includes a number of new language features, most notably generic types, which increase both the complexity and the power of the language. Most
[1] Java 5.0 represents a significant change in version numbering for Sun. The previous version of Java is Java 1.4 so you may sometimes hear Java 5.0 informally referred to as Java 1.5.
The Java Virtual Machine, or Java interpreter, is the crucial piece of every Java installation. By design, Java programs are portable, but they are only portable to platforms to which a Java interpreter has been ported. Sun ships VM
Although interpreters are not typically
The Java platform is just as important as the Java programming language and the Java Virtual Machine. All programs written in the Java language rely on the set of predefined classes
[2]
that comprise the Java platform. Java classes are organized into
[2] A class is a module of Java code that defines a data structure and a set of
methods (also called procedures, functions, or subroutines) thatoperate on that data.
It is important to understand what is
Java is not an operating system. Nevertheless, the Java platform provides APIs with a comparable breadth and depth to those defined by an operating system. With the Java platform, you can write applications in Java without sacrificing the advanced features available to programmers writing native applications
The Java platform is not an operating system, but for programmers, it is an alternative development target and a very popular one at that. The Java platform
As of this writing, there have been six major versions of Java. They are:
This was the first public version of Java. It contained 212 classes organized in 8 packages. It was simple and elegant but is now completely
This release of Java more than
This was a very significant release of Java; it tripled the size of the Java platform to 1,520 classes in 59 packages. Important additions included the Collections API for working with sets, lists, and maps of objects and the Swing API for creating graphical user interfaces. Because of the many new features included in the 1.2 release, the platform was rebranded as "the Java 2 Platform." The term "Java 2" was simply a trademark, however, and not an actual version number for the release.
This was primarily a maintenance release, focused on bug fixes, stability, and performance improvements (including the high-performance "HotSpot" virtual machine). Additions to the platform included the Java Naming and Directory Interface (JNDI) and the Java Sound APIs, which were previously available as extensions to the platform. The most interesting classes in this release were probably java.util.Timer and java.lang.reflect.Proxy . In total, Java 1.3 contains 1,842 classes in 76 packages.
This was another big release, adding important new functionality and increasing the size of the platform by 62% to 2,991 classes and interfaces in 135 packages. New features included a high-performance, low-level I/O API; support for pattern matching with regular expressions; a logging API; a user preferences API; new Collections classes; an XML-based persistence mechanism for JavaBeans; support for XML parsing using both the DOM and SAX APIs; user authentication with the Java Authentication and Authorization Service (JAAS) API; support for secure network connections using the SSL protocol; support for cryptography; a new API for reading and writing image files; an API for network printing; a handful of new GUI components in the Swing API; and a simplified drag-and-drop architecture for Swing. In addition to these platform changes, the 1.4 release introduced an assert statement to the Java language.
The most recent release of Java introduces a number of changes to the core language itself including generic types, enumerated types, annotations,
In addition to the language changes, Java 5.0 includes a number of additions to the Java platform as well. This release includes 3562 classes and interfaces in 166 packages. Notable additions include utilities for concurrent programming, a remote management framework, and classes for the remote management and instrumentation of the Java VM itself.
See the Preface for a list of changes in this edition of the book, including pointers to coverage of the new language and platform features.
To write programs in Java, you must obtain the Java Development Kit ( JDK). Sun releases a new version of the JDK for each new version of Java. Don't confuse the JDK with the Java Runtime Environment ( JRE). The JRE contains everything you need to run Java programs, but it does not contain the tools you need to develop Java programs (primarily the compiler).
In addition to the Standard Edition of Java used by most Java developers and documented in this book, Sun has also released the Java 2 Platform, Enterprise Edition (or J2EE) for enterprise developers and the Java 2 Platform, Micro Edition (J2ME) for consumer electronic systems, such as handheld PDAs and cellular telephones. See Java Enterprise in a Nutshell and Java Micro Edition in a Nutshell (both by O'Reilly) for more information on these other editions.