Pages

Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Tuesday, 22 October 2013

Dynamic Polymorphism

Poly means Many and Morphism means forms, and if this happens at run time, is called Dynamic Polymorphism.

Let's observe the following code

class Person{
  public void joiningDate(){
    System.out.println(" Person's Joining Date");
  }    
}

class Student extends Person{
  public void joiningDate(){
        System.out.println(" Student's Joining Date");
  }    
}

class Employee extends Person{
  public void joiningDate(){
         System.out.println(" Employee's Joining Date");
  }    
}



public class MainClass{
public static void mian(String args[]){
    Person p = new person();
    p.joiningDate();

    Student s =  new Student();
    p = s;
    p.joiningDate();

    Employee e  = new Employee();
    p = e;
    p.joiningDate();
  }
}


output:-
     Person's Joining Date
     Student's Joining Date
     Employee's Joining Date


Explanation: - In the above code Person is super class and both Student and Employees classes are childs of Person class. The method joiningDate() is overridden in both children classes.

 Student s =  new Student();  // Created an object of type Student
    p = s;                             // Assigned the child's object to parent
    p.joiningDate();               // invoking the child's function.

At runtime p references to the Student , so overridden joiningDate() method in Student class is class invoked. Similarly overridden joiningDate() method in Employee class is class invoked for 
    Employee e  = new Employee();
    p = e;
    e.joiningDate();

In all the three cases we are calling  p.joiningDate(); same method, But which joiningDate() method is to be called is decided at runtime dynamically (depends on address of the subclass?). This is called Dynamic Binding or Dynamic Polymorphism.

Dynamic Polymorphism is achieved through method Overriding.
Static Polymorphism is achieved through method Overloading.



Friday, 11 October 2013

Setting up the Hibernate

Setting up the Hibernate

                    
      1)   Download Hibernate jars
      2)   Download and install any database and database drivers
      3)   Setting up the eclipse environment for Hibernate project

         

  1)Download Hibernate jars

                Go to http://www.hibernate.org/downloads and click on ReleaseBundle.
                 


   
Download the latest version(hibernate-distribution-3.6.4.Final)
                   

unzip the downloaded folder and this folder will contains sub folders like documentation,lib,project,and hibernate jar. 
    

02)Download and install any database and database drivers

Download any database (like postgresql , oracle etc…)from the web  and install. And also download the corresponding jdbc drivers ( JDBC drivers are database specific).
 
 03)Setting up the eclipse environment for Hibernate project 
       01) Create a new Java project (Eg : HibernateFirst)   
           using Eclipse IDE.
       02) Add below jars to the buildpath of the project    
             2.1) hibernate3.jar  which is downloaded in step1
             2.2) All the jars  present in lib/required 
             2.3) Jars present in jpa folder
             2.4) Any one jar from byte code folder
       03) Add database driver to the buildpath

Hibernate configuration file

Hibernate.config.xml