GETTING STARTED WITH JBUILDER (updated: 6/30/05)
CS 219 ADJUNCT TEACHERS: At Park University, we've used JBuilder in CS 219 for the past several years because it's one of the industry-leading Java IDE's, it's powerful, and the academic version is free. Unfortunately, a number of students have complained that it's flaky and that it's too hard to use. After much deliberation, Park's ICS Department has decided to install a second industryleading, powerful, and free IDE – Eclipse. We'd prefer to maintain only one of the two IDEs (these tutorials take a lot of effort to maintain!), and this year will be a fight to the death. Hopefully, Eclipse will work out well during the 2005-2006 school year, and if that's the case, then next year we'll only install Eclipse, and not JBuilder.
OBTAINING AND INSTALLING JBUILDER FOR YOUR HOME PC: Since JBuilder is installed in the lab, obtaining it for your home PC is recommended, but not required. The JBuilder 2005 Foundation IDE has these system requirements: 256 MB RAM minimum (512 MB RAM recommended) 280 to 650 MB hard disk space minimum (depending on edition, plus additional space for development files and temporary space during installation) Intel® Pentium® III/500 MHz or higher (or compatible) Microsoft® Windows® 2000 (SP4), Windows XP, or Windows 2003 If your home PC meets the system requirements and you'd like JBuilder for home usage, for either download option, start by going to this Web site: http://www.borland.com/products/downloads/download_jbuilder.html To download JBuilder 2005 Foundation, click on the Foundation link that says 2005 to its right. Be forewarned that the download is rather hefty, so if you use a dial-up modem, it may take several hours. After reading the instructions and following the appropriate links on the foundation Web site, you'll eventually reach a window that contains the actual download links. There should be links for downloading the JBuilder application itself and links for downloading the JBuilder documentation. You should download the English, Windows version for the JBuilder application and you should also download the English, Windows version for the JBuilder documentation. As part of the download registration process, you'll be asked to provide your e-mail address. Borland uses that address to e-mail you your license key. When you receive the license key e-mail, follow the e-mail's instructions. After both downloads are done, use Windows Explorer to find each of the downloaded files. Since the downloaded files are in zip format, you'll need WinZip to unzip the files. If you don't know about WinZip, go to www.winzip.com. After winzip is installed, double click the JBuilder documentation download file to unzip it. When asked which directory you'd like to unzip to, feel free to choose any directory. Note that the unzip creates a jbxdocs directory inside the directory you choose. After the unzip is done, look for a doc_install.exe file in your newly installed jbxdocs directory and double click it. Follow the instructions.
2.
Double click the JBuilder application download file to unzip it. When asked which directory you'd like to unzip to, feel free to choose any directory. Note that the unzip creates a jbx_windows directory inside the directory you choose. After the unzip is done, look for an index.html file in your newly installed jbx_windows directory and double click it. In the window that pops up, look for and follow the Install JBuilder instructions. After the JBuilder installation is done, follow the Run JBuilder instructions.
SAVING FILES:
Modern IDE's (integrated development environments) have trouble compiling files on diskettes. That's because modern IDE's typically require lots of extra auxiliary memory space to do their work. Thus, do not attempt to compile your programs while they are on a diskette. If you're on your home PC, I assume that you'll want to use your PC's hard disk. If you're at the school's lab, do not use the hard disks! Instead, use a USB flash drive storage device. Most PC's (including our lab PC's) have USB ports, so this is a viable option in most cases. Prices are coming down for this new technology. This Web site has decent prices: http://shop.store.yahoo.com/digi4me/newusbflasdi.html
Typically, to install your USB flash drive, you simply have to plug your flash drive cable into your USB port. To copy to and from your USB flash drive, open Windows Explorer and drag files with your mouse. Typically, to remove your USB flash drive, you simply have to click an unplug icon in your system tray and then unplug your cable from your USB port. See your USB flash drive's product packaging for details. FYI: The diskette problem appears sporadically. This cryptic error message is usually indicative of running out of room on a diskette when you compile:
Internal compiler error: java.lang.StringIndexOutOfBoundsException: String index out of range: -2
3.
JBUILDER TUTORIAL: When doing your homework programming exercises, use this JBuilder tutorial as a guide. As explained in the tutorial, for each homework programming exercise, you will need to create a new project, set project properties, etc. It is up to you to carefully reread the JBuilder tutorial and figure out how to do things for your homework programming exercises. This tutorial uses x: to refer to the drive that you're saving your work to. In the lab, x: should be replaced by the USB drive (assuming that you're using a USB flash drive storage device). At home, x: should be replaced by the USB drive or the hard drive, whichever you prefer. Whenever you are asked to do an action (left column below) that you've already done before, I will refrain from providing the supplemental information (right column below). If you don't remember the details of how to do something, look for it earlier in the tutorial. I expect you to have to look up a lot of previously covered material. This is my attempt to force you to start memorizing how to do things.
Actions Load JBuilder.
Supplemental Information Click on the Start menu. Select Programs. If you don't see a selection for JBuilder X Foundation yet, drill down further with an appropriate selection(s). Select JBuilder X Foundation. JBuilder should now be loaded.
Clear the default loaded project.
If the JBuilder environment ever loads a project by default (i.e., the environment is not empty) or if you're not sure whether a project has been loaded by default, close the project as follows: Click the File menu. Select Close Projects… In the Close Projects dialog box, click the All button. Click OK.
4.
Actions Create a myJavaFiles directory in x:\. Supplemental Information To create a directory, you may want to use Windows Explorer or the My Computer icon. Since, in my opinion, Windows Explorer is a more elegant tool than My
Computer, I’ll provide an explanation of how to create a directory using Windows Explorer:
Right click on the Start button. Select Explore from the pop-up menu. That should cause a Windows Explorer window to appear. In that window, a directory tree (= a folder tree) should appear in the left pane. Drag the left pane's scrollbar all the way up until you see the x: drive. Click on the x: drive. Click the File menu. Select the New entry and wait for the sub-menu to appear. On the sub-menu, click Folder. A newly generated directory should appear in the right pane of your Windows Explorer window. The name of the new directory is New Folder by default. You now need to rename the directory to myJavaFiles: 1. If the name New Folder is already selected/highlighted, you should be able to just immediately enter myJavaFiles and it should overlay New Folder. 2. If that doesn’t work, then try clicking on the New Folder icon with the right mouse button. That should cause a menu to pop up. Select Rename from the pop-up menu. Immediately enter myJavaFiles and it should overlay New Folder. Close down the Windows Explorer window. What is a project? A project is a tool that helps to organize all the files in a particular program. More specifically, a project is a file with a .jpx extension that keeps track of a program's files and settings. The "jp" in .jpx stands for JBuilder project. I'll describe a few project settings shortly.
5.
Actions Create a project file. Supplemental Information After you've returned to the JBuilder environment, click the File menu. Select New Project… You should now be at the first of three screens that comprise the Project Wizard. In the Name box, type tutorial. In the Directory box, click the … button, find and highlight the myJavaFiles directory, and click OK to select it. In the Template box, accept the default value. Make sure the project notes box is unchecked. Click the Next button to go to the wizard's second screen. On the second screen, you'll see boxes for various paths. Enter x:/myJavaFiles/tutorial for the Output path, Backup path, and Working directory boxes. Under the Source tab, you'll see Default and Test path values. If those path values don't say x:/myJavaFiles/tutorial, highlight the path value, click the Edit button, enter x:/myJavaFiles/tutorial in the Directory box, and click OK. Click Yes in response to the "No such directory. Accept it anyway?" prompt. Click the Next button to go to the wizard's third screen. You won't use the features on the third screen. Click the Finish button. Multiple projects? Multiple directories? Note that you could use one project file to handle all your programs for the entire semester. But in the interest of improved organization, I recommend that you create a new project file for each new homework assignment. Thus, for homework 1, you'd create a hw1.jpx file, for homework 2, you'd create a hw2.jpx file, etc. All of your source code for homework 1 would be added to the hw1.jpx project, all of your source code for homework 2 would be added to the hw2.jpx project, etc. You'll see shortly how to add source code to a project. It's up to you whether you'd like to store all of your project files in one directory or whether you'd like to store them in separate directories. The default is to create a separate directory for each new project (above, you created a separate tutorial directory for your tutorial project). I recommend that you stick with the default and use a separate directory for each project. But in so doing, be aware that you'll need to put a copy of the Input.java file in each directory. Set the indentation widths for your project. Click the Project menu. Select Project Properties… Click the Basic Formatting selection in the container tree at the left. In the Indent area, enter 2 for all three of the indentation boxes. Click OK. Note that the above-specified path properties and indentation settings apply only to your current project. If you're working at home, you may want to have those settings apply to all your projects by default. That way, you don't have to hassle with setting the property for each new project. To set a default project property, select Project / Default Project Properties. The Default Project Properties dialog box is similar to the Project Properties dialog box so you should be able to reuse the instructions above.
Understand default project properties.
6.
Actions Set default editing preferences. Supplemental Information Click the Tools menu. Select Preferences… Click the Editor container in the container tree at the left. In the Editor frame, expand the Brace match container and make sure that all of its items are unchecked, and then expand the Indent container and make sure that all of its items are unchecked. To apply the newly entered options, click OK. Click the File menu. Select Open File… In the File name box, type x:\myJavaFiles\tutorial\Hello.java (note that Java is case-sensitive; Hello.java must use an uppercase "H" so that it matches your Hello class name in your program below). Click OK. At the top of the frame, the Hello tab should be selected; at the bottom of the frame, the Source tab should be selected. Enter this text in the source pane such that is replaced with your actual name.
/**************************************** * Hello.java * * * This program says "hello" to the world. ****************************************/ public class Hello { public static void main(String[] args) { System.out.println("Hello world!"); } // end main } // end class Hello
Create a source code file.
Prepare to enter source code.
Enter this text:
Understand the code.
The top section is known as the prologue section. It provides documentation for human readers. The compiler ignores everything between the opening /* and the closing */. main methods should be enclosed in a class that is public and whose name matches the name of the enclosing file. For example, the main method above is enclosed in a public class named Hello. The class must be named Hello since the enclosing file is named Hello.java. Note that JBuilder is a bit lenient in applying one part of the above rule - you can get away with the class not being public. Nevertheless, you should follow the rule so your code is portable.
Save the source file.
Click on the save icon (the save icon looks like a diskette).
7.
Actions Add the source file to the project. Supplemental Information In the left pane, right click on the tutorial.jpx file. Select Add Files/Packages/Classes… Search for and select Hello.java in the x:\myJavaFiles\tutorial directory. Click OK. Click the Project menu. Select the Make Project “tutorial.jpx”.
Make your project.
If necessary, fix errors. Set the Main class property for your project. Click the Project menu. Select Project Properties… Click the Run container in the container tree at the left. In the Run window, since this is your first project, the Runtime configurations pane should be empty. Click the New… button. That should cause a New Runtime Configuration window to appear. In the Name box, type tutorial. Click the Main class’s "…" button. Click the Browse tab. In the Class name box, type Hello. Click OK. Click OK in the New Runtime Configuration window. Click OK in the Project Properties window. Run your project. Click the Run menu. Select Run Project. Hello world! should appear in the output/messages frame at the bottom of the IDE. (IDE stands for Integrated Development Environment. JBuilder is an IDE.) Note that there's lots of other text that appears above the Hello world! output line. You may safely ignore that text. It's the command that's used behind the scenes to initiate the run process. If necessary, fix errors. Save the project. Click the File menu. Click Save Project "tutorial.jpx".
8.
Actions Create a second program. Supplemental Information You're now going to create a second program and this program will use the textbook's input class. For the remainder of this tutorial, I'll assume that you're using the Dean textbook's input class – Input. But if you're using the Savitch textbook, then whenever you see Input, replace it with SavitchIn. Since much of what you're going to do for this program is identical to what you've done for the previous program, I will refrain from providing many of the details this time. If you don't remember the details of how to do something, look up above. I expect you to have to look up above a lot. This is my attempt to force you to start memorizing how to do things in JBuilder. Create a source code file. Enter this text: The name of the source code file should be x:\myJavaFiles\tutorial\NameInquiry.java
/**************************************************** * NameInquiry.java * * * This program prompts the user for his/her * name and then says hello to the user. ****************************************************/ public class NameInquiry { public static void main(String[] args) { String name; System.out.print("What's your name? "); name = Input.readLine(); System.out.println("Hello, " + name + "."); } // end main } // end class NameInquiry
Save the NameInquiry.java source file. Add the NameInquiry.java source file to the project. Set the Main class property for the project. Note that you're using the same project file (tutorial.jpx) for both this new NameInquiry program and also your old Hello program. The IDE knows which program to run by looking at its Main class property. Set the Main class property to your NameInquiry class. Previously when you set the Main class property, you clicked the New… button because you were creating a runtime configuration for the first time. This time you're editing an existing runtime configuration. So this time, you should see an Edit… button. Click it and proceed.
9.
Actions Understand the Input.java file. Supplemental Information Your program uses the Input.readLine method call to read in a line of text. The Input class is not built into the Java language. You need to get the Input class's file and store it in the same directory as any file that uses the Input class. Since your NameInquiry.java file is in the cs151 directory, then your Input.java file also needs to be there. To find the Input.java file, go to Park's ICS Department Web site (http://captain.park.edu/ics/), click on the Course Resources / Source Code option, and then click on the Input.java link. In the download dialog box, select the Save option. That should cause a Save As dialog box to appear. In the Save As dialog box, enter f:\myJavaFiles\Input.java in the File name box. Click Save to continue.
Copy the Input.java file to the current directory.
Add the Input.java source file to the project. Display Input.java contents. After you've added the Input.java file to your project, you should see the Input.java file appear inside your tutorial.jpx project file tree in JBuilder's left pane. Note that even though you've added the Input.java file to your project, the contents of the Input.java file is not displayed in the right pane. To display its contents, double click on the Input.java file (in the tutorial.jpx project file tree in JBuilder's left pane). Make the project. Click the Project menu. Select Make Project “tutorial.jpx”. Note that the make command compiles all the files in your project, not just the one file that's displayed in the right frame. Thus, Hello.java, NameInquiry.java, and Input.java are all compiled when you make your project this time. If necessary, fix errors. Run your project. Click the Run menu. Select Run Project. You should see a prompt to enter your name. In order to enter a value at the prompt, you first need to put the cursor in the proper spot. To do that, click somewhere to the right of the prompt. Enter your name. You should see a message with your name in it. If necessary, fix errors.
10.
Actions Print the output. Supplemental Information Use your mouse to select the output (in the output frame at the bottom of the IDE). Press Ctrl+c to copy the selected text. Your output is now copied to your computer's buffer. You'll next need to paste it into a text editor so you can print it from there. Use the NotePad text editor, not Word or WordPad. NotePad is the preferred text editor because NotePad uses monospace font. Monospace font is good because that's what your actual program output uses. To open NotePad, click on the Start button. Then select Programs / Accessories / NotePad. That should cause a NotePad window to appear. To paste the previously copied text into NotePad, press Ctrl+v. To print the contents of NotePad, click on the File menu and select Print … Save the project. Close the project (!!!) Unfortunately, when JBuilder loads, it attempts to load any projects that had been open at the time that JBuilder was previously shut down. That's OK if you're using a computer that you don't share with anyone. However, in the lab, that can be a very big problem,
SO MAKE SURE THAT YOU CLOSE YOUR PROJECT BEFORE EXITING JBUILDER !!!
When using JBuilder in the lab, you're supposed to save your work on a USB flash drive storage device. If you forget to close your project before exiting JBuilder, then the next person who attempts to use JBuilder on that same computer may get an error message saying that the file doesn't exist. That's because JBuilder attempts to open up your old project on a USB flash drive and that project is no longer there because your USB flash drive is no longer there. In a worse scenario, suppose the computer, unbeknownst to you, saves your project to a default directory on the hard disk on one of the lab's PC's (that in and of itself is VERY BAD!!). In that case, if you forget to close your project before exiting JBuilder, then the next person who attempts to use JBuilder on that same computer will see your project loaded up on his/her screen. That leads to the possibility of cheating. Please reread my policy on cheating in the course syllabus now. The bottom line is that there are severe repercussions for the person who "borrowed" the code and also for the person whose code was borrowed (even if that person was totally unaware of the infraction). Click the File menu. Select Close Projects… In the Close Projects dialog box, click the All button. Click OK.
11.
Actions Skim the online help. Supplemental Information This tutorial provides bare minimum instructions in terms of how to create a project, create a source file, compile, and run. Use JBuilder's online help for more detailed information. The online help provides more detail than you need for this class, but skim it at this point so that you will know where to go for help in the future. More specifically, do this: Click on the Help menu. Select Help Topics. In the help window, select Building Applications with JBuilder and skim the contents. Also, select JDK Documentation and skim the contents. Exit from JBuilder.