Apart from these questions on Singleton pattern, some of my reader contribute few more questions, which I included here. Thank you guys for your contribution. 11) Why you should avoid the singleton anti-pattern at all and replace it with DI? Answer: Singleton Dependency Injection: every class ...
This is an application of the Strategy design pattern, and in UML it would look as follows:Then the action() method would simply be:public void action(){ this.weapon.attack(); }Concrete implementations of Weapon should handle the particular types of attacks....
You need to write a regular expression and assign it to the pattern such that it can be used to validate an IP address. Use the following definition of an IP address: IP address is a string in the form “A.B.C.D”, where the value of A, B, C, and D may range from 0 to ...
interface, enum and get their methods and field details. Reflection API is an advanced topic and we should avoid it in normal programming. Reflection API usage can break the design pattern such as Singleton pattern by invoking the private constructor...
A request URI that matches this pattern will have the following form. http://www.my_site_name.com/mycontext/do/action_Name The classorg.apache.struts.action.requestProcessorprocess the request from the controller. You can sublass the RequestProcessor with your own version and modify how the ...
This core Java question is followup of previous question and expecting candidate to write Java singleton using double checked locking. Remember to use volatile variable to make Singleton thread-safe. check 10 Interview questions on Singleton Pattern in Java for more details and questions answers ...
The signature of main method should follow specific pattern for the JVM to recognize it as a entry point. Since it is an important method of Java, you need to have proper understanding of its signature in detail. The signature of main method for displaying "Hello World" looks like below, ...
87. Explain the circuit breaker pattern?The basic idea behind the circuit breaker is very simple. You wrap a protected function call in a circuit breaker object, which monitors it for failures. When we apply this pattern, we prevent possible application problems. This pattern follows the same ...
Java Collection iterator provides a generic way for traversal through the elements of a collection and implements **[Iterator Design Pattern](/community/tutorials/iterator-design-pattern-java "Iterator Design Pattern in Java – Example Tutorial")**. ...
http://stackoverflow.com/questions/17967114/how-to-remove-duplicates-from-an-array-in-java 6. Write a program on Singleton? //howtodoinjava.com/design-patterns/singleton-design-pattern-in-java/ 7. I have two arrays which contains integer. Write a program to merge those two arrays and remov...