Static Control Flow

Static Control Flow

Static Control Flow decides the sequence of activities that will be executed in order when we run a java class that contains static variables, methods, and blocks.

Process of static control flow

1. Identification of static members from top to bottom.

i = 0 (RIWO) Read Indirect Write Only
j = 0 (RIWO)

(1-6) Steps.

2. Execution of static variable assignments and static block from top to bottom

i = 0 (R & W)
j = 0 (R & W)

(7-12) Steps.

3. Execution of Main Method.

(12-15) Steps.

If the variable is in RIWO state then we r not allowed to perform read operation directly, violation leads to C.E Saying “Illegal forward reference”.

static blocks

If we want to perform some activity at the time of class loading, Then we should define that activity at static blocks because these(static blocks) will execute at the time of class loading only.

We have to load native libraries at the time of class loading. Hence we have to define this activity inside the “static block”.


public class Native {
   static {
      System.loadLibrary("native Library path");

After loading database driver compulsory we should register with the driver manager. But it is not required to perform explicitly this registration because in every driver class there should be one static block to perform this registration.

Hence at the time of loading the database driver automatically registration will be performed.

public class DatabaseDriver {
   static {
      //Register Driver with Driver Manager

With out using main method we can able to print some statement to the console.

public class StaticDemo {
   static {
      System.out.println("Hello....I can print ");

Static Control Flow

Scroll to top