LAB MANUAL
LAB #03
Course Title: Programming Fundamentals LAB
Course Code: IT24-313
Topic: Variables and Data Types: Writing programs using primitive data types, variables,
and type conversions.
Instructor: Uzair Anees Bhutto | (IT) UMPK
Lab Objective: By the end of this lab, students will be able to:
1. Understand primitive data types in Java.
2. Learn how to declare and use variables.
3. Perform type conversions (implicit and explicit).
Technologies/Tools Required:
JDK (Java Development Kit): The software development environment for writing
Java applications.
Eclipse IDE: An integrated development environment for Java.
Step 1: Open the Existing Project
1. Launch Eclipse:
o Open Eclipse IDE on your computer / laptop.
2. Navigate to the ITPROGRAMMINGFUNDAMENTALS_LAB project in
the Package Explorer.
3. Right-click on the src folder, select New > Class.
4. Name the class lab03 and click Finish.
Step 2: Understanding Primitive Data Types
Primitive data types are the most basic data types in Java. They are predefined by the language
and used to store simple values. These data types are not objects and do not have methods.
They are the building blocks for creating more complex data structures in Java.
Java has 8 primitive data types:
o Integer types: byte, short, int, long
o Floating-point types: float, double
o Character type: char
o Boolean type: boolean
Step 3: Declaring Variables
Variables are containers for storing data. To declare a variable:
dataType variableName = value;
Example:
int age = 20;
double salary = 1500.50;
char grade = 'A';
boolean isJavaFun = true;
Step 4: Writing the Program
1. Open the lab03.java file.
2. Write the following code:
public class lab03 {
public static void main(String[] args) {
// Step 1: Declare variables of different primitive data
types
byte myByte = 100;
short myShort = 5000;
int myInt = 100000;
long myLong = 15000000000L;
float myFloat = 5.75f;
double myDouble = 19.99;
char myChar = 'D';
boolean myBoolean = true;
// Step 2: Print the values of the variables
System.out.println("byte: " + myByte);
System.out.println("short: " + myShort);
System.out.println("int: " + myInt);
System.out.println("long: " + myLong);
System.out.println("float: " + myFloat);
System.out.println("double: " + myDouble);
System.out.println("char: " + myChar);
System.out.println("boolean: " + myBoolean);
// Step 3: Perform type conversion
int newInt = (int) myDouble; // Explicit conversion
(double to int)
double newDouble = myInt; // Implicit conversion (int
to double)
System.out.println("Converted int from double: " +
newInt);
System.out.println("Converted double from int: " +
newDouble);
}
}
Step 5: Running the Program
1. Save the file (Ctrl + S).
2. Right-click on the lab03.java file in the Package Explorer.
3. Select Run As > Java Application.
4. Observe the output in the Console window.
Step 6: Expected Output
byte: 100
short: 5000
int: 100000
long: 15000000000
float: 5.75
double: 19.99
char: D
boolean: true
Converted int from double: 19
Converted double from int: 100000.0
Conclusion: This lab introduced the concept of primitive data types, variable declaration, and
type conversions in Java, providing a foundation for writing basic programs.
"Just like every data type has its purpose; every step you take in learning brings you closer to
mastering the art of programming!"