Lab 02
Lab 02
Lab Manual
OOP
Note: Eclipse also needs jdk. The jdk 17 which was installed in previous lab can be used.
1. Introduction to Eclipse: To write code and make class you have to create a new
project in eclipse. On main menu FILE > NEW > Java Project. You will see this
window.
Click finish. A project is created with the name Lab1 in the left tab of eclipse. Now create a
class. Right click on project name and select NEW > Class
Write the name of your class like firstProgram, check the first box and then click on Finish.
Now you will also see the class named firstProgram in the project named Lab1. You can now
see the Editor where you can write your code.
Now start writing your code as you use to write in notepad. After writing your code you will
go in to RUN on the main menu. Press this button and you will see the output below.
Run the following programs. Observe the output. Focus on comments to enhance the
understandability.
Program1:
public class firstProgram {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(" Welcome to java world ! ");//println()
displays the string which is passed to it.
}
LAB TASKS
Task 1:
Create a Java program and write the following statements one by one to find the
difference between print() and println() methods. Closely examine how the outputs
differ.
1.
System.out.println("Which one is your favourite programming language?");
System.out.print("java");
3.
System.out.println("Which\n one\n is\n your\n favourite\n programming\n language?");
System.out.println("java");
Task 2:
Calculate the average, sum & difference of 876 &767. First store these values in variables
and then calculate the result.
Task 3:
Task 4:
Write a program to declare three variables; a, b, and c. Assign some values to a and b and save
their sum in variable c. Now, print the sum.