by Bryan Morgan
The Visual J++ development environment is unique among Java tools because it is also used by several other Microsoft development tools. In appearance, it is the same integrated development environment (IDE) used by Microsoft's Visual C++, FORTRAN PowerStation, Test, and Development Network software packages. This IDE-named the Microsoft Developer Studio-is an extremely popular, award-winning environment and should be a hit in the Java world. Because the look and feel of the IDE is common to an entire suite of Microsoft development tools, thousands of developers can use Visual J++ with little or no additional learning above the standard Java learning curve.
This chapter examines the capabilities and options of the Developer Studio and pays special attention to the features only used by Visual J++.
Because Microsoft has chosen to include Visual J++ in the Developer Studio family, J++ developers can be certain that this tool will not be ignored or subject to haphazard IDE changes. This positioning is also a good indication that Microsoft perceives this tool to be extremely important. For years, Windows programmers have relied on two general-purpose Microsoft tools: Visual Basic and Visual C++. Visual J++ allows Microsoft to enter the world of cross-platform development and to continue to use the technology it has worked on for more than five years (namely, ActiveX).
The first section in this chapter introduces the Developer Studio and explains the general features of the IDE. The remainder of the chapter focuses on the many capabilities and options of Visual J++.
After Visual J++ has been installed, run the Developer Studio tool to enter Visual J++. The opening screen shows the Developer Studio tools and highlights the toolkits currently installed on your machine. Figure 2.1 shows the Microsoft Developer Studio with no project loaded.
Figure 2.1 : The Developer Studio IDE.
Although Visual J++ projects are covered in detail in Chapter 9, "Managing Visual J++ Projects," I'm explaining them briefly here because the word project is used throughout this chapter.
Nearly all graphical user interface (GUI) development tools today group related files together within units known as projects. In contrast, earlier C++ programming projects contained C++ source code files only; a file (known as a makefile) held the compiler instructions to compile and link the individual C++ files. In a contemporary GUI environment, however, files above and beyond the source code files are integrated into the development project. These files include elements such as bitmaps, dynamic link libraries (DLLs), and controls (for example, ActiveX controls). Tools such as Visual C++, Visual Basic, and Delphi group the disparate files into a project file. The project file may also contain overall project information such as the application name, compiler flags to be used, and debugger settings.
Visual J++ allows you to keep all the files used to build a program in a single project. In fact, if you try to create a simple class and compile it, Visual J++ will inform you that a project workspace is required before a class can be compiled. In other words, all Java applets or applications created with Visual J++ must be contained in a Visual J++ project workspace.
In order to fully explore the IDE interface, you need to create a new project. The first step is to select File|New...|Project Workspace.... Figure 2.2 shows the New Project Workspace dialog box.
Figure 2.2 : The New Project Workspace dialog box.
Type in a project name and select Java Virtual Machine in the Platform box. A new subdirectory will be created in the location you specify in the Location edit box, and your project workspace files will be created within this subdirectory. Once a project workspace has been created and opened, its files will appear in the project workspace window. The Developer Studio IDE comprises three primary windows:
You can resize the windows to create an environment that is comfortable for you. These three windows have a Docking View option that causes the window to be docked, or frozen, in place. If the Docking View option is unselected, the window is free to be moved. Click the right mouse button within any main window to display a pop-up menu from which you can select the Docking View option.
The Project Workspace window is used to present project information as well as information about Visual J++ in general. Figure 2.3 shows the Animator example and how it appears in the ClassView frame of the Project Workspace window.
Figure 2.3 : The Project Workspace window.
Notice the three tabs at the bottom of the window: ClassView, FileView, and InfoView. Clicking on any tab will display a frame containing more information about the current project.
The ClassView frame displays all of the classes used in this project and illustrates relationships between classes and interfaces in that project. This view is very useful because it does not force you to remember which class is in which file. In addition, all members of a class (variables and methods) are displayed underneath the class name. A small icon next to the class gives some information about the class, such as public, private, or static. For now, don't worry about what these keywords mean. They are explained in Chapters 3, "Object-Oriented Programming with Java," and 5, "Elements of the Java Language."
ClassView can be used to perform the following operations:
To add a method to a class, right-click over a class, select the Add Method... option, and complete the Add Method dialog box, shown in Figure 2.4.
Figure 2.4 : The Add Method dialog box.
To add a variable to a class, right-click over a class, select the Add Variable... option, and complete the Add Variable dialog box, shown in Figure 2.5.
Figure 2.5 : The Add Variable dialog box.
To add a new class to a project, right-click over the Projectname-classes parent node on the class tree and select the Create New Class... option. (Another way to add a class is to right-click over an individual class file.) Complete the information in the Create New Class dialog box, shown in Figure 2.6. A new class (with its associated Java file) will be created in the project directory.
Figure 2.6 : The Create New Class dialog box.
To set a breakpoint on a specific method in a class, right-click over the method name in the ClassView and select the Set Breakpoint option. A breakpoint will then be set at the method definition in the application frame.
The purpose of the FileView frame is to show relationships among files in the current project (just as the ClassView frame illustrated relationships among Java classes and interfaces in the project). Figure 2.7 shows the Animator sample applet project loaded in the FileView frame.
Figure 2.7 : The FileView frame.
Note that the relationships shown in FileView are not physical relationships. That is, the trees presented in FileView do not correspond to directory trees on your hard disk. Instead, the relationship tree is used to demonstrate the relationships among the contents of the individual files.
Each file in Visual J++ has a corresponding property sheet. You can view the properties sheet by selecting the file in the FileView pane and doing any of the following:
Figure 2.8 shows the properties sheet for the Animator.java file in the Animator sample project.
Figure 2.8 : A project file's properties sheet.
The General tab of the Source File Properties sheet shows the filename and the date it was last modified. The Inputs and Outputs tabs show the relative pathnames of the input and output files of the project, as well as the tool that will be used to compile this file. The Dependencies tab shows the list of files that this file is dependent on, as well as the tool that will be used to compile this file.
You can also set some project-level options in the FileView frame. Right-click over the project name (the root node of the file view tree) and select the Settings... option from the pop-up box. The Project Settings dialog box (see Figure 2.9) allows you to set CLASSPATH directories, debugging information, and compiler switches.
Figure 2.9 : Setting project properties within FileView.
You can also set these options by selecting main menu choices. (See Chapter 9for details.)
The InfoView frame contains information about the Visual J++ tool,
including all online books, class library documentation, and Java
language documentation, as well as readme and release notes. Although
putting this information on the main screen right next to a project's
object and file information may seem a bit odd, within a matter
of minutes you probably won't be able to imagine working without
it.
| NOTE |
Listing all the information about Visual J++ in one place makes the Developer Studio environment an excellent tool for the person who spends hours a day writing code. |
The 1.0 release of Visual J++ lists the following online documentation in InfoView:
The Visual J++ programming samples include all the standard Java programming samples provided in the Java Developer's Kit (JDK) as well as samples from Microsoft written in Java that use ActiveX controls.
All Microsoft Developer StudioÐaware products feature online documentation in the form of online books. Topics within these books are displayed in a list view within the InfoView frame of the Project Workspace window. To view any of the topics, double-click on that topic in the Project Workspace window. The topic will then be displayed within the Application window (see Figure 2.10).
Figure 2.10 : A Books Online topic.
Several interesting options are available via the right-button pop-up menu. The Search option allows you to search through all topics for keywords or to query topics for information. Selecting the Options item displays an Options dialog box from which you can completely configure the display and operation of the Help system. Like the text editor, the text within the Help window can be highlighted, depending on the context, to provide the reader with more information. The Docking View option can be turned on or off to display the topic in one of two modes. If Docking View is turned on (denoted by a check mark), the window containing the topic will "pop out" of the Application window and appear as a modeless window that can be minimized, maximized, or closed. If the window containing the topic is minimized, it will appear to be "docked" at the bottom of the Developer Studio environment.
The contents of the Application window depend on the context in which you are working. If you double-click on a class (or any of its members) in the ClassView frame, that class will be opened in the Application window. If you select a topic from the Online Books list in the InfoView frame, that topic will also be displayed in the Application window. Resource file contents are also displayed in this window when a resource file is being edited (this is discussed later in this chapter).
Basically, the Application window is used for the real work you do on a project. The Project Workspace window is used by you and Visual J++ to provide tools for managing your project. The Output window at the bottom of the screen is used by Visual J++ to display feedback to you as it is doing its work (compiling, debugging, searching, and so on).
The next two sections discuss the options available in the Application window for editing code and viewing the online book topics.
Visual J++ features a powerful text editor that is completely configurable by the user. The various capabilities of this editor are discussed here; the configuration options are explained later in the chapter.
The Visual J++ editor uses syntax-aware color highlighting to highlight Java keywords, operators, and comments. This feature means that you can, for example, configure the editor to display all Java keywords in red, all comments in blue, and everything else in purple-and that rainbow is just the foreground colors! You can also change background colors. (You should use some restraint, though, to avoid going blind after staring at brilliant colors while hacking code in the wee hours of the morning.)
Highlighting keywords and comments helps you find key attributes within the Java code. The unique aspect of Visual J++ is that you use highlighting to customize virtually every bit of text in the entire environment-Java source files, HTML source files, debugging output, call stacks, watch windows, and so forth.
Visual J++ also supports recording and playing back a series of keystrokes. In addition to reducing the risk of repetitive stress injuries, record and playback is useful when you need to repeat a set of keyboard operations within a class. Some restrictions apply to keystroke recording:
To begin recording a series of keystrokes, select Tools | Record Keystrokes or press Ctrl+Shift+R. A small dialog box displays the standard Pause and Stop buttons. Perform the desired keystrokes and then click the Stop button. To play back your keystrokes, position the cursor at the desired location and select Tools | Playback Recording or press Ctrl+Shift+P.
Right-clicking within the text editor will display a pop-up menu. In addition to the normal cut, copy, and paste functionality, this menu provides some other useful operations. Use the Insert/Remove Breakpoint selection to add or remove a breakpoint at the current cursor location. Use the Enable/Disable Breakpoint to enable or disable a breakpoint at the current cursor location.
Selecting Insert File into Project displays a File Select dialog box. You can select a file from this dialog box to add it to the current project. One really cool feature is the Open menu option, which you can enable by selecting an import filename statement in a Java source file. The following code snippet shows some import statements:
import java.io.InputStream; import java.awt.*; import java.awt.image.ImageProducer; import java.applet.Applet; import java.applet.AudioClip;
Selecting any one of these statements and then selecting the Open menu option will open that file in the IDE. Cool, don't you think?
Selecting the Properties item from the pop-up menu displays the dialog box shown in Figure 2.11.
Figure 2.11 : The Source Window Properties dialog box.
Changing the Language selection will affect the color highlighting chosen for the text display of this file. Note that the tab size and indent size can be modified from this dialog box.
You can use bookmarks to mark a position within a file; then, after scrolling through that file, you can return directly to the bookmark. This feature greatly reduces the amount of time you spend searching for text when you need to move back and forth in a file. You can remove a bookmark when it is no longer needed.
Visual J++ supports two types of bookmarks. Named bookmarks are given a name by the user and persist between editing sessions. Unnamed bookmarks are temporary bookmarks that are removed as soon as the source file is closed.
To create a named bookmark, select the Bookmark option from the Edit menu; then enter the name of the bookmark into the Bookmarks dialog box. Because named bookmarks store a bookmark's name as well as the cursor's current row and column location, even if characters or entire lines of code are deleted, the bookmark will always be set to the exact location where the cursor is at the time of the bookmark's creation.
To delete a named bookmark, open the Bookmarks dialog box (select Edit|Bookmark...), select the desired bookmark or bookmarks, and press the Delete button. To jump to a bookmark, click the Go To button in this dialog box.
Unnamed bookmarks are temporary bookmarks that disappear once a source file is closed. Unlike named bookmarks, however, they provide visual notification (a cyan-colored square, by default) that a bookmark exists at the current line. To create an unnamed bookmark, select the Bookmark toggle button from the Edit toolbar. (For more information on adding and removing toolbars such as the Edit toolbar, see the section titled "Using and Configuring the Visual J++ Toolbars" later in this chapter.) When this button is clicked, a small cyan square should appear in the current line's left margin.
To remove an unnamed bookmark, click the Bookmark toggle button again. Other buttons in the Edit toolbar allow the developer to jump to the next or previous bookmark as well as clear all bookmarks within the current file.
The Output window, by default, appears at the bottom of the Developer Studio environment. (Because the Output window is a dockable window, you can drag it to another portion of the screen.) The Output window, like the Project Workspace window, contains a number of tabbed frames that correspond to the tools you can use to display output. These tabs are Build, Debug, Find in Files, Java Type Library Wizard, Profile, and Source Control (if it is being used). For example, when a project is being compiled, compiler messages are forwarded to the Build frame.
Messages in these frames are not simply "dumb" text
messages. When an error triggers a compiler message, for example,
double-clicking on that compiler message will immediately highlight
the line in the source code that caused the error. Features like
this combined with the lightning-fast speed of the Visual J++
compiler make it an ideal tool for rapid application development
(RAD). With products like Visual J++ and the upcoming Symantec
Visual Caf setting a new standard for visual development,
Java programmers don't have to worry about using clunky, command-line
tools any longer.
| Note |
Although C++ tool vendors have worked for years to make their tools easier to use and quicker to compile, these vendors have never really been able to turn the corner and compete head-to-head with true RAD tools such as Visual Basic and Delphi |
When you right-click in any of the Output windows, a pop-up menu displays several options:
If you select the Hide option or close a dockable window and are unable to figure out how to bring the window back, don't worry. The View main menu contains a list of all the dockable windows under Visual J++, including Project Workspace, InfoViewer Topic, Output, Watch, Variables, Registers, Memory, Call Stack, and Disassembly. If the window is currently showing, selecting its View menu option will have no effect; however, if the window has been closed, selecting its View menu option will display it in its last known state.
The Watch, Variables, Registers, Memory, Call Stack, and Disassembly windows have not been mentioned in this chapter. Because these options relate to viewing Java runtime information, they are examined in detail in Chapter 10, "The Visual J++ Compiler," Chapter 12, "Debugging with the Visual J++ Debugger," and throughout the remainder of the book.
You'll find another really cool Visual J++ feature by selecting the Full Screen option from the View menu. This option blows up the current source code text to fill the entire screen. That's entire as in no menus, no window title bar, no system menu, and so on. Click the small button at the top of the screen to return the IDE to its normal mode. Using the Full Screen option enables you to view a few more lines of code than normal and removes all other visual distractions from the screen.
This concludes the description of the three primary windows most often visible in Visual J++. The following section examines the different Visual J++ menus and toolbars; the chapter concludes with a look at customizing the IDE.
The Visual J++ toolbars duplicate functionality that can be found in main menu (or submenu) selections. Experience has shown that many users prefer visual toolbars to menus. Toolbars have become even easier to use since the introduction of ToolTips. To see a ToolTip in action, hold your mouse over a toolbar button. A little rectangle should appear within a second or so that displays text describing the purpose of that button. Like the main windows in the Developer Studio environment, toolbars are dockable, which means that you can drag them to different parts of the screen. This feature allows you to completely customize the look of the environment without losing any functionality.
You will find the most commonly used features in Visual J++ on a variety of toolbars. In fact, as you will see shortly, you can not only assign every single menu selection in Visual J++ to a toolbar of your choice but also create new toolbars. (When I said Visual J++ was really, really configurable, I meant it!)
Table 2.1 lists the toolbars (and the corresponding functionality)
that are available to the Vi-sual J++ user.
| Toolbar | Functionality |
| Standard | Performs the most common file operations: File New, File Save, Save Project, Cut/Copy/Paste, Undo/Redo, and Search. |
| Project | Contains the most commonly used project-specific options: Compile, Build, Set Breakpoint, Debug Go, and Default Project Settings. |
| Resource | Used in the creation and viewing of resource information. Examples of resources that can be created from this toolbar are dialog, menu, cursor, icon, bitmap, accelerator, string, and version resources. |
| Edit | Contains options that are most useful when editing source files: the ability to create new windows containing the same source file, the ability to tile a window within itself so that different parts of a file can be viewed simultaneously within one window (cool if you've got a big monitor), Find in Files, and bookmarks. Find in Files is a feature that allows a developer to search through one or more files for a keyword. This feature is similar to the grep command familiar to many programmers. |
| Debug | Contains the commonly used debugger commands: Start debugging, Stop debugging, Step into/over/out/to, and options to show/hide the Watch, Variables, Registers, Memory, Call Stack, and Disassembly windows. |
| Browse | Provides commonly used options for viewing symbol definitions and references. Included in these options are selections to display the current/next/previous symbol definition and reference as well as options to view the call and callers graph of a selected method. |
| InfoViewer | Allows the user to quickly switch among installed documentation and includes Search and Bookmark options when viewing online documentation. |
| InfoViewer Contents | Allows the user to filter the contents that are displayed in the InfoView window. Options include a Define Subset button and a drop-down list that shows the current information that may be displayed in InfoView. |
All toolbars can be displayed and hidden using functionality built into the Developer Studio IDE. You can access the Toolbars dialog box, shown in Figure 2.12, by selecting the Toolbars option from the View menu.
Figure 2.12 : The Toolbars dialog box.
As you can see, this dialog box lists all the toolbars mentioned in Table 2.1. Selecting a check box will cause that toolbar to be displayed in an undocked state. To dock the toolbar, simply drag its frame to the desired location. Here are two ways to hide a toolbar:
Note the two selection boxes at the bottom of the dialog box in Figure 2.12. These two selection boxes are used to turn ToolTips off or to display the ToolTip with/without the shortcut. Displaying the ToolTip with the shortcut gives you some idea of which shortcut key can perform the same function.
In addition to being able to turn toolbars on and off, you also have complete control over the contents of toolbars. You can also build and name custom toolbars from the Toolbars dialog box in Figure 2.12.
To modify an existing toolbar, select the Customize... button. The Customize dialog box contains a list of all the main menu selections along with buttons that are equivalent to the individual menu options (see Figure 2.13).
Figure 2.13 : The Customize dialog box.
To modify a toolbar, grab any of the buttons displayed in the dialog box and drag it onto the toolbar you want to modify. This step makes the button part of that toolbar until you remove the button or reset the toolbar to its default settings. To remove a button from a toolbar, simply grab it, drag it off, and release it anywhere but over another toolbar. To reset a toolbar to its default settings, select the Reset button in the Toolbars dialog box.
After using Visual J++ for a while, you'll recognize the top 10 or top 20 commands you use over and over. You can save yourself time and energy by building your own toolbar and keeping it displayed (if the extra screen space required won't interfere with your work environment). Select the View|Toolbars menu option to display the Toolbars dialog box. Click the New button. Enter the name of your toolbar in the next dialog box. A small, empty toolbar should appear on your screen. If the dialog box is in front of the new toolbar, move it over to the side or, better yet, dock it underneath your current toolbars.
Now that you have created an empty toolbar, review the menu selections in the Toolbar dialog box and drag the ones you want onto your new toolbar.
Figure 2.14 shows a toolbar named The Visual J++ Unleashed Top Ten that contains 10 of my favorite commands.
Figure 2.14 : A custom toolbar.
You can also configure the Visual J++ main menus, although not to the degree of detail that you can achieve with customized toolbars. With the menus, you can
The shortcut keys can be modified by selecting Tools|Customize . The Customize dialog box (refer to Figure 2.13) will appear. To modify shortcut keys for a variety of editors, select the Keyboard tab. Clicking on the different commands will display their current shortcut keystrokes at the bottom of the dialog box. To modify any of these shortcuts, enter your own shortcut keystroke in the Press new shortcut key text field.
To add your own tools to the bottom of the Tools menu, select the Tools tab in the Customize dialog box. The current contents of the menu will be displayed, as well as pushbuttons for adding, relocating, and removing tools from the menu. Any tool that was added using this method will appear above the Java Resource Wizard... menu option.
As you probably realize by now, the Visual J++ environment is completely customizable. In addition to modifying toolbars and menus and relocating dockable windows, you can customize many other items, including
The rest of this chapter discusses some of these customization options. The compiler options and file location paths are examined in detail in Chapter 10.
You can use the Options dialog box to modify most of the IDE options. (Select Options from the Tools menu.) The Options dialog box uses tabbed controls to essentially display the equivalent of six different dialog boxes; the tabs-except for Debug and Directories, which are saved for later chapters on the debugger and compiler (Chapter 10 and Chapter 12)-are explained in the following subsections.
The Editor tab (Figure 2.15) contains several settings that customize the appearance of the Text Editor window.
Figure 2.15 : The Editor Options page.
Options within this page allow you to toggle the vertical and horizontal scrollbars, drag and drop, and the use of automatic window recycling. Convenient options at the bottom of the page force the saving of files and the automatic reload of externally modified files. The last feature is particularly useful when using source-code control software because it forces the automatic reloading of all externally modified files. Often, a file may be updated that was modified by another user, but your project may not be aware that that file was modified because it wasn't done by you.
The Tabs Options page (see Figure 2.16) is where you can modify tab and indent sizes.
Figure 2.16 : The Tabs Options page.
Note the Smart Indent Option. Selecting this option forces the IDE to indent based on the program language element.
The primary purpose of the Compatibility Options page (see Figure 2.17) is to determine the default editor style to be used by Visual J++.
Figure 2.17 : The Compatibility Options page.
Nearly all development environments come with a default text editor that most programmers feel comfortable with. However, popular third-party editing tools are also available:
Therefore, in addition to the default Developer Studio editing tool, emulations are provided for both Epsilon and Brief as well as Visual C++ 2.0 (which didn't use the Developer Studio IDE). One area in which these three editors differ is in their search expressions. For information on the specific syntax used in each editor's search expressions, see the Visual J++ documentation.
The Workspace Options page (see Figure 2.18) is where you can configure the workspace.
Figure 2.18 : The Workspace Options page.
This page gives you the capability to enable or disable the Visual J++ windows' docking characteristics. By default, the Output, Watch, Variables, Registers, Memory, Call Stack, and Project Workspace windows are dockable. The InfoViewer Topic and Disassembly windows are, by default, not dockable.
The Format Options page (Figure 2.19) contains configuration options for various categories of foreground color, background color, font types, and font size.
Figure 2.19 : The Format Options page.
You can make changes to code elements in a particular window or apply the changes to all Visual J++ windows from the Format Options page. This page enables you to modify the environment colors to suit your exact tastes. Elements whose colors and fonts can be modified include
The final page is the InfoViewer Options page (see Figure 2.20). This page allows you to modify the appearance of the InfoViewer (which is the Developer Studio Online Help System).
Figure 2.20 : The InfoViewer Options page.
The Zoom features on this page control the size at which the topic title and text are displayed. The larger the number, the larger the title or text will be displayed in the topic's window.
By now you should be impressed with the wide range of features and options available to the Visual J++ programmer. None of the options mentioned in this chapter affect the actual Java applications produced by Visual J++. Instead, this chapter describes the many configurable items in Visual J++ and explains how you can modify their appearance or behavior to create a comfortable working environment. (Specific compiler and Virtual Machine features that utilize ActiveX [and thereby force Java to be platform dependent] are introduced in Chapter 10.)
The Developer Studio contains three primary windows in which nearly all development work is done:
Each window has a specific purpose and can contain an extremely large amount of information. However, because each window can be completely customized and placed anywhere on the screen, you have complete control over your working environment. (User control of the working environment is the goal of nearly all modern development tools; unfortunately, although many have tried to achieve this goal, few have succeeded.)
The Project Workspace window contains three tabbed frames. Each frame presents a different view of the information that is currently used to develop Visual J++ projects. These views are
ClassView displays information about each class in a project. FileView displays any relationships that may exist among the files in the current project. InfoView lists all online documentation, samples, and associated information that is provided with the Visual J++ installation.
Toolbars and menus within the Developer Studio perform specific context-sensitive operations. Toolbars are completely configurable, can be created from scratch, and can be located anywhere on the screen. Menus, on the other hand, allow their shortcut keys to be modified, but little else. (The Tools menu is an exception in that you can add new tools to the bottom of the list.)
Another item that you can modify is the syntax highlighting of source code.
Although this chapter deals with the Visual J++ product, before you can use Visual J++ to build an actual program (see Chapter 6, "Creating Programs with Java"), you need to learn the nuts and bolts of the Java language. The following two chapters discuss object-oriented programming with Java and the basic elements of the Java language.