![]() |
|
An Integrated Development Environment (IDE) is a software tool intended to make the process of writing programs easier. An IDE typically works as a unit with your compiler environment. It allows you to edit your program source code, compile it with the compiler, fix syntax errors, run it, and debug it, all from inside a consistent and convenient environment.
VIDE is somewhat different that other Java IDEs such as Borland's JBuilder or Sun's Forte. VIDE is much smaller than those IDEs, and simpler to use. VIDE is not really intended for giant Java projects (although is still could be used for a big project.) Instead, VIDE is meant to be a step up from using the command line and a simple editor, and a full blown IDE. It can make things simpler.
VIDE has been designed to work with Sun's JDK (Java Development Kit). Instead of using the compiler and interpreter from command shells (MS-DOS prompts), you interact with them using VIDE. The entire development process is simplified.
I will discuss the specifics of Sun JDK later (if you have programmed before, or if you have used an IDE before, you can probably skip to that section right now). But first, here's the general procedure for building a working Java application using VIDE and Sun's JDK.
Generally, any application you write will consist of various source files, and required data files. In order to get your program to compile and run, you must have all the files available. To track all the files, and to set various options required by the compiler, you will create a VIDE Project for your application. The VIDE Project file contains all the information needed to build and run your application using the JDK tools.
Thus, using VIDE, the normal work cycle goes something like this:
Getting a Java program to run on your machine normally takes several steps. First you create the source file (using the VIDE editor). That source code is then compiled by the Java compiler javac, which produces Java bytecode output. Java bytecode can be run on any computer that supports Java. Using the JDK, you typically execute your bytecode by running the Java bytecode interpreter. There are two versions for MS-Windows: java (for console apps), and javaw (for GUI window apps). On Linux, because applications are started much differently than on MS-Windows, there is just one: java.
If you have an applet, you need an HTML file to go with the applet bytecode, and then run the applet either by running your usual web browser, or using the JDK's appletviewer.
Typically, you run the compiler and interpreter from a command window. This is usually an MS-DOS Prompt on Windows, or the normal command shell or console window on Linux. (Note that using VIDE, however, eliminates the need to explicitly use a command window.)
To summarize:
Linux and MS-Windows start programs in a fundamentally different way. Because of this, Sun supplies both java and javaw for MS-Windows. And because Sun supported the JDK for MS-Windows first, VIDE was designed to work best for that environment. This means there is a little difference between the Linux and the MS-Windows version.
When you run a Java console app from inside VIDE, you need to create a console shell to see your output. VIDE uses the fact that you've specified java as the interpreter to decide to run your app in a console. If you've specified javaw, then VIDE will launch your app so that it does not have a console. Even though the Linux version of the Sun JDK does not have a javaw interpreter, you still need to specify javaw for Linux GUI apps. When you create a new Java project, VIDE will automatically fill in javaw. When you actually run your app, VIDE will run the correct java, even though the project file says javaw. This slightly strange convention allows VIDE project files to be identical on MS-Windows or Linux.
VIDE allows you to interact with the JDK tools from within VIDE rather than running all the JDK components directly from a command window. VIDE also takes advantage of some of the advanced features found in the JDK component. VIDE lets the JDK compiler javac handle all the file dependencies for projects that require more than one source file.
Once you start VIDE, the first action normally is to open a VIDE Java Project or select a Java source file. The opening window is the message window, and is used to output the results of your compiles. If you have a small Java application (not an applet), you can simply specify the name of the top level Java class file from the Project:Select Makefile or Java file menu. However, it is almost always better to use a VIDE Java Project. If you have an applet or need to specify compiler options, you must create a new Java Project file.
Once you've opened a project or specified a Java source file, you can compile your project with theBuild:Compile Java menu command, or click on the Make/Compile button on the tool bar. This runs the Java compiler, javac. The results of the compile are shown in the message window. If you get an error, you can usually right click on the error line and the source file will be loaded into an edit window, and the cursor placed on the offending line.
VIDE takes advantage of the way the Java compiler (javac) works. If you use javac from the command line, you can always compile every file in your program simply by entering "javac YourProgram.java". The compiler will compile your program, and then produce all the class files you need.
To keep things as simple as possible, VIDE works with only a single Java file - the one with your "main" method in it. It will usually be the easiest to call the project file by the same name as well.
When you are first creating a new project (or moving an existing program to VIDE), click on the Project:New Java Project menu. You will get a dialog box with various tabbed items. You will only need to use the Main and Files tabs for most projects. Once you've specified the required information, you can compile your project as described earlier.
Note that the name you specify on the "Main" tab will be the name of top level file in your program. You won't have to specify any other file names like you do in some other IDEs. The Java compiler knows how to find all the rest of the files you need.
This pane lets you specify the name of your application or applet. This should be the Java Class name of the top class. You don't need to add .java or other extension. If you are creating an applet, then you will need to specify the name of the file with the HTML code that runs your applet. When you run an applet, VIDE uses JDK's appletviewer.
If you have JDK 1.3, you usually won't need to use the CLASSPATH setting. However, earlier JDKs and some circumstances may require the CLASSPATH to be specified. This information is passed to the compiler and interpreter via switches. See Sun's documentation for more information about CLASSPATH.
HINT: When you open a new project file, VIDE assumes some options and switch settings that are commonly appropriate to use with the compiler. It is likely that the defaults will not be the one you want. There is an easy solution. Simply create a new project, change the settings to be just what you want, and then save that project as a "template" using an appropriate name. Next time, open that template project file, and immediately use Project:Save Project As... to save it under the working name of the new project.
This pane lets you specify the source directory for your Java files, as well as the output directory for the generated .class files. Typically you will want to put all your source files and the VIDE project file in the same directory.
You can also leave the default values for the output directory, and the .class files will be generated to the same place as your source files. If you specify a directory, VIDE will pass it to the compiler using the -d switch.
Simply by putting your main Class definition in the top level source directory, you end up with everyting compiled that needs to be. You can also put files in a subdirectory of the project file, and put the class files in another directory. Putting the source code for different packages in directories below the top level source also will work just how you want. But the very simplest thing to do is to leave the default values for these, and just put all your source into a sigle diectory.
This pane lets you specify which Java compiler to use. It is almost always javac, but you can change it for other development environments. The Compiler Switch Pool has the standard switches supported by JDK 1.3. Click the > button to use a switch. You can add your own switches to the Pool if you need to (for other JDKs, for example).
This pane lets you specify the interpreter to use to run you app. The default value is java, which is suitable for running console-type apps. If you use awt or swing for GUI base apps, you should use javaw. You can still use java to run GUI apps, but you will get an extra command window on the screen as well as your GUI window.
Note that you specify java or javaw on Linux, even though the Linux JDK does not have a javaw. VIDE will start your app correctly automatically: java means a console app, javaw means a GUI app.
Java applets are handled differently. To view an applet, you must specify the HTML source in the Main pane, which will cause VIDE to launch appletviewer. If you want to see your applet inside a browser window, you can edit the associated HTML file, and use File:Send to Browser to start your browser.
This pane will let you specify options you may need for the debugger.
Once you have created your source files and created your project, you will compile your Java code from inside VIDE. It is this part of the development cycle that VIDE really shines and makes your life easier. All programmers, but especially beginning programmers, make errors when entering the source program. These errors result in what are called syntax errors, and cause the compiler to generate error output.
When you use the compiler from a command window, you first must enter the compiler command and the name of the file. For example, javac Calculator.java. The output of the compiler is then displayed in the command window as shown in the following figure:
Often, a single syntax error will cause the compiler to generate multiple errors. If there are too many errors, the error output often scrolls off the command window. And then you have to edit the source code by finding each line with an error.
Using VIDE is much simpler. To compile, you either use the
Build:MakeC++/Compile Java menu command, or click
on the build button .
When you run the compiler from within VIDE, the resulting error
output is put in the VIDE status window:
If there are too many errors, you can scroll the window to see them all. But best of all, you can right-click on error line, and VIDE will open the source file, and put the cursor on the line with the error.
(Note: you must put the cursor on a line that has the form "Filename:line#:message". If you click on a different line, VIDE will not open the source file.)
Once you've corrected the syntax error, you can simply click the build button again, and recompile the program. You continue this process until your program compiles successfully.
Once you have your program compiled, you need to run
it with the Java interpreter. When you enter the
Tools:Run Project menu command,
or click the run icon ,
you will
run your program with the interpreter
set in the Interpreter pane of the project dialog.
The java interpreter will run both
console-type apps and GUI apps, but is really
more suitable for running console-type apps. If you
use awt or swing for GUI base apps,
you should use javaw.
Java applets are handled differently. To view an applet, you must specify the HTML source in the Main pane of the project dialog. VIDE will then use the JDK appletviewer to run your applet. If you want to see your applet inside a browser window, you can edit the associated HTML file, and use File:Send to Browser to start your browser. Run your program by clicking the run button.
Just as most program have syntax errors when they are first created, they have logic errors when you first run them. There are three main ways to find logic errors.
Most programmers neglect what is often the best way to find logic bugs - simply reading the source code carefully. While reading code isn't as much fun as running a debugger, it often is faster and easier. You should try to look at the code carefully first!
The second common way to find errors is to insert well placed print statements into your code. Print statements can easily show how far your code has gotten, and show values of variables. It also works well because you have to read the code to decide where to put the print statements.
The third way to find bugs is with the debugger. This way seems like the most fun, but often takes longer to find the bug than the more traditional code reading or trace print statements.
The most common way to find bugs with a debugger is to set breakpoints. By setting a breakpoint, the debugger will stop your program when it tries to execute that statement. By setting breakpoints on statements just before and after the spot where the program seems to be going wrong, and then examining the values of variables after the breakpoint hits, you can often find out what is going wrong, and then fix the logic error in the code.
Besides examining variable values at a breakpoint, you can also step through the code a statement at at time. This will show you exactly which statements your program is executing.
As valuable as a debugger is for finding logic errors, it often is a real time waster. It is very easy to waste lots of time setting breakpoints where there is no error, or single stepping through perfectly correct code. Even so, there are many bugs that just can't be found without a debugger.
VIDE supports the standard GNU gdb and Sun jdb debuggers. The VIDE interface to the debuggers makes it far easier to debug your code, but is of minimalist design. The goal is to make using the native debuggers as easy as possible for casual users, while maintaining the full power of the debugger for experienced users. VIDE accomplishes this by showing a command window interface to the debugger. You can enter any native debugger command in this window, and thus have full access to all debugger features.
VIDE makes using the debugger easier by providing a dialog box with the most often used commands. And most importantly, VIDE will open the source file in an editor window and highlight the current execution line on breakpoints or steps. It is very easy to trace program execution by setting breakpoints, and clicking on the Step over or Step into debug dialog buttons. VIDE also allows you to inspect variable values by highlighting the variable in the source and right clicking the mouse.
A description of debug dialog commands and tool bar buttons is provided in the VIDE Command Reference section.
To effectively use jdb, you need a pretty good understanding of Java. One of the most confusing aspects of using jdb is threads. Many java apps, especially Java GUI apps, use threads, and this can lead to some confusion of just what you are debugging, and what will be displayed. This is just part of using Java.
To debug Java programs with jdb, you must first compile the program with debugging information. This is accomplished with the -g switch on the compile line. The current version of VIDE does not provide automatic generation of debug or release versions. The easiest way to define VIDE projects for both debug and release versions is to use the Project:Save Project as... command. First, define a release version of the project. Then, using that project as a template, change the switches as needed for your debug version, and save the project under a different name.
The full power of jdb is available in the debugger command window. You may enter any standard jdb command after the ">" prompt. In fact, there really is limited interaction between VIDE and jdb, mostly handling breakpoints. VIDE maintains its own list of breakpoints, which it keeps even if you start and stop the debugger. It is important that you use VIDE commands to set and delete breakpoints. If you enter breakpoints directly into the jdb command window, VIDE won't know about them, and won't highlight them in your source code.
Depending on whether you are debugging a Java app or a Java applet, you must start jdb differently. The standard way to start jdb from a command line is jdb AppName. To debug an applet, you would start jdb with appletviewer -debug Applet.html. What does this mean to you? It means when you want to debug an applet, you need to use the Java Project Editor (Project->Edit) and set the debugger name to "appletviewer -debug" on the Debugger tab. Normally, the debugger name is set to "jdb". If you created an applet project initially, this will be done automatically. Note that the appletviewer with the debugger is likely to take a long time to begin execution. Be patient.
VIDE works quite well with jdb. In fact, it extends some of the capabilities by allowing you to delete all breakpoints at once.
The VIDE help system has been designed to provide an excellent help environment for the programmer. The help files are supplied in HTML format. Different files are supplied depending on which VIDE distribution you have. The entire set of help files are available in a separate download from the ObjectCentral web site. V Help uses your default Web Browser to show the help files.
There are several help topics available from the VIDE help menu.
This program is provided on an "as is" basis, without warranty of any kind. The entire risk as to the quality and performance of the program is borne by you.
Bruce E. Wampler, Ph.D.
bruce@objectcentral.com
www.objectcentral.com