<<

Getting Set-up with BlueJ

Dr. Fernando Loizides

1 Setting up your Developer Environment In this chapter you will learn to set up your developer environment. This is where you will be writing your code and making it work. There are many such developer environments that you can use to develop in. For now and to start us o we will be using BlueJ. This is specically created in order to help those learning Java to get right into the programming without much fuss. It is also straight forward to install. When you are more familiar with programming and if you want to start developing professionally then you may choose to look at other options such as NetBeans (https://netbeans.org/ ) or (https://eclipse.org/). But for now lets get you up and running. To accompany this lesson, you can also follow the video on 'Installing BlueJ'. 2 Step 1 - Downloading and Installing BlueJ Go to the BlueJ website at (http://www.bluej.org/).

Figure 1: The BlueJ Website (http://www.bluej.org/)

Scroll down to where you can download BlueJ. Download the Installer with the JAVA JDK (This means that you are downloading a way for your computer to JAVA as well as the interface that you will use to program together instead of separately). We are showing the Windows set up but you can also do the same on a MAC or on Linux.

1 Figure 2: Download the BlueJ Installer with the JDK

Run the downloaded le. You should see a screen welcoming you. Press next.

Figure 3: BlueJ Installer Screen 1

The next screen will ask you if you want every account or just you to be able to use BlueJ. This is asking basically if you have more than one accounts on a computer (your mom, sister, wife, dog), do you think others would also like to be able to use BlueJ. Most likely, you would be the only one that would want to use BlueJ so keep the Install just for me setting selected and press next.

2 Figure 4: BlueJ Installer Screen 2

Leave all three tick boxes checked and click next on the third screen.

Figure 5: BlueJ Installer Screen 3

Leave the path on the next screen as it is and click next.

3 Figure 6: BlueJ Installer Screen 4

Click Install.

Figure 7: BlueJ Installer Screen 5

BlueJ should now install. If Windows asks you for authorisation to install BlueJ give it permission.

4 Figure 8: BlueJ Installer Screen 6

BlueJ should now be installed and ready to go.

Figure 9: BlueJ Installer Screen 7

3 Step 2 - Using your Developer Environment When you open BlueJ you will see an empty environment.

5 Figure 10: BlueJ Empty Environment

Create a new project by clicking on Project -> New Project. Name this MyFirstProject and click on Create. You should now see a similar screen to before but you are actually now in your project and there is a text document icon called README.TXT. This is where you will be writing about your project so that someone else can understand what it is about. This is not compulsory but is good practise.

Figure 11: BlueJ Empty Environment

In order for us to start programming we will need to create something called a class and run code through that. Don't worry about what that means at the moment, we will be learning about classes later on in the text. Let's get right to it... Create a new class by clicking on the New Class button. Ignore all the options at the moment and keep the radio button selected on Class. Name the class helloWorld (notice we are keeping it to one word) and click OK.

6 Figure 12: BlueJ Empty Environment

You should now have a class box appearing next to the README.TXT with the helloWorld name. Right-click on this box and click Open Editor. What you are seeing is actual code. Don't worry if it now seems like Klingon (Klingon is a Star Trek reference to an alien language), it will all make sense as you learn to further program.

Figure 13: BlueJ Empty Environment

In order to start programming we will modify this code now to get you started. Delete everything you see there and enter the following code: public class helloWorld

7 { public static void Main() {

} } This code basically strips out everything and gives you the opportunity to focus only on very things. For now, we will be using this code in order to demonstrate the early programming principles. As it stands, this code does nothing in itself. Nothing will appear on the screen, no calculations are made, no fancy graphics or sound. So let us give the rst instruction to the computer. This is to print something to the screen. Add the following line to your code: public class helloWorld { public static void Main() { System.out.println("Hello World"); } } This instructs the computer to print Hello World to the screen. Now let's run the program you wrote and see it printing to the screen. Click on the Compile button on the top left of the screen. When it is nished it should say on the bottom Class compiled - no syntax errors. We Compile the code we write so that the computer can understand it. Believe it or not, the code you see here is only meant to be understood by humans. Compiling the code then translates them to machine language. In JAVA this works a little dierently to that but it's not important right now. What is important is that you compile the code you write and that there are no errors. Close the code editor. Right click on the helloWorld class and click on the void Main option. Congratulations! If all goes right, you should be seeing a Hello World appearing in a window.

Figure 14: BlueJ Empty Environment

8 Feel free to change the text, add lines with:

System.out.println("something else");

Just remember to compile the program before you run the void Main. Also, if you want to clear the screen of the text select Options -> Clear. If you want the program to always clear the screen before running your code, select Options -> Clear screen at method call. Now that we have set up the environment, let's get started in learning the of programming and get you writing some programs.

9