We shall now use the BlueJ IDE to develop a simple Java program to say ‘Hello’.
NB: Java is case sensitive
In BlueJ select: Project – New Project. Create a project ‘Summer project’ in a suitable location - Create – New Class – type HelloWorld for class name - Ok.
Double click to type code
Double click the HelloWorld class to open the code edit window (or right click – Open Editor).
Java multi line comment
Java single line comments start with //
Don’t worry about this line – just that it is needed for now
Delete all the example code and type in the HelloWorld code as shown below, but with your own name after author (and not anything in the dashed rectangles which are notes to help you).
Note:
Java comments do not affect how a program runs but are used to help a programmer
Indent code to help readability (does not affect compilation / execution): use Edit - Auto-layout
Semi colon ; curly brackets {, } round brackets (, ) and square brackets [, ] must be used correctly and are NOT interchangeable.
To see line numbers (in the code editor): Options – preferences – display line numbers.
BlueJ reference site: http://www.bluej.org/
Click compile (you should get ‘Class compiled - no syntax errors’ - otherwise check lines 5 to 11 are correctly typed – Java is case sensitive, and remember curly brackets and semicolon – Java is fussy!
Close the editor.
Right click the HelloWorld class
Select void main(String[] args)
Select Ok
The terminal window should contain “Hello World!” as output as shown:
{Note:
It is possible to write Java using a normal text editor, and compile and run java programs using the Java SDK without need for an IDE such as BlueJ by using the command line interface. You are not required to do so, but if you are interested to do this, see Chortle chapter 7 or YouTube tutorial 2 running Java: http://www.youtube.com/watch?v=5u8rFbpdvds&feature=fvwrel.}
youTube reference links for installing BlueJ and a HelloWorld program, zaychenok Java Lesson 1&2:
http://www.youtube.com/watch?v=aqQefkprf3s, http://www.youtube.com/watch?v=l9nHHCgXBMk&feature=related
Now you are ready to start work. Allow at least 12 hours to complete the work that follows.
Share with your friends: |