----

Friday, October 4, 2013

Java Developer Tools

Java Developer Tools:

Oracle has released Java 7 update 40, with some major new features in JDK 7 Update 40 (7u40) release. Java Mission Control is bundled with this JDK release a JVM monitoring tool, Rule Sets for Java applets and Web Start applications, and a lots of bug fixes.

Mission Control

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collection framework built into the Oracle JDK. It allows Java administrators and developers to gather detailed low level information about how the Java Virtual Machine (JVM) and the Java application are behaving.

Using the Java SE Advanced and Java SE Suite you can do the following

JMC GUI



Wednesday, October 2, 2013

Abstract Factory Design Pattern Example

Abstract Factory Design Pattern: Provide an interface for creating families of related or dependent objects without specifying their concrete classes -- By THE GOF BOOK.

The abstract factory pattern is an extension of the  Factory Method pattern. Both are about creating the new objects, while abstract factory cares more about a family of objects or products to be produced.

In simple words, A normal factory is used to create sets of related or similar objects and an abstract factory is used to return instance of factories. Thus, we can say, an abstract factory is used to return instance of factories that can be used to create similar or related objects.


As there is a ‘abstract’ word in the pattern name don’t mistake and confuse it with java ‘abstract’ keyword. It is not related to that. This abstract is for abstraction from object oriented programming point of view.

Lets understand this with a simple example.
Problem: As in my previous post  Factory Method pattern, we created a media player and a decoder factory to decode the given media file before playing. If we see the code of decoder factory we will notice that there is a problem with the code, as audio and video decoders are mixed in the DecoderFactory.java..


Saturday, September 28, 2013

Factory Design Pattern Example

Factory Design Pattern: The factory method pattern is an object-oriented creational design pattern. Factory Pattern deals with the problem of creating objects without specifying the class of object that will be created. 

Creating an object often requires complex processes, which is not appropriate to include within a composing object. The object's creation may lead to a significant code duplication and may not provide a sufficient level of abstraction. In an application if object creation code is spread in whole application, and if you need to change the process of object creation then you need to go in each and every place to make necessary changes.

Factory design pattern handles these problems by defining a separate method for creating the objects.
In simple words, if we have a super class and many sub-classes, and based on data provided, we need to return the object of one of the sub-classes, then we use a factory pattern.

This pattern introduces loose coupling between classes which is the most important principle one should consider and apply while designing the application. Loose coupling can be introduced by using abstract entities rather than concrete implementations.

When to use: The Factory patterns can be used in following cases:
1. When a class does not know which class of objects it must create.
2. A class specifies its sub-classes to specify which objects to create.
3. At run time you need to create an object based on input parameter...



Monday, September 23, 2013

Strategy Design Pattern Example


Strategy Design Pattern: Strategy pattern defines family of algorithms which are encapsulated and are interchangeable at run time depending on a factor that requires a particular algorithm to be executed. Strategy pattern encourages open-close design principle where a class is open for extension but closed for modification.

It is a suitable replacement for a if-else or switch-case statements or complex conditional logic within a method. It also leads to more testable code, especially when coupled with IOC.

When to use: Let us assume that you are a Telecom service provider and you provide prepaid recharge facility to the customer. Depending on the recharge amount you would like to provide free SMS and free Talk time offer.

The Telecom service system can have a TelecomOperator class. On each recharge this class has to determine different offer depending on the recharge amount....