Tino APCS

JAVA Setup

In order to write, compile, and run Java programs you need two pieces of software:

  • A text editor in which to type your code
  • Java Development Kit (JDK) to compile and run Java code

The text editor we will begin with is BlueJ. It's an excellent editor designed for education and it includes the JDK so you have nothing else to download and configure. One step. Easy!

Click here to download and install BlueJ

Test your Java installation.

  • Start BlueJ and select New Project from the menu.
  • Enter a project name such as "Semester 1" where you will store your Semester 1 work.
  • For Location, choose a folder on your computer that you can access easily such as your Desktop.
  • Create a new Java file by clicking the New Class button or selecting Edit-->New Class in the menu.
  • Name your class HelloWorld and leave the other options as they are. Press OK.
  • Open the HelloWorld class (shaded box) and delete the existing code. The fastest way to do this is to select all text using Ctrl+A on a PC or Command+A on a Mac.
  • Then press delete. Replace the code with this:

    public class HelloWorld {
       public static void main(String[] args) {
           System.out.println("Hello World!");
       }
    }
    
  • Close the editor window and go back to the main BlueJ window

  • Compile your program by pressing the Compile button (shown below). Compiling converts your human-readable Java code into machine code that the computer understands.
  • Finally, run the program by right-clicking the HelloWorld file (the shaded box) and selecting void main(String[] args)

If everything goes smoothly, you will see "Hello World!" displayed in BlueJ's terminal window.

Install the gpdraw library.

  • A library is a collection of pre-compiled code organized into a .jar file.
  • We will be using the grdraw library for easy-to-use drawing capability in our programs.
  • Download gpdraw.jar and save it to your desktop or wherever you can find it later.
  • Next, open BlueJ's Preferences menu. (To get there, first make sure you're in the main BlueJ window that has the boxes showing each class. Then, if you're on a PC, select Tools-->Preferences. If you're on a Mac, select BlueJ-->Preferences)
  • Select the Libraries tab. In the Libraries tab, select Add File and then select gpdraw.jar from wherever you downloaded it.
  • After pressing OK, you are warned that the changes will not take effect until the Java Virtual Machine (JVM) is restarted. To restart the JVM select Tools-->Reset Java Virtual Machine from the menu or click the u-turn arrow in the bottom right corner of the main BlueJ window.

Test your gpdraw installation.

  • Make sure you have reset the Java Virtual Machine as described above.
  • Download DrawingTest.java by right-clicking the link and selecting Save link as (or Save Target As). Choose a location you can find easily.
  • Add the file to your project by selecting Edit-->Add Class from File in the BlueJ menu.
  • Compile and run the program the same way you did for HelloWorld.

If everything goes smoothly, you will see a triangle drawn in a window named DrawingTool.

Last modified: August 22, 2023

Dark Mode

Outline