Getting Started with Microsoft Visual J++ 6.0

This page contains a very simplified introduction to using the Microsoft Visual J++ 6.0 development environment.  It draws heavily from sections of the Visual J++ User's Guides (available on-line when using Visual J++).  Read the online documentation for more complete information.

Topics

 

Starting and Stopping

To start Developer Studio:  Microsoft Developer Studio is a single programming environment that can be used with several programming languages, including C++, Java, and Visual Basic.  You should be able to start Developer Studio 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++.

To log off:  Save your files.  Close Developer Studio.  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.  If you forget to log off, your files will be accessible to the next person who sits down at the terminal.

Developer Studio Layout

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

There are several windows that will contain information about your project, but they will be empty when you first start up.  In the standard configuration, the main window is for viewing Java source files, the window to the left has several panes that give information about the current document you are viewing or various tools, the Project Explorer window on the upper right will contain a hierarchical view of all files in your project, the Properties window on the lower right will contain information about GUI (graphical user interface) objects for Windows applications, and the Task List window along the bottom is for compilation and execution messages.

Online Help 

The online help system is quite extensive.  Select Contents... from the Help menu, and a separate window labeled MSDN Visual Library should pop up.  You can set a filter in the upper left corner of this window so as to get only Java-related information.

Projects and Workspaces

Developer Studio uses the project as its mechanism for organizing source code and related files.  A project is a collection of one or more source code files together with one or more configurations.  Other kinds of files (html files and text files, for instance) can also be included in a project.  A configuration tells the compiler what kind of object code to produce.  There are two standard project configurations:

For the most part, you'll want to use the Debug configuration.

Projects are created within a project workspace which corresponds to a folder in which related projects are stored.  It's possible to have more than one project in a single workspace, but for this course, we won't make use of this feature.  For us, the project workspace and the project are roughly synonymous.

To create a new project: Select New Project... from the File menu or click on the New Project button in the toolbar.  A dialog box will pop up.   Select Visual J++ Projects/Applications on the left.  Select Console Application on the right.  Specify the location of your project folder; if you are in the CSUGLab, this should be somewhere in your own directory on the Z: drive.  Click Open.  A project folder should appear in the upper right window.  Click the +, and a main file Class1.java should be visible.  Double click it.  The file should open in the main window.  In the left window, there should be a tab Class Outline on the bottom.  Click it.  You should see a hierarchical view of all your classes.

To save a project:  From the File menu choose Save All, or click the Save All button on the toolbar.

To open an existing project:  From the File menu, choose Open...   The Open dialog box appears.  Make sure that the Files of type: drop-down menu is set on All Project Files, then select the appropriate drive and directory.   Double click on the project name to open it.

To add a file to a project:  From the Project menu, choose Add Item..., then click the Existing tab.  Navigate to the file you want and double click it.

To remove a file from a project:  Right-click on the file in the Project Explorer window (upper right) and select Remove from Project.

Project Explorer:  The Project Explorer window depicts the organization of the project's files.  When the project folder is opened (by clicking the +), the source files and any other files belonging to the project are listed.  An individual file can be opened by double-clicking on its name.

Class Outline:  If you open a java source file in the main window, the Class Outline pane will appear on the left. It will show all classes and functions of the file.  By double-clicking on a class name, you can see all the class's fields and methods, each with a little pictogram indicating its access restrictions. If you double click on one of these, it will go to its definition in the file.

Compilation and Execution

If you want to try this out as we go along, create a project as described above, and open the file Class1.java.  Cut and paste the following code into the procedure main just after the comment //TODO: Add initialization code here:

        System.out.println("Hello world");
        try {
            System.in.read();
        } catch (Exception e) {}

To compile:  Select Build from the Build menu.   To rebuild the entire project, select Rebuild. 

To run the project:  Select Start from the Debug menu.   There is also a toolbar button that does this.

For errors during compilation:  During the build process, the Output window will display error from the compiler and the linker.  Developer Studio makes it easy to jump to the line where the error occurred: just double-click on the error message.  To get more information about a particular error, click on the number of the error message and press F1.

Project settings:  Developer Studio automatically sets your project settings to reasonable defaults.  You'll need the information here if you want to change the settings---for instance, if you want to run a program as a windows application instead of as a console application, or if you want to change the name of the class you want the system to run.

To change the project settings, choose (Projectname) Properties...  From the Project menu.  A dialog box appears.  The Configuration: pull-down menu on the top lets you choose a configuration---for the most part, you'll be working with the Debug configuration.

On the top of the dialog box are several tabs that bring up various panes.   For now, the only pane you should need to use is the Launch pane.  This lets you specify the name of the class to be run by the interpreter.  Just the name of the class is sufficient; the .class extension is not needed.  Java is case-sensitive, so watch capitalization.  The "Launch as a console application" box should be checked.

Saving Your Output

To save text output:  Click at the left end of the jview.exe window's control bar to get a menu.  Choose Mark from the Edit submenu.  Then use the mouse to highlight the portion of the window you want copied. Now choose Copy from the Edit submenu.  Back in Developer Studio, choose New File... from the File menu and request a new Text File. Now you can choose Paste from the Edit menu to paste your text into this new file. At this point you should be able to print the file by choosing Print... from the File menu.

If you can't get enough lines in the jview.exe window:  Right-click on the top bar of the jview.exe window and select Properties..., then choose the Layout tab and reset the size.  (This does not seem to work under Windows 95.)

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 other applications 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:  From the Debug menu, select Start.  The debugging system is 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 appears telling you so.  The place in your code at which the exception occurred is indicated by a yellow arrow.

Inserting/Removing Breakpoints:  Click on the gray bar to the left of the line of your code where you want a breakpoint.  A red dot should appear. When this line is about to be executed, the program will halt there with a large yellow arrow pointing at this line. Select Continue from the Debug menu to continue execution. Click on the red dot to remove the breakpoint.

The Call Stack window:  When the program is halted at a breakpoint, a new toolbar automatically appears, the Debug toolbar, which gives you access to information about the call stack, the values of variables, etc. (You can also get this toolbar to remain permanently by right-clicking an empty part of the toolbar area and selecting Debug.) To see the Call Stack window, click on the Call Stack icon in this toolbar.  If you double-click on any method in the Call Stack window, the debugger will display the code for that method and indicate your position in the code.

The Locals and Auto windows:  These show the variables accessible from your current code location and their current values and types.

Stepping through your code:  You can either choose a stepping method from the Debug menu or you can use the icons on the Debug toolbar.  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.  See the online documentation for more information.