Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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
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
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: What does the "static" block in following class does?
It's not a secret anymore!