i
Understanding Requirement: Why Java
Why Java is important to the Internet
Java On Linux
First Java Program
Java Virtual Machine Architecture
Class Loading Process by Class Loaders
Role Of Just In Time Compiler
Execution Engine
Data Types
Variables
Arrays
Operators
Arithmetic Operations
Shifting Operators
Logical Operators
Control Statements
Object Oriented Paradigms
The Three OOP principles
Looping Statements
JAVA Class Fundamentals
Command Line Arguments
Static Initialize
Creating an Object
Instance Variable Hiding
Overriding and Overloading of methods
Understanding The Access Controls
Nested And Inner Classes
Dynamic Method Dispatching
Abstract Classes
Using Final To Prevent Overriding & Inheritance
Garbage Collection
Defining a package
Understanding Classpath
Access Protection
Importing packages
Defining and Implementing An Interface
Abstract classes vs Interfaces
Generics
Annotations
Varargs
Foreach
Fundamentals Of Exception Handling
Types Of Exceptions
Learning exception handling, try-catch, multiple catch clauses
Nested Try Statements
Throw, Throws and Finally
Custom Exceptions
Java Thread Model
Creating A Thread
Context Switching
Synchronization: Methods And Statements
Inter-thread Communication
Generally in java to initialize class fields we need to create an instance of object even if we have initialization blocks in our class.
We need the actual class object to be created. We have mentioned that static fields don’t belong to any instance, they are part of the class but in order to initialize them in normal initialization block, we still need the instance to be created. Is there any other solution?
Of course, it is. In java we can have static initializer block which runs during class loading and we will be able to initialize and access static fields of any class before creating actual object of it. Below is the example, how static initializer block looks like
As we mentioned, static initializers are running before constructors. Actually, to be more precise they run before we access any static field after class loading.
Don't miss out!