The Java Platform: Tools

Sun allows you to download either the JRE (Java Runtime Environment) or the JDK (Java Development Kit; also known as the Java SDK). (As of late 2004, Sun also allows you to download the NetBeans IDE together with the JDK.) The JRE does not include the compiler (or other development tools) and thus is not for us; it's for people who just want to run Java programs. The Java libraries have seen several large upgrades since Java first appeared on the scene in 1995: JDK1.1 was the standard for a while, but the jump to JDK1.2 was significant, and all versions at 1.2 and beyond are often referred to as "Java2" or "J2SDK". With JDK1.5, the language is known as "Java 5.0". From there, who knows?

At some point, Sun made available versions of the Java libraries that were geared for servers (the Enterprise Edition) and for phones, embedded chips, etc. (the Micro Edition). The "normal" version (that we will be using) is referred to as the Standard Edition. So J2SE refers to any version of the Java Development Kit at v1.2 or later, with the Standard Edition libraries.

All versions of the Mac OS before OS X only support Java 1.1.8. Thus those platforms are not appropriate for development in this course. Mac OS X, however, includes Java 1.4.2 with installation. (or through Software Update). The newest release of Mac OS X, "Tiger" supports installation of Java 5.0 (follow this link. (Note that "Tiger" is also the codename for Java 5.0; this is an unfortunate coincidence.)

The most important tools that are installed when you install the JDK are

javac

The Java compiler can be used at the command line simply by providing it the name of your code file:

% javac MyFile.java
(Note that I use % to mark the command prompt.) For this compile attempt to work, the current directory must contain "MyFile.java", and javac must be in the path that the system searches for executables. (The installation of the JDK should have set this up for you. If entering just javac at the command prompt yields some error about it not being recognized as a valid command, it's not in the path.)

If the compile attempt is successful, you will see nothing output by the compiler. However, the file "MyFile.class" has been created: it contains the bytecode that corresponds to your Java source code. If the compile attempt is unsuccessful, you will see one or more error messages.

java
Since compiled Java is machine-independent, it cannot be executed natively on the machine. It must either be compiled [further] to native code, or else executed with an interpreter. java is the interpreter (a "virtual machine") that you will use to run your Java programs. You simply tell it the name of the ".class" file that you want to run (omitting the ".class" extension).
% java MyClass

Any output produced by your program will appear on the screen. If your program is graphical, the appropriate windows will pop up.

appletviewer
Java was the first technology that allowed you to run programs in your web browser. Those little programs are known as applets, and can be tested without a web browser (or web server), using the appletviewer command. An applet must be embedded in an HTML file, the simplest of which might look like:
<html>
<body>
  <applet code="MyClass"
    height="400" width="400">
  </applet>
</body>
</html>
  
where "MyClass.class" sits in the same directory as this HTML file, which might be called "testMyClass.html". You can then invoke your applet through the HTML with:
% appletviewer testMyClass.html  
  
Several other command-line tools are likely provided with your installation of the JDK, including:
javadoc
As you peruse all the wonderful online documentation that is available for Java libraries, you will marvel at the time and effort someone put into creating those web pages. Marvel no more! If you write your comments using the javadoc conventions, simply running javadoc on your code file, or directory of code files, will create a website of documentation for your software!
jar
When you want to package several Java files (source or bytecode) together for delivery, as well as any supporting graphics or sound files, the jar tool is what you use. It's really just a "zip" file, with an extra file called MANIFEST that holds some meta-information about your code. The syntax for jar is quite similar to Unix tar, in case that helps.
javap
For fun, you might want to take your bytecode (which is a binary file) and dump it in a human-readable format. javap will do that for you.

These tools each have Unix-style "manual pages" available, which can be browsed online at Oracle's Website.