Free University of Bolzano/Bozen
Faculty of Computer Science - Bachelor in Applied Computer Science
Bachelor in Production Engineering
Introduction to Programming - A.A. 2006/2007

Exercise 1

Access to the lab PCs and to the Java development environment

1. Turn on the PC

When you turn the PC on, it will start loading the operating system. The lab PCs use MS Windows as well as Linux. You might want to choose MS Windows.

After MS Windows has been loaded you will see a message window prompting you to log into the system. To log in, you need to press together three keys: CTRL, ALT and DELETE. Note that on the german keyboard layout these are labeled STRG, ALT and ENTF - on the italian keyboard layout they're labeled CTRL, ALT and CANC.

After pressing CTRL, ALT and DELETE, give your username and password to log in. Choose the unibz domain to access your data from any one of the lab PCs.

To shut the PC down click Start on the MS Windows task bar on the lower left corner and select log off. After that, you can choose to shut down the PC or just to log out.

2. Access to the course web site

The course web site is online at http://www.inf.unibz.it/~calvanese/teaching/ip/.

To access the web site you need to start a web browser application. You can use Firefox or Internet Explorer. Find them in the Start menu or just click the corresponding icons on your desktop!

Once the browser is running, just enter the above web site address in its location bar. Navigate the web site simply by using the mouse and clicking the links you find interesting.

To save Java programs from the web site, right-click the link to the program and select save link target as (or similar, depending on which browser you're using). Choose the folder you want to save the file into and click ok.
Try it out with Program1.java.

3. Edit, compile and run a Java program

It is possible to edit, compile and run a Java program on any operating system (including Windows) by using just the Java command-line compiler + interpreter (JDK), without the need for additional development environments.

To do that on MS Windows you can use any text editor (Notepad, WordPad, etc.) to write the program code. Once the code is written, save it as a plain text giving the file the same name as the class your defining plus the extension .java. For instance, a file holding the class Program1 must be saved as Program1.java.

To compile a program file (regardless whether it's one written by you or one saved from the course web site) run the command prompt. You can find it on your desktop or in the menu under Start -> Programs -> Accessories.

At the command prompt change to the directory (aka folder) where your saved file is. For example if you've saved the file in Programs\Java\ on the E: hard disk, you need to digit the following commands to change to that directory (cd is for change directory):

> e:
> cd \Programs\Java
Next, use the command javac (Java compiler) to compile the file:
> javac Program1.java
If there is no error message, the program has been successfully compiled and a file called Program1.class has been generated. If there have been compilation errors, javac will show them and you need to go back correcting the errors with the text editor.

To run the Java program use the command java (Java interpreter):

> java Program1
Please note you must not give the extension .class and Java names are case sensitive. If, for instance, the name of the class is Program1 the command java program1 will throw an error.

4. Using a development environment

Open the BlueJ development environment and write a Java program inside the editor window. Note that some Java instructions have already been filled in by BlueJ. Following is an example program (Program1.java):
public class Program1 {
   public static void main(String[] args)  {
      System.out.println("Welcome To Java!");
   }
}

A few tips:

Common operations performed in a development environment:

Exercise 1

Download the file Exercise1.java and save it. Run the BlueJ development environment, open Exercise1.java and compile it. The program contains errors. Fix all the errors in order to obtain a correct program. When you're done, run the program.

Solution

Exercise 2 (optional)

  1. Modify the program file from the preceding exercise: given the String object " Hello ", print it in upper case and without leading and trailing spaces by using methods from the String class.
  2. Modify the program again so as to print the concatenation of the previously obtained String object with the object obtained from the " World! " String object, also in upper case and without leading and trailing spaces (see http://www.wikipedia.org/wiki/Hello_world).

Solution


Back to exercise groups
Last modified: Wednesday, 11-Oct-2006 4:19:44 CEST