Final Lab Sheet: Introduction to Java Programming

Lab Practical 1: Introduction to Java Programming
Objective: Write a simple Java program to print "Hello, World!" and compile/run it using the command line.
Task:
Write a Java program that prints
"Hello, World!".Compile and run it using
javacandjavacommands.Modify the program to print your name in the next line.
Lab Practical 2: Using an IDE (IntelliJ/Eclipse)
Objective: Familiarise with an IDE by creating and running a Java project.
Task:
Create a new Java project in IntelliJ/Eclipse.
Write a program that calculates the sum of two numbers (5 and 7) and prints the result.
Debug the program by setting a breakpoint and inspecting variables.
Lab Practical 3: Variables and Data Types
Objective: Demonstrate understanding of Java variables and data types.
Task:
Declare variables to store:
Your age (
int),Your height in meters (
double),Your first initial (
char),Whether you are a student (
boolean).
Print all variables with descriptive messages (e.g.,
"My age is 20").
Lab Practical 4: Expressions and Operators
Objective: Use arithmetic and logical operators in Java.
Task:
Write a program that calculates the area of a rectangle (length = 5.5, width = 3.2).
Check if a number (input) is even or odd using the modulus operator.
Swap two numbers without a temporary variable.
Lab Practical 5: Control Statements (If-Else, Switch)
Objective: Implement decision-making in Java.
Task:
Write a program that checks if a number is positive, negative, or zero.
Use a
switchstatement to print the day of the week based on a number (1-7).Determine the largest of three numbers using nested
if-else.
Lab Practical 6: Loops (For, While, Do-While)
Objective: Use loops for repetitive tasks.
Task:
Print numbers from 1 to 10 using a
forloop.Calculate the factorial of a number (e.g., 5! = 120) using a
whileloop.Print all even numbers between 1 and 20 using a
do-whileloop.
Lab Practical 7: Arrays
Objective: Work with single and multi-dimensional arrays.
Task:
Create an array of 5 integers and find the sum of all elements.
Find the largest number in an array.
Transpose a 2x3 matrix (hardcoded values).
Lab Practical 8: Methods and Parameter Passing
Objective: Write reusable methods in Java.
Task:
Create a method
isPrime()that checks if a number is prime.Write a method
calculateCircleArea()that takes radius as input and returns the area.Overload a method
print()to acceptint,String, anddoubleparameters.
Lab Practical 9: Exception Handling
Objective: Handle runtime errors using try-catch blocks.
Task:
Write a program that divides two numbers and handles
ArithmeticException.Use
try-catchto handleArrayIndexOutOfBoundsExceptionwhen accessing an array.Throw a custom exception if a user enters a negative number.
Lab Practical 10: Classes and Objects
Objective: Implement OOP concepts in Java.
Task:
Create a
Studentclass with fields (name,rollNo,grade) and methods to display details.Add a constructor to initialize the object.
Use access modifiers (
private,public) and provide getter/setter methods.




