Page | 1
Index
[Link] Pg no. Sign
Title
1 Acknowledgment 4
2 WAP to add two numbers 5
3 WAP to calculate area of circle 6
4 WAP to show that number is +ve or -ve (concept 7
of if-else )
5 WAP to find largest number from three(concept of 9-10
nested if)
6 WAP to make calculator using switch statement 11-12
7 WAP to print a table using for loop. 13
8 WAP to calculate area of rectangle with objects 14
9 WAP to show concept of Method Overloading at least 15
3 functions.
10 WAP to show concept of Method Overriding. 16
11 WAP to show concept of Method Overriding. 17
12 WAP to show concept of single Inheritance . 18-19
13 WAP to show concept of Multilevel Inheritance . 20-21
14 WAP to show concept of Hierarchical Inheritance 22-23
15 WAP to show the concept of constructor overloading 24-25
16 WAP to Implement abstract classes . 26-27
17 WAP to Implement Interfaces . 28
18 WAP to Implement Multiple Inheritance with 29
Interfaces
Page | 2
19 WAP to Concatenate Strings in JAVA 30
20 WAP to Show String Comrison in JAVA 31
21 WAP to Find Substring from a String in JAVA 32
22 WAP to Create and Import User Defined Package 33-35
23 Write a Java Program to to perform various operations 33-35
in MySQL database
24 WAP to show file reader and writer stream 36
25 WAP to show buffered input and output stream 37-38
Page |3
WAP to handle Arithmetic Exception
import [Link];
public class ArithmeticExceptionExample {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter the dividend: ");
int dividend = [Link]();
[Link]("Enter the divisor: ");
int divisor = [Link]();
try {
int result = dividend / divisor;
[Link]("Result: " + result);
} catch (ArithmeticException e) {
[Link]("Error: " + [Link]());
}
[Link]();
}
}
OUTPUT:
WAP to Handle Multiple Exception using Multiple Catch
Block
Page |4
public class MultipleCatchBlocksExample {
public static void main(String[] args) {
try {
int[] numbers = {1, 2, 3};
int index = 4;
int result = numbers[index];
[Link]("Result: " + result);
} catch (ArrayIndexOutOfBoundsException e) {
[Link]("Error: Array index out of bounds");
} catch (ArithmeticException e) {
[Link]("Error: Arithmetic exception occurred");
} catch (Exception e) {
[Link]("Error: An exception occurred");
}
}
}
OUTPUT:
WAP to Handle Multiple Exception using Throw Keyword
public class ThrowKeywordExample {
public static void main(String[] args) {
Page |5
try {
int age = -5;
validateAge(age);
[Link]("Age is valid");
} catch (IllegalArgumentException e) {
[Link]("Error: " + [Link]());
}
}
public static void validateAge(int age) {
if (age < 0) {
throw new IllegalArgumentException("Age cannot be negative");
}
}
}
OUTPUT:
WAP to Implement Super Keyword
class Animal {
String name;
Animal(String name) {
Page |6
[Link] = name;
}
void sound() {
[Link]("Animal makes a sound");
}
}
class Dog extends Animal {
String breed;
Dog(String name, String breed) {
super(name);
[Link] = breed;
}
void sound() {
[Link](); // calling the sound() method of the parent class
[Link]("Dog barks");
}
void display() {
[Link]("Name: " + [Link]); // accessing the name variable of the
parent class
[Link]("Breed: " + breed);
}
}
public class Main {
public static void main(String[] args) {
Dog myDog = new Dog("Buddy", "Labrador");
[Link]();
[Link]();
}
}
OUTPUT:
Page |7
WAP to show Multitasking using single thread
class Task1 implements Runnable {
public void run() {
for (int i = 1; i <= 5; i++) {
[Link]("Task 1 - Count: " + i);
}
}
}
Page |8
class Task2 implements Runnable {
public void run() {
for (int i = 1; i <= 5; i++) {
[Link]("Task 2 - Count: " + i);
}
}
}
class Main {
public static void main(String[] args) {
Thread t1 = new Thread(new Task1());
Thread t2 = new Thread(new Task2());
[Link]();
[Link]();
}
}
OUTPUT:
WAP to show Multitasking using Multiple Threads
class Task1 extends Thread {
public void run() {
for (int i = 1; i <= 5; i++) {
[Link]("Task 1 - Count: " + i);
}
}
}
Page |9
class Task2 extends Thread {
public void run() {
for (int i = 1; i <= 5; i++) {
[Link]("Task 2 - Count: " + i);
}
}
}
class Main {
public static void main(String[] args) {
Task1 t1 = new Task1();
Task2 t2 = new Task2();
[Link]();
[Link]();
}
}
OUTPUT: