< Zurück | Inhalt | Weiter >

Chapter 5

The Sun Microsystems Java Software Development Kit


The Sun Microsystems Java Software Development Kit (Java SDK) is the most basic toolkit for Java development. In some ways, it remains the most flexible. Your understanding of Java development should include this very basic toolset, even if you move beyond it to more “hand-holding” Integrated Development Environments (IDEs). This chapter introduces all the major components of the Java 2 Standard Edition (J2SE)1 development kit. The Enterprise Edition is discussed later. There is a third Java SDK (the Micro Edition) for embedded development which we will not cover in this book.



1. What does the “2” in “Java 2” mean? Hoo boy. Explaining product marketing names is not always easy. There was Java 1.0. Then there were several releases of Java 1.1.x. Then Sun re- leased Java 1.2.x, but they started calling it “Java 2”. Since then, they have released Java 1.3.x, Java 1.4.x and they still call it “Java 2”. But it gets even more confusing. Sun is now releasing what had been preliminarily numbered 1.5, but is now officially called the 5.0 release, though they still call it Java 2. That’s what the 2 in “J2SE” refers to. So it is Java 2 platform, version

5.0. Any questions? See http://java.sun.com/j2se/naming_versioning_5_0.php.



In this chapter you will learn about the purpose of the programs in the Sun Java Software Development Kit. We will provide you with some details of their op- tions and demonstrate their use in compiling our two sample applications. The next step up in tool automation would be the build tool known as Ant (see Chapter 9 for more information).


These days, many programmers are what we affectionately call “tool junkies.” They can only develop software with the support of complex integrated devel- opment environments, their supporting classes, and screen painting tools. By this, we do not mean to imply that we are Luddites. The right IDE can indeed be an enormous boost to productivity, but a programmer should be able to work with any tool. The Sun Java SDK is the lowest common denominator; if you can be productive with it, then you can be productive with absolutely any Java development environment. That makes your skills more portable. And that means more jobs are open to you. And that is good for you and your employers.

The Sun Microsystems Java SDK (formerly known as, and often still re- ferred to as the Sun Microsystems Java Development Kit, or JDK) provides you with all the tools you need to compile, document, run, package, debug, and deploy Java applications and applets. It does this with a collection of purely text-based command-line tools. This is no-frills software development. But a lot of us crusty old types really like that.

You should become comfortable and familiar with these tools. Some IDEs are just fancy window dressing that calls these tools underneath (some are not—some have written their own Java compilers, for example). If you can use these tools comfortably to build any kind of Java program, then you know you have a mastery of the basics and are not “addicted” to a particular tool. You also know the “hardest” way to get the job done. This will help you to make good choices about tools that enhance productivity. Some tools, we find, actually slow you down or get in your way in some cases. If you know the lowest level, you can better recognize the merits and flaws of more advanced tools. Enough justification. On to the SDK.


By the way, you will notice that we do not cover the installation of the Develop- ment Kit in this chapter. That is because we are deferring the discussion of in- stallation for the next chapter, where we also introduce the concept of multiple concurrent Development Kits on a single box. See Chapter 6 for details.



At the heart of the SDK is javac, the Java compiler. The general form of javac


javac [option...] [sourcefile...] [@optfile...]

The option list may be zero or more command-line options. We’ll detail those later. The sourcefile list may be the name of zero or more Java source files. Usually you specify just the “main” class of an application. As we will de- scribe later, javac generally will compile all necessary .java files for any classes that main() class references, directly or indirectly. If you prefix a filename with the at sign (@), the contents of the file will be treated as if they had been typed on the command line.


5.3.1 Compiler Behavior, Defaults, and Environment Variables

5.3.2 javac Options

5.4.1 The Basics

5.4.2 java Options

5.5.1 Running javadoc

5.5.2 Javadoc Command-Line Options

5.5.3 Javadoc Comments

5.8.1 A Brief Introduction to RMI

5.8.2 The rmic Tool

5.8.3 The rmiregistry Tool

5.8.4 Setting Up Servers and Clients

5.8.5 RMI Summary

5.11.1 Deploying Applications

5.11.2 Basic jar Operation