This page contains a very simplified introduction to using the Microsoft Visual J++ development environment. This page has been copied from the page developed by Dan Grossman in spring 98. These documents draw 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.
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++, then Microsoft Developer Studio.
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.
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 code to produce. There are two standard project configurations:
For the most part, you'll want to use the Debug version.
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.
FileView: The FileView pane of the Workspace window depicts the organization of the project's files. The project is represented as a folder. When the folder is opened (by double-clicking), 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.
ClassView: The ClassView pane of the Workspace window shows all classes of the project. 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.
To create a project:
To save a project: From the File menu choose Save All.
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 menus is set on Workspaces then select the appropriate drive and directory. Double click on the project name to open it.
To add files to a project: From the Project menu, choose Add to Project, then choose Files on the resulting submenu. A dialog box appears in which you can select files. In typical use, you first place the files you plan to add in the project's folder.
To add an open source file to a project: With the mouse in the source file window, click the right mouse-button and choose Insert File into Project.
To remove a file from a project: Select the file in the FileView pane of the Workspace window. From the Edit menu choose Delete.
To compile a project: From the Build menu, choose Rebuild All. It's also possible to compile just the source code file that is currently open. There are toolbar buttons and short cut keys for these operations.
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.: 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 number of the error message and press F1.
Project settings (applet or application):
Before you run a Java project, you must decide whether you want the project to run as an applet or as an application, and you have to tell the system which class you're trying to run. From the Project menu, choose Settings... The Project Settings dialog box appears. The Settings For: pull-down menu on the upper left lets you choose a configuration --- for the most part, you'll be working with the Java Virtual Machine Debug configuration.
On the right side of the dialog box are several tabs that bring up various panes. The only pane you should need to use is the Debug pane. Within the Debug pane, choose Category: General. Fill in a class name in the box labeled Class for debugging/executing. Type in just the class name itself; no .class extension is needed here. Java is case-sensitive, so watch your capitalization. Click a radio-button for either Browser or Stand-alone interpreter.
For an application: If your program takes command-line arguments, you need to set them in settings. To give arguments to the program when executing with the Stand-alone interpreter, go to Project, Settings, click the Debug tab and select the Stand-alone interpreter for Category. The Stand-alone interpreter should be C:\WINNT\jview.exe. Do not enter anything for Stand-alone interpreter arguments unless you want to give arguments to jview.exe. Type in the arguments for the program in Program arguments.
For an applet: Go back to the Category box on the Debug pane and choose Browser. This changes the Debug pane, allowing you to choose a particular browser and allowing you to specify an HTML page. If you don't specify an HTML page then Developer Studio will generate a default page for you. I don't like the default page --- it has a little bitty area for the applet. Type the name of the html file that you want to use; you need to include the .html extension. Now you can click the OK button.
To run the project: From the Build menu, choose Execute. There is also a toolbar button (the exclamation mark) that does this.
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... 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 (choose Print... from the File
menu).
If you can't get enough lines in the jview.exe window:
Choose Properties... from the jview.exe menu. Then choose the Layout tab in the
resulting Properties dialog box. Once here, it's easy to see how to increase
your Screen Buffer Size (determines how many lines are kept at a time).
It appears that this does not work if you're running under Windows 95 instead
of Windows NT.
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.
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 Build menu, select Start Debug then choose Go on the resulting submenu. Note that you do this instead of using Execute to run your program. 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 window appears telling you that an exception has occurred. You can find out what kind of exception by looking at the Output window. The place in your code at which the exception occurred is indicated by a large yellow arrow. Both the Output window and the source code with 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 Select/Remove Breakpoint. When this line is about to be executed, the program will halt with a large yellow arrow pointing at this line.
The Call Stack window: To see the Call Stack window, right-click in an empty part of the Developer Studio toolbar and choose Call Stack from the resulting menu. There is also a button for the Call Stack window on the Debug toolbar. 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 Variables window is also updated to match the location of the green triangle.
The Variables window: To see the Variables window, right-click in an empty part of the Developer Studio toolbar and choose Variables from the resulting menu. There is also a button for the Variables window on the Debug toolbar. The Variables window shows the 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. There are several tabs in this window for different sets of variables; the Auto tab usually shows the variables that are useful. Click on the plus sign next to a variable to see its subfields.
Stepping through your code: You can either choose a stepping method from the Debug menu (the Debug menu shows up in place of the Build menu when you're debugging) or you can use the buttons 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. 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 Variable window, the value that's shown uses a Developer Studio format that sometimes hides the information you really want beneath several levels of indirection.