Java Dev Environments
Volume Number: 14 (1998)
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.
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 modifying them.
One last feature worth mentioning is Metrowerks' Java Constructor. The original Constructor was a RAD tool for designing user interfaces for PowerPlant. The Java Constructor application is a visual interface builder for the Java Abstract Windowing Toolkit, or AWT. Layouts, Windows, Components, Containers, Menus and Menubars all can be created and used inside applets and applications. The Constructor uses a project file similar to the CodeWarrior IDE. The output of the visually constructed project is a Java source file which can be used directly by a Java project. The Java project need make only a couple of simple calls and include the generated Java file and a Reanimator.Zip file to invoke the user interface. Unfortunately, this tool has not been updated to support the new JDK 1.1 Event Model and JavaBeans.
As always, Metrowerks ships all of their documentation on CD. The hard copy book "Inside CodeWarrior Professional Release #" containing some of the manuals (including the "Targeting Java" section) usually can be purchased soon after that revision of the product ships (for around $40 dollars). Metrowerks makes up for not shipping the printed version of the manual by including many additional manuals and books on a second CD. This includes most of the Sun documentation and examples, as well as some very good Metrowerks examples. In addition, Dave Mark's book "Learn Java on the Macintosh" is included on the CD for free.
Metrowerks minimum requirement for running CodeWarrior, regardless of target language, is an 68020 Mac (or better), 8 Meg of RAM, System 7.1, CD ROM drive, and a very large hard drive. (Installing all the features, called Metrowerks Heaven in the installer, can take over 400 Meg without all the documents and examples!) Even Metrowerks recommends at least 68030 Mac with 16 Meg of RAM (a PowerPC would be best). While the IDE is a fat Mac application, realistic developers would consider a PowerPC Macintosh a truer requirement. The more RAM, the better! Installing only the Java portion of the Metrowerks IDE requires a little over 100 Meg of disk space, not including examples and documentation, which are separate.
Metrowerks CodeWarrior is sold for $449 and includes the Mac and the Windows version of the product. Purchasing the product provides one free upgrade (they come out regularly) and one year of tech support. Tech support answers feature questions more readily than programming questions.
Visual Cafe: RAD For Mac Java
Symantec took a different approach when creating Visual Cafe 2.0. They wanted to create a Macintosh Java Rapid Application Development tool. They have succeeded beyond the greatest expectations of Macintosh developers. In the Mac package, there is no C/C++/Pascal support, no Windows support, and there is no custom VM. The Windows version of Visual Cafe is a separate product. Visual Cafe ships with a pre-release version of Apple's MRJ 2.0. Java applications run from the desktop, and the default setting has Applets executed from Apple's Applet Runner.
Visual Cafe is built around components, forms and project files. A component is a user interface element (called a visual component) or a logical entity (called an invisible component) that can be attached to the Java program. For example, buttons are visual components, while timers are an invisible one. The first thing a programmer notices when starting Visual Cafe is the floating tools palette across the top of the window. A configurable list of components is displayed on the palette using a tab interface. These and other components also are in the Component Library Window. All components have properties which include their icon and position.
Figure 4. Visual Cafe Appearance.
Forms are containers for other components, like windows, dialog boxes and applets. When opened, they appear like a drawing program, with any components attached to them visible on the form. Components can be moved around, added to and deleted from the form, just like drawing primitives are modified on a drawing document. Forms are themselves components, and as such can be added to the Component Library.
Project files keep track of the files that Visual Cafe is currently working with. The project window can be set to show the files, the objects (components) or the packages (targets to be created). Selecting an item from the project file invokes the appropriate editor.
To create a Java applet or application, the user selects a New Project template. Since such templates are themselves components, they can be added and removed from the IDE by the developer. Usually the project has some preset files, forms and components. Components on the form are linked to the source code files. The user opens the forms using the Forms Editor, and modifies the components on it, which causes changes to the source code. Similarly, changes to the code using the Source Editor can change the forms layout. Both editors function the way developers would expect with Find/Replace/Grep features, Layout Menu Items and Insert Menu Items.
Besides moving components on the form, the developer can edit components in other ways. Each component has properties associated with it. When the Property window is open and a component is selected, the Property window displays the editable properties for the programmer to change. This is similar to using ResEdit to open and change a resource. Changes to the property of a component will be reflected in the code.
Which type of component you modify is unimportant. Adding a component to a form might create simple Java AWT drawing commands, or it might generate code to create a AWT object like a Bbutton, or it might generate code to instantiate a JavaBean. To help generate code, Visual Cafe has a set of powerful tools called the Interactive Assistants. These tools may also be referred to as Wizards (the common name for such utilities in the Windows world). Double-click a component, and the Add Event Assistant appears with a list of all events for that component. Selecting an event will automatically generate source code to handle that event. This usually generates some empty method source, which the user can modify.
Some component actions can be linked to already defined methods on other objects, thus creating programming logic without the developer typing a single line of code. Menu Editor is used in similar way to handle Menu Events inside the Java code. Similar Assistants exist to link two components together, to create dependency. The Insert Class Assistant quickly creates custom classes in the Java project. The Java Bean Assistant automates the formerly difficult process of JavaBean creation.
The ease of Visual Cafe development can not be understated. You can create entire Java applets graphically without any code being entered. When new routine need to be added, Visual Cafe handles the insertion of empty methods with a simple few clicks. You do not have to look up the call, or the correct parameter list or format. Adding additional code to existing programs is that simple!
Once the source is created, the developer outputs the code in the three standard formats; applet, application and library. Each output is compiled in a debug version (with debugging information) or a final version (without debugging information, thus smaller). The three outputs are in the form of class files, a zip file or the newer JAR file format, either compressed JAR or uncompressed JAR. If the output is an application, there is an additional option of creating a MRJ Application.
Figure 5. Visual Cafe Project Options.
A MRJ application is a stand alone Mac application, thus it has custom icons and is double-clickable. Since this application still uses bytecodes, it requires Apple's MRJ on the computer. You do not need a separate tool to invoke the application, but there is no command line interface. The command line for the application is set as part of the compiler options. MRJ applications are the only way to run Visual Cafe created applications on the Macintosh. If the developer wants to generate a JAR file, and the MRJ Application option is turned off, but the he still wants to run or debug the application, the MRJ application is still created and invoked.
Symantec hopes to have a Java to Mac Native code compiler before long. The Windows versions of Visual Cafe already has an early release of this feature. Windows Visual Cafe can compile a Java application directly into x86 code. Such an application can be executed on any PC even if Java is not installed.
As long as the MRJ VM is being used to execute the applet or application, Visual Cafe can use it's built in source level debugger. Any browsers that support MRJ can run the Applet, while Visual Cafe steps through the actual code. This includes Apple's Applet Runner, Symantec's Visual Page, and depending on the release, Microsoft's Internet Explorer. The debugger tools are what one expects with Watch, Call Stack and Breakpoints windows. The code can have a breakpoint at a source line or it can break due to a Java exception. The debugger easily steps through the various defined class libraries, which is a good way to learn about the framework.
Figure 6. Visual Cafe Editor/Debugger.
Other Visual Cafe Tools
JavaDoc, the utility to convert Java source code files into HTML based documentation, is built into Visual Cafe as a project option. The developer can set where the document is created, whether the Author or Version information should be included, whether a index of all the classes should be created and whether a hierarchy tree of all the classes should be created.
Other compiler options include creating optimized code, using Finder memory, updating imported files when needed, selecting the error reporting and selecting the Unicode support used. Optimized code runs faster, but is larger due to inlining of methods. Project command include setting search paths, disassembling the source, bundling the external classes into the project, and removing the class files. The majority of these commands are similar to most other project based IDE. Visual Cafe has all the project commands you would expect if you had used CodeWarrior, just in different locations.
Visual Pages, an excellent WYSIWYG web authoring tool is included on the CD by Symantec. This product will do almost everything a web designer needs to do, without forcing the designer to learn HTML. The graphic design portion of the program will look familiar to anyone with experience in any draw or paint program. For those who like the power of directly editing the HTML source, there is a mode to do that. One can switch editing between either mode (graphic or HTML) without losing changes or features. Since Visual Cafe is an editor and browser, applets running under it can be debugged by Visual Cafe.
Figure 7. Visual Page.
While there is additional documentation on the CD, the product ships with 4 printed manuals. There are Getting Started manuals for both Visual Cafe and Visual Page, as well as the User Guides for both products. The application comes with built in help documentation including the Java API Document in hyper-linked format. Symantec seems to know their developers will have a learning curve, and tries to ease them over it.
Symantec's minimum requirement for Visual Cafe is an PowerPC Mac, 32 Meg of RAM, System 7.6 with QuickTime, CD ROM drive, and 80 Meg of disk space. There are two versions of the software package. The Professional Development Version has all the features mentioned above. The Database Development Version includes everything from the Development Version, plus features designed for Java database applications. Database components include dbAware Project Assistant which quickly sets up database-aware applets and applications. Copies of the Windows application dbANYWHERE Workgroup Server and the Mac applications Lasso and FileMaker Pro are also included on the CD. There are also three comparable Windows versions of the product (Web Developer, Professional and Database). The Web version has all the features of the Professional, without the incremental debugger and the Java to Native x86 compiler.
The Development version of the product for the Mac is sold for $299.95 while the Database version is priced at $499.95. Prices for the Windows versions of the product are identical, while the Windows Web version is a low $99.95. The upgrades have been steady, but are not on any regular schedule, nor is the policy for upgrade cost always set. Symantec has Standard Care support, which mostly includes installation questions, for 90 days, starting with the first phone call. Various other paid support packages are available, such as per minute, per call and per year.
Which is for You?
CodeWarrior has many advantages. For instance, most developers already have it. It will probably be their first taste of Java development; they probably used Metrowerks VM before they ever installed the one from Apple. CodeWarrior has a huge installed base of developers and users. Most are already familiar with the IDE and the Metrowerks Debugger. Metrowerks tools have been refined over time, and it shows. Developers will feel comfortable with the editor and debugger, and will have little learning curve required for using the tools. Learning Java is another thing!
As most cross platform developers know, using two development systems (C++ and Java, Mac and Windows) at the same time can drive one to distraction. A programmer is always hitting the wrong keys on the wrong software program. A cross platform system like CodeWarrior can solve this problem.
If a developer is creating some Java application while at the same time creating a Macintosh application (ex. client/server), then the ability to have projects with both Java and Mac targets is priceless. Similarly, developers who are creating Mac code that calls Java code (or visa versa using JManager), would want to use CodeWarrior. Since both the Macintosh and Windows versions of the IDE ship with the package, cost effective cross platform developers may prefer CodeWarrior.
Another advantage is that the performance of CodeWarrior is superior. This is especially noticeable when running an applet and switching to the Metrowerks Java application. The compilers and linkers are quick and smooth, while invoking an applet takes almost no time at all.
On the negative side, CodeWarrior is not a Java Rapid Application Development (RAD) tool. Once a project template has been created, the user is on his own when programming Java. The Class Browser and Constructor provide some user interface support, but not the capability of visually linking actions and events to code. There is no built in Java class creator, nor any built in visual tool to link events to methods. The Constructor needs to be updated to handle JavaBeans, which are quickly becoming the component of choice for Java programmers.
CodeWarrior's weaknesses and strengths are reversed in Visual Cafe. What Visual Cafe does, it does well. It uses JavaBeans, and to lesser extent all of it's components, the way component software was designed to work. It is a breeze to add third party beans or components the programmer makes himself. Visual Cafe support for creating JavaBeans is hard to beat. For developers creating applets with web pages, Visual Page with Visual Cafe is an excellent bundle.
The Interactive Assistants are a joy to use. Using a traditional editor under C++, a good portion of the programmer's time is spent creating or editing interfaces of functions. Under Visual Cafe, the outline of the method is constructed for the programmer, all he does is enter the important code. Nor does the program need to spend time tweaking the layout of the form from the source code. He can graphically lay out the form or come back later to change it.
All of the helpful features of Visual Cafe seem to be at a price of performance. Moving from one function to another can be slow. Like all applications, this is less noticeable with more powerful machines, so the users will have to judge this themselves. Learning all the commands and components, while not endless (after all, this is RAD), will take time. Symantec seems to be aware of this, and tries to offset the problem with Online Help, Tours and Examples. One last problem is the definite "new software" feel of the product. Features are hidden, or implemented in ways other than expected. For example, there is no debugger command window and too many Command-Shift keys. The "software polishing" of Visual Cafe is something that will just have to take time.
Still, Visual Cafe is a RAD tool. Any slow down in switching between sections is more than compensated by the speed of development of the project. Once learned, Visual Cafe can make a major difference in total project time. As JavaBeans become more dominant and more available from third parties, the time saving in using visual tools will increase.
Which one will you use? It would not be surprising to see both products on a developer's hard drive. Many developers use CodeWarrior and MPW at the same time for projects. If Metrowerks provide better RAD features, or if Symantec "polishes" the product more, one could edge out the other. Until then, the best tool for a developer may be the one he is most comfortable with. Isn't that always the case?
Web Surfing for More Information
Here are some useful sites for Java developers. As always, let the developer beware when using Alpha or Beta software. There is a reason they call it "bleeding edge" technology!
Steve Sheets, MageSteve@AOL.Com, has been happily programming the Macintosh since 1983, which makes him older than he wishes, but not as young as he acts. Being a native Californian, his developer wanderings have led him to Northern Virginia. For those interested, his non-computer interests involve his family (wife and 2 daughters), Society for Creative Anachronism (Medieval Reenactment) and Martial Arts (Fencing, Tai Chi). He is currently an independent developer, taking on any and all projects.