|
home—info—labs—hws—exams
textbook—java.lang docs—java.util docs—archive
Today we will learn how to type in a Java program using BlueJ, and how to call the program once it's been typed in.
BlueJ is an “Integrated Development Environment” for Java -- a fancy way of saying, a program which lets you write your own Java programs. BlueJ is installed in the Davis Hall labs (1st and 2nd floors), and the basement of Stuart Hall, although not other labs. If you want to download and run BlueJ on your own computer (it's free!), it is an easy install from BlueJ.org; here are some additional tips.
On your H: drive, make a folder to keep all your ITEC120 work in.
Do all your ITEC120
work on your H: drive.
Even if you live off-campus, you can access your H: drive
(by first running VPN on your computer; see a PI for advice).
Not only does this keep you from accumulating multiple versions
of your homework or lab work on different computers,
but you can pull up your homework in a professor's office hours,
no problem (and they can verify the date your file was last modified,
should that ever be an issue).
To evaluate expressions written in Java:
/** * * @author Ian Barland * @version 2008.Jan.10 */ class HelloTester { /** Change some pixels on the console-window. * No value is returned. */ public static void main( String[] args ) { System.out.println( "Hello, World!" ); } } /* Even though it looks like there are a lot of magic words * (like 'static' and 'String[]' and ...), in the above program, * we will ignore those. * The hard part of programming has nothing to do with those. * Really. */ |
Once you have done this, you can check for superficial errors by pressing "compile".
Return to the BlueJ's main window (the one you saw first, with the codepad in the lower-right). Right-click (mac users: control-click) on the tan “PizzaServer” box. Choose the very second option, void main( String[] ). BlueJ will pop up a box; press Ok (leaving { } in the text-box1).
You should see a window pop up (named something like BlueJ: Terminal Window - lab01a-hello-world), with your message printed inside of it!
Math.sqrt(2*8); |
Gotcha: When typing into BlueJ's code pad, do not put a semicolon at the end of an expression. If you ever type in something and don't get any answer at all, double-check that you don't have a semicolon.
After having done this, take a few moments to explore BlueJ -- look at the menus, right-click on various items and look at all the choices, etc..
1 the { } is an array of no Strings at all -- the program main needs to be handed an array of Strings before it can run (the String[] mentioned in the program); that's why we have to provide some array of Strings, and { } is the simplest one there is. Sound complicated? That's only because there is a lot of overhead/scaffolding for making any Java program (even this simple one). By week 11 the semester, this all will be clear. ↩
2Technically, the semicolon turns the expression (which has a value) into a statment — which is an expression which doesn't yield an answer!(?). ↩
home—info—labs—hws—exams
textbook—java.lang docs—java.util docs—archive
©2008, Ian Barland, Radford University Last modified 2008.Aug.31 (Sun) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |