This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 24183
    
  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
 
Similar Threads
Class Loading Doubt..
Question on - System.out.println method (static Vs non-static)
Web app startup - order of execution
doubt in majji
(static ) variables in multple classes