Initializers | Core Java | Codes and Outputs |

Опубликовано: 14 Июнь 2026
на канале: Prasanna Rahangdale
4
3

In this video we are discussing about initializers in Core Java through their examples based on their codes and outputs.
In Core Java, initializers are special blocks or statements used to initialize variables when a class or object is created. They help perform setup operations before constructors or methods are executed.

There are two main types of initializers in Java:
1. Static Initializer block
2. Instance Initializer block

1. Static Initializer Block

a. Declared using the keyword static.
b. Executes only once, when the class is first loaded into memory (before the main() method or any object creation).
c. Used to initialize static variables or perform class-level setup.

2. Instance Initializer Block

a. Declared without static keyword.
b. Executes every time an object is created, before the constructor.
c. Used to initialize instance variables or run common setup code for all constructors.

Key Points

a. Static initializers run once per class (class loading time).
b. Instance initializers run once per object (object creation time).
c. They help avoid repeating initialization code in multiple constructors.
d. Order of execution:
1. Static variables and static blocks (in order of appearance)
2. Instance variables and instance blocks (in order of appearance Constructor.

To see the theoretical part of core java so click the below link:
   • Core-Java Notes