Using Microsoft Visual J++

CS409 - Spring 2000

This page contains a very simplified introduction to the Microsoft Visual J++ development environment.  Read the online documentation for more complete information.

Please email me if you have suggestions for improving this document.

Topics

Starting and Stopping

To start J++:  Microsoft Visual J++ is part of a single development environment that can be used with several programming languages, including C++, Java, and Visual Basic.  You should be able to start J++ by using the Start button in the bottom-left corner of the screen.  You should see a series of menus from which you choose Programs, then Microsoft Visual J++ 6.0.

To write a program: You must create a project (see below).  For the project to run it must include a file (with a .java extension) that contains an appropriate class declaration.  To place a file in the project, you can either add an existing file or you can create a new file (see below).

To log off:  Save your files.  Close J++.  Click on the Start button on the bottom-left corner of the screen.  Choose Shut Down.   A dialog box should appear; choose the option "Close all programs and log on as a different user?" and click on the Yes button.

J++ Projects

Microsoft Visual J++ uses the project as its mechanism for organizing source code and related files.  Files other than source-code files, such as html files and text files, can also be part of a project.  A project is intimately tied to the file system; a project corresponds (roughly) to a folder and the project's files are contained within this folder.  If you move a file into the project folder then that file becomes part of the corresponding project (although J++ can sometimes get confused when this is done --- it can sometimes help to close J++ and restart it).  It's possible to have multiple projects in the same folder, but we won't be making use of this feature.  For us, the project and the project folder are roughly synonymous.

To create a project: Choose New Project... from the File menu.  You should then see the New Project dialog.  Choose Visual J++ Projects; the Empty Project Icon should appear.  Choose a Name for your project and make sure the Location is one where you are allowed to save files (each student is supposed to have their own file area in the CSUGLab).  When you then click the Open button, your project folder will be created.  Initially, the project folder contains a bunch of weird files that J++ uses to keep track of your project.  You can ignore these files, although deleting them is a bad idea.

To save a project: Choose Save All from the file menu.

To open an existing project: Choose Open Project... from the File menu.  You'll get a dialog box with choices that are relatively clear.

To create a new file in a project: To create a new file, choose New File... from the File menu.  You'll get a dialog box in which you should choose the Visual J++ Java File.  When you click on the Open button you should see an empty java file ready for editing; its name is chosen when you save the file.  Note that for Java it is important that a public class resides in a file with the same name as the class; note also that consistent capitalization is important here.

To add an existing file to a project: This appears to be done most easily by moving the file into the project folder using the regular file system rather than J++.  It may be necessary to close and restart J++ to get J++ to see the new file.

To remove a file from a project: Select the file in the Project Explorer window.  Then choose Remove from Project on the Project menu.  Note that the file is actually deleted --- it no longer exists within the project's folder --- so be sure you really want the file to disappear completely before you do this.  You can also remove a file from a project by using the regular file system rather than J++.

J++ Windows

The standard menu bar and toolbars are at the top.  If you place the mouse pointer over a button then a short description will appear, describing what it is that the button does.

There are lots of windows and they can all be moved anywhere you want.  Many of these windows are used for things that we won't be doing in our course (such as adding various ActiveX controls to Web pages).  To reduce clutter, I usually close as many windows as I can.  The following windows are those that I have found to be most useful:

The Project Explorer window.  This window shows the currently open project and the files that are contained in it.  You can open a file for editing by double-clicking its icon in this window.  If you don't see this window, you can open it by choosing Project Explorer from the View menu.  I keep this window open all the time.

The Class Outline window.  This window shows a class-outline view of the file that is currently being edited.  This includes the class itself and all of its methods.  You can go to a method by double-clicking the method name in this window.  This window also shows all imported classes and all superclasses.  You can go to any of these classes by double-clicking them.  If you double-click on a class or a method that is part of the standard Java packages then the source-code for that class should appear in the editing window.  If you don't see the Class Outline window, you can open it by choosing Document Outline from the Other Window submenu of the View window.  I keep this window open all the time.

The Output window:  This is the where J++ writes its standard output (i.e., System.out.println() writes to here).  When you run a program that uses the standard output then this window sometimes appears briefly while your program is running and then disappears.  To get it back so that you can actually look at your output, choose Output from the Other Windows submenu of the View menu.  The contents of this window can be printed by clicking on the Output window to select it and then choosing Print... from the File menu.  Generally, I keep this window closed so that I have more space for editing.

The Object Browser window: This window shows all the packages and classes that are part of Java and/or J++. You can open a class to view the class's source code by double-clicking on the class name.  To open this window, choose Object Browser from the Other Windows submenu of the View menu.  This window covers up the editing window when it's in use so I usually keep it closed.  Depending on how you have your editing window set up, the close button for this window may be way over by the close button for J++.

Compilation and Execution

To compile and run a project: Find the button that looks like the play button on a VCR or CD player (i.e., the button with the little triangle).  When you press this, all the files in your project are compiled and an attempt is made to run your project.  It is possible to compile your files without running by choosing Build on the Build menu.  The first time you run your project, you'll be presented with a Project Properties dialog.  This is explained below.

To control the way your project runs: When you choose Project Properties... from the Project menu or when you first run your project, you are presented with the Project Properties dialog.  At this point, you choose the Configuration and the file to be Launched.  There are two default Configurations: Debug and Release.  Normally you'll use the Debug configuration; the Release configuration runs faster, but the debugging tools aren't available.  There are several tabs to choose from in this dialog, but the only one that you'll need to use is the Launch tab.  Within the Launch tab, you have to choose which of your classes is the one that should be run.  Any class with a main() method can be run.  In addition, any class that is a subclass of Applet can be run as an applet. 

For errors during compilation:  The Task window displays errors from the compiler and the linker.  J++ makes it easy to jump to the line where the error occurred: double-click on any part of the error message.  Keep in mind that an error (such as a missing semicolon) on one line may not be caught by the compiler on exactly that line.  You can get more information about a particular error if you click on the error message and press F1.

Saving Your Output

To save text output (from the Output window):  To save output to a file, you have to use Copy and Paste to move the output into an editing window.  Simply printing the output is easier: as mentioned above, the contents of the Output window can be printed by clicking on the Output window to select it and then choosing Print... from the File menu. 

To capture an image of the currently-active window:  Press ALT + PRINT SCREEN.   This will copy the image of the window to the Clipboard.  You can then paste the image into a document.  Pasting the image into Microsoft Word or into Paint seems to work well; some of the other application programs distort the image in various unpleasant ways. 

Basic Debugging

Developer Studio contains an elaborate debugging system, a system much more versatile than the traditional approach of inserting lots of print statements into your code. 

To use the debugging system:  If you used the Debug configuration (as you should have) when you choose Project Properties (see the section on Compilation and Execution) then the debugging system is active, but effectively invisible until your program halts.  Typically, your program halts for one of two reasons: an unhandled Java exception has occurred or execution has reached a breakpoint that you've purposely placed in your code.  Once your program is halted, you can get a great deal of information about the program's current state.  For instance, you can see the call stack and the values of any variables in any method in the call stack

Unhandled Java exceptions:  When such an exception occurs, a message window appears telling you that an exception has occurred.  The place in your code at which the exception occurred is indicated by a yellow arrow.  The source code and the yellow arrow should appear automatically when the exception occurs.

Inserting Breakpoints:  Right-click on the line of your code where you want a breakpoint and choose Insert Breakpoint.  When this line is about to be executed, the program will halt with a large yellow arrow pointing at this line.  Once the breakpoint is inserted, you can right-click on the line to modify properties of the breakpoint.  For instance, you can arrange it so the breakpoint doesn't cause a halt until the line is executed 3 times.  You can also remove a breakpoint by right-clicking on a line containing a breakpoint.

The Debug windows: Depending on how you've moved things around in J++, a selection of Debug windows will open automatically when your program halts.  Note that these windows are inactive except when your program is halted due to either an unhandled exception or a breakpoint.  If you can't see the Debug window in which you're interested, you can open it by choosing it from the Debug Windows submenu of the View menu.  Some specific Debug windows are described briefly below.  You should experiment with these windows to get a better of idea of how they can be used.

The Call Stack window:  This window shows the current call stack (i.e., your current location, where that was called from, then where that was called from, etc.).  You can double-click on any method in the Call Stack window; the debugger will display the code for that method using a green triangle to indicate your position in the code.  The Autos and Locals windows are also updated to match the location of the green triangle.

The Autos window:  This window shows a useful selection of local and nonlocal variables accessible from your current code location.  Your current code location is shown by the large yellow arrow or, if you've moved around in the call stack, by a green triangle.  Click on the plus sign next to a variable to see its subfields.

The Locals window: This window shows all the local variables for your current location.  Aside from the choice of variables this window works just like the Autos window.

Stepping through your code:  You can either choose a stepping method from the Debug menu or you can use the buttons on the Debug toolbar.  The Debug toolbar should appear automatically when your program halts.  If the Debug toolbar is not visible, right-click in an empty part of the Developer Studio toolbar and choose Debug from the resulting menu.  There are five ways you can step through your code in the debugger:

Other features:  This document describes only some of the debugger's features.  There are a number of useful features that haven't been covered at all; for instance, it's possible to manually change the value of a variable while your program is halted during debugging.  Read the documentation for more information.

Wished-for feature:  The debugger does not make use of the toString()  method that almost all Java classes include.  When a variable appears in the Autos or Locals window, the value that's shown uses a J++ format that sometimes hides the information you really want beneath several levels of indirection.

Online Java Documentation

It's not as easy to find the online Java documentation as it should be.  Choose Contents... from the Help menu.  This will launch a separate application called MSDN Library Visual Studio 6.0.  The Contents tab (on the far left) should already be selected.  Click on the + sign next to the little book-icon to open MSDN Library Visual Studio 6.0.  From there open Visual J++ Documentation.  Then open WFC and Java Reference.  At this point you should see little book-icons corresponding to the Java API and the Java Language Specification.  The Java API (Applications Programming Interface) has documentation for all the packages that are part of standard Java.  The Java Language Specification is where you should look for syntax details or information on how various parts of Java work.