Exercise – 1
-------------
1. Aim:
To write a simple Java program to display "Hello World".
2. Prerequisites:
Basics of Java programming, Java Development Kit (JDK) installation, and knowledge of compiling
and running a Java program.
3. Program:
class HelloWorld {
public static void main(String[] args) {
[Link]("Hello, World!");
}
}
4. Output:
Hello, World!
-----------------------------------------------------
Exercise – 2
-------------
1. Aim:
To demonstrate basic control structures in Java.
2. Prerequisites:
Understanding of conditional statements (if-else, switch) and loops (for, while, do-while).
3. Program:
class ControlDemo {
public static void main(String[] args) {
int num = 10;
if (num % 2 == 0)
[Link](num + " is Even");
else
[Link](num + " is Odd");
}
}
4. Output:
10 is Even
-----------------------------------------------------
Exercise – 3
-------------
1. Aim:
To implement classes and objects in Java.
2. Prerequisites:
Knowledge of Object-Oriented Programming concepts: classes, objects, and methods.
3. Program:
class Student {
String name;
int age;
void display() {
[Link]("Name: " + name + ", Age: " + age);
}
}
class StudentDemo {
public static void main(String[] args) {
Student s = new Student();
[Link] = "John";
[Link] = 20;
[Link]();
}
}
4. Output:
Name: John, Age: 20
-----------------------------------------------------
Exercise – 4
-------------
1. Aim:
To implement inheritance and polymorphism in Java.
2. Prerequisites:
Understanding of inheritance (superclass and subclass) and method overriding in OOP.
3. Program:
class Animal {
void sound() {
[Link]("Animal makes a sound");
}
}
class Dog extends Animal {
void sound() {
[Link]("Dog barks");
}
}
class InheritanceDemo {
public static void main(String[] args) {
Animal a = new Dog();
[Link]();
}
}
4. Output:
Dog barks