Posts

Java Program to Check Palindrome Number

c lass PalindromeNumber {   public static void main(String[] args )   {         int num = 755, reversedNum = 0, remainder ;         // store the number to originalNum     int originalNum = num ;         // get the reverse of originalNum     // store it in variable     while ( num != 0) {       remainder = num % 10;       reversedNum = reversedNum * 10 + remainder ;       num /= 10;     }         // check if reversedNum and originalNum are equal     if ( originalNum == reversedNum ) {       System. out .println( originalNum + " is Palindrome." );     }     else {       System....

Java Program to Check Palindrome String

c lass PalindromeString { public static void main(String[] args ) { String str = "darga" , reverseStr = "" ; int strLength = str .length(); for ( int i = ( strLength - 1); i >=0; -- i ) { reverseStr = reverseStr + str .charAt( i ); } if ( str .toLowerCase().equals( reverseStr .toLowerCase())) { System. out .println( str + " is a Palindrome String." ); } else { System. out .println( str + " is not a Palindrome String." ); } } } Output :  darga is not a Palindrome String. Explanation : 1. class PalindromeString: 2. This is a Java class named "PalindromeString." 3. public static void main(String[] args): 4. This is the main method where the program starts executing. 5. String str = "darga", reverseStr = "";: 6. It initializes two strings, str...

How To Move Zeros To End Of An Array?

Problem : Write a Java program to separate zeros from non-zeros in the given array. You have to move zeros either to end of the array or bring them to beginning of the array. For example, if{14, 0, 5, 2, 0, 3, 0} is the given array, then moving zeros to end of the array will result {14, 5, 2, 3, 0, 0, 0} import java.util.Arrays;   public class   MoveZerosToEndOfAnArray {     static void moveZerosToEnd( int inputArray [])     {         //Initializing counter to 0           int counter = 0;           //Traversing inputArray from left to right           for ( int i = 0; i < inputArray . length ; i ++)         {             //If inputArray[i] is non-zero         ...

Scenario : 2

Create the Following Tables with suitable Primary keys , Foregin keys and identify the order of tables ? Dept Table                     : id, name Course Table                 : id, name, dept, other_info Teacher Table                : id, fname, lname, phone Section Table                 : id, course, teacher_id, capacity Student Table                : id, fname, lname, dob, phone Student_section Table   :         id, studid, sectionid Dept Table: id (Primary Key) name Teacher Table: id (Primary Key) fname lname phone Course Table: id (Primary Key) name dept (Foreign Key referencing Dept Table) other_info Section Table: id (Primary Key) course (Foreign Key referencing Course Table) teacher_id (Foreign Key refere...

Scenario : 1

Create the Following Tables with suitable Primary keys , Foregin keys and identify the order of tables ? Movie Table : movieid, movie_name, rating, duration, seatno, timeslotid Theatre Table : theatreid, seatno, moviename, movieid, staffid, timeslotid Timeslot Table : timeslotid, moviename, movieid, staffid, theatreid Booking Table : bookingid, bookingdate, bookingseat, booking_timeslot, staffid Ticket Table : ticketid, movieid, staffid, theatreid, bookingid Staff Table : staffid, fullname, mobile, email, dob Solution : Staff Table: staffid (Primary Key) fullname mobile email dob Timeslot Table: timeslotid (Primary Key) moviename movieid (Foreign Key referencing Movie Table) staffid (Foreign Key referencing Staff Table) theatreid (Foreign Key referencing Theatre Table) Movie Table: movieid (Primary Key) movie_name rating duration seatno timeslotid (Foreign Key referencing Timeslot Table) Theatre Table: theatreid (Primary Key) s...

Method Overriding

Method Overriding :    Explanation:            Method overriding allows a subclass to provide a specific implementation for a method defined in its superclass. Example: c lass Animal {     void makeSound() {         System. out .println( "Animal makes a sound." );     } }   class Cat extends Animal {     @Override     void makeSound() {         System. out .println( "Cat meows." );     } }   public class Main {     public static void main(String[] args ) {         Animal myCat = new Cat();         myCat .makeSound(); // Output: Cat meows .     } }

Method Overloading

Method Overloading : Explanation :               You can define multiple methods in a class with the same name but different parameters. The appropriate method is chosen based on the arguments provided. Example: c lass MathOperations {     int add( int a , int b ) {         return a + b ;     }       double add( double a , double b ) {         return a + b ;     } }   public class Main {     public static void main(String[] args ) {         MathOperations math = new MathOperations();         System. out .println( math .add(5, 7)); // Output: 12         System. out .println( math .add(3.5, 2.5)); // Output: 6.0     } }

Constructor

Constructor: Definition:            A constructor is a special method called when an object is created to initialize its attributes. Explanation:               Constructors ensure proper initialization of an object's state when it's instantiated. Example: c lass Person {     String name ;       Person(String n ) {         name = n ;     } }   public class Main {     public static void main(String[] args ) {         Person person = new Person( "Darga" );         System. out .println( "Name: " + person . name ); // Output: Name: Darga     } }

Abstraction

Abstraction: Definition :          Abstraction involves modeling classes based on essential attributes and behaviors, ignoring unnecessary details. Explanation :             Abstract classes can't be instantiated and provide a blueprint for subclasses. Interfaces define method signatures that implementing classes must provide. Example:   abstract class Shape {     abstract void draw(); }   class Circle extends Shape {     @Override     void draw() {         System. out .println( "Drawing a circle." );     } }   class Square extends Shape {     @Override     void draw() {         System. out .println( "Drawing a square." );     } }   public class Main {     public stati...

Inheritance

Inheritance :   Definition:             Inheritance allows a class (subclass) to inherit properties and behaviors from another class (superclass). Explanation:                  Subclasses extend the functionality of the superclass by inheriting its attributes and methods. Method overriding lets subclasses provide specific implementations for inherited methods. Example: class Animal {     void sound() {         System. out .println( "Animal makes a sound." );     } }   class Dog extends Animal {     @Override     void sound() {         System. out .println( "Dog barks." );     } }   public class Main {     public static void main(String[] args ) {         Animal ...