Java Dev Environments
Volume Number: 14
Issue Number: 5
Column Tag: Javatech
Java Development Environments
by Steve Sheets
A look at Metrowerks CodeWarrior using Java and Symantec
Visual Cafe for Java
State of the Mac
Until now, there has probably been a larger industry in writing about Java
programming than actually programming in this new computer language. This may
finally be a thing of the past. There are significant reasons (Web usage, cross platform
ability, Internet tools and others) for Macintosh programmers to learn and use the
Java environments.
This article is not intended to sing the praise of or explain how to program in Java, but
to quickly educate the Macintosh programmer about the Java tools that he can use. We
will examine the two most common Java IDEs (Integrated Development Environments):
Metrowerks CodeWarrior using Java and Symantec Visual Cafe for Java. Each tool
offers a different approach to developing Java and has different strengths. In this
article we will discuss the current release of both IDEs, CodeWarrior Pro 2 and Visual
Cafe 2.0. The next revision of both products may be out soon after this article is
printed. We will also explain some of the promised new features.
Metrowerks Java: One More Language Target
It is fair to say that the premier tool for Macintosh programming is Metrowerks'
CodeWarrior. It is by far the most popular programming environment. Even the
developers who use other IDEs recognize CodeWarrior's advantages. Programmers can
develop Macintosh and PC programs in C, C++ and Pascal, and now in Java.
Figure 1. CodeWarrior Appearance.
Metrowerks accomplished this by adding Java features to existing tools, rather than
building all new ones. Java developers use the same IDE that Mac developers have been
working with for years. Programmers create CodeWarrior project files to manipulate
sets of targets and source files. The same refined and powerful editor is used to
manipulate Java source files. In fact, if BBEdit users wish, they can continue to use
BBEdit (from Bare Bones) as a replacement editor. Programmers also will not be
surprised to find the Metrowerks' source level debugger (MWDebug) has been updated
to handle Java code. The Class Browser, Constructor and Profiler tools also have been
updated to run with Java code.
Figure 2. CodeWarrior Editor.
Metrowerks has added Java support by adding a Java Compiler and a Java Linker (both
IDE plug-ins), along with a few other tools (JavaDoc, Class Wrangler, Java
Constructor), including several Virtual Machines (VMs). Remember, Java is both a
language and a target platform. You must understand this or the rest of this article will
not make sense. When a Java developer compiles a source file, it is converted into
bytecodes, not into 68000 or PowerPC assembler. These bytecodes are designed to run
on a Java Virtual Machine (VM). The VM will interpret the bytecodes (or compile
them, using just-in-time technology) into whatever native code runs on a specific
platform.
After the Java compiler converts the Java text source into standard Metrowerks object
files, and after the Java Linker has converted the object files into some executable
target, some VM must be used to execute the code. When a developer uses the
Metrowerks CodeWarrior for Java, he has three versions of the VM available.
Metrowerks decided to ship two separate versions of their VM: one with JITc
(just-in-time compiler), and one without it. They recommend using the non-JITc
version for debugging, and using the faster JITc version in the finished product. Both
versions support the JDK 1.1 API. They also included a pre-release version of MRJ
2.0 from Apple (which also was supports the JDK 1.1 API). The final MRJ 2.0
(shipped with 8.1) works flawlessly with Metrowerks Java.
For those familiar with Metrowerks' array of options for C++ Compiler, the Java
compilers options are few and easy to understand. You can use the Profiler Information
option to generate timing information. You then use the MWProfiler tool to examine
this information. The compiler also can generate Dependency Maps. These maps list all
the class dependencies for each class in the target. Other compiler options include
inlining of small methods, using strict source and package hierarchy paths, using
strict Java filenames, giving warning messages about depreciated methods, creating
headers for any native methods (using JNI style headers or Sun VM style headers) and
using semicolon delimited list of names that will not show up in the class browser.
Java Outputs
There are three types of executable targets that the Java Linker produces; Applets
(intended to be run inside of Web Browser such as Internet Explorer or Navigator),
Applications (stand alone code to be run under a VM) and Java Libraries. All three
types of output are available as template projects, which quickly automate the process
of creating a project. All three outputs can be generated three ways: as class files (JDK
1.x method to distribute executable files), as JAR files (JDK 2.0 method that uses
compression similar to ZIP) and as Macintosh executables (not true 68000 or
PowerPC executable, more about this in bit). JAR files are quickly becoming the best
method of output. They come in compressed and uncompressed versions, and can have
manifest files (a JavaBean feature) generated for them. Unfortunately, there is no
direct control of the content of the manifest files, thought this may be changed in
future versions. When an Applet is generated, the developer can specify the browser
that will be used to display the Applet. While this can be any browser (Apple's Applet
Runner, Netscape's Communicator/Navigator, Microsoft's Internet Explorer),
Metrowerks supplies it's own default tool, "Metrowerks Java". They could have been a
little less confusing with that name! This application contains several utilities,
including simple and command-line interfaces for executing Applets and Applications,
a bytecode disassembler, the Sun version of the Java Compiler, and a Native Code
Generator (to create C interface files). Experienced Sun Java users would consider
this the "Java" tool for the Macintosh. Metrowerks Java is the only way Java code can
be debugged by the Metrowerks' source level debugger. When either of Metrowerks'
VMs are selected and the Java files are compiled with debug information, MWDebug can
be used to step through the code being executed by the Metrowerks Java application.
Figure 3. CodeWarrior Debugger.
MWDebug has been updated for several Java specific features. The developer can view
a disassembly of the Java VM instructions and registers, view and debug several
threads at the same time (each in it's separate process window), and set break points
on lines of source code or Java exceptions. So far, JAR compressed files can not be
debugged, though this may change in the future. Metrowerks will be updating
CodeWarrior to allow debugging while running other browsers (Applet Runner,
Internet Explorer) in the near future. Debugging applets while running under
Netscape products may take a little longer, because they use only their own VM.
Rather than creating a Java Class file or JAR file, a developer can output a Java
application as a Macintosh application. There are two flavors of such an output; one
without VM embedded and one with VM embedded. Both flavors have the advantage of
being double-clickable like any Mac application, and being able to have their own
custom icons. The non-VM version still runs either Metrowerks or Apple's VM in
order to execute. There are specific rules about where the VM must reside in relation
to the application the programmer has developed. The VM version has the bytecodes as
well as an entire copy of a Virtual Machine inside the application as resources. Java
does not have to be installed on the target computer for this type of application to run.
The main disadvantage of the VM version is size. The embedded VM takes over 5 Meg of
hard disk space per application.
For now, this is the only way to use Java CodeWarrior to create true stand alone,
Macintosh applications. Metrowerks has promised a true Java to native code product in
the near future. This would create true Macintosh applications from Java source. The
CodeWarrior Pro 3 release may have a prototype of such a feature, though it will
probably support x86 native code first, followed by 68000 code, then PowerPC
native. When the Mac and Windows versions are completed, we will see some of the
promise of commercial cross platform usage of Java.
Other CodeWarrior Tools
One other useful Java tool is the JavaDoc compiler/linker. This tool processes Java
source code files to generate HTML based documentation for the code. It uses the
comments preceding classes and methods for it's content. This tool is often used on the
Sun workstations to produce the manuals. Since Metrowerks uses Javasoft's Compiler,
the tool is implemented as a compiler/linker. To use it, you must add another target to
the project file, setting the JavaDoc target option. CodeWarrior's various project
templates include the JavaDoc target. The options for this tool include deciding which
comments are ignored, the scope of the documentation, and whether to generate indexes
or hierarchies.
Class Wrangler is a utility for viewing and modifying JAR files that contain Java
classes. These Java Classes can be added, removed or copied to other JAR files.
Information like source files, super classes, interfaces, methods and fields also can be
viewed. You can add or remove manifest files, but there is no direct support for