Unless you have a Mac, you will need to install both the Java JDK (Java Development Kit) (also referred to as SDK) and BlueJ (On MacOS X, a recent Java JDK is installed by default).
To install the BlueJ Integrated Development Environment (IDE), go to the BlueJ website: http://www.bluej.org/. Here you will find much information, which you can explore later. To download, use the “download” link in the left column, which takes you to http://www.bluej.org/download/download.html
You will follow the directions for installation, but you must first install the Java JDK. When you take the “JDK 6” link (on the righthand side of the BlueJ download page, in the “Systems Requirements” box), you'll get to the downloads page: Java SE Downloads (“SE” means “standard edition”). About halfway down the page, you'll want to install “Java SE 6 Update 43” … the “Download JDK” button. The download link takes you to a page of choices. Pick the appropriate one for your platform (windows, linux, solaris).
Now back on the BlueJ download page, install the latest offcial release for your platform (Windows, MacOS X, others).
All your code must be contained in a “Project” in the BlueJ IDE. Later, you will write complex programs consisting of many components, but for now, for most of the programs you write, all your code will be in one file in the project. Before creating a new project, you'll want to set up a folder where you will put all your projects. If you have a folder for CSS 161/162, you may want to create a subfolder called “Projects” that will contain all your Java projects. Create that subfolder first.
Now start BlueJ. To create a new project, under the Project menu, click New Project… . (You'll click on Open Project… to open an existing project.) Get to the folder where you decided you'd store all your Java projects. To get there, use the pull-down menu and then keep clicking on subfolders until you get to your Projects subfolder. Now name your project anything you'd like, but always use meaningful names. Notice that if you look in that Projects subfolder, you'll see a folder named the name of the project you created.
Now you need to create a class where you will put your code. Under the Edit menu, click on New Class… (or click the New Class button). The class type is Class. The name you give it must follow the rules for all Java identifiers. The rules are that all identifiers must contain:
- only letters,
- the underscore symbol,
- and cannot start with a digit.
For simple programs, you can use the same name as the project (assuming you followed the naming rules). Double-click the class icon to get you into the editor. Delete everything between the first left curly brace and the ending right curly brace. This is where you will type your code.
Before you can execute your code, you must compile it. In the editor window, click the Compile button. If you have compiler errors, the line with the error is highlighted and the error is in the lower window. Note that sometimes the error may actually be on the line above the highlighted line. Compiling shows you one error at a time, so keep compiling until it says
''Class compiled - no syntax errors''
Syntax and compiler errors refer to the same thing; you have not followed the language rules (although from your point of view, they are often just typos).
After you have a successful compile, back at the BlueJ main window, you execute by first right-clicking on the class icon. Click on the method you wish to execute. To run the whole program, click on the
main method, and then the Ok button.
When you run it, the execution appears in the terminal window. Each time you run it, the output is added to what is already there. If you'd like to start with a clear window each time, under the Options menu, click the “Clear screen at method call” item.