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 / General / April 2007

Tip: Looking for answers? Try searching our database.

static as only identifier

Thread view: 
Philipp - 12 Apr 2007 17:43 GMT
Hello
I've been looking around the apache Harmony java files and found a
statement which I have never seen before.
 package: org.apache.harmony.x.imageio.plugins.jpeg
 file: JPEGImageWriter.java

public class JPEGImageWriter extends ImageWriter {
    //ctor and member vars are here

    static {
        System.loadLibrary("jpegencoder");
        initWriterIds(ImageOutputStream.class);
    }

    // rest of class methods is here
}

What's this "static" without a name or identifier? How is it used?
What's it for?

Thanks for your answers.
Phil
Eric Sosman - 12 Apr 2007 18:15 GMT
Philipp wrote On 04/12/07 12:43,:
> Hello
> I've been looking around the apache Harmony java files and found a
[quoted text clipped - 15 lines]
> What's this "static" without a name or identifier? How is it used?
> What's it for?

   Look up "static initializer" or "static initialization
block" in your Java textbook.  In the snippet you've shown,
the code inside the { } will be executed once, during the
initialization of the class.

Signature

Eric.Sosman@sun.com

Martijn - 12 Apr 2007 18:38 GMT
> Philipp wrote On 04/12/07 12:43,:
>> public class JPEGImageWriter extends ImageWriter {
[quoted text clipped - 15 lines]
> the code inside the { } will be executed once, during the
> initialization of the class.

This way you can have static objects, but still have the opportunity to
properly initialize them without special constructs like factories and the
sorts.

Signature

Martijn
http://www.sereneconcepts.nl

Mark Space - 12 Apr 2007 18:56 GMT
>     Look up "static initializer" or "static initialization
> block" in your Java textbook.  In the snippet you've shown,
> the code inside the { } will be executed once, during the
> initialization of the class.

In Java parlance, "initialization" means when the class is loaded by the
classloader.
Oliver Wong - 12 Apr 2007 18:31 GMT
> public class JPEGImageWriter extends ImageWriter {
>     //ctor and member vars are here
[quoted text clipped - 9 lines]
> What's this "static" without a name or identifier? How is it used?
> What's it for?

   See http://java.sun.com/docs/books/tutorial/java/javaOO/initial.html

   - Oliver
Greg R. Broderick - 12 Apr 2007 20:51 GMT
Philipp <sicsicsic@freesurf.ch> wrote in news:1176396236_1015
@sicinfo3.epfl.ch:

> What's this "static" without a name or identifier? How is it used?
> What's it for?

It is a static initializer for the class.

c.f. <http://www.developer.com/java/other/article.php/2238491>

Cheers!

Signature

---------------------------------------------------------------------
Greg R. Broderick            gregb+usenet200612@blackholio.dyndns.org

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------



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.