File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes What does the Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "What does the "static" block in following class does?" Watch "What does the "static" block in following class does?" New topic

What does the "static" block in following class does?

Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186

I have static block as follows in my java class:-

public class SimpleWeb extends Thread {
static {
String image = "image/";
MIME_TYPES.put(".gif", image + "gif");
MIME_TYPES.put(".jpg", image + "jpeg");
MIME_TYPES.put(".jpeg", image + "jpeg");
MIME_TYPES.put(".png", image + "png");
String text = "text/";
MIME_TYPES.put(".html", text + "html");
MIME_TYPES.put(".htm", text + "html");
MIME_TYPES.put(".txt", text + "plain");
//other methods in class

What does this static block does??

Thanks in advance.


********Deserve Before You Desire********
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401

It guarantees that when your class is loaded, the member MIME_TYPES is filled with the values being set. It's just a way to soon initialize the MIME_TYPES member.

Leandro Melo
SCJP 1.4, SCWCD 1.4
It is sorta covered in the JavaRanch Style Guide.
subject: What does the "static" block in following class does?
It's not a secret anymore!