wood burning stoves 2.0*
The moose likes Java in General and the fly likes static code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "static code?" Watch "static code?" New topic
Author

static code?

roul ravashimka
Ranch Hand

Joined: Mar 16, 2004
Posts: 53
Hello,
I was wondering what the code at line 4 does? Does static mean that this code is always executed when an instance is made?
public class ServiceLocator {
private InitialContext ic;//1
private Map cache; //2
private static ServiceLocator me;//3
static {//4
try {
me = new ServiceLocator();
}
catch(ServiceLocatorException se) {
System.err.println(se);
se.printStackTrace(System.err);
}
}

private ServiceLocator() throws ServiceLocatorException {
try {
ic = new InitialContext();
cache = Collections.synchronizedMap(new HashMap());
}
catch (NamingException ne) {
throw new ServiceLocatorException(ne);
}
catch (Exception e) {
throw new ServiceLocatorException(e);
}
}

static public ServiceLocator getInstance() {
return me;
}


MSc Electronics, ICT
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
Here is a good explanation:
http://java.sun.com/developer/JDCTechTips/2004/tt0406.html#2
Brian


My Java Freeware:<br />MACCC - <a href="http://maccc.pipasoft.com" target="_blank" rel="nofollow">http://maccc.pipasoft.com</a><br />Nator - <a href="http://nator.pipasoft.com" target="_blank" rel="nofollow">http://nator.pipasoft.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static code?