Home Java Docker
Home     Java

Java Topic

What is Java
History of Java
Freature of Java
Difference Between Java & C++
Java Environment Set Up
Java Hello World Program & its Internal Process
Java Hello World Program
JDK, JRE and JVM
Java Variables
Java Data Types & Unicode System
Java Operators
Java Keywords
Java Control Statements
Java if else
Java switch
Java for loop
Java While loop
Java Do While loop
Java break
Java continue
Java Oops Concept
Java Object & Class
Java Method
Java Constructor
Java Static Keyword
Java this Keyword
Java Inheritance
Java Hybrid Inheritance
Aggregation(HAS-A)
Java Polymorphism
Java method overloading
Java method overriding
Java Runtime polymorphism
Java Dynamic Binding
Super keyword
Final keyword
Difference Between method overloading and method overriding
Java Abstraction
Java Interface
Abstract class vs Interface
Java Encapsulation
Java Package
Java Access Modifiers
covariant return type
Instance initializer block
Java instanceof operator
Object Cloning in Java
Wrapper classes in Java
Java Strictfp Keyword
Recursion in Java
Java Command Line Arguments
Difference between object and class
Java String
Java String Class
Java Immutable String
Java Immutable Class
String Buffer
String Builder
String Buffer vs String
String Builder vs String Buffer
String Tokenizer in Java
Java Array
Java Exceptions Handling
Java Try-Catch block
Java Multiply Catch Block
Java Finally Block
Java Throws Keyword
Java Throw Keyword
Java Exception Propagation
Java Throw vs Throws
Final vs Finally vs Finalize
Exception Handling With Method Overridding
Java Multithreading
Lifecycle and States of a Thread in Java
How to create a thread in Java
Thread Scheduler in Java
Sleeping a thread in Java
Calling run() method
Joining a thread in Java
Naming a thread in Java
Thread Priority
Daemon Thread
Thread Pool
Thread Group
Shutdown hook
Multitasking vs Multithreading
Garbage Collection
RunTime Class
Java Synchronization
Synchronized block in Java
Static Synchronization in Java
Deadlock in Java
Inter Thread Communication in Java
Interrupting Thread in Java
Reentrant Monitor in Java
Java Applet
Animation in Applet
EventHandling in Applet
Display image in Applet
Displaying Graphics in Applet
Parameter in Applet
Java 8 Features
Java Lambda Expressions
Method References
Functional Interfaces
Java 8 Stream
Base64 Encode Decode
Default Method
for Each() Method
Collectors class
String Joiner Class
Optional Class
JavaScript Nashron
Parallel Array Sort
Type Interface
Parameter Reflection
Type and Repeating Annotations
JDBC Improvements

Binding in Java

    Binding is a mechanism that connects the call to a method with the actual implementation of the method. An object can take on a variety of forms according to the polymorphism concept in Java. Both at compile time and during runtime, object forms can be resolved. Static binding or dynamic binding are terms used depending on whether the linking between a method call and its implementation is resolved at compile time or at run time. While static binding uses a class's type and fields, dynamic binding uses objects to resolve binding.

Table Of Content

  • Binding in Java
  • Type of instance
  • Static Binding in java
  • Dynamic Binding in java
  • Difference Between Static Binding and Dynamic Binding





Static binding is used for private, final, and static members (methods and variables), whereas run-time binding is used for virtual methods (Java methods are virtual by default).

While dynamic binding resolves to bind using objects, static binding uses type information to do so.

While overridden methods use dynamic binding, which occurs at run time, overloaded methods use static binding to resolve (choose which method to call when there are multiple methods with the same name).


Type of Binding

  • Static Binding (Early Binding).
  • Dynamic Binding (Late Binding).

Type of instance


1.Each variable has a type


Every variable has a type; these types range from primitive to non-primitive.


Syntax


 int   Score=30; 

2.There is a type of reference


Every variable has a type; these types range from primitive to non-primitive.


Syntax


 class   Exam{   
 public static void  main(String args[]){    
     Exam exam; //Here exam is a type of Exam     
   }  
 }  





3.Each object has a type.


An object is an instance of one or more Java classes, as well as an instance of those classes' superclasses.


Syntax


 class   FinalExam{}   
 class   Exam{   
 public static void  main(String args[]){    
     Exam exam;//Here exam is a type of Exam     
  }  
 }  

Static binding (also known as Early Binding)

Static binding occurs when the type of the object is established at the time of compilation (by the compiler).

There is static binding if a class contains any private, final, or static methods.


Example of Example of static binding
 // Java static binding example  
class Shape{  
    void draw(){
	  System.out.println("Drawing...Shape");
    }  
}  
class DockerTpoint{  
	public static void main(String args[]){  
		Shape shape=new Shape();
		shape.draw();
	}  
}



Output:

Drawing...Shape 

Dynamic binding (also known as Late Binding)


In dynamic binding, the method to be called is not chosen by the compiler. Dynamic binding is perfectly illustrated by overriding. Both parent and child classes use the same method for overriding.


Java program with Dynamic binding
class Shape{  
    void draw(){
	  System.out.println("Drawing ");
  }  
}  
class Rectangle extends Shape{  
  void draw(){
	  System.out.println("Rectangle");
   }  
}  
class Circle extends Shape{  
  void draw(){
	  System.out.println("Circle ");
  }  
}  
 
class DockerTpoint{  
	public static void main(String args[]){  
		Shape shape;  
		shape=new Rectangle();  
		shape.draw();  
		
		shape=new Circle();  
		shape.draw();
	}  
}  



Output:

Rectangle 
Circle  

Comparison Chart

Difference Between Static Binding and Dynamic Binding are mention below


S.N Static Binding Dynamic Binding
1. Early binding refers to the process that occurs during compilation. It is known as late binding because it happens during runtime.
2. More specifically, it employs the method overloading method. Overriding methods are used.
3. It happens with regular operations. It is carried out using virtual functions.
4. Static binding is never used on real objects. Dynamic binding is used by real objects.
5. Static binding is used for private, final, and static methods and variables. Dynamic binding is used by virtual methods.



Java Super keyword Next »
« Perv Next »


Post your comment





Read Next Topic
Java Tutorial - Topic
Java Polymorphism
Java method overloading
Java method overriding
Java Runtime polymorphism
Java Dynamic Binding
Super keyword
Final keyword
Difference Between method overloading and method overriding
Difference between Early and Late Binding in Java
Read Other Java Chapter
Java Topic
Java Basic Tutorial
Java Control Statements
Java Classes & Object
Java Inheritance
Java Polymorphism
Java Abstraction
Java Encapsulation
Java OOPs Miscellaneous
Java Array
Java String
Java Exception Handling
Java Multithreading
Java Synchronization
Java Applet
Java 8 Features
Java 9 Features
Java Collection
Java Mcq
Java Interview Question
Tools
  

Useful Links

  • Home
  • Blog
  • About us
  • Contact Us
  • Privacy policy

Contact Us

Police Colony
Patna, Bihar
India

Email:

About DockerTpoint


India's largest site for Programming Tutorial as well as BANK, SSC, RAILWAY exam
and Campus placement preparation.