Professional Documents
Culture Documents
TM
IDE 3.6
Feedback
TM
Setting Up Your Project r Basic IDE Concepts s The Filesystems Window s Projects in the IDE r Accessing Source Directories s Filesystems and the Java Classpath s Correctly Mounting Java Packages s Mounting Resource Libraries r Advanced Project Setup Creating and Editing Java Source Code r Creating Java Files s GUI Templates and Java Templates r Editing Java Files in the Source Editor s Using Abbreviations, Word Matching, and Code Completion s Configuring Code Completion s Adding Fields, Bean Properties, and Event Listeners s Working With Import Statements s Search and Selection Tools s Formatting Java Source Code r Navigating Between Documents r Configuring the Editor
Page 1 of 58
Compiling Java Programs r Compiling Files r Working with Compiler Types s Specifying the Compiler Type for Files and Projects s Creating Custom Compiler Types s Setting the Target Directory for .class Files r Cross-Compiling Between Java Platforms r Using JavaMake to Manage Class Dependencies Debugging Java Programs r Basic Debugging s Starting a Debugging Session s Debugger Windows s Stepping Through Your Code r Working With Breakpoints s Setting a Breakpoint s Setting Conditions for Breakpoint s Customizing the Output for a Breakpoint s Breakpoint Types r Setting Watches Packaging and Deploying Your Applications r Creating a JAR File s Creating a JAR Recipe s Compiling and Creating the JAR File s Mounting and Checking the JAR File r Modifying a JAR File s Adding Files to a JAR Recipe s Modifying the Manifest File s Setting the JAR Content Filter r Executing a JAR File Using Javadoc r Integrating Java API Documentation into the IDE s Making Javadoc Documentation Available in the IDE s Searching and Displaying Javadoc Documentation s Configuring the External Browser to Display Javadoc Files r Adding Javadoc Comments to Your Code r Generating Javadoc Documentation
Page 2 of 58
Specifying an Output Directory for Javadoc Files Team Development With CVS r Checking Out Sources s Mounting a CVS Filesystem s Specifying Advanced Command Options r Configuring a CVS Filesystem s Setting the Relative Mount Point s Shortening and Hiding File Status r Working With CVS Files s Using the Graphical Diff Tool s Creating and Applying Patches s Resolving Merge Conflicts Graphically r Making Safe Commits Configuring the IDE r Setting IDE Default Settings s Configuring IDE Startup Switches s Configuring General Java Settings s Working with Unknown File Types r Enabling and Disabling IDE Functionality s Disabling Modules s Installing New Modules from the Update Center r Boosting NetBeans Performance s Tuning JVM Switches for Performance
s
Page 3 of 58
Basic IDE Concepts - The Filesystems window and working with projects. Accessing Source Directories - Adding source files and directories to a project, understanding filesystems, configuring the Java classpath, correctly mounting Java packages, and making class libraries (JAR files) available to the project. Advanced Project Setup - An example of a more advanced IDE project with two separate output directories for compiled classes and one for Javadoc documentation.
Page 4 of 58
The starting point for development in the IDE is the Filesystems window. The Filesystems window is where you organize your project contents, access and run commands on individual files, and view the structure of your source files. The Filesystems window contains all of the directories, packages, and archive files that you have added to your project. When you first run the IDE, the Filesystems window contains the NetBeans sample directory with some sample code. Each source file has its own Filesystems window node. These nodes have:
q
Contextual Menu Commands - You can run commands on files by right-clicking them and choosing from the contextual menu. The commands that are available vary depending on the type of node you are working with. Properties - Choose Window > Properties (Ctrl-1) to open a contextPage 5 of 58
sensitive Properties window. The Properties window always shows the properties of the component in the NetBeans user interface that has the focus. If you want to open a persistent Properties window that only shows the properties of one Filesystems window node, right-click the node and choose Properties. If a property contains an ellipsis button (...), you can click the button to access a special property editors that you can use to define properties visually. Subnodes - You can expand most nodes in the Filesystems window to view subnodes representing the internl structure of the node's file. These subnodes often have their own properties and contextual menu commands.
The Filesystems window does not show a node for every file in a mounted directory. For example, for the compiled ColorPicker form object, the source directory contains the ColorPicker.java source file, the ColorPicker. form file used to build its GUI in the IDE, and the ColorPicker.class compiled class. The IDE hides .form and .class files by default, so only one node is shown for ColorPicker. You can also choose to hide files by type and extension.
Page 6 of 58
When you open the IDE, the default project opens with some sample source mounted in the Filesystems window. If you do not need the examples, you can remove the sample filesystem by right-clicking the filesystem node and choosing Unmount Filesystem. You can also create an empty project by choosing Project > Project Manager and clicking the New button.
Each project also contains some hidden filesystems that are added by the IDE. These filesystems contain the JDK sources which you can view in debugging sessions, common Java libraries, and Javadoc documentation libraries. You can view all of the filesystems in your project by right-clicking the root Filesystems node and choosing Customize. Note: If the sources you are working with are under version control, you can mount them as a VCS filesystem. VCS filesystems let you see files' versioning status and run VCS commands right in the Filesystems window. For more information, see Team Development With CVS.
Page 7 of 58
made up of all the mounted filesystems, including hidden filesystems and filesystems that are mounted by default by the IDE. Note: You can view all of a project's filesystems, including hidden filesystems, by rightclicking the root Filesystems node and choosing Customize. In general, whenever you want to add something to the classpath, you should mount it in the Filesystems window. This includes Java libraries (JAR files) that your code depends on (see Mounting Resource Libraries). You can also customize the classpath for various operations, like running, compiling, and debugging, using the filesystem's property sheet. Go to the filesystem's property sheet and set the Capabilities properties accordingly. For example, you should exclude filesystems that only contain Javadoc documentation from the classpath for running, compiling, and executing. In addition to building the classpath, mounting files in the Filesystems window also makes them available for other IDE tools such as code completion.
Page 8 of 58
If you have multiple source trees with the package root of each tree grouped together under one directory, you have to mount each package root separately. For example, in the directory structure pictured on the right, src is the package root for the class com.myapp.MyApp.java and lib is the package root for the class com.mylib.MyLib.java. In this example, you cannot simply mount MyProject - you have to mount src and lib separately. You can add more than one directory at a time by holding down the Control key and selecting multiple directories in the Mount wizard.
myApp src // contains sources for myApp lib // contains binary libraries (JAR files) used by myApp myLib src // sources for a library used by myApp and other applications lib // contains binary libraries (JAR files) used by myLib build myApp // output dir for compiled classes for myApp myLib // output dir for compiled classes for myLib lib // contains binary libraries (JAR files) used by both myApp and myLib doc // contains generated Javadoc for the project First, mount the myApp/src and myLib/src directories as separate filesystems. These are our main development directories - except for the doc directory, they will be the only filesystems that are visible in our Filesystems window when we are done setting up our project. Next, mount the output directories for our classes, build/myApp and build/ myLib, as separate filesystems. There is no reason to keep the output directories visible in the Filesystems window, since you can execute files from their source nodes in the development directories. Hide the filesystems by setting their Hidden property to True. Now let's set up the compiler types that will place the compiled classes for myApp and myLib in the correct build directories. First, go to the Options Window and make a copy of External Compilation called myApp Compilation. To set this compiler type to store compiled classes in the build/myApp directory, set the compiler type's Target property to build/ myApp. Then create another copy of External Compilation called myLib Compilation and set its Target property to build/myLib. Now we are ready to assign our custom compiler types to the sources in our source tree. This is a bit tricky, since you cannot just select a filesystem or group of files in the Filesystems window and set the Compiler property for all of them. Instead, we will search for all Java objects in each filesystem and assign the compiler type from the Search Results window. First, choose Window > Properties (Ctrl-1) to open the Properties window. Then right-click the myApp/src filesystem and choose Find. Click the Type
Page 10 of 58
tab and select Java Source Objects, then click Search. The Search Results window returns all the Java source files in myApp/src. Select all of the sources, then in the Properties window set the Compiler property to myApp Compilation. Follow the same process to assign myLib Compilation to all the Java sources in myLib/scr. Next we can set up our Javadoc output directory. Mount the doc directory as a filesystem. In the filesystem's property sheet, set the Use in Execution, Use in Compiler, and Use in Debugger properties to False and set the Use as Documentation property to True. Then go to the Options window and set the IDE to use it as the default Javadoc output directory for the project. The directory will then house all of the Javadoc documentation you generate for the source you are developing. This documentation will also be available for Javadoc index searches in the IDE. Finally, mount your resource libraries in the Filesystems window. In our example, the libraries are stored in JAR files throughout our source tree, so you have to mount them with the Mount > Archive File command. If you do not need to browse through the code in these libraries, hide the filesystems so that they do not clutter up your Filesystems window.
Page 11 of 58
Creating Java files - Using the New wizard and the IDE's templates to create new files, GUI form templates versus Java source templates. Editing Java files in the Source Editor - Using code completion and abbreviations, generating bean properties and event listeners, working with import statements, search and selection tools, and formatting Java code. Navigating between documents - switching between open files, cloning the view of a file, and splitting the Source Editor. Configuring the Source Editor - customizing the Source Editor to fit your development style.
Page 12 of 58
Although we talk about the Source Editor as one component, it is really a collection of editors. Each type of source file has its own editor that provides different functionality. In this section we'll be dealing with the Java editor, but many of the same concepts apply to other editors. To open a Java source file in the Source Editor, double-click the file's node in the Filesystems window. Note: Double-clicking a Java form node ( ) in the Filesystems opens two tabs in the Source Editor: a source tab containing the Java source code for the form, and a Form Editor tab showing the designtime view of the form. To edit the source code for a Java form without opening the Form Editor, rightclick its node and choose Edit.
Page 13 of 58
Page 14 of 58
public int getGreen() { return this.green; } public void setGreen(int green) { this.green = green; } So far, so good. But to fully generate a working bean that can get and set the value of each of the color bean properties and notify the caller of its changes, we have to add event listeners to each of the set methods. There are two ways to do this. You could right-click the Bean Patterns node and choose Add > Multicast Event Source to add the java.beans.propertyChangeListener methods, then enter the rest of the source by hand. An easier way is to generate all of the necessary code when you create the bean properties. First, let's get rid of all of the methods and fields we have created so far. You can do so by deleting the nodes from the Filesystems window or just by deleting the code in the Source Editor. Next, right-click the Bean Patterns node and choose Add > Property. Enter red for the name, int for the type, and select the Bound checkbox. Now you can set the dialog to generate not just the field and methods for the property, but also the property change support code. Click OK to generate the following code in the Source Editor: private int red; private java.beans.PropertyChangeSupport propertyChangeSupport = PropertyChangeSupport(this); new java.beans.
public void addPropertyChangeListener(java.beans.PropertyChangeListener l) { propertyChangeSupport.addPropertyChangeListener(l); } public void removePropertyChangeListener(java.beans.PropertyChangeListener l) { propertyChangeSupport.removePropertyChangeListener(l); } public int getRed() { return this.red; } public void setRed(int red) { int oldRed = this.red; this.red = red; propertyChangeSupport.firePropertyChange("red", new Integer(oldRed), new Integer(red)); } Then all you have to do is repeat the process for the green and blue properties and change the ColorPreview constructor to the following: public ColorPreview() { propertyChangeSupport = new java.beans.PropertyChangeSupport(this); }
Page 15 of 58
And that's it! You've got a nice working bean ready to be used by the ColorPicker program.
Page 16 of 58
Page 17 of 58
Alt-Shift-O
Open the Fast Open dialog box, which lets you quickly open a file. Start typing a class name in the dialog box. As you type, all files that match the typed prefix are shown. The list of files is generated from the the project's mounted filesystems. Go to source. This shortcut opens the file where the item at the insertion point is defined. Go to declaration. Similar to the previous shortcut, this opens the file where the variable at the insertion point is declared. Go to line. Enter any line number for the current file and press Enter to jump to that line. Add a bookmark ( ) to the line of code that the insertion point is currently on. If the line already contains a bookmark, this command removes the bookmark. Go to the next bookmark. Go to the next location in the jump list for the currently selected file. The jump list is a history of all locations where you made modifications in the Editor. Go to the previous location in the jump list for the currently selected file. Go to the next jump list location in all files (not the currently selected file). Go to the previous jump list location in all files.
F2 Alt-L
Page 18 of 58
q q
Use the drop down list at the top-right of Source Editor. The drop down list displays all of your open files in alphabetical order. Press Alt-Left and Alt-Right to move one editor tab to the left or right. Press Ctrl-` to open the IDE window manager, which contains icons for each open document in the Source Editor as well as all open windows like the Filesystems window.
Maximize the Source Editor. Double-click any document tab or press Shift-Escape to hide all other IDE windows. If you have split the Source Editor, only the partition you maximize is displayed. Clone a document. Right-click the document in the Source Editor and choose Clone Document. Split the Source Editor. Grabbing any document tab and drag it to the left or bottom margin of the Source Editor. A red box shows you where the new Source Editor partition will reside once you drop the document. Any Source Editor partition can also be split any number of times. Move documents between Source Editor partitions. Grab the document tab and drag it to the row of tabs in the destination partition.
q q
View or change abbreviations. Open the property editor for the Abbreviations property and make any changes to the list. View or change all keyboard shortcuts for the IDE. Open the property editor for the Key Bindings property. View or change all recorded macros. Open the property editor for the Key Bindings property. Turn off code completion. Set the Auto Popup Completion Window property to False. Set the font size and color for code. Use the Font Size property to quickly change the font size for all Java code in the Source Editor. Open the property editor for Fonts and Colors to change the font and color of each type of Java code, like method names or strings. Change the indentation used in your code. You can switch between indentation engines by choosing a new engine from the Indentation Engine property. You can also configure each indentation engine by opening the property editor for the property. Set how many spaces are inserted for each tab in your code. Set the Tab Size property accordingly. Turn off Javadoc for code completion. Go to the Expert tab and set the Auto Popup Javadoc Window to False.
Page 19 of 58
you tools to deal with more complex project compilation, such as JavaMake for dependency management and advanced compilation options for cross-compiling for different SDK versions. In this section you will learn about the following:
q
TM
Compiling files - the behavior of the Compile and Build commands and viewing output from the compiler. Working with compiler types - which one to use, creating custom compiler types, setting the output target directory. Cross-compiling between Java platforms - specifying the compiler executable or libraries used in compilation. Using JavaMake to Manage Class Dependencies - managing complex dependencies between Java classes.
Compiling Files
To compile a file or directory, select it in the Filesystems window and choose one of the following from the main window:
q
Build > Compile (F9) to compile only those files that are new or have changed since the last compile. The up-to-date check is done by comparing timestamps between the source (.java) and products (.class) of the compile. This command does not compile the files in subfolders. Build > Compile All (Shift+F9) to compile only those files that are new or have changed since the last compile, including the files in subfolders. Build > Build (F11) to build all the selected files from source regardless of their up-to-date status. This command deletes the sourcename.class files in the folder and compiles the source files. This command does not remove .class files or compile source files in subfolders. Build > Build All (Shift+F11) to build all files from source within the selected folder and its subfolders .
Any compilation errors and output are displayed in the Output Window. In the Output Window you can:
q q q
Click any error to jump to the location in the source file where the error occurred. Copy the output to the clipboard by right-clicking in the window and choosing Copy. Redirect the output to a file by right-clicking in the window and choosing Start Redirection of This View to File. The output is written to the output directory in your IDE's user directory. You can also choose a specific directory to redirect the output to under Output Window settings in the Options window.
Page 20 of 58
Internal Compilation compiles files within the same virtual machine as the IDE using the javac compiler of the IDE's default SDK. External Compilation spawns a new VM for compilation. While Internal Compilation is faster, External Compilation offers you greater configuration options. All other compiler types shipped with the IDE are basically copies of External Compilation that have been configured for different compiler executables. Additional IDE modules may insert their own compiler types, such as the RMI Stub Compiler from the RMI module.
The project-wide default compiler type. Open the Options window, select Editing > Java Sources, and set the Default Compiler property. The compiler type for an individual file. Right-click the file in the Filesystems window, choose Properties, and set the Compiler property.
Page 21 of 58
Each compiler type contains properties that affect how the compiler generates code, such as whether to generate debugging information and which libraries to use. You can configure compiler types in the Options window under Building > Compiler Types. Remember that when you change a compiler type's property, that property is changed for all files that use that compiler type. If you need to set different options for only some files in your project, you should make a copy of the compiler type with the desired configuration changes, then set the appropriate files to use this new compiler type. You can create a new compiler type with default settings by right-clicking the Compiler Types node in the Options window and choosing from the New menu. To copy an existing compiler type with all of its settings, right-click the compiler type and choose Copy. Then right-click the Compiler Types node and choose Paste > Copy. Note: You can also change compiler options from any Java source file node's property sheet. Just rightclick any Java source file node in the Filesystems window, choose Properties, and click the ellipsis (...) in the Compiler property. Remember, though, that the properties you change in the Compiler dialog box are applied to all files that use this compiler type.
Page 22 of 58
This dialog defines how the IDE makes calls to the compiler executable. The Process field points to the executor that is used. In this case, the Process field is using the {jdk.home}variable to point to your computer's default SDK. The Arguments field uses variables to insert the various compilation options that are defined for the compiler type, such as Debug or Optimize. To switch this compiler type to use a different Java platform's compiler executable, click the ellipsis button and browse to the executable, or type the absolute path to the executable in the field. Also, since you are not using the JDK 1.4 compiler, make sure to uncheck the Enable JDK 1.4 Source property. However, you might need to compile an application against an older JDK version without using the older JDK's compiler. For example, you might need to compile applets against JDK 1.1, but not want to use the JDK 1.1 compiler because of performance reasons. In this case, set the compiler type's Boot Class Path property to the desired Java platform libraries. Again, make sure the Enable JDK 1.4 Source property is unchecked.
Page 23 of 58
JavaMake/index.html. NetBeans IDE solves this problem by integrating JavaMake, a tool that provides more extensive dependency management between Java classes. You can enable JavaMake for all of your project's Java classes by selecting Editing > Java Sources in the Options window and checking the Use JavaMake property. The first time you compile a project with JavaMake, the IDE examines all of the classes in a project's mounted filesystems and records the dependency information in a project database. The IDE only records dependency information for filesystems which have compilation enabled. The IDE uses this information during compilation to perform a complete check for any dependent classes that need compilation. When JavaMake is enabled, the Compile and Build commands behave differently than when using normal compilation. The behavior of the commands is as follows:
q
Compile/Build. Only compiles or builds the selected files without checking the status of dependent classes. Compile All/Build All. Compiles the selected file and checks all dependent classes. If any dependent classes are not up-to-date, the IDE compiles them. These commands effectively build or compile the entire project, regardless of which class they are run on
Page 24 of 58
arrayFill.java sampleBean.java
Feedback
Basic debugging - Starting a debugging session, using the Debugger windows, and stepping through your code. Working with breakpoints - Adding and removing a breakpoint, different types of breakpoints, setting breakpoint conditions, and customizing the output of a breakpoint. Setting watches - Adding a watch or fixed watch to an object.
Basic Debugging
In this section, we will use a simple example to demonstrate how to start a debugging session, step through your code manually, and monitor variables and method calls in the Debugging workspace. We will leave more advanced functions like setting breakpoints and watches for the following sections. Our example for this section is the arrayFill program. This program is very simple. It creates an array of sampleBeans, each one of which has two properties, firstName and lastName. It then assigns values to the properties of each bean and prints out the values. The first thing you want to do is run the program to see if it throws any exceptions. Open arrayFill.java and press F6 to execute it. The following output should appear in the Output window: java.lang.NullPointerException at arrayFill.loadNames(arrayFill.java:27) at arrayFill.main(arrayFill.java:34) Exception in thread "main"
Page 25 of 58
Start > Run in Debugger (Alt-F5). Runs the program until the first breakpoint is encountered. Step Into (F7). Starts running the program and stops at the first executable statement. Run to Cursor (F4). Starts a debugging session, runs the program to the cursor location in the Source Editor, and pauses the program.
Since you did not set any breakpoints in the example program, just select arrayFill in the Filesystems window and press F7. The IDE opens the file in the Source Editor, displays the Output window and Debugger windows, and stops just inside the main method.
Debugger Windows
Let's take a minute to look at the Debugger windows. The Debugger windows automatically open whenever you start a debugging session and close when you finish the session. By default, the IDE opens three Debugger windows: the Local Variables window, Threads window, and Call Stack window. You can open other Debugger windows by choosing from the Window > Debugger menu. When you open a Debugger window during a debugging session, it closes automatically when you finish the session. If you open a
Page 26 of 58
Debugger window when no debugging session is open, it stays open until you close it manually. You can arrange Debugger windows by dragging them to the desired location. The following table lists the Debugger windows. Name Local Variables Watches Shortcut Ctrl-Alt-1 Ctrl-Alt-2 Description Lists the local variables that are within the current call. Lists all variables and expressions that you elected to watch while debugging your program. Lists the sequence of calls made during execution of the current thread. Displays the hierarchy of all classes that have been loaded by the process being debugged. Lists the breakpoints in the current project. Lists the debugging sessions currently running in the IDE. Lists the thread groups in the current session. Provides session, threads, calls, and local variables in a single view.
Step Over (F8). Executes one source line. If the source line contains a call, executes the entire routine without stepping through the individual instructions. Step Into (F7). Executes one source line. If the source line contains a call, stops just before executing the first statement of the routine. Step Out (Alt-Shift-F7). Executes one source line. If the source line
Page 27 of 58
q q
is part of a routine, executes the remaining lines of the routine and returns control to the caller of the routine. Pause. Pauses program execution. Continue (Ctrl-F5). Continues program execution. The program will stop at the next breakpoint. Run to Cursor (F4). Runs the current session to the cursor location in the Source Editor and pauses the program.
In our example, use the F7 key to step through the code one line at a time. The first time you press F7, you are presented with a dialog saying that the IDE couldn't find java. lang.ClassLoader. loadClassInternal in the mounted filesystems. If you want to be able to step through methods in the JDK as well, mount the JDK sources in the Filesystems window. Otherwise, use the Step Out option in this dialog to have the debugger execute the process without trying to open the file in the debugger. The NullPointerException occurred in the loadNames call, so when you step to that call, watch the value of the names array in the Local Variables view. Each of the beans have a value of null. You can continue stepping through the loadNames method - the names beans are null throughout. The problem here is that while the line sampleBean[] myNames=new sampleBean[fnames.length]; initiates the array that holds the beans, it does not initiate the beans themselves. The individual beans have to be initiated in the loadNames method by adding the following code in line 28: names[i]=new sampleBean();
Page 28 of 58
you set a breakpoint at the location where you think a problem is occurring and then run the program to that location. You can also set more specialized breakpoints, such as conditional breakpoints that only stop execution if the specified condition is true or breakpoints for certain threads or methods. In this section, we will use the arrayFill program from the last example, so you will have to recreate the bug by commenting out the code you added above.
Setting a Breakpoint
If you just want to set a simple line breakpoint, you can click the left margin of the desired line. A line breakpoint icon ( ) appears in the margin. You can remove the line breakpoint by clicking it again. For more complex breakpoints, use the New Breakpoint (Ctrl-Shift-F8) command in the Debug menu. The New Breakpoint dialog box lets you choose the type of breakpoint you want to create and set breakpoint options such as conditions for breaking or the information that the breakpoint prints to the Output window.
Page 29 of 58
Breakpoint Types
The following table lists the different breakpoint types that are available. Type Line Description You can break execution when the line is reached, or when elements in the line match certain conditions.
Page 30 of 58
Method
When you set a breakpoint on a method name, program execution stops every time the method is executed.
Exception You have several options for setting a breakpoint on an exception. You can break whenever a specific exception is caught, whenever a specific exception is not handled in the source code, or whenever any exception is encountered regardless of whether the program handles the error or not. Variable You can stop execution of your program whenever a variable in a specific class and field is accessed (for example, the method was called with the variable as an argument) or modified. You can break program execution whenever a thread starts, stops, or both. When you set a breakpoint on a class, you can stop the debugger when the class is loaded into the virtual machine, unloaded from the virtual machine, or both.
Thread Class
Setting Watches
A watch enables you to track the changes in the value of a variable or expression during program execution. To set a watch, select the variable or expression you want to set a watch on in the Source Editor, then right-click and choose New Watch (Ctrl-Shit-F7). You can also create fixed watches in the Watches view. While a normal watch describes the content of a variable, a fixed watch describes the object that is currently assigned to the variable. To create a fixed watch, right-click any item in the Local Variables or Watches view and choose Create Fixed Watch.
Page 31 of 58
Feedback Creating a JAR File - Using JAR recipes to specify JAR file contents and properties, creating a manifest, creating and mounting the JAR file. Modifying a JAR File - Adding and removing files to an existing JAR file, making changes to the manifest, and setting custom file filters. Executing a JAR File - Specifying the main method in the manifest and executing your application.
Page 32 of 58
The fourth page of the wizard lets you set special options for the JAR file contents. The most important part of this page is the Target Directory column, which shows the directory structure of the JAR file's contents. For Java sources, the directory structure must correctly match the Java package structure of the Java classes. If the filesystem from which you added the contents was correctly mounted at the Java package root, this should automatically be configured correctly. For example, the target directory for our examples.colorpicker.ColorPicker class is correctly set at examples/colorpicker. Finally, the fifth page of the wizard lets you generate the manifest file for the JAR file. The JAR manifest file contains meta information for handling the files contained in the JAR file, such as the location of the main method or signing information. For more information about the JAR manifest file, click here.
In the JAR Manifest page of the wizard, you can generate basic manifest information automatically, enter information by hand, or use an existing file as the manifest file. For now, let's just enter the basic manifest information by clicking the Generate button. Then click Finish to create the JAR Recipe.
Page 33 of 58
The JAR recipe node appears in the Filesystems window, as shown in the figure on the right. The JAR recipe node includes a subnode for the JAR file it creates and a Contents subnode listing all of the JAR recipe contents. You can use the property sheet to modify the contents and properties of the JAR recipe, such as the compression level and file filter used to produce the JAR file. To open the property sheet, right-click the JAR contents node and choose Properties.
Page 34 of 58
In our case, we want to add the entire colorpicker directory to the JAR recipe, since the ColorPicker application will not work without the other classes in the directory. To do so, select the directory and click Add. Then click OK and recompile the JAR recipe to update the JAR file.
Page 35 of 58
Page 36 of 58
Using Javadoc
Javadoc is the Java programming language's tool for generating API documentation. Java API documentation describes important elements of your code, such as methods, parameters, classes, fields, and so forth. You can insert special Javadoc comments into your code so that they will be automatically included in the generated documentation. Describing your code within the code itself rather than in a separate document helps to keep your documentation current, since you can regenerate your documentation as you modify it. In this section, you will learn about the following:
q
Feedback
Integrating Java API documentation into the IDE - Searching for and displaying Javadoc, mounting and configuring Javadoc filesystems, configuring the IDE's Web browser to display Javadoc files, and integrating Javadoc with code completion. Adding Javadoc comments to your code - Rules and special tags for Javadoc comments, tools for automatically commenting your code, and correcting errors in comments. Generating Javadoc documentation - Using the standard Javadoc doclet, initializing generation, and specifying the output directory for the generated files.
Page 37 of 58
Hidden. Specifies whether this filesystem is visible in the Filesystems window. You should set this property to False if you want to browse through the documentation tree in the Filesystems window. Search Engine. Specifies the default Javadoc search engine. The Japanese version of the search engine lets you to search internationalized Javadoc documentation. Root Offset. If your Javadoc documentation is inside a JAR or zip file, the Javadoc index is sometimes buried in the file's hierarchy. Since you can only mount the JAR or zip file as a whole, you have to set the Root Offset for these filesystems to the directory that contains the Javadoc index. (For HTTP and local filesystems, you just mount the filesystem directly at the directory that contains the Javadoc index.)
Page 38 of 58
If you prefer to browse through your Javadoc filesystem hierarchy, choose the Javadoc filesystem from the View > Documentation Indices menu. The filesystem's index page is opened in your external web browser.
Page 39 of 58
If you select a web browser and it does not open correctly, it is possible that the IDE does not have the correct location for the browser executable. You can configure the web browser by opening the Options window, expanding IDE Configuration > Servers and External Tool Settings > Web Browsers and selecting the web browser. Open the property editor for the Browser Executable property, then click the ellipsis button for the Process field to locate your browser executable. Then click OK to exit the dialog box. If your Web browser uses a proxy to access the Internet from behind a firewall, you must also configure the browser to bypass the proxy for local files. If this option is not set, you could get a 404 File Not Found error when you try to display Javadoc files that reside on your local machine.
Page 40 of 58
colors. The code is already completely documented, so to see how the Auto Comment tool works let's first put some errors in the documentation. In the comment above the addPropertyChangeListener method, remove one of the stars (*) to change it from a Javadoc comment to a regular comment. Now right-click anywhere inside the Source Editor and choose Tools > Auto Comment. The Auto Comment tool shows all of the methods in the file that should be commented in the top left of the tool. You can use the buttons above this field to choose which methods are processed by the tool.
As you can see, all of the methods in the file have the green "correct Javadoc" icon except for addPropertyChangeListener, which has a red "missing Javadoc" icon. Select addPropertyChangeListener to see what problem the tool found with the method's comment. Use the View Source button to jump to the line in the Source Editor where the method first appears and the Refresh button to rescan the file for incorrect comments. You can add Javadoc comment text and tags in the right side of the tab.
Page 41 of 58
Generate Javadoc command on the sampledir filesystem, the javadoc directory contains the Javadoc index for the filesystem and a directory called examples with all of the individual documentation files.
Page 42 of 58
q q
Checking Out Sources - Mounting CVS filesystems, selecting which sources to check out, and running CVS commands. Configuring a CVS Filesystem - Configuring CVS filesystems and changing the display of file status information. Working With CVS Files - Generating diffs and patches, applying patches, and resolving merge conflicts. Making Safe Commits - Finding all modified files in your working directory, checking for mistakes, committing your changes.
Page 43 of 58
Now you can start filling in the CVS repository information. First, you need to create a directory to house the sources. Click the Browse button in the Working Directory field and create a directory called beans somewhere on your system. Then fill in the following CVS server information:
q q q q q
CVS Server Type - pserver CVS Server Name - cvs.netbeans.org CVS Server User Name - the anonymous login name, anoncvs CVS Repository - the location of the sources on the repository server, /cvs Use Built-In CVS Client - sets which CVS client the IDE uses
Before you finish mounting the CVS filesystem, you have to log in to the server. Click the Login button without entering a password. . (No password is necessary for the anoncvs account.) If the command succeeds, the text beneath the Password field changes to You are already logged in. If the command fails, check your connection to the Internet and your firewall settings.
Page 44 of 58
Note: To use CVS, you must be able to access the Internet on the CVS port (2401 by default). Click Finish to close the wizard and mount the filesystem. A new CVS filesystem node appears in the Filesystems window. Now that you have mounted the filesystem, you can get the sources from the repository. Right-click the filesystem node and select the CVS submenu. This submenu contains CVS commands that you can run on your files. Hold down the Ctrl key and choose Checkout from the CVS menu. The CVS Checkout dialog box lets you set advanced options for the CVS Checkout command. The "." in the Module(s) field indicates that you want to check out the entire CVS repository. Since we only want to check out the Beans module, enter beans in this field and click OK. Alternatively, you can click the Select button to view a list of all modules in the repository and then select from the list. Once you run the command, the VCS Output window opens listing the CVS command status and the CVS output. You can kill the command by clicking the Stop button. When the command finishes, you can expand the filesystem and begin working with the files.
Page 45 of 58
Page 46 of 58
NetBeans IDE uses a graphical diff viewer to display both file revisions side-by-side with the differences highlighted. The repository version is shown in the left pane, and your working file is shown in the right pane. You can use the buttons in the top left-hand corner of the viewer to navigate through the revision differences.
To run a graphical diff on a file, right-click it in the Filesystems window and choose CVS > Diff Graphical. If you run the command without any advanced options specified, it compares your working directory version with the head revision in the repository. If you want to specify which revisions to diff by tag name or date, hold down the Ctrl key while choosing the command and enter the information in the advanced command dialog. Unlike the Diff Textual command, you cannot run the Diff Graphical command on a directory. You can, however, select several files in the Filesystems window and run the Diff Graphical command on them. The diff for each file appears in its own Source Editor tab. As we will see in the Making Safe Commits section, you can also use the Search Results window as a powerful tool to find and diff all Locally Modified files in a filesystem.
Page 47 of 58
The patch is displayed in the VCS Output window. Right-click inside the VCS Output window and choose Save to File, then specify a location and name for the file. To apply a patch file, right-click the exact file or directory from which the patch was created and choose Tools > Apply Patch. Then browse to the location of the patch file and click OK. If you want to undo the changes made by the patch, you can delete the modified files and then run the Update command to get a clean version from the repository.
Page 48 of 58
Use the Accept buttons to choose which of the two versions you want to accept. You can use the Accept & Next buttons to resolve a conflict and jump to the next conflict. You cannot write into the bottom panel of the Merge Conflicts Resolver, so if you want to write something new rather than accepting either of the two versions, close the dialog and resolve the conflict manually in the Source Editor.
Page 49 of 58
clicking it and choosing Remove From Search. r For Merge Conflict files, right-click and choose Resolve Conflicts. r For Local or Unknown files, make sure the files don't belong in the repository. If they do belong in the repository, add them by right-clicking them and choosing CVS > Add. The files' status changes to Locally Added - they will be added when you perform your commit. r For any Locally Removed or Locally Added files, make sure you really want to remove or add the files from the repository. r For any Needs Merge, Needs Patch, or Needs Update files, update the files by right-clicking them and choosing CVS > Update. 4. Diff your files. Select all of the files in the Search Results window and run the Diff Graphical command on them. Examine your changes in the Diff Viewer to make sure nothing slipped in by mistake. 5. Build and run your project. The best way to make sure that your changes will not break the build is to build your project and quickly test it for any obvious bugs. 6. Commit your changes. Finally, you're ready to commit your changes to the repository. Select all of the files in the Search Results window, right-click the files, and choose CVS > Commit. Type a description of your changes in the Commit dialog box and click OK.
Page 50 of 58
Setting IDE default settings - Using the Options window and startup switches, setting general settings for Java source files, and dealing with unknown file types. Enabling and disabling functionality - Turning modules on and off and downloading new modules from the Update Center. Boosting NetBeans performance - Getting better performance using startup parameters, disabling modules, and manually initializing garbage collection.
IDE settings are grouped under Options window nodes in the left panel of the window. Select any node to set its properties in the right panel of the window. As with regular property sheets, many properties in the Options window contain special property editors. You can tell that a property editor is available for a property if the property contains an ellipsis button, as in the Error Expression property in the figure above. Most changes you make to IDE settings are applied to the open project. Only settings that you are not likely to vary from project to project, like indentation settings for the Source Editor or proxy information, are applied to all projects. The tells you that a particular settings node is defined at the project level. icon
You can apply project-level settings to all projects by clicking the << at the top of the options window, clicking the node's cell in the User column, and choosing Define Here. To revert a node's settings to the IDE's factory defaults, choose Revert to Default in the node's Default column.
Page 51 of 58
--open file
Page 52 of 58
The first thing you should do to configure the IDE is make sure it is using the correct Java Standard Development Kit (JDK) version. The JDK in which the IDE runs is important because it is automatically used as the platform against which all of your sources are compiled and executed. (You can, of course, configure the IDE for cross-compiling on a different Java platform than the one the IDE is using.) To see which JDK your IDE is running on, choose Help > About and click the Detail tab. The JDK's locations is listed under Java Home. By default, the IDE uses the JDK that is specified in your system's registry as the latest one. If you only have one version of the JDK installed on your computer, this is not a problem. If you have multiple JDK versions installed, it can be a good idea to explicitly specify which one the IDE should use. You can do so by using the --jdkhome JDK directory switch (for example, --jdkhome c:\j2sdk1.4.0\) on the command line or in your ide.cfg file. Note that if you are developing code for use on JDK version 1.4, you must have the Enable JDK 1.4 Source property set to True on both the Java Sources node and your compiler type in the Options window. You must also have the Enable Asserts property set to True on your Default Debugger and External Execution. These options allow features introduced in JDK version 1.4, such as assertions, to be properly handled by the JVM. Another important tool in defining Java settings is the Java Sources node in the Options window. The Java Sources node, which is located under the Editing node, contains general settings for how the IDE handles Java source files. You can use the Java Sources node to do any of the following:
q
q q
Set the default service types (Default Compiler, Default Debugger, and Default Executor) for Java source files. For each of these properties, you can click the ellipsis button to configure the service types themselves. Enable JavaMake for Java compilation (Use JavaMake). Define whether Java source files are parsed every time you open containing folder in the Filesystem window (Prescan Sources) and how quickly they are parsed after you make changes to them (Automatic Parsing Delay). If you set Prescan Sources to False, the IDE only parses source files when you run an action on them, like opening them or expanding their Filesystem window node. This makes browsing through large directory trees faster, but the icons for the node do not show whether the file contains a main method or errors until the file is parsed.
Page 53 of 58
unused modules helps improve your IDE's startup time and performance. You can also add functionality to your IDE by downloading new modules from the Update Center.
Disabling Modules
The Setup wizard is the most convenient tool for enabling and disabling modules. Disabling a module only causes the IDE to ignore the module. The module is not deleted and it can be enabled again at any time. To open the Setup wizard, choose Tools > Setup Wizard, then click Next to go to the Module Installation page of the wizard.
The Module Installation page groups related modules into module groups. For example, the Distributed Application Support group contains all of the modules that deal with distributed application development. You can disable all modules in a module group by unchecking the checkbox in its Enabled column, or expand the module group node to disable individual modules. When only certain modules in a module group are disabled, the Enabled column for the group displays [boolean]. When you are finished, click Finish to activate your changes. Certain modules depend on other modules to function properly. Disabling or enabling one of these modules may require you to also disable or enable the modules upon which it depends. If this is the case, the IDE displays a dialog that tells you which modules will also be disabled or enabled and asks for your confirmation.
Page 54 of 58
when you are ready to proceed. The second page of the wizard shows you all of the modules that are available on the Update Centers. The wizard only displays modules that are not already installed in your IDE or newer versions of modules that are already installed. Newer versions of modules that you already have are marked with an upward arrow, like the Ant 1.5.1 Documentation module in the figure below. Select any module to see detailed information about the module, including a description, the version number of the module on the Update Center, and the version number of the module already installed on your system. To schedule a module for installation, select it in the window on the left and click the right arrow button. To install an entire group of modules, select the module group node and click the double right arrow. When you are ready to proceed, click the Next button to view the modules' certificates and install the modules.
Disabling prescanning for Java source files. When prescanning for Java source files is enabled, the source files in any directory are parsed the first time you open the directory that contains them in the Filesystem window. Prescanning source files lets the IDE show whether the file contains a main method or compilation errors in the file's node. It also makes expanding through source directories slower. You can disable source prescanning by going to the Java Sources node in the Options window and setting the Prescan Sources property to False. The file is then parsed only when you open the file in the Source Editor or expand it in the Filesystem window. Switching off unused modules. As noted above in Disabling Modules, switching off unused modules can significantly decrease the IDE's startup time. For example, if you do not program distributed applications or Java GUIs, you can turn off the JNDI and Form Editor modules. NetBeans IDE's memory footprint while running is also smaller the less modules you have installed. Adjusting the JVM switches with which you start the IDE. See below.
-J-Xverify:none - This switch turns off Java bytecode verification, making classloading faster and eliminating the need for classes to be loaded during startup solely for the purposes of verification. This switch improves startup time, and there is no reason not to use it. -J-Xms24m - this setting tells the Java virtual machine to set its initial heap size to 24 megabytes. By telling the JVM how much memory it should initially allocate for the heap, we save it growing the heap as the IDE consumes more memory. -J-Xmx96m - this setting specifies the maximum amount of memory that the the Java virtual machine should use for the heap. Placing a hard upper limit on this number means that the Java process cannot consume more memory than physical RAM available. This limit can be raised on systems with more memory - the 96 megabyte setting helps to ensure that the IDE performs tolerably on 128Mb to 256Mb systems. Note: Do not set this value to near or greater than the amount of physical RAM in your system or it will cause severe swapping during major collections. -J-XX:PermSize=20m - this is a more exotic JVM switch, but one which also improves startup time. This setting sizes the "permanent area" of memory, where classes are kept. Since we know that all of NetBeans IDE's classes take up a specific amount of memory, we give the JVM a hint as to how much memory it will need. This setting eliminates major garbage collection events during startup on many systems. Users of SunONE Studio or other IDEs that include more modules may want to set this number higher.
Listed below are some additional JVM switches which have either anecdotally or measurably impacted NetBeans performance on some, not all, systems. Your mileage may vary, but they may be worth a try.
Page 55 of 58
-J-XX:CompileThreshold=100 - This switch will make startup time slower, by HotSpot to compile many more methods down to native code sooner than it otherwise would. The reported result is snappier performance once the IDE is running, since more of the UI code will be compiled rather than interpreted. This value represents the number of times a method must be called before it will be compiled. -J-XX:+UseConcMarkSweepGC -J-XX:+UseParNewGC - Try these switches if you are having problems with intrusive garbage collection pauses. This switch causes the JVM to use different algorithms for major garbage collection events (also for minor collections, if run on a multiprocessor workstation), ones which do not "stop the world" for the entire garbage collection process. If you are using the PermSize switch, you should also add the line -JXX:+CMSClassUnloadingEnabled to your ide.cfg file so that class unloading is enabled (it isn't by default when using this collector). Note: It is unclear as yet if this collector helps or hurts performance on uniprocessor machines. -J-XX:+UseParallelGC - Some tests have shown that, at least on systems fairly well equipped with memory, the durations of minor garbage collections is halved when using this collection algorithm, on uniprocessor systems. Note that this is paradoxical - this collector is designed to work best on multiprocessor systems with gigabyte heaps. No data is available on its effect on major garbage collections. Note: this collector is mutually exclusive with -J-XX: +UseConcMarkSweepGC. . The measurements supporting the use of this algorithm can be found on the performance web site.
Previous - TOC
Page 56 of 58
/* * arrayFill.java * * Created on March 6, 2003, 7:01 PM * * This nicely demonstrates how to manage array of beans, mainly each array cell has to be initialized separately */
/** * * @author bohemius */ public class arrayFill { private final static String[] fnames={"Jack", "Bob", "Lao", "Michael"}; private final static String[] lnames={"Wood", "Goat", "Duck", "Bond"}; private static void printNames(sampleBean[] names) { for (int i=0; i<names.length; i++) { System.out.println(names[i].getFirstName()+", "+names[i].getLastName()); } } private static void loadNames(sampleBean[] names) { for (int i=0;i<names.length;i++) { names[i].setLastName(lnames[i]); names[i].setFirstName(fnames[i]); } } public static void main(String[] args) { sampleBean[] myNames=new sampleBean[fnames.length]; loadNames(myNames); printNames(myNames); } }
Page 57 of 58
/* * sampleBean.java * * Created on March 6, 2003, 7:05 PM */ import java.beans.*; /** * * @author bohemius */ public class sampleBean extends Object implements java.io.Serializable { private String lastName; private String firstName; private PropertyChangeSupport propertySupport; /** Creates new sampleBean */ public sampleBean() { propertySupport = new PropertyChangeSupport( this ); } public String getLastName() { return lastName; } public void setLastName(String value) { String oldValue = lastName; lastName = value; propertySupport.firePropertyChange("Last name", oldValue, lastName); } public String getFirstName() { return firstName; } public void setFirstName(String value) { String oldValue = firstName; firstName = value; propertySupport.firePropertyChange("First name", oldValue, firstName); } public void addPropertyChangeListener(PropertyChangeListener listener) { propertySupport.addPropertyChangeListener(listener); } public void removePropertyChangeListener(PropertyChangeListener listener) { propertySupport.removePropertyChangeListener(listener); } }
Page 58 of 58