Thursday, February 29, 2024

DDL command in sql

DATA DEFINITION LANGUAGE



DBMS language

database language are used to read,update and store data in a database.There are several such language that can be used for this purpose : one of them is SQL (Structured Query Language).

    DDL



  • is used for specifying the database schema.It is used for creating tables,schema,indexes,constraint etc.And its used to buld and modify the structure of our table and other objects in the database.When we execute a ddl statement it take effects immediatly.DDLis a subset of Sql and the part of DBMS
  • DDL changes the structure of the table it is work whole table
  • All command of ddl are auto-committed that means it permanently save all the changes in the database.
  • There are some comands:
    1. CREATE
    2. ALTER
    3. DROP
    4. TRUNCATE
    5. RENAME

    1.CREATE

    it is used to create the object,database,tables,views and stored procedure.

    creating Database
    CREATE database demo;

    Explanations

    • CREATE is the syntax
    • database is the syntax follow attribute
    • demo is the database name (its user defined one)
    creating Table
    CREATE TABLE DEMO_TAB (NAME VARCHAR (20),EMAIL VARCHAR(30),DOB DATE);

    Explanations

    • CREATE is the syntax
    • table is the syntax follow attribute
    • demo_tab is the table name (its user defined one)
    • Inside in parenthesis name is the variable object.That corresponding datatype is very mandatory
    • if the datatype or the variable have any restriction is in size is mentioned in this (0).

    2.DROP

    This command it is used to delete both the structure and record stored in the table.And we can able to drop the database too.

    Drop Database
    DROP database demo;

    Explanations

    • DROP is the syntax.
    • database is the syntax follow attribute
    • demo is the database name (its user defined one)
    DROP Table
    DROP TABLE DEMO_TAB;

    Explanations

    • DROP is the syntax
    • table is the syntax follow attribute
    • demo_tab is the table name (its user defined one)

    3.ALTER

    it is used to Alter the structure of th database.This change could be either to modify the charectristucs of an existing attribute or probably to add a new attributes.

    Using alter command to ADD colums
    ALTER table demo_tab add si_no int;

    Explanations

    • ALTER is the syntax
    • table is the syntax follow attribute
    • demo_tab is the database name (its user defined one)
    • ADD or add alter requires
    • si_no is the variable objects.
    • As well us variable objects with the corresponding data type
    Using alter command to DROP column
    ALTER table demo_tab drop si_no;

    Explanations

    • ALTER is the syntax
    • table is the syntax follow attribute
    • demo_tab is the table name (its user defined one)
    • DROP command is the alter requires

    4.TRUNCATE

    it is used to delete an entire objects .delete all records from a table but does not delete the table structure.

    TRUNCATE the table
    TRUNCATE table demo_tab;

    Explanations

    • TRUNCATE is the syntax
    • table is the syntax follow attribute
    • demo_tab is the table name (its user defined one)


    All of those commands either defines or update the database schema that why they come under Data Definition Language


    Thursday, January 25, 2024

    POLYMORPHISM AND OOPS UNSERSTANDING

     

    <

    POLYMORPHISM IN JAVA

    Before going to the polymorphism we want to know what is oops(Object Oriented Programming)

    OOPS

    OOPS Which stands for object oriented programming .Object-oriented programming (OOP) is a computer programming model that organizes software design around data, or objects, rather than functions and logic.(OOP) is a fundamental programming paradigm used by nearly every developer at some point in their career. OOP is the most popular programming paradigm used for software development.

    Why is called an oops?

    In dictionary meaning of an object is "an entity that exists in the real world", and oriented means "interested in a particular kind of thing or entity". In basic terms, OOP is a programming pattern that is built around objects or entities, so it's called object-oriented programming.

    Father of oops concept



    Object-Oriented Programming” (OOP) was coined by Alan Kay circa 1966 or 1967 while he was at grad school

    OOPS have seven rules of instructions provide. Each one have some Specific functionable one. 


    They are four major concept are in oops:



    This blog we discuss about the one of the pillar of  OOPS - polymorphism 


    POLYMORPHISM

    Polymorphism is the ability of a variable, object or function to take an multiple forms

       


     EASY TO UNDERSTAND BY THIS ONE 


    multiple form:
    Which means in the program two or more method have a same name but differ in the parameter passing ( different no of parameter, without parameter and different types of parameter ).The same no of methods have a same name is called a Method overloading.  In single line we will said about the multiple form "The same name of the functions or methods performs different operation.

    Types of polymorphism

    • Compile time polymorphism
      1. Function overloading
      2. Operator overloading
    • Run time polymorphism
      1. Virtual Function

    COMPILE TIME POLYMORPHISM

    The term method overloading allows us to have more than one method with the same name. Since this process is executed during compile time, that's why it is known as Compile-Time Polymorphism. Compile-time is the time period when a program code is translated into a low-level code or machine code, either by a compiler or an interpreter. Compile-time is the period of time from the beginning to the end of the process.

    RUN TIME POLYMORPHISM

    Run-time polymorphism is also known as dynamic or late binding polymorphism. The method functionality is decided dynamically at run time based on the object. It is also called “Late Binding” as the process of binding the method with the object occurs late after compilation.

    ________________________________________________________________________
    Method overloading Method overriding
    Same method name used multiple time with different no of parameter , different types of parameter the same method using more time is called method overloading


       Function overriding is called dynamic                      polymorphism. same function call will perform different types of operation at run time.


    Method overloading & compile time Polymorphism

    1.Different no of parameter

    package methodol;


    public class MethodOverLoading {



    //This program to demonstrate the working of method

    //overloading by changing the number of parameters

    // 1 parameter

    void meth1(int num1)

    {

    System.out.println("number 1 = " + num1);

    }


    // 2 parameter

    void meth1(int num1, int num2)

    {

    System.out.println("number 1 = " + num1

    + " number 2 = " + num2);

    }


    public static void main(String[] args)

    {

    MethodOverLoading obj = new MethodOverLoading();

    // 1st show function

    obj.meth1(3);

    // 2nd show function

    obj.meth1(4, 5);

    }

    }

    OUTPUT:

    number 1 = 3

    number 1 = 4 number 2 = 5

    example, we implement method overloading by changing several parameters. We have created two methods, meth1(int num1 ) and meth1(int num1, int num2 ). In the meth1(int num1) method display, one number and the void meth1(int num1, int num2 ) display two numbers


    2.Different types of datatypes

    //Java program to demonstrate the working of method

    //overloading by changing the Datatype of parameter


    public class MethodOverLoading {


    // arguments of this function are of integer type

    static void meth1(int a, int b)

    {

    System.out.println("This is integer function "+a+" "+b);

    }


    // argument of this function are of float type

    static void meth1(double a, double b)

    {

    System.out.println("This is double function "+a+" "+b);

    }


    public static void main(String[] args)

    {

    // 1st show function

    meth1(1, 2);

    // 2nd show function

    meth1(1.2, 2.4);

    }

    }

    OUPUT:

    This is integer function 1 2

    This is double function 1.2 2.4

    example, we changed the data type of the parameters of both functions. In the first meth1() function datatype of the parameter is int. After giving integer type input, the output will be ‘ This is integer function.’ In the second meth1() function datatype of a parameter is double. After giving double type input, the output would be ‘This is double function.’

    Different types of data types using char

    //Java program to demonstrate the working of method

    //overloading by changing the sequence of parameters


    public class MethodOverLoading {


    // arguments of this function are of int and char type

    static void meth1(int a, char ch)

    {

    System.out.println("integer : " + a

    + " and character : " + ch);

    }


    // argument of this function are of char and int type

    static void meth1(char n, int a)

    {

    System.out.println("character : " + n

    + " and integer : " + a);

    }


    public static void main(String[] args)

    {

    // 1st show function

    meth1(6, 'G');


    // 2nd show function

    meth1('s', 7);

    }

    }

    OUTPUT:

    integer : 6 and character : G

    character : s and integer : 7

    In the above example, in the first show, function parameters are int and char, and in the second shoe, function parameters are char, and int. changed the sequence of data type.


    Method over riding & run time polymorphism

    RULES OF METHOD OVERRING

    1. The method must have the same name as in the parent class.
    2. The method must have the same parameter as in the parent class.
    3. There must be an IS-A relationship (inheritance).

    1.Without override

    package methodoride;


    class vechi {



    void meth1()

    {

    System.out.println("Vehicle is running");

    }

    }

    //Creating a child class

    class MethodOverRide extends vechi{

    public static void main(String args[]){

    //creating an instance of child class

    MethodOverRide obj = new MethodOverRide();

    //calling the method with child class instance

    obj.meth1();

    }

    }

    OUTPUT:

    Vehicle is running

    I have to provide a specific implementation of run() method in subclass that is why we use method overriding.

    2.Example of Java Method Overriding 

    class Vechi{

    //defining a method

    void run(){

    System.out.println("Vehicle is running");

    }

    }

    //Creating a child class

    class MethodOverRide extends Vechi{

    //defining the same method as in the parent class

    void run(){

    System.out.println("Bike is running safely");

    }

    public static void main(String args[])

    {

    MethodOverRide obj = new MethodOverRide();//creating object

    obj.run();//calling method

    }

    }


    OUTPUT:

    Bike is running safely


    3.way one to method override:

    class Sharemar{

    int getRateOfInterest(){

    return 0;

    }

    }

    //Creating child classes.


    class Itc extends Sharemar{

    int getRateOfInterest(){

    return 8;

    }

    }

    class Ipo extends Sharemar{

    int getRateOfInterest(){

    return 7;

    }

    }

    class Index extends Sharemar{

    int getRateOfInterest(){

    return 9;

    }

    }

    //Test class to create objects and call the methods

    class MethodOverRide{

    public static void main(String args[]){

    Itc s=new Itc();

    Ipo i=new Ipo();

    Index a=new Index();

    System.out.println("Itc Rate of Interest: "+s.getRateOfInterest());

    System.out.println("Ipo Rate of Interest: "+i.getRateOfInterest());

    System.out.println("Index Rate of Interest: "+a.getRateOfInterest());

    }

    }

    OUTPUT:

    Itc Rate of Interest: 8

    Ipo Rate of Interest: 7

    Index Rate of Interest: 9

    -----------------------------------------------------------------------------------

    Note:📔🖉

    a static method cannot be overridden. It can be proved by runtime polymorphism

        Can we override main method ?

                                 No, because the main is a static method.

    Monday, January 22, 2024

    sql( DELETE, TRUNCATE AND DROP)

     

    DIFFERANCE BETWEEN DELETE,TRUNCATE AND DROP



      5 Different Types of SQL Commands

    1. DDL or Data Definition Language.
    2. DQL or Data Query Language.
    3. DML or Data Manipulation Language.
    4. DCL or Data Control Language.
    5. TCL or Transaction Control Language.

    DDL command

    A data control language (DCL) is a syntax similar to a computer programming language used to control access to data stored in a database (authorization). In particular, it is a component of Structured Query Language (SQL). Data Control Language is one of the logical group in SQL Commands.

    DML command

    DML is an abbreviation for Data Manipulation Language. Represents a collection of programming languages explicitly used to make changes to the database, such as: CRUD operations to create, read, update and delete data. Using INSERT, SELECT, UPDATE, and DELETE commands.


    1.DELETE

    The MySQL DELETE statement is used to delete a single record or multiple records from a table in MySQL.e careful when deleting records in a table! Notice the WHERE clause in the DELETE statement. The WHERE clause specifies which record(s) should be deleted. If you omit the WHERE clause, all records in the table will be deleted!



    create  schema stdmarks;
    use stdmarks;
    create table stddet( id int primary key   ,name varchar(20),percentage decimal(4,2));
    desc stddet;
    alter table stddet modify id   int auto_increment;




               
                .insert into  stddet (name ,percentage) values("Aakash",74.89),("Santhosh",88.98),(" siva",                      86.80);
                select * from stddet;
         
     
                  delete from stddet where id =3;
                   delete  from   stddet ;


    ___________________________________________________________________________________

    2.TRUNCATE

    TRUNCATE is faster than DELETE as it is a DDL (Data Definition Language) operation rather than a DML (Data Manipulation Language) operation. TRUNCATE is essentially a drop and recreate operation for the table, making it more efficient for large tables.
    Unlike DELETE, TRUNCATE cannot be rolled back. Once the TRUNCATE statement is executed, the data is permanently removed from the table.


    SYNTAX:
                     
    TRUNCATE TABLE table_name;

    (i.e)
    use constraints;
    create table con_det( name varchar (20) not null, age int not null, nationality varchar(20) );
    desc con_det;

    insert into   con_det (name ,age, nationality)value("Aakash",21,"indian");
    insert into con_det  ( name,AGE,nationality)values( "siva",21,"indian");
    select * from con_det; 



    truncate table  con_det;
    ______________________________________________________________________________

    3.DROP

    The DROP DATABASE statement is used to delete a MySQL database and all of its tables and data.Be extremely cautious when using this command, as it irreversibly deletes the entire database.
     
       
    create database droppro;
    use droppro;
    create table droptab(name varchar(20), age int , gender char(2));
    insert into  droptab values("Aakash",21,"M"),("Siva",21,"M"),("Santhosh",20,"M");
    select * from droptab;

      
              
             alter table droptab drop age;
             



     drop table droptab;

    NOTE:
                    Table 'droppro.droptab' doesn't exist

    .

    Saturday, January 13, 2024

    JVM block approach and its defines

     

           TYPES OF BLOCKS JVM APPROACH



    WHAT ARE THE TYPES OF BLOCK S IN JAVA ?

    There are two types of initialization blocks in java :approach
    • INSTANCE
    Instance initialization Block. As explained above, the block which defined inside the class directly without the static modifier is known as the initialization block.

    • STATIC
    static block will be run only once in the execution of program . so if you want some thing that should print before the instance of that class created then put it in the static block.

    ABOUT JVM ?



          JVM stands for Java Virtual Machine. It provides a runtime environment for driving Java applications or code. JVM is an abstract machine that converts the Java bytecode into a machine language. It is also capable of running the programs written by programmers in other languages (compiled to the Java bytecode).

    1.Static blocks

                                    JVM approach the block one by one .we know the normal block which means main method's block. But if  an interview or any other requirement to run the value without using main method block .Its possible to achieve by using Static and Instance blocks. JVM first read is there any Static block s are in the program if any block there first print or approach the static block's properties, condition .

    package jvmpro;


    public class Jvmpros {

    static {

    System.out.println("Static block in java ");

    }

    public static void main(String[] args) {

    System.out.println("Normal block in java ");

    }


    }


    OUTPUT:

    Static block in java

    Normal block in java




                                       We can't directly approach the static block properties in another block .But it can possible to create a variable declaration as instance with static mood for visibilities for the inside of the existing static block's variable. Now can get the variable 's value  an another block .

    package jvmpro;


    public class Jvmpros {

    static int a;

    static {

    a=10;

    System.out.println("Static block in java ");

    }

    public static void main(String[] args) {

    System.out.println("The value of a :"+a);

    System.out.println("Normal block in java ");


    }


    }


    OUTPUT:

    Static block in java

    The value of a :10

    Normal block in java




    2.  INSTANCE BLOCK 

                                              This type of block don't have any name .JVM approach this block after the approach of static block .we can write two ways to run that. if we want to perform initialize of instance variables, then we should go for Constructor, other than initialization activity if we want to perform any activity at the time of object creation then we should go for instance block.

    package jvmpro;


    public class Jvmpros {

    {

    System.out.println("Instance block in java ");

    }

    public static void main(String[] args) {

    Jvmpros dd=new Jvmpros();

    System.out.println("Normal block in java ");


    }


    }


    OUTPUT:

    Instance block in java

    Normal block in java




    Lets see how was the order was works line by line  approach by java's jvm:

    package jvmpro;


    public class Jvmpros {

    {

    System.out.println("Instance block in java ");

    }

    static {

    System.out.println("Static block in java ");

    }

    public static void main(String[] args) {

    Jvmpros dd=new Jvmpros();

    System.out.println("Normal block in java ");


    }


    }


    OUTPUT:

    Static block in java

    Instance block in java

    Normal block in java



    Monday, January 8, 2024

    SWAP THE NUMBER IN DIFFERENT WAYS .

     

                  SWAPPING THE VARIABLES


    What is swap?

                              Transfer the value of one variable to another and take the value of the second variable and put it to first. Simply explain (you have two variable var1 & var2. Value of var1 is 20 & value of var2 is 40. So, after swapping the value of var1 will become 40 & value of var2 will become 20.)


    Why do we swap variables?

                                 Swapping two variables in a code can be useful in various scenarios. One common reason is to reassign the values of the variables to each other, allowing for a more efficient way to organize and manipulate data. This can be helpful in sorting algorithms, mathematical operations, or simply reordering data.

    We can achieve the swap in many ways in this blog .We will using two different way to achieve the concept swapping.

    there are :-

    1.USING THIRD VARIABLE.
    2.WITHOUT USING THIRD VARIABLE.
    3.GETTING RUN TIME INPUT.

    1.USING THIRD VARIABLE

    Fist create the variable declaration like ( a , b and c).Assign the value for a and b ,use the c as a temporary variable.


    How its works ?

    1. First add the two assigned variable such as a and b .
    2. Then store the added value in c (third variable).
    3. assign the value for a is c-a. And assign the value for b is c-a.
           c=10+20;     c= 30;
           a=c-a;
           a=30-10;      a=20;
           b=c-a;
           b=30-20;      b=10;

    package swappro;


    static int a=10,b=20,c;

    public static void main(String args[]) {


    System.out.println("Before swapping\n");

    System.out.println("the value of a :"+a+"the value of b :"+b);

    c=a+b;

    a=c-a;

    b=c-a;

    System.out.println("\nAfter swapping \n");

    System.out.println("the value of a :" +a +"the value of b :"+b);

    }

    }



    OUTPUT

    Before swapping


    the value of a :10the value of b :20


    After swapping


    the value of a :20the value of b :10

    2. WITHOUT USING THIRD VARIABLE

    Fist create the variable declaration like ( a and b).

    How its works ?

    1. First add the two assigned variable such as a and b ..
    2. assign the value for a is a+b. And assign the value for b is a-b .Then re-assign the value for a is a-b.
          
      a=a+b;
           a=10+20;     a= 30;
      b=a-b;   
           b=30-20;      b=10;
      a=a-b;
           a=30-10;      a=20;

    package swappro;



    public class Swapiing {


    static int a=10,b=20;

    public static void main(String[] args) {

    System.out.println("Before swapping\n");

    System.out.println("the value of a :"+a+"the value of b :"+b);

    a=a+b;

    b=a-b;

    a=a-b;

    System.out.println("\nAfter swapping \n");

    System.out.println("the value of a :"+a+"the value of b :"+b);

    }


    }


    OUTPUT

    Before swapping


    the value of a :10the value of b :20


    After swapping


    the value of a :20the value of b :10

    3.GET THE RUN TIME INPUTS


    We use the same method  .which is  using third variable ,just get the input at the run time by using Scanner class.

    package swappro;


    import java.util.Scanner;


    public class Swapiing {


    static int a=10,b=20,c;

    public static void main(String[] args) {


    Scanner ss=new Scanner(System.in);

    System.out.println("ENTER THE VALUE OF a :");

    a=ss.nextInt();

    System.out.println("ENTER THE VALUE OF b :");

    b=ss.nextInt();

    System.out.println("Before swapping\n");

    System.out.println("the value of a :"+a+"the value of b :"+b);

    System.out.println("\nAfter swaping \n");

    c=a+b;

    a=c-a;

    b=c-b;

    System.out.println("\nAfter swapping \n");

    System.out.println("the value of a :"+a+"the value of b :"+b);

    }


    }

    OUTPUT

    ENTER THE VALUE OF a :

    20

    ENTER THE VALUE OF b :

    30

    Before swapping


    the value of a :20 the value of b :30


    After swapping


    the value of a :30 the value of b :20

    .

    DDL command in sql

    DATA DEFINITION LANGUAGE DBMS language database language are used to read,update and store data in a database.There are several suc...