Question: You have to write a java program that can read files of varying sizes, ranging from 100 KB (very small) to few GBs (large size). Can you give me space optimized and memory optimized approach to solve this ?
Question: How will you design your Singleton Patten class to be thread-safe? (a standard interview question!)
Adding synchronized keyword to the getSingleton() method is inefficient solution. Initialize the static private Singleton object within Synchronized block. In this way you can achieve it.
What Design Pattern can be used for classical Producer Consumer problem? (a simple question)
Use observer pattern (publisher subscriber model)
Question: M.S Word can store million lines of text. Each character in the text will have set of properties like font-color, font-size, font-style and etc. So, M.S Word application has to maintain a property structure for each and every character and that may lead to heavy storage. What design pattern will you apply to overcome this problem?
You have to create property group for each possible styles (font-size, font-color, font-face & etc). So, common characters will be part of a property group, there by reducing the storage of each character. This is called FlyWeight Pattern.
Your application uses 1000 classes and they have interaction among each other. This will lead to complex communication across objects, so what design pattern can solve this problem?
Use Mediator pattern to separate the direct communication across objects.
Question: An application reads input from various clients in multiple stages and creates a binary tree structure out of all received inputs. Which design pattern can be used to design such application?
Building an object in multiple set – you call it Builder pattern! The realworld example is XSDBuilder class in Java.
You have to design a budget management application for global users. But, have to provide an option to configure their native tax rules. Which design pattern, do you think, can solve this?
Use Template Pattern. It provides templates of methods and allowing you to override certain portion of logic.
You have a core application class. But, you have to be able assign extra functionalities to the core class on the fly (at runtime). Which patterns deserves this purpose?
Decorator Pattern. This is similar to the pattern designed for java.io.* classes(BufferedReader, DataInputStream and etc.)