Skip to main content

Command Palette

Search for a command to run...

Final Lab Sheet: Introduction to Java Programming

Published
3 min readView as Markdown
Final Lab Sheet: Introduction to Java Programming
A
I co-founded🫆digizen (fighting internet chaos 🧠), building an AI app to tackle misinformation, and running ideaGeek to turn “I have an idea” into real startups. I also share tech + travel on YouTube (TechNomad & Rz Omar). I touch grass too 🌱… but mostly to debug life 💻

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:

  1. Write a Java program that prints "Hello, World!".

  2. Compile and run it using javac and java commands.

  3. 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:

  1. Create a new Java project in IntelliJ/Eclipse.

  2. Write a program that calculates the sum of two numbers (5 and 7) and prints the result.

  3. 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:

  1. Declare variables to store:

    • Your age (int),

    • Your height in meters (double),

    • Your first initial (char),

    • Whether you are a student (boolean).

  2. 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:

  1. Write a program that calculates the area of a rectangle (length = 5.5, width = 3.2).

  2. Check if a number (input) is even or odd using the modulus operator.

  3. Swap two numbers without a temporary variable.


Lab Practical 5: Control Statements (If-Else, Switch)

Objective: Implement decision-making in Java.
Task:

  1. Write a program that checks if a number is positive, negative, or zero.

  2. Use a switch statement to print the day of the week based on a number (1-7).

  3. 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:

  1. Print numbers from 1 to 10 using a for loop.

  2. Calculate the factorial of a number (e.g., 5! = 120) using a while loop.

  3. Print all even numbers between 1 and 20 using a do-while loop.


Lab Practical 7: Arrays

Objective: Work with single and multi-dimensional arrays.
Task:

  1. Create an array of 5 integers and find the sum of all elements.

  2. Find the largest number in an array.

  3. Transpose a 2x3 matrix (hardcoded values).


Lab Practical 8: Methods and Parameter Passing

Objective: Write reusable methods in Java.
Task:

  1. Create a method isPrime() that checks if a number is prime.

  2. Write a method calculateCircleArea() that takes radius as input and returns the area.

  3. Overload a method print() to accept int, String, and double parameters.


Lab Practical 9: Exception Handling

Objective: Handle runtime errors using try-catch blocks.
Task:

  1. Write a program that divides two numbers and handles ArithmeticException.

  2. Use try-catch to handle ArrayIndexOutOfBoundsException when accessing an array.

  3. Throw a custom exception if a user enters a negative number.


Lab Practical 10: Classes and Objects

Objective: Implement OOP concepts in Java.
Task:

  1. Create a Student class with fields (name, rollNo, grade) and methods to display details.

  2. Add a constructor to initialize the object.

  3. Use access modifiers (private, public) and provide getter/setter methods.

More from this blog

T

TechNomad

46 posts

TechNomad is mostly coding exercises, not long boring explanations 😌. I share what I teach and learn through hands-on problems—mainly for my students, but anyone can jump in. If you learn by doing (and breaking things), you’ll fit right in. Less theory, more “try this and see what happens.”