Q1-Write a Java program to print 'Hello' on screen and your name in separate line
Output
Ques-2 Write a Program to check whether a year is Leap Year or not
Output
2024 is a leap year.
Ques-3 Write a program to display the given pattern using nested Loop
**
***
****
Output
Q-4 Write a program in java to Compute the sum of the digits of an integer using
user defined method
Q 5 Write a program to find maximum and minimum number from an array
Q-6 Write a program declaring a class Rectangle with data member’s length and Breadth and member
functions Input, Output and CalcArea
Output
Length-5
Breadth-3
Area=15
Q7 Write a program to demonstrate the use of static variable, static method and static block
Output
Q8 Write a program in java to implement constructor using parameter
Output
Q-9 Write a program to demonstrate use of method overloading to calculate area of square, rectangle
and triangle
Output
Ques 10 Write a program to use super() to invoke base class constructor.
Output
Q11 Write a program to demonstrate the concept of abstract class with constructor and ``final`` method
Output
Q12 Write a Java program to create an interface Shape with the getArea() method. Create three classes
Rectangle, Circle, and Triangle that implement the Shape interface. Implement the getArea() method for
each of the three classes.
class Shape {
double getArea();
class Rectangle implements Shape {
double length, width;
Rectangle(double length, double width) {
this.length = length;
this.width = width;
public double getArea() {
return length * width;
class Circle implements Shape {
double radius;
Circle(double radius) {
this.radius = radius;
public double getArea() {
return Math.PI * radius * radius;
class Triangle implements Shape {
double base, height;
Triangle double base, double height) {
this.base = base;
this.height = height;
public double getArea() {
return 0.5 * base * height;
public class Main {
public static void main(String[] args) {
Shape rect = new Rectangle(5, 3);
Shape circle = new Circle(4);
Shape triangle = new Triangle(6, 2);
System.out.println("Rectangle Area: " + rect.getArea());
System.out.println("Circle Area: " + circle.getArea());
System.out.println("Triangle Area: " + triangle.getArea());
Output
Rectangle Area: 15.0
Circle Area: 50.26548245743669
Triangle Area: 6.0
Q13 Write a Program to create user define package and then import the package
1. . Create a package named mypackage
// File: mypackage/MyClass.java
package mypackage;
public class MyClass {
public void displayMessage() {
System.out.println("Hello from MyClass in mypackage!");
}
2. Create a main program that imports the package
// File: Main.java
import mypackage.MyClass;
public class Main {
public static void main(String[] args) {
MyClass obj = new MyClass();
obj.displayMessage();
Output
Hello from MyClass in mypackage!
Q14 Write a Java program to get a list of all file/directory names in the given directory
Output
Q-15 Write a Java program to read input from the Java console
Output
Q-16 Write a Java program to create a method that reads a file and throws an exception if the file is not
found.
Output
Q17 Write a Java program to throws user define exception
Output
Q18 Write a Java program that reads a list of integers from the user and throws an exception if any
numbers are duplicates
import java.util.*;
class DuplicateNumberException extends Exception {
public DuplicateNumberException(String message) {
super(message);
public class DuplicateChecker {
public static void checkForDuplicates(List<Integer> numbers) throws DuplicateNumberException {
Set<Integer> uniqueNumbers = new HashSet<>();
for (int num : numbers) {
if (!uniqueNumbers.add(num)) {
throw new DuplicateNumberException("Duplicate number found: " + num);
System.out.println("All numbers are unique.");
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<Integer> numberList = new ArrayList<>();
System.out.print("Enter how many numbers: ");
int count = sc.nextInt();
System.out.println("Enter " + count + " numbers:");
for (int i = 0; i < count; i++) {
numberList.add(sc.nextInt());
try {
checkForDuplicates(numberList);
} catch (DuplicateNumberException e) {
System.out.println("Error: " + e.getMessage());
sc.close();
Output
Q19 Write a Java program to create a basic Java thread that prints "Hello, World!" when executed
Output
Q20 Write a Java program to create multi threading that prints message when executed
Output