Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8580159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:46:05+00:00 2026-06-11T20:46:05+00:00

I am not clear on the following: A class is loaded by JVM when

  • 0

I am not clear on the following:
A class is loaded by JVM when needed, like lazy initialization, right?
Now if class A does an import of class B which class B actually is not in the file system (e.g. B.class was deleted or not delivered or any reason)
then does class A get loaded and runs if no method of class B is called?
Or class A is not able to run at all since the imports can not be resolved?
Or class A is loaded and run up to a certain point?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:46:06+00:00Added an answer on June 11, 2026 at 8:46 pm

    import statement is only important for the compiler. In bytecode all references to other classes are fully qualified. That’s why superflous imports don’t matter at runtime.

    In your case JVM will try to load all classes that are required to load and verify A, so it will try to load B immediately, but dependant classes are loaded lazily only when they are needed. Check out the following example:

    public class A {
    
        public static void bar() {
            new B().foo();
        }
    
        public static void main(String[] args) {
            //bar();
        }
    
    }
    

    Compile A.java and delete B.class. Without calling bar() method your program will run just fine. But once you uncomment piece of code actually using B class you’ll get nasty:

    Exception in thread "main" java.lang.NoClassDefFoundError: B
        at A.bar(A.java:4)
        at A.main(A.java:8)
    Caused by: java.lang.ClassNotFoundException: B
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        ... 2 more
    

    If B is not available, you’ll get NoClassDefFound or similar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope the title and following text are clear, I'm not very familiar with
I am not clear on the actual difference between these two styles of class
I have a simple table like following: class SnookerCurrentInfo extends Doctrine_Record { public function
I have two entities like the following: @Entity public class Trip { @OneToMany(mappedBy =
I have two classes like the following: class Super(object): def __init__(self, arg): self.arg =
I added a Meta class which contains the following permissions but i don't know
Not clear on some fundamental syntax here. define-key accepts a set of inputs, one
It's not clear, to me anyway, if a UIView is automatically released from its
It's not clear to me if the Eclipse plugin completely replaces the need to
I'm not clear on the status of XHTML - v1.0 versus v1.1. Can someone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.