Posts

Showing posts with the label BCA JAVA RECORD

JAVA PROGRAM TO UNDERSTAND FINAL METHOD

 class XYZ{      final void demo(){       System.out.println("XYZ Class Method");    }   }         class ABC extends XYZ{      void demo(){       System.out.println("ABC Class Method");    }            public static void main(String args[]){         ABC obj= new ABC();         obj.demo();      }   }

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 INHERITANCE

 // 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); ...

JAVA RECORD PROGRAM TO CHECK PRIME OR NOT

 class Prime {   public static void main(String[] args) {     int num = 29;     boolean flag = false;     // 0 and 1 are not prime numbers     if (num == 0 || num == 1) {         flag = true;     }     for (int i = 2; i <= num / 2; ++i) {       // condition for nonprime number       if (num % i == 0) {         flag = true;         break;       }     }     if (!flag)       System.out.println(num + " is a prime number.");     else       System.out.println(num + " is not a prime number.");   } }

JAVA RECORD PROGRAM TO FIND BIGGEST OF THREE NUMBERS

 class Biggest {   public static void main (String[]args)   {    int num1 = 10, num2 = 20, num3 = 30;     if (num1 >= num2 && num1 >= num3)         System.out.println (num1 + " is the greatest");    else if (num2 >= num1 && num2 >= num3)         System.out.println (num2 + " is the greatest");     else if (num3 >= num1 && num3 >= num2)         System.out.println (num3 + " is the greatest");   } }

JAVA RECORD PROGRAM TO UNDERSTAND METHOD OVERLOADING

 class Sum {  int sum(int x, int y)      { return (x + y);   }   int sum(int x, int y, int z)     {        return (x + y + z);    }   double sum(double x, double y)     {        return (x + y);    } }   public class Overload {  public static void main(String args[])     {         Sum s = new Sum();         System.out.println(s.sum(10, 20));         System.out.println(s.sum(10, 20, 30));         System.out.println(s.sum(10.5, 20.5));     } }

JAVA RECORD PROGRAM FOR AREA AND PERIMETER OF RECTANGLE

 // Java program to calculate  the area and perimeter of a rectangle using class concept import java.util.*; // Rectangle Class File class Rectangle {     // data members     int length, width;     // methods     //constructor to create Object     Rectangle(int length, int width) {         this. length = length;         this.width = width;     }     // prints the area of rectangle     public void area() {         int areaOfRectangle;         areaOfRectangle = this.length * this.width;         System.out.println("Area of rectangle with the given input is : " + areaOfRectangle);     }     // prints the perimeter of rectangle     public void perimeter() {         int  perimeterOfRectangle;         perimeterOfRectangle = 2 * (this...