Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2006

Tip: Looking for answers? Try searching our database.

enclosed code with static???

Thread view: 
QQ - 10 Nov 2006 00:44 GMT
Another question please.

why use static to enclose a few lines of code???
e.g.
static {
...
...
}

Thanks
Steven
Nicholas Sherlock - 10 Nov 2006 00:47 GMT
> Another question please.
>
[quoted text clipped - 4 lines]
> ....
> }

This is a static initializer. It is run once when the class is first
loaded, and is typically used for setting up the values of static fields.

Cheers,
Nicholas Sherlock

Signature

http://www.sherlocksoftware.org

QQ - 10 Nov 2006 01:23 GMT
Cool. thanks for your help. Steven
> > Another question please.
> >
[quoted text clipped - 10 lines]
> Cheers,
> Nicholas Sherlock
www.pulpjava.com - 10 Nov 2006 00:53 GMT
The static code block gets called the first time a class is loaded.

This addresses the age old question: when should I initialize my static
variables? In a constructor? Somewhere else?

Well, the answer is simple: in a static code block.

Cheers!

-Cameron McKenzie

Free Sun Certified Java Associate Mock Exams: www.scja.com
Free Java and J2EE Tutorials: www.mcnz.com

www.technicalfacilitation.com www.pulpjava.com www.examscam.com

> Another question please.
>
[quoted text clipped - 7 lines]
> Thanks
> Steven
QQ - 10 Nov 2006 01:24 GMT
Thank you, your answer are quite helpful for both of my questions,
really appreciate it. Steven

> The static code block gets called the first time a class is loaded.
>
[quoted text clipped - 23 lines]
> > Thanks
> > Steven


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.