St Brendan’s as computer Science Summer task Summer 2016 St Brendan’s Computer Science Summer task



Download 1.82 Mb.
Page7/10
Date28.05.2018
Size1.82 Mb.
#51383
1   2   3   4   5   6   7   8   9   10









2 Simple program using BlueJ


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 //

Class name must be exactly the same as file name

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.




Download 1.82 Mb.

Share with your friends:
1   2   3   4   5   6   7   8   9   10




The database is protected by copyright ©ininet.org 2024
send message

    Main page