• Post Reply Bookmark Topic Watch Topic
  • New Topic

Qn. on loading the classes...  RSS feed

 
Gurumurthy Ramamurthy
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Can you tell me something about what precautions we have to take while using Class.forName("className")?

Thanks,
Guru
 
Nischal Tanna
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure that the class name which is passed as a String, is a full package path. Also, that the class exists in the application classpath, else ClassNotFoundException will be thrown.
 
Gurumurthy Ramamurthy
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nischal for your fast reply.

I was thinking about the classloaders' conflict. I mean if I use Class.forName("className"), then the class loader which loaded the class (which contains thie code piece), and the class loader which is going to load this class "className" can be different? a bit confused...?

ok, let's take this:
MainProgram.java
----------------

--
--
Class.forName("className", boolean initialize, myClassLoader)
--
--

So, the bootstrap class loader and this myClassLoader is different, is it permissible? Or any precautions we have to take?

Thanks,
Guru
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't say there are precautions, really, but as with many things, it doesn't hurt to understand what you're doing. This paper by Ted Neward is a great way to learn about this topic.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!