Posts

Showing posts from August, 2025

JAVA PROGRAM TO PERFORM MULTI THREADING USING RUNNABLE INTERFACE

 class Multithreading implements Runnable {     public void run()     {         try {             // Displaying the thread that is running             System.out.println(                 "Thread " + Thread.currentThread().getId()                 + " is running");         }         catch (Exception e) {                          // Throwing an exception             System.out.println("Exception is caught");         }     } } // Main Class public class Geeks {     public static void main(String[] args)     {         int n = 8; // Number of threads         for (int i = 0; i < n; i++) {...

JAVA RECORD PROGRAM TO UNDERSTAND MULTIPLE INTERFACE

 // Define two interfaces interface Interface1 {     void method1(); } interface Interface2 {     void method2(); } // Implement both interfaces in a single class class MyClass implements Interface1, Interface2 {     @Override     public void method1() {         System.out.println("Implementation of method1");     }     @Override     public void method2() {         System.out.println("Implementation of method2");     } } public class Main {     public static void main(String[] args) {         // Create an instance of MyClass         MyClass myClass = new MyClass();         // Call methods from both interfaces         myClass.method1();         myClass.method2();     } }

JAVA RECORD PROGRAM TO UNDERSTAND EXCEPTION HANDLING

import java.util.Scanner; public class JavaExample {   public static void main(String[] args) {     int num1, num2;     Scanner scan = new Scanner(System.in);     System.out.print("Enter first number(dividend): ");     num1 = scan.nextInt();     System.out.print("Enter second number(divisor): ");     num2 = scan.nextInt();     try {       int div = num1 / num2;       System.out.println("Quotient: "+div);     }catch(ArithmeticException e){       System.out.println("Do not enter divisor as zero.");       System.out.println("Error Message: "+e);     }   } } 

JAVA RECORD PROGRAM TO UNDERSTAND STRING OPERATIONS

 public class StringExample {     public static void main(String[] args) {         // Creating a string         String str = "Hello, World!";                  // Length of the string         int length = str.length();         System.out.println("Length of the string: " + length);                  // Getting character at a specific index         char ch = str.charAt(7);         System.out.println("Character at index 7: " + ch);                  // Substring         String substr = str.substring(7, 12);         System.out.println("Substring from index 7 to 11: " + substr);                  // Converting to uppercase       ...

JAVA PROGRAM TO UNDERSTAND ABSTRACT METHODS AND CLASSES

 abstract class Animal {   abstract void makeSound();   public void eat() {     System.out.println("I can eat.");   } } class Dog extends Animal {   // provide implementation of abstract method   public void makeSound() {     System.out.println("Bark bark");   } } public class Main {   public static void main(String[] args) {     // create an object of Dog class     Dog d1 = new Dog();     d1.makeSound();     d1.eat();   } }

JAVA RECORD PROGRAM TO UNDERSTAND BANK OPERATIONS USING INHERITANCE

//Run this code in https://www.jdoodle.com/online-java-compiler  import java.util.Scanner; class Bank{     protected String name;     protected int accno;     protected double p;     public Bank(String n, int a, double p){         name = n;         accno = a;         this.p = p;     }     public void display(){         System.out.println("Customer Name: " + name);         System.out.println("Account Number: " + accno);         System.out.println("Principal Amount: " + p);     } } class Account extends Bank{     double amt;     public Account(String n, int acc, double p){         super(n, acc, p);         amt = 0.0;     }     public void deposit(){         Scanner in = new Scanner(System.in); ...