Author: dharam

Memory Model of Java Virtual Machine

The Java Virtual Machine is an abstract computing machine. It is responsible for most of the features which made Java a great technology. Few of the major selling points of Java was: Platform Independence Hardware Independence Operating System Independence Security from malicious programs It is said to be abstract computing machine because it offers all the specification which if implemented properly can act as a machine to execute instructions. Sun Microsystems (now acquired by Oracle) offers an implementation of the JVM. The JVM understands a particular binary format wh...
Read More

The Pitfalls of Singleton Design Pattern

Yes! its true that a Singleton object is the loneliest construct in Programming. :) Let us keep the humor aside and listen to this interesting story. Last time we had a fun story while understanding the Factory Method Design Pattern. This time let us have a story from one of our software developers  Manish. He wants to create this wonderful application. An awesome application This application uses the socket connections heavily and has to write data over the network. Manish wrote a code which works great. Every time he wants to use the connection he creates one and starts using it. In no ...
Read More

Abstract Factory Pattern

Extending our story of Jay the Carpenter, O! you missed the beginning ? Check my previous post. Last we heard from Jay, he was selling furniture happily and was able to define a strict process for franchises to follow and he also gave them freedom to make furniture as they like. He basically controlled the post making process, where the customers would get a well painted, polished and packed furniture. Of course the franchises were not very happy as they were not able to churn out more money after this was outlined. They thought of doing other nasty things. They figured out their own ...
Read More

Factory Method Pattern

It is most likely that you read my previous post on the Misconceptions . If you missed that, then I would advice you to please read that, it is a small post. So, in this post we will learn about few things: What exactly is Factory Method Pattern ? What purpose does it solve? Where in JDK is Factory Method Design Pattern used? Key points of Factory Method Design Pattern. What exactly is Factory Method Pattern Continuing our story from the previous post, where Jay is now happy with his shops and the simple factory setup. As a business grows people see it and try to earn profit f...
Read More

Misconception about Factory Method Design pattern

Introduction This post is intended mostly for beginners who want to understand the Factory Method Design Pattern. Yes! the name is Factory Method Design Pattern and not Factory Pattern. It is very important for me to start with the misconception about Factory Method Design pattern, this is a starter post and you might not learn anything about the Factory Method design pattern here. But yes! I will tell you what is not a factory method design pattern. The story Once upon a time there lived a Carpenter Jay in a village. He had this nice way of making beautiful wooden furniture and he used ...
Read More

Identify the Poisoned Bottle

Problem Statement The king has hosted a dinner which is about to start in one hour and guests have arrived. The king plans to offer his exquisite wine collection to the guests. There are 16 different bottles of wines (labeled 1 through 15) available and they are to be served to the guests. The minister comes to know from a trusted source that one of the bottles is poisoned. Also, the poison takes one hour to come into affect and kill someone. It is a tough time for the king and the minister and it becomes utmost priority to identify the poisoned bottle. The only way to test the bottles ...
Read More

Identify Safe Height by Dropping Eggs

Problem Statement If you have 2 eggs and you want to figure out what's the highest floor from which you can drop the egg without breaking it, how would you do it? What's the optimal solution to Identify Safe Height by Dropping Eggs? Note: For simplicity we can assume that the building is 100 floors high. Solution As any other aptitude problems let us list down what we know: The building is 100 floors high We have two eggs We can drop the eggs as many times as possible (if it is not broken in the previous drop) We understand that the question demands an optimal solution, but ...
Read More