javadoc tool.If you are not used to debugging Java programs, you should get used to it soon. Even small programs of the sort we deal with in CS 146 are often so complicated that a debugger is very helpful in dealing with run-time errors.
Using TextPad is not recommended for CS 146 because of its lack of a debugger. Similar cautions apply to the free version of JCreator, and to the use of Sun's JDK without a graphical IDE. Both Microsoft's Visual J++ and their Visual J# fail to support the Collections API, and so neither is suitable for this course.
The (free) Java implementation that is supported and recommended by the department is Eclipse. A brief introduction to Eclipse, and to debugging in general, is given in the second half of a CS department web page at
http://www.cs.sjsu.edu/web_mater/cs46a/cs46alab/lab6/lab6.html (that's an underscore and not a space in the URL). Eclipse itself is available for download at http://www.eclipse.org/downloads.
BlueJ is a smaller and perhaps less intimidating free IDE that you may find adequate for CS 146. It is designed specifically for education. The size of the download is about 1 MB compared to about 63 MB for Eclipse. The BlueJ debugger is rather minimal, and you may or may not find its limitations annoying in CS 146. For example, it offers no "run to cursor" or "run to end of method" option. BlueJ is quite simple to use, and has useful tutorials available from the Help menu.
BlueJ is available for download at www.bluej.org. A 32-page tutorial in PDF format is available at that site; there's no real local help available in the IDE itself. Note that when BlueJ runs, a DOS window is opened. Don't try to close this window.
Both BlueJ and Eclipse, as well as other Java implementations, support the important notion of a project. A project is a collection of classes that are considered as a unit. In particular, they can be compiled together in a single operation. Each programming assignment should be treated as a separate project. Note that a project is not the same thing as a package.
For CS 146, it is both possible and desirable to keep all the source code files for a project in the same folder. This way it's easy to tell Java where to look for class definitions (when compiling a class, the Java compiler usually needs to know where to find definitions of other classes). When you create a project in either BlueJ or Eclipse, you will be asked to specify a folder for the source code classes. In Eclipse, it is apparently illegal for two projects to share a folder.
The table below describes how to perform common tasks in BlueJ and Eclipse. For Eclipse, it is important to understand the notions of perspectives and views. When using Eclipse, one is always in a perspective such as the Java, Debug, or Resource perspective. Various views are possible within each perspective. Perspectives and views can be selected by clicking the icons at the left of the main Eclipse window, or through its Windows menu.
| Blue J | Eclipse | ||
|---|---|---|---|
| to create a new project | Select New Project from the Project menu. Select a folder to contain the project, give the project a name, and click on the Create button |
Select New and then Project from the File menu. In the New Project window, select Java, and in the next window, give a project name. Also uncheck the default in this window to select an existing folder for the project. You may switch to the Java perspective after creating the project. | |
| to open an existing project | Select Open Project from the Project menu. Select the folder that contains to the project. |
In the Resource perspective, select the desired project from the Navigator window. | |
| to create a new class | Click on the New Class button, or choose New Class from the Edit menu |
In the Java perspective, right-click on the project name in the Package Explorer window and choose New and then Class. Enter the desired class and choose it to be public. |
|
| to edit a file or class | Double click on its icon in the main project window | In the Package Explorer window (in the Java perspective), look inside the appropriate package (which may be the default package) for the file/class and double click on it. | |
| to build a project (compile all its files) | Click on the Compile button in the project window, or select Rebuild Package from the Tools menu. Individual files can be compiled by right clicking on the class icon and (left) clicking on Compile, or clicking on Compile in the edit window. |
Select RebuildProject from the Project menu. |
|
| to run (execute) a class or project | Right click on the class icon and (left) click on main (or other desired method) |
Select RunAs and then Java application from the Run menu. |
|
| to debug a class or project | Selecting Show Debugger in the project window's View menu will show the debugger, as will clicking on the striped icon during execution. Setting a breakpoint in the editor will also show the debugger window when the breakpoint is reached. |
Select DebugAs and then Java application from the Run menu. Note that debugging puts you into the Debug perspective. Icons for common debugging operations may be found in the Debug window. |
|
| to redirect output* | Text in a BlueJ terminal window may be saved to a file by selecting Save to file from the window's Options menu. For large files you may need to have selected Unlimited Buffering from the Options menu in the terminal window |
Select the Console window and use the usual keyboard shortcuts (or the Edit menu in the Java perspective) to select and copy all or part of the text. The text may then be pasted to any file. |
|
creating javadoc files
| The Project Documentation choice from the Tools menu of a project window will generate and display javadoc documentation. When editing a class, its documentation may be viewed by selecting Interface (rather than Implementation) from the editor's toolbar |
Select Generate Javadoc from the Project menu. |
* The output window may be cleared in each case by using similar instructions. Also, output can be redirected to any desired file by running the JDK Java interpreter directly on the class file containing the main method, and redirecting the output to the desired file.