Professional Documents
Culture Documents
Objective
At the end of this lab, the student is able to: Install a Java compiler
Compile and Debug Java programs
Run Java programs
3.
4.
Double click on the JDK folder. You should be able to see a bin folder. Copy the location of the bin
folder and paste it on the notepad. Example : C:\Program Files\Java\jdk1.8.0_25\bin. You need to set
the environment variables to enable you to compile anywhere in your computer.
Go to Control Panel and double click on System icon. A System Properties window will appear on your
screen as shown in Figure 1.
5.
Go to Advanced tab and click on the Environment Variables button as shown in Figure 2. Environment
Variable window will be shown on your screen as depicted in Figure 3.
Click here
Click on PATH variable in User Variable section and click Edit. Edit User Variable will appear on your
screen as show in Figure 4.
7.
Add the full path of java bin location at the end of variable value as shown in Figure 5. Example : ;
C:\Program Files\Java\jdk1.6.0_05\bin;. Then, Click OK.
10. If you get the following message as shown in Figure 7, you have successfully installed a Java compiler.
^
1 error
Description of error
Total error
Figure 11 : Description of Error
Exercises
Exercise 1
1. Compile Greeting.java from Lab1/Exe1.
2. You will get the following compile error.
Greeting.java:11: class greeting is public, should be declared in a file named greeting.java
public class greeting {
^
1 error
3. Fix the error and re-compile Greeting.java. The program shall produce Greeting.class.
4. Run class Greeting. The program shall produce Welcome to Java on console.
Exercise 2
1. Compile Greeting.java from Lab1/Exe2.
2. The program will produce several errors.
3. Fix the errors and re-compile Greeting.java. The program shall produce Greeting.class.
4. Run class Greeting. The program shall produce Java is Cool on console.
Exercise 3
1. Compile Greeting.java from Lab1/Exe3.
2. The program will produce several errors.
3. Fix the errors and re-compile Greeting.java. The program shall produce Greeting.class.
4. Run class Greeting. The program shall produce I LOVE JAVA PROGRAMMING on console.
Exercise 4
1. Compile Greeting.java from Lab1/Exe4.
2. The program will produce several errors.
3. Run class Greeting. The program shall produce runtime error message.
4. Fix the error and re-compile Greeting.java. The program shall produce Greeting.class.
5. Run class Greeting. The program shall produce Eat. Drink. Sleep. Drink. Java on console.
Exercise 5
1. Compile Greeting.java from Lab1/Exe5.
2. The program will produce an error.
3. Fix the error and re-compile Greeting.java. The program shall produce Greeting.class.
4. Run class Greeting. The program shall produce Java Rules on console.
Exercise 6
1. Compile MyClass.java from Lab1/Exe6.
2. The program will produce several errors.
3. Fix the errors and re-compile MyClass.java. The program shall produce MyClass.class.
4. Run class Greeting. The program shall produce Congratulation!!! Youve made it!!! on console.
Exercise 7
1. Run class DemoClass from Lab1/Exe7.
2. The program shall produce Your journey mastering Java begins now on console.
Exercise 8
1. Compile DemoClass.java from Lab1/Exe8.
2. The program will produce several errors.
3. Fix the errors and re-compile DemoClass.java. The program shall produce DemoClass.class.
4.
Run class Greeting. The program shall produce Its a rough ride ahead. Brace yourself!!! on console.
Exercise 9
1. Compile DemoClass.java from Lab1/Exe9.
2. The program will produce several errors.
3. Fix the errors and re-compile DemoClass.java. The program shall produce DemoClass.class.
4. Run class Greeting. The program shall produce I come, I see, I conquer on console.
Exercise 10
1. Compile DemoClass.java from Lab1/Exe10.
2. The program will produce several errors.
3. Fix the errors and re-compile DemoClass.java. The program shall produce DemoClass.class.
4. Run class Greeting. The program shall produce
+-------+
| SPAIN |
+-------+
on console.
Exercise 11
1. Compile WorldClass.java from Lab1/Exe11. The program shall produce DemoClass.class.
2. Run class WorldClass. The program produce a runtime error.
3. Fix the errors and re-compile WorldClass.java.
4. Run class WorldClass. The program shall produce ITS A FLAT WORLD on console.