GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Java Patterns
Go To First  |  Previous Question  |  Next Question 
 Java Patterns  |  Question 19 of 20    Print  
java patterns
Explain java patterns in detail? Any difference between Design patterns and java patterns ? . Explain about advantages of using patterns with an example.


  
Total Answers and Comments: 2 Last Update: November 21, 2008     Asked by: Rashmi 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: vibha_kant
 

Let's first understand what a design pattern is. When a problem occurs repetitively in all application across programmers, the solution to that problem is defined as a design pattern. Most of design patterns are language independent strategies to common object oriented problems.
Typically java has three design patterns.

1. Creational Design Pattern

As the name suggests, this pattern is all about instantiated a class and how object is managed across the program to reduce duplicate objects and unnecessary coding which might be caused by using the basic form of object creation. This pattern is again subdivided in to class creational patterns and object creational patterns. Common examples of such patterns are -

a. Factory

Delegates the work of creating the object instance to derived classes of the interface.

b. Abstract Factory

used for creating groups of dependant instances of classes without specifying their concrete classes. It's the centralize decision of what factory to instantiate.

c. Builder

It's used to separate the instantiation of a complex object from its representation so that same construction process can be used for different representations.

d. Singleton

Ensures at every point in the application, there is only and only one instance of that class and also provides a global access point to the same.

e. Prototype

When the typical way of instantiating an object (i.e. "new") is costly. In this pattern new instances are created by copying the prototype of that class.

f. Lazy initiation

Supply when demanded. Instead of already having a created object, create only when it's required.

g. Objects pool

Recycling the objects when they are not in used, rather than releasing them and created new ones when they are required.

2. Structural Design Patterns

These are the patterns used for realizing the relationship between different entities. It defines ways to compose an object to obtain new functionality. Common examples of such patterns are:

a. Adapter/Wrapper

Its used to convert an interface into the one that client expects to see. That is, it adapts the interface to an expected class. It makes incompatible interfaces work together by wrapping them with its own interface.

b. Composite

It's used for defining a whole hierarchy tree structure of objects where each object has the same interface. This allows client to treat a group of different objects in the same way.

c. Bridge

It separates an abstraction from its implementation so that two can vary differently. That is the implemented class can be launched independently and work as its own system.

d. Decorator

Used for adding functionality to the objects at runtime. It's an alternative for sub classing. Sub classing ads functionality to an object at compile time where as decorating adds functionality at the runtime.

e. Facade

Providing an additional layer to existing subsystems to hide complexities. It makes an entry system to the sub systems.

f. Flyweight

When data is shared between numbers of objects to prevent memory consumptions. It's not possible to share all the object state data; therefore it's commonly put in external data structures to populate object's property at runtime (On the Fly).

g. Proxy

Using a mirror substitute of original object if creation of original object is time taking or memory consuming (when that memory consuming operation is not needed for this object to perform). This is often used in as a placeholder typically used in conjunction which flyweight pattern where one instance and multiple proxy are created all pointing to same reference.



Above answer was rated as good by the following members:
suchitra_gupta, Gerda
March 10, 2008 15:30:33   #1  
vibha_kant Member Since: May 2007   Contribution: 5    

RE: java patterns

Let's first understand what a design pattern is. When a problem occurs repetitively in all application across programmers the solution to that problem is defined as a design pattern. Most of design patterns are language independent strategies to common object oriented problems.
Typically java has three design patterns.

1. Creational Design Pattern

As the name suggests this pattern is all about instantiated a class and how object is managed across the program to reduce duplicate objects and unnecessary coding which might be caused by using the basic form of object creation. This pattern is again subdivided in to class creational patterns and object creational patterns. Common examples of such patterns are -

a. Factory

Delegates the work of creating the object instance to derived classes of the interface.

b. Abstract Factory

used for creating groups of dependant instances of classes without specifying their concrete classes. It's the centralize decision of what factory to instantiate.

c. Builder

It's used to separate the instantiation of a complex object from its representation so that same construction process can be used for different representations.

d. Singleton

Ensures at every point in the application there is only and only one instance of that class and also provides a global access point to the same.

e. Prototype

When the typical way of instantiating an object (i.e. "new") is costly. In this pattern new instances are created by copying the prototype of that class.

f. Lazy initiation

Supply when demanded. Instead of already having a created object create only when it's required.

g. Objects pool

Recycling the objects when they are not in used rather than releasing them and created new ones when they are required.

2. Structural Design Patterns

These are the patterns used for realizing the relationship between different entities. It defines ways to compose an object to obtain new functionality. Common examples of such patterns are:

a. Adapter/Wrapper

Its used to convert an interface into the one that client expects to see. That is it adapts the interface to an expected class. It makes incompatible interfaces work together by wrapping them with its own interface.

b. Composite

It's used for defining a whole hierarchy tree structure of objects where each object has the same interface. This allows client to treat a group of different objects in the same way.

c. Bridge

It separates an abstraction from its implementation so that two can vary differently. That is the implemented class can be launched independently and work as its own system.

d. Decorator

Used for adding functionality to the objects at runtime. It's an alternative for sub classing. Sub classing ads functionality to an object at compile time where as decorating adds functionality at the runtime.

e. Facade

Providing an additional layer to existing subsystems to hide complexities. It makes an entry system to the sub systems.

f. Flyweight

When data is shared between numbers of objects to prevent memory consumptions. It's not possible to share all the object state data; therefore it's commonly put in external data structures to populate object's property at runtime (On the Fly).

g. Proxy

Using a mirror substitute of original object if creation of original object is time taking or memory consuming (when that memory consuming operation is not needed for this object to perform). This is often used in as a placeholder typically used in conjunction which flyweight pattern where one instance and multiple proxy are created all pointing to same reference.


 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
November 21, 2008 05:48:59   #2  
manivannan57 Member Since: July 2007   Contribution: 3    

RE: java patterns
It can't be explained in one or two lines. You gotta read nearly 23 patterns in OO. And write yourself some application. You have to have application knowledge of patterns than theoritical knowledge. I'll recommend you to go through the book written by GangOfFour
 
Is this answer useful? Yes | No

 Related Questions

Latest Answer : dynamic class loading is done by Class.forName ...
Read Answers (2) | Asked by : kartheek

Latest Answer : It is a bridge between Objects of different classes..so that they can talk to each other ...

Latest Answer : There is three category in the design pattern realm 1- Creation2- Structure3- Behavioraleach category has its pattern this page may help you:http://en.wikipedia.org/wiki/Category:Software_design_patternsActually the most suitable pattern for web application ...
Read Answers (1) | Asked by : surendra babu

One set of Design Patterns is known as "Antipatterns." Referring to the statement above, how does an Antipattern help in designing a code solution? Choice 1 It allows code to be optimized by demonstrating ways to use bit-wise complements of integers. Choice 2 To enable an implementation of a problem to be developed as quickly as possible when a deadline is approaching Choice 3 To document and explain a code design technique that experience shows does not work well in practice
Read Answers (2) | Asked by : Teena

Explain java patterns in detail? Any difference between Design patterns and java patterns ? . Explain about advantages of using patterns with an example. 
Latest Answer : It can't be explained in one or two lines. You gotta read nearly 23 patterns in OO. And, write yourself some application. You have to have application knowledge of patterns than theoritical knowledge. I'll recommend you to go through the book written ...
Read Answers (2) | Asked by : Rashmi


 Sponsored Links

 
Related Articles

Service Oriented Java Business Integration Review

Service Oriented Java Business Integration Review Introduction If you ve read through the texts which give you an introduction to SOA or Web Services you will often find them to be quite frustrating and the reason for this is because they spend too much time referencing business processes which are
 

Java and Client Server Models

Java and Client Server Models The Role of Client Servers on the Web Client server models provide the essential mechanisms for working with the Internet In fact most of the World Wide Web is built according to this paradigm In client server models the web browsers run by millions of users are the cli
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

Using UML with Java

Using UML with Java While Java is not a new language its application for the development of embedded systems is quite new Developers are beginning to take a second look at modeling languages such as UML and many feel it can be a powerful tool in their development arsenal mosgoogle center Introductio
 

NLP Persuasion Patterns and Benefits

NLP Persuasion Patterns and Benefits Persuasion is an art mastered by only a select few Most often than not people engage in conversations that lack tact skill and wit In this modern age it has become highly essential to persuade and influence people in business or in personal life mosgoogle center
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

Java Technology Trends

Technology Trends Involving Java Java is an object oriented programming language OOP for Web browsers It is organized around data rather than actions and supports polymorphism which allows the same code to be written generically so it can function with different datatypes inheritance which allows on
 

HR Interview - HR Interview Mistakes You Will Want To Avoid

HR Interview Mistakes You Will Want To Avoid The job interview can be a stressful process This is especially true for those who are going after a competitive position Your nonverbal communication combined with the answers you give during the interview will determine if you are hired mosgoogle While
 

HR Interview - Behavioral HR Interviews

Behavioral HR Interviews As the name implies a behavioral interview is an interview that is held by a human resources department to determine if an applicant has the behaviors that are appropriate for a job The company must know how an applicant will behave in a certain situations mosgoogle The logi
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape