Core Java Tutorials


Introduction

Java Hello World

Java Compilation

JDK New Features

JVM Architecture

Java OOPs Concepts

Java Package

Array

Exception Handling

String

Immutable Class

File Handling

Serialization

MultiThreading

Volatile

Concurrent Package

Collection

Collection Internal

Generics

Cloning

Reflection In Java

Annotation

Class Loader

Java Inner classes

Garbage Collector

JDBC

References In Java

Heap Dump & Thread Dump

Constructor in Java

Constructor in Java is a method with no rerun type and name is same as class name, which has really it;s own importance.



In Java, we have two types of constructor:-
 Default Constructor
 Parameterized Constructor

jvm-architecture Default Constructor :-
A Default Constructor is a constructor which does not take any argument. it is used to give initial default state to the java objects at the moment it's getting initialize . Java Compiler injects default constructor to the java byte code(Class File). If programmer writes parameterized constructor inside java file(Source File) then compiler will not inject Default Constructor.
default-constructor

jvm-architecture Parameterized Constructor :-
A Parameterized Constructor is a constructor which takes one or more arguments. it is used to give initial state as per the business need to the java objects at the moment it's getting initialize . parameterized-constructor


jvm-architecture Constructor Overloading :-
Constructor Overloading is a mechanism which allows to write more than one constructors inside a class.
Condition to overload a constructor:-
To overload a constructor either
 Number of arguments should be differ
               or
 Type of arguments or order of arguments should be differ

Example of constructor overloading:-
constructors-overloading



Constructor Chaining Constructor Chaining In Java :-
Constructor chaining in java allows to the programmer to call once constrcutor inside another constrcutor to reused the code for java object initialization process.

constructor-chaining-in-java


jvm-architecture Some importants Points about Constructor :-
          Constructor does not have return type
           A constructor can not be final, abstract or synchronized.
          Constructor can be overloaded
          Constructor is not inherited.
           Constructor can be chained
          Call Constructor using this() and super().
          Constructor should have same name as class in which it is defined.