4

I got known and also experienced that JVM does lazy loading classes, that is, even the class is imported, it will not be loaded if this class is not used, it is loaded only when it's actively needed.

I am not sure do JDK constantly use this lazy loading strategy or another implementation will be used in some cases, any JDK specification or doc make this clear?

I have this question is because that I ship class which import some class that is not present and will not be used.

C.c
  • 1,905
  • 6
  • 30
  • 47

1 Answers1

0

Below program say Yes,

package code;


import code.one.Test1;


public class code {

    public static void main(String[] args) {
         Test1 test1=null;
    }

    private static void callmethod() {

    }


}

package code.one;

public class Test1 {
static{

    System.out.println("hello");
}
}

But in main method if you write Test1 test1=new Test1(); instead of Test1 test1=null; you will get the o/p

Abhishek Mishra
  • 611
  • 4
  • 11