0% found this document useful (0 votes)
2 views9 pages

Lab 01 - Understanding and Running Basic Java Program

This lab manual provides an introduction to Java programming using Eclipse IDE, covering installation of JDK, writing and running basic Java programs, and understanding the structure of Java code. Students will learn to create projects, write simple programs, and execute them while completing various tasks to reinforce their understanding. The manual outlines specific tasks that involve printing outputs, variable manipulation, and using different print methods.

Uploaded by

mn552598
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

Lab 01 - Understanding and Running Basic Java Program

This lab manual provides an introduction to Java programming using Eclipse IDE, covering installation of JDK, writing and running basic Java programs, and understanding the structure of Java code. Students will learn to create projects, write simple programs, and execute them while completing various tasks to reinforce their understanding. The manual outlines specific tasks that involve printing outputs, variable manipulation, and using different print methods.

Uploaded by

mn552598
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

2ndSemester Lab-01: Understanding and Running Basic Java Program

Lab Manual

OOP

Dr. M. Bilal Shahnawaz Lab-01 1


2ndSemester Lab-01: Understanding and Running Basic Java Program

Laboratory 01: Introduction to Eclipse, Writing Java programs, Basic


Programming Structure of Java
Lab Objectives: After this lab, the students should be able to

1. Install JDK
2. Become familiar with the Eclipse Integrated Development Environment (IDE)
3. Write and run simple Java Programs
4. Understand the basic structure of a Java program

Software Development Kit (SDK) that contains the following:

Libraries: also known as Application Programming Interface (API), these files are
previously written classes and methods that contain some common functionality.

Compiler: the program that translates files written in Java language (human language) into
binary files (machine language) in order to execute them.

Interpreter: Some programming languages do not compile the source code file into directly
executable form (native code), but they instead compile it into partially compiled file that
could be executed by a program called interpreter.

Java Programming Language:

Java programming language is an interpreted programming language, that is, when the source
code is compiled into binary file, it needs an interpreter called Java Virtual Machine (JVM) to
run it. Java compiler is called [Link], and interpreter is called [Link].

The Figure below shows a complete path of running Java programs.

1. JDK INSTALLATION:

For compiling and running java programs we need to install JDK.

A JDK distribution consists of a JRE distribution (a Java Virtual Machine implementation)


plus a collection of development tools including javac: a Java compiler, and javadoc: Java
documentation generator.

Dr. M. Bilal Shahnawaz Lab-01 1


2ndSemester Lab-01: Understanding and Running Basic Java Program

DOWNLOADING JDK 7:

Follow the steps for downloading jdk from net.

 Go to this link and download latest JDK (Java SE Development Kit 17).
[Link]

 Click on the exe file and it will start downloading.

 After downloading, double click the jdk icon to start installation process.
INSTALLATION STEPS:

 Click NEXT to move ahead.

 Click NEXT
 Now JRE will start installing.

Dr. M. Bilal Shahnawaz Lab-01 2


2ndSemester Lab-01: Understanding and Running Basic Java Program

 Click close button to end installation process.

 Now you can create, compile and run java programs.

Note: For Lab, JDK will be provided to you to install in the system or you can directly
download if internet is available.

2. Eclipse:

Eclipse is an integrated development environment used in computer programming. A popular


IDE simplifies Java development by providing a user-friendly environment.

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.

Dr. M. Bilal Shahnawaz Lab-01 3


2ndSemester Lab-01: Understanding and Running Basic Java Program

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-01 4


2ndSemester Lab-01: Understanding and Running Basic Java Program

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.

Dr. M. Bilal Shahnawaz Lab-01 5


2ndSemester Lab-01: Understanding and Running Basic Java Program

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
[Link](" Welcome to java world ! ");//println()
displays the string which is passed to it.
}

LAB TASKS:
Task 1:

Write a code to print your name and roll number.

Task 2:

Can we save this code with some other name like [Link] rather than with the class
name? Try it.

class FirstProgram
{
public static void main(String abc[])
{
[Link]("My first Java Program");
}
}

Task 3:

Run the following code and see the result.

Run the following programs. Observe the output. Focus on comments to enhance the
understandability.

class Program2 {
public static void main(String args[]) {
int a,b,c; //this statement declares three variables a, b and c.
a=2;
b=3;
c=a+b;
[Link]("Sum of two numbers = "+c); }
}

Dr. M. Bilal Shahnawaz Lab-01 6


2ndSemester Lab-01: Understanding and Running Basic Java Program

Task 4:

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.
[Link]("Which one is your favourite programming language?");
[Link]("java");

2.
[Link]("Which one is your favourite programming language?");
[Link]("java");
[Link]("java");

3.
[Link]("Which\n one\n is\n your\n favourite\n programming\n language?");
[Link]("java");

Task 5:

Calculate the average, sum & difference of 876 &767. First store these values in variables
and then calculate the result.

Task 6:

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

Task 7:

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-01 7

You might also like