This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When Class.forName() executes what internally happens?

 
Praveen palukuri
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Class.forName("****") we can load the class at runtime. Apart from this can any specify what happens internally when we call this ?

Thanks in Advance.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class.forName(...) loads the class that you specify using the current ClassLoader.

What do you want to know more, what the JVM internally does when you call this?

You can have a look at the source code. In your JDK folder, you should have a file called src.zip. In this file, lookup the source code for class java.lang.Class. If you look at the implementation of forName(...) it looks like this:

So, it calls forName0. If you lookup the source for forName0, it looks like this:

It's a native method, so if you'd want to know what it does, you'd need to get the native source code of the JDK; have a look here if you're really interested.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic