1. Create a Java program that demonstrates the concept of classes and objects by modeling dogs with different names and breeds //Classes and Objects class Dog { String name; // Attribute String breed; // Attribute // Method void bark() { System.out.println(name + " barks!"); } } public class Main { public static void main(String[] args) { Dog myDog = new Dog(); // Creating an object named myDog myDog.name = "Buddy"; // Setting attribute values myDog.breed = "Golden Retriever"; Dog anotherDog = new Dog(); // Creating another object anotherDog.name = "Lucy"; anotherDog.breed = "Labrador"; // Calling methods on objects myDog.bark(); anotherDog.bark(); } } 2. Write a Java program using BufferedReader to read a string, an integer, a float, and a boolean value from the user and display them. import java.io.*; class Main { public static void main(String[] args)throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter name"); String a=br.readLine(); System.out.println("enter Integer No"); int i=Integer.parseInt(br.readLine()); System.out.println("enter Float No"); float f=Float.parseFloat(br.readLine()); System.out.println("enter boolean value"); boolean b=Boolean.parseBoolean(br.readLine()); System.out.println(a); System.out.println(i); System.out.println(f); System.out.println(b); } } 3. Write a Java program to demonstrate data abstraction using an abstract class and subclasses //Data Abstraction abstract class Animal { // Abstract method (does not have a body) public abstract void makeSound(); // Regular method public void sleep() { System.out.println("Zzz..."); } } // Subclass (inherited from Animal) class Dog extends Animal { @Override public void makeSound() { System.out.println("Woof"); } } // Subclass (inherited from Animal) class Cat extends Animal { @Override public void makeSound() { System.out.println("Meow"); } } // Use the abstract class class Main { public static void main(String[] args) { Animal dog = new Dog(); Animal cat = new Cat(); dog.makeSound(); // Output: Woof dog.sleep(); // Output: Zzz... cat.makeSound(); // Output: Meow cat.sleep(); // Output: Zzz... } } 4. Write a Java program to calculate the area of a rectangle using the concept of encapsulation. // ENCAPSULATION class Area { // fields to calculate area int length; int breadth; // constructor to initialize values Area(int length, int breadth) { this.length = length; this.breadth = breadth; } // method to calculate area public void getArea() { int area = length * breadth; System.out.println("Area: " + area); } } class Main { public static void main(String[] args) { // create object of Area // pass value of length and breadth Area rectangle = new Area(5, 6); rectangle.getArea(); } } 5. Write a Java program to demonstrate polymorphism by creating a superclass Polygon and its subclasses Square and Circle, each having their own implementation of the render() method. //Polymorphism class Polygon { // method to render a shape public void render() { System.out.println("Rendering Polygon..."); } } class Square extends Polygon { // renders Square public void render() { System.out.println("Rendering Square..."); } } class Circle extends Polygon { // renders circle public void render() { System.out.println("Rendering Circle..."); } } class Main { public static void main(String[] args) { // create an object of Square Square s1 = new Square(); s1.render(); // create an object of Circle Circle c1 = new Circle(); c1.render(); } } 6. Write a Java program using the Scanner class to read an integer and a string from the user and display them together in a formatted message. import java.util.Scanner; public class ScannerDemo { public static void main(String args[]) { Scanner scanner = new Scanner(System.in); System.out.println("Enter a number:"); int a = scanner.nextInt(); System.out.println("Enter your name:"); String nm=scanner.next(); System.out.printf(nm + " you entered : " + a); } } 7. Write a Java program to demonstrate inheritance. //Inheritance class Animal { void eat() { System.out.println("Animal is eating"); } } // Subclass class Dog extends Animal { void bark() { System.out.println("Dog is barking"); } } public class Main { public static void main(String[] args) { Dog myDog = new Dog(); myDog.eat(); // Output: Animal is eating myDog.bark(); // Output: Dog is barking } } 8. Write a Java program to demonstrate the use of both parameterized and default constructors. public class Main { int num1; int num2; // Creating parameterized constructor Main(int a, int b) { num1 = a; num2 = b; } public static void main(String[] args) { // Creating two objects by passing the values // to initialize the attributes. // parameterized constructor will invoke Main obj1 = new Main(10, 20); Main obj2 = new Main(100, 200); // Printing the objects values System.out.println("obj1"); System.out.println("num1 : " + obj1.num1); System.out.println("num2 : " + obj1.num2); System.out.println("obj2"); System.out.println("num1 : " + obj2.num1); System.out.println("num2 : " + obj2.num2); } } 9. Write a Java program to demonstrate multiple inheritance in Java using interfaces. public class Tester{ public static void main(String[] args){ // creating instance of hockey Hockey hockey = new Hockey() { // implementing the methods of interfaces public void start() { System.out.println("Start Event"); } public void play() { System.out.println("Play Sports"); } public void show() { System.out.println("Show Hockey"); } }; // calling the methods using instance hockey.start(); hockey.play(); hockey.show(); } } interface Event { // interface 1 public void start(); } interface Sports { // interface 2 public void play(); } // another interface extending 1st and 2nd interface interface Hockey extends Sports, Event{ public void show(); } 10. Write a Java program to demonstrate the use of the throw keyword. public class Main { static void checkAge(int age) { if (age < 18) { throw new ArithmeticException("Access denied - You must be at least 18 years old."); } else { System.out.println("Access granted - You are old enough!"); } } public static void main(String[] args) { checkAge(15); } } 11. Create an HTML form that collects a user’s first name, last name, favorite programming language using radio buttons, and owned vehicles using checkboxes, and includes a submit button. <html><head><title>Html Forms</title></head> <body> <form> <label for="fname">First name:</label><br> <input type="text" id="fname" name="fname"><br> <label for="lname">Last name:</label><br> <input type="text" id="lname" name="lname"> <br> <br> <input type="radio" id="html" name="fav_language" value="HTML"> <label for="html">HTML</label><br> <input type="radio" id="css" name="fav_language" value="CSS"> <label for="css">CSS</label><br> <input type="radio" id="javascript" name="fav_language" value="JavaScript"> <label for="javascript">JavaScript</label> <br> <br> <input type="checkbox" id="vehicle1" name="vehicle1" value="Bike"> <label for="vehicle1"> I have a bike</label><br> <input type="checkbox" id="vehicle2" name="vehicle2" value="Car"> <label for="vehicle2"> I have a car</label><br> <input type="checkbox" id="vehicle3" name="vehicle3" value="Boat"> <label for="vehicle3"> I have a boat</label> <br> <br><br> <input type="submit" value="Submit"> </form> </body> </html> 12. Create an HTML page that displays a table with columns for Firstname, Lastname, and Age, and includes at least three rows of data. <html> <head> <title>HTML tables</title> </head> <body> <table> <tr> <th>Firstname</th> <th>Lastname</th> <th>Age</th> </tr> <tr> <td>Priya</td> <td>Sharma</td> <td>24</td> </tr> <tr> <td>Arun</td> <td>Singh</td> <td>32</td> </tr> <tr> <td>Seema</td> <td>Kadam</td> <td>41</td> </tr> </table> </body> </html> 13. Program based on Document Object Model to change the background color of the web page automatically after every 5 seconds. <!DOCTYPE html> <html> <head> <title>Auto Background Color Changer</title> <script> // List of colors to rotate through const colors = ["lightblue", "lightgreen", "lightpink", "lightyellow", "lavender", "peachpuff"]; let index = 0; function changeBackgroundColor() { // Change the background color using DOM document.body.style.backgroundColor = colors[index]; // Move to the next color (loop back if at end) index = (index + 1) % colors.length; } // Automatically call changeBackgroundColor every 5 seconds (5000ms) window.onload = function() { setInterval(changeBackgroundColor, 5000); }; </script> </head> <body> <h1>Background Color Changes Every 5 Seconds</h1> </body> </html> 14. Create an HTML page using inline styles. <html> <head> <title> Inline Stylesheets Demo</title></head> <h1 style="color:blue;">A Blue Heading</h1> <p style="color:red;">A red paragraph.</p> </html> 15. Create an HTML page that demonstrates both ordered and unordered lists. <html> <head> <title>HTML Lists</title> </head> <body> <h2>Welcome To Lists in HTML</h2> Example of Unordered list <ul> <li>Programming Languages</li> <li>Data Structures & Algorithm</li> <li>Web Technology</li> <li>Aptitude & Logical Reasoning</li> </ul> Example of Ordered List <h5>Programming Languages</h5> <ol> <li>C Programming</li> <li>Python Programming</li> <li>Java Programming</li> <li>Servlets</li> <li>JSP</li> </ol> </body> </html >