System.getProperties().put( "http.proxyHost" , "someProxyURL" );System.getProperties().put( "http.proxyPort" , "someProxyPort" );System.getProperties().put( "http.proxyUser" , "someUserName" );System.getProperties().put( "http.proxyPassword" , "somePassword" ); |
System.getProperties().put( "http.proxyHost" , "someProxyURL" );System.getProperties().put( "http.proxyPort" , "someProxyPort" );System.getProperties().put( "http.proxyUser" , "someUserName" );System.getProperties().put( "http.proxyPassword" , "somePassword" ); 12 .Java Singleton exampleRead this article formore details.Update:Thanks Markus for the comment. I have updatedthe code and changedit to |
more robust implementation. |
public class SimpleSingleton private staticSimpleSingletonsingleInstance = new SimpleSingleton(); //Markingdefaultconstructor private //to avoid direct instantiation.privateSimpleSingleton() //Get instance for class SimpleSingletonpublicstatic SimpleSingleton getInstance() returnsingleInstance; |
public class SimpleSingleton private staticSimpleSingletonsingleInstance = new SimpleSingleton(); |
//Marking default constructor private//to avoiddirectinstantiation.private SimpleSingleton() |
//Get instance for class SimpleSingletonpublicstaticSimpleSingleton getInstance() |
return singleInstance;One more implementation of Singletonclass.Thanks to Ralph and Lukasz Zielinski |
for pointing this out. |
public enum SimpleSingleton INSTANCE; publicvoiddoSomething() //Call the method fromSingleton:SimpleSingleton.INSTANCE.doSomething(); |
public enum SimpleSingleton INSTANCE; public voiddoSomething() |
//Call the methodfromSingleton:SimpleSingleton.INSTANCE.doSomething(); |