Creating and running a Java program. This tutorial is an introduction to running a computer program written in the computer programming language Java using the BlueJ IDE (Integrated Development Environment). Create an area to hold your program either: On a networked drive at the University: Do this by creating on the m: drive (Accessed via start menu link Computer [The m: drive has your login id as name]) the subdirectory CI101. The m: drive is an area of network disk space that belongs to you and only you. Your m: drive can be seen from any computer that you login to within the University. On a memory stick / USB drive Does this by creating on your memory stick/ USB drive the subdirectory CI101. However, do remember to take a backup of your memory stick, as they are very small and easy to lose. Remember it is very easy to lose (Accidently delete etc) your files. I also use Dropbox, to keep my current precious files, so even if I accidently delete them, I can still recover them up to 30 days later. There are several other companies that also offer free network storage in this way. M A Smith University of Brighton Page 1 04/10/2016
Run the application BlueJ To do this you will need to: Open the folder Applications (That is on the desk top) then open the subdirectory Computing. In this subfolder is a link to the application BlueJ. Now click on the link BlueJ to open the BlueJ IDE (Integrated Development Environment) When BlueJ launches select the bottom option for the 64 bit JDK to run. However, if the link to BlueJ is not present Right click on Applications Icon, and select open folder location Navigate to Program Files (X86) and open this directory Navigate to BlueJ and open this directory Now double click on the file BlueJ When BlueJ launches select the bottom option for the 64 bit JDK to run. M A Smith University of Brighton Page 2 04/10/2016
You will now be presented with the BlueJ IDE The Project menu allows you to create a BlueJ project in which will be held the files for your Java program. M A Smith University of Brighton Page 3 04/10/2016
Now after selecting the menu option Project, navigate to where you want your project to be created (At the University use your m: drive). The example below shows a project named About being created in the directory CI101. If you store a file on the c: drive then it will be stored on the machines local disk. This may/will be deleted immediately after your have logged out. It will not be available on any other machine at the University. M A Smith University of Brighton Page 4 04/10/2016
Now in the Project About create a new Class called Main. Then Select OK The name Main is used as a class name and by convention always starts with an upper case letter. M A Smith University of Brighton Page 5 04/10/2016
Double click on the Main icon (or right click on it and then select edit). Now replace the skeleton program code with the example program at (hyperlink): http://www.cem.brighton.ac.uk/staff/mas/mas/courses/ci101_2016/programs1/s00_about_01_java.html Make sure you only copy the program code and not also the header and footer text on the web page. Alternatively go to the web page http://www.cem.brighton.ac.uk/staff/mas Then follow the links courses -> CI101 -> Programs 1 The first program in week 1 is the program to copy and paste into BlueJ M A Smith University of Brighton Page 6 04/10/2016
You can indent the program code by selecting Auto-layout from the Edit menu. By indenting your program, you will find it easier to read/ follow and others will find it easier to read/ follow. The above shows how to indent your program. Many mistakes in a program are hidden by poor indentation. M A Smith University of Brighton Page 7 04/10/2016
Now compile the Java code. It should say Class compiled no syntax errors If it does not, then try to find the mistake or after about two minutes of looking ask for help. M A Smith University of Brighton Page 8 04/10/2016
To run the program, in the main window right click on Main and then select void main(string[] args). To the dialog box you now see click ok M A Smith University of Brighton Page 9 04/10/2016
The program will run and you will see the output on the screen. M A Smith University of Brighton Page 10 04/10/2016
Next, add some details about yourself to the above program. You will need to add the text you wish to output between the double "" in the program. If you want to add an extra line then just add another print statement (see below) System.out.println( "text to be added" ); Now re-compile the program and re-run. Next, add an extra fact about yourself to the program. Have the program print this as another fact about youself at the end. Now re-compile the program and re-run. Experiment by changing the initial value of the variable fact in the line int fact = 1; to a value other than 1. Now re-compile the program and re-run. M A Smith University of Brighton Page 11 04/10/2016
Try some of the other programs from week 1. http://www.cem.brighton.ac.uk/staff/mas/mas/courses/ci101_2016/programs1/index.html For example, the program s00_apples_02.java If you get the error message cannot fine symbol variable BIO. Then create a new class in the project called BIO and into this paste the code from, the top link (the last web page opened) for the BIO code. Now recompile and the error will go away. The reason for this is that your machine does not have the file BIO.jar included in the ext directory for the JDK and or JRE. Warning BlueJ will stop working (Endless loop), if you create the class BIO and the file BIO.jar exists in the JDK/ JRE ext directory. The only solution is to exit BlueJ and then outside of BlueJ delete the file for BIO in your BlueJ project. Now run this program. M A Smith University of Brighton Page 12 04/10/2016