my dog learned polymorphism*
The moose likes Beginning Java and the fly likes How to call static block without creating initiating a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to call static block without creating initiating a class" Watch "How to call static block without creating initiating a class" New topic
Author

How to call static block without creating initiating a class

Bk Jacky
Ranch Hand

Joined: Jun 11, 2005
Posts: 74
Hi Rancher,

I have some classes with static blocks(having some variables in side).I want to initiate variables inside static block without creating object of that particular class. I know that i have to load a class in the memory but how?


SCJP1.4<br />SCWCD1.5<br />"Nothing is impossible"
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

There are several ways to load a class without creating an instance of the class. One simple, direct method is this:

Class.forName("com.the.ClassName");

Just calling the static "forName()" method in java.lang.Class, passing the class's name as a String, will load that class for you.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to call static block without creating initiating a class