Using J++ in CSE 8A and CSE 11

 

You can use any of the standard Java compilers in these classes. J++ is one such choice. (Other choices are discussed in the preface to the text).

Below are some hints on how to get started with J++.

Summary of Setting Up and Running a J++ Program

The following are instructions on how to set up and run a simple J++ program:

Start the J++ environment.

  1. Click on the Console Application icon in the right-hand panel of the New Project dialogue box.
  2. Type in the name of your project in the Name text field. (This name often is, but need not be, the same as the name of the file with the main method.)
  3. Next, set the Location text field so that it lists the folder that you want your project to go into. The easiest way to do this is to click the Browse button next to the Location field. This will produce a display similar to the Windows Explorer window. Use this window as you would use Windows Explorer to find and click on the desired folder. Then, click the OK button, and the Location text field will be set.
  4. Next, click the Open button in the New Project dialogue box.
  5. The J++ environment automatically gives your project a file named Class1.java . You probably want to delete the file Class1.java . Look at the Project Explorer panel in the upper right-hand corner of the J++ environment. You will see the file name Class1.java . If you do not see Class1.java , then click the plus sign in front of the project name, and Class1.java should appear. Once you can see Class1.java , click it on with your mouse and choose Remove from project on the Projects menu.
  6. Add the class SavitchIn as follows. Choose Add Class... on the Projects menu at the top of the J++ environment. Click the tab labeled Existing in the resulting dialogue box. Then, click the down arrow head next to the Look in field. This produces a display similar to the Windows Explorer window. Use this display to find the folder that contains SavitchIn.java and click on SavitchIn . Finally, click the Open button. SavitchIn.java should now be added to your project. The display will change so that a new window with program text (from the file SavitchIn.java ) appears. You do not need this window, so choose Close from the File menu to close the window. (Be sure that you choose Close and not choose Close All .) You can add other files in addition to or instead of SavitchIn.java by repeating this process for each existing file you want to add.
  7. Add the file that contains the main method as follows. Again choose Add Class... on the Projects menu at the top of the J++ environment. The tab labeled New should already be in front. (If for some reason it is not in front, just click the tab labeled New .) Click on the ClassMain icon so that it is highlighted. In the field labeled Name enter the file name you want, and then click the Open button. The file will automatically be opened so you can edit the file, that is, so you can type in Java code.
  8. Tell the J++ environment which of the classes you added contains the main method. To do this, choose Project Name Properties on the Properties menu at the top of the J++ environment. (Use your project name in place of Project Name .) Check the text field labeled When project runs, load . It should contain the name of the file with the main method. If it does not contain this file, change it so that it does, then click the OK button. Note that you must click the OK button even if the text field (labeled When project runs, load ) already contains the correct file name and does not need to be changed.
  9. To build your project, choose the Build command on the Build menu at the top of the J++ environment.
  10. You can run your program by choosing Start on the Debug menu.

You Can Use Files from Any Folder

As we described the production of your first project (program), the file SavitchIn.java was in a folder named First Try , but all the other files were in a folder named HelloProgram , which was a subfolder of First Try . The folder HelloProgram is the project folder. If you use Windows Explorer to look at the folders First Try and HelloProgram , you sill see that there is a copy of SavitchIn.java in each of these folders. When you add a file to a project and the file is not in the project folder (in the previous example this means not in the HelloProgram folder), then the J++ environment makes a copy of the added file in the project file. It is this copy that is used in the project. So, any change to the file in the project will not alter any file outside the project folder.