0% found this document useful (0 votes)
28 views

Lab 02

The document discusses how to create and run simple Java programs in the Eclipse IDE. It provides instructions on starting a new Java project in Eclipse, creating a class, and writing and running sample code. It also lists tasks for students to create Java programs that compare print and println methods, perform basic math calculations, and demonstrate variable assignment.

Uploaded by

shagufta yaseen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Lab 02

The document discusses how to create and run simple Java programs in the Eclipse IDE. It provides instructions on starting a new Java project in Eclipse, creating a class, and writing and running sample code. It also lists tasks for students to create Java programs that compare print and println methods, perform basic math calculations, and demonstrate variable assignment.

Uploaded by

shagufta yaseen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

NUML

2nd Lab-02: Creating &Running Java Programs in Eclipse


Semeste

Lab Manual

OOP

Dr. M. Bilal Shahnawaz Lab-02 1


2nd Lab-02: Creating &Running Java Programs in Eclipse
Semeste

Laboratory 02: Creating &Running Simple Java Programs in


Eclipse
Lab Objectives: After this lab, the students should be able to

1. Use the Eclipse IDE for Java programs development


2. Run simple Java Programs (provided in manual) in Eclipse
3. Create simple Java programs in Eclipse

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

Dr. M. Bilal Shahnawaz Lab-02 1


2nd Lab-02: Creating &Running Java Programs in Eclipse
Semeste

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.

Dr. M. Bilal Shahnawaz Lab-02 2


2nd Lab-02: Creating &Running Java Programs in Eclipse
Semeste

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.

2. Run the following codes in Eclipse and see the result.

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");

Dr. M. Bilal Shahnawaz Lab-02 3


2nd Lab-02: Creating &Running Java Programs in Eclipse
Semeste
2.
System.out.println("Which one is your favourite programming language?");
System.out.print("java");
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:

Calculate the area of circle when radius is 9.8 cm. (A=πr2)

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.

Dr. M. Bilal Shahnawaz Lab-02 4

You might also like