Appendix C

IDEs and Tools

by David Medinets


CONTENTS

This book has shown you how to create simple Java programs. When you start to create larger programs with multiple classes you will need some tools to help you organize and compile your programming projects.

Fortunately there are IDEs, or Integrated Development Environments. An IDE is a program that lets you group a bunch of files into a project and thereby increase programmer productivity. Even though the Java language is still in its infancy the cutting-edge programmers of the world already have started to create the tools needed to bring Java into the world of corporate America and mainstream programming.

In addition to the basic IDE, a number of tools are becoming available to help you with programming tasks. For example, there is a program available that will let you design a dialog box in Visual Basic and have it automatically converting into Java using the AWT.

This appendix will take a quick look at the IDEs and tools that are available for downloading from the World Wide Web. Please remember that the state-of-the-art in Java development is changing so rapidly that the any details presented here are almost guaranteed to be obsolete when you read them. Therefore, only one IDE will be discussed in depth-to give you an idea what you can expect in an IDE.

There are two good ways to find more information about IDEs or Java tools:

IDEs

I believe that the greatest advantage of an IDE is that it acts to isolate you from the command-line of a compiler. When a source file needs to be compiled, frequently you will only need to highlight the file and click a compile icon. The Java compiler will be called as a subprocess and all compiler messages will be captured into a window. Typically, you need only click an error message in order to see the offending source code.

You will also see gains in both productivity and organization because you will no longer need to type in the file name each time a compilation is needed. This will help organization-you will no longer be reluctant to give your classes (and hence, the source files) descriptive names because of the amount of typing needed for each compilation.

All IDEs work-more or less-in the same manner:

  1. The IDE creates a project file. It is usually a good idea to isolate each project to its own directory. However, this is not a hard-and-fast rule. I frequently place small projects or example programs in the same directory.
  2. The IDE changes project settings and preferences to reflect the requirements of the current project. For example, you might want all of your .class files to be placed into the same directory when the compiler creates them. Another example might be setting the command-line options for the compiler.
  3. The IDE enables you to add source files to the project. Each project file holds a list of which .java files are used by the project. Some IDEs will also let you associate .htm or .html files with a project. This makes working with applets easier. When creating new source files, most IDEs will ask if you want to add the new file to the project.
  4. A built-in editor allows you to change the source code as needed.
  5. You can compile code by selecting a menu option or icon. Messages from the compiler are captured to a window.
  6. You can run Appletviewer, Web browser, or Interpreter by selecting a menu option or icon. This allows you to test your code.

NOTE
In order for any IDE to compile your Java source code, Sun's Java Development Kit (JDK) must already be loaded. It will help if you place the BIN directory of the JDK into your path. This can usually be accomplished by added the following line to your AUTOEXEC.BAT file:
set PATH=%PATH%;C:\JDK\BIN;
Of course, you will need to replace the C:\JDK with the name of the directory in which you installed the JDK.

Let's take a close look at the Diva IDE. Diva will be used for the examples in this chapter for several reasons. The most important being that you can download it from the Net. The file JAVA.htm on the CD has a link that you can use to download Diva. Once you have created a project in Diva, you will probably be able to adapt to any Java IDE with ease.

Diva

It is important to note that the version of Diva that is described here is an alpha version. The version that you download and use might look different.

Before you can follow along with the examples shown below, you will need to install both Sun's Java Developement Kit (JDK) and Diva. I'll assume that you already know how to install the JDK. Diva is installed by uncompressing the DIVA.ZIP. I'll use C:\DIVA as the base directory for the following examples, but you can use any directory you'd like.

An Example

In this example you will use Diva to create an application that displays a window-called a frame in Java-that responds to the user's clicking the Close button. Follow these steps:

  1. Start Diva by double-clicking the DIVA.EXE file in the C:\DIVA directory.
  2. Select the File, Create New Project menu option to display the Create New Javaside Project dialog box, as shown in Figure C.1
    Figure C.1 : The Create New Project dialog box.
  3. Enter myFrame into the file name field and click the Save button to close the dialog box. The Diva screen should now look like Figure C.2
    Figure C.2 : The Diva IDE.
  4. Select File, New File to display the New dialog box. Then select Java in the choice list and click the OK button to close the dialog box. Diva will create another window to hold the contents of the new file as shown in Figure C.3. I added the text "Enter text here" to the new file so that you could easily see which window was added.
    Figure C.3 : An almost empty Java File in the Diva IDE.
  5. Enter Listing C.1 into the editor window.

    NOTE
    Diva was previously named Javaside. Some of the messages and dialog boxes in this alpha version still show the old name.


    Listing C.1  MYFRAME.JAVA: A Program To Display a Simple Frame.
    
    import java.awt.*;
    
    
    
    class myFrame extends Frame {
    
    			
    
    	public myFrame(String title) {
    
    		super(title);
    
    		resize(200, 350);
    
    		show();
    
    	}
    
    	
    
    	public boolean handleEvent(Event e) {
    
    		if (e.id == Event.WINDOW_DESTROY) {
    
    			dispose();
    
    			return true;
    
    		} else 
    
    			return super.handleEvent(e);
    
    	}
    
    
    
    	public static void main(String args[]) {
    
    		myFrame app = new myFrame("myFrame");
    
    	}
    
    }
    
    

    NOTE
    You'll notice that the color of various words change as you enter the listing into the Diva editor. This cool feature is called syntax highlighting.
  6. Enter Listing D.1 into the editor window. When done, select File, Save and use myFrame.java as the file name. The file name and the class name must be identical in order to compile. As you save, Diva will ask if you want to add the file to the current project. Say yes. The saved file will be added to the myFrame project, as shown in Figure C.4.
    Figure C.4 : myFrame.java is now part of the myFrame project.
  7. Select Build, Compile Active Java File. This will start the javac compiler. Any messages produced by the compiler will be displayed in the window along the bottom of the IDE.
  8. Right-click the myJava.java file in the project window, and then select Project Settings from the context menu. The Settings for the open project dialog box should appear with the Files tab displayed. If not, select the Files tab.
  9. Click myFrame.java entry in the list and then click Mark as "main." This lets Diva know which Java file contains the main procedure. You'll notice that myFrame.java is now marked with a yellow star in the project window. You click OK to close the dialog box.
  10. Click Build, Run Java to display the Run java dialog box. Then, click the Run button to actually start the Java interpreter. First, a DOS Window will appear entitled Java Console and then the myFrame application will appear.
  11. Click the Close button to exit the myFrame application.

The Java console will continue running after the Java application is finished. Leave it running. It will be used for the next interpreted Java program that you run. After you close Diva, you can click the Close button of the DOS window to close it also. Be warned, however, that it may take a while to close.

The Hierarchy Window

The middle window in the top row of the Diva IDE shows the hierarchy of the open Java file. Figure C.5 shows the Hierarchy window for myFrame.java file.

Figure C.5 : The Hierarchy window for myFrame.java.

The Hierarchy window is very useful because you can collapse and expand sections of the file so that it's easy to see what a file contains-handy when looking at someone else's code. You'll also see that all of the procedures are shown. You can click any procedure name, and its corresponding code will be displayed.

Other Features

Diva has a primitive user interface design ability. You access this by creating a new file and selecting Diva Design Document as the new file type. However, very little documentation exists for this feature. You might be better off waiting for the beta version.

You can also use Diva to automatically generate skeleton code to handle a variety of common programming situations. Figure C.6 shows part of the list of code snippets that Diva has available. You access this list by selecting Edit, Insert Skeleton Code.

Figure C.6 : Diva lets you insert code snippets by selecting from a list.

You can also add your own code to the list of snippets so that you can share code with other programmers or simply avoid retyping.

Java+

The Java+ IDE, shown in Figure C.7, seems to be designed to work with applets. You can compile your Java classes and the IDE will display any compiler messages in a separate window. This IDE does not use project files to group source files. Therefore, it is useful for only small development projects.

Figure C.7 : The myFrame.java file inside the Java+ IDE.

JavaMaker

This is another IDE that automates the compilation process. It does have a nice Print Preview mode so that you can see how your Java code will print. Some people like to try to have only one procedure per page so that the code is more understandable. You can also launch the compiler and Appletviewer from inside the IDE. Figure C.8 shows what the myFrame.java file and the output of the compiler looks like inside the JavaMaker IDE.

Figure C.8 : The myFrame.java file inside the JavaMaker IDE.

Tools

There are some programs out on the Net that are not directly related to compiling and running Java programs. Some programs will help you create a base program to start your project, and some will help with finding Java documentation.

This section describes a few of the tools that are available.

AppletGen

This extremely useful program is a source code generator. AppletGen creates a skeleton applet customized according to your needs. It has no provisions to help you compile or edit the code; it simply generates a text file. However, this ability might come in very handy. For example, it will free you from needing to remember how to add a menu to a frame. If you specify that your applet needs a menu, the basic menu code will be added to the text file.

When AppletGen is first started, you will see the window shown in Figure C.9.

Figure C.9 : The AppletGen program.

As you can see, AppletGen has eight tabs. Here is a summary of the tabs:

Applet Info-This tab lets you add some documentation to your applet. You can also specify which packages you need to import.
Applet Tab-This tab lets you specify the information that will be added to the <applet> HTML tag when AppletGen generates a HTML file. You can also list out the parameters needed for your applet.
Applet Attributes-This tab has two subtabs. One, called Options, lets you select the font, colors, and determine if menus, frames, or a stand-alone app is used. The other, called Constants, lets you enter a list of constants that your applet will be using.
Events-This tab lets you select which events your applet will respond to. Procedure stubs will be created for each events that you select.
Threading-Shown in Figure D.9 above, this tab will let you specify information about how you would like threads to be used in your application.
URLs-You can indicate which URLs your applet will be using as a resource.
Resources-This is a listing of the AU, GIF, or JPEG files that your applet will be using. If the files are not local, the resource names defined on the URLs tab will be used.
Code Options-This tab lets you determine which types of files AppletGen will create. You can choose to create HTML, Java Code, Documentation, Debug info, and an INI file. The INI file stores all of the choices that you made during the AppletGen session.
Code Window-This tab displays the Source code that AppletGen has created. You can also see the HTML and INI files. Each type of file has its own subtab. You need to click the button near the file name (top left of the tab) in order to save the files.

The AppletGen program is great if you are just learning Java. By changing the options on the various tabs and then looking at the source code that is generated, you will be able to see a lot of different situations. In addition, you can always recreate any given situation if you need a base of code to start developing from.

NOTE
You can download this application-in beta form-from http://ugWeb.cs.ualberta.ca/~nelson/AppletGen/AppletGen1.html.

VbToJava

This application will let you design using Visual Basic and then convert the design into Java code. It has only one screen, shown in Figure C.10, which lets you specify which FRM file to convert. You will also need to specify the Java class name and .java file to create.

Figure C.10 : The Visual Basic to Java Convertor.

PortaFilter

The Java documentation is a little difficult to search because it is in HTML format. Bill Bercik has converted the documentation into the Windows Help format and made the files available for you to download. You can download the 1.4M file by looking at this URL:


http://www.dippybird.com/download.html

The following documents have been converted into the Windows Help format:

Java-- Language Specification
Java-- White Paper
Java-- API
Java-- Man Pages
Java-- Virtual Machine Specification
Java-- FAQ's
Java-- Tips and Tricks
Java-- Resource Guide

The help file was last updated on March 3, 1996, so it is pretty up-to-date.

Summary

This has been a small sampling of the IDEs and tools available to you for downloading from the net. By monitoring the comp.lang.java newsgroup, or searching the Alta Vista for Java + IDE, you can easily find others. Take a few moments to look at each tool to see if it will be useful to you. Every programmer uses a different set of utilities and it takes effort to find the set that is right for you.

One important determinate of which tools to use is the scope of your project. If you are just learning Java, your tools should be simple and easy to learn. If you are an accomplished programmer, using a complicated tool with many options might make more sense. Similarly, if you are developing a large program, a tool that tracks many files in a project-oriented way like Diva will be more useful than Java+, which does not.

Finally, the Java language itself is still evolving. It will change and so will the tools that support it. Java has a bright future ahead. Don't be blinded by it and don't wait for the perfect tool. Start coding today!