Powered by Blogger.

AbstractFactory Design Pattern with an Example program

>> Tuesday, May 31, 2011

Creational Patterns - Abstract Factory Pattern

Definition:
  • Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
  • A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.
  •  The new operator considered harmful.
Where to use & benefits
  1. Creates families of related or dependent objects like Kit.
  2. Provides a class library of products, exposing interface not implementation.
  3. Needs to isolate concrete classes from their super classes.
  4. A system needs independent of how its products are created, composed, and represented.
  5. Try to enforce a constraint.
  6. An alternative to Facade to hide platform-specific classe.
  7. Easily extensible to a system or a family.
  8. Related patterns include.

Decorator Design Pattern with an Example

>> Monday, May 30, 2011

Definition:
               Attach additional responsibilities or functions to an object dynamically or statically. Also known as Wrapper.
Where to use & benefits:
  1. Provide an alternative to subclassing.
  2. Add new function to an object without affecting other objects.
  3. Make a responsibility easily added and removed dynamically.
  4. More flexibility than static inheritance.
  5. Transparent to the object.
  6. Related patterns include  
Decorative Design Pattern with Example_JavabynataraJ
  •  Adapter pattern, which provides a different interface to the object it adapts, whereas a decorator changes an object's responsibilities,

Factory Design Pattern with a real time Example

>> Friday, May 27, 2011

The Factory design pattern comes under Creational design pattern.

Definition

Provides an abstraction or an interface and lets subclass or implementing classes decide which class or method should be instantiated or called, based on the conditions or parameters given.

Where to use & benefits
  1. Connect parallel class hierarchies.
  2. A class wants its subclasses to specify the object.
  3. A class cannot anticipate its subclasses, which must be created.
  4. A family of objects needs to be separated by using shared interface.
  5. The code needs to deal with interface, not implemented classes.
  6. Hide concrete classes from the client.
  7. Factory methods can be parameterized.
  8. The returned object may be either abstract or concrete object.
  9. Providing hooks for subclasses is more flexible than creating objects directly.
  10. Follow naming conventions to help other developers to recognize the code structure.

Can I have more than one struts-config.xml file for a single Struts application?

>> Thursday, May 26, 2011

Yes! One can have more than one struts-config.xml file for a single Struts application.
You can define different struts-conifg.xml file for different modules in a single web application. It is useful when you are developing a distributed application. But you must enter those struts-config.xml files details in deployment descripter (i.e., web.xml) file.

If you are working with multiple modules in your project, then you can have one configuration file for each modules. Let's say the project has two modules admin and reports. You access the admin screens using the URI admin/admin-module1 and reports using the URI report/report-1. Here the admin and report are two different modules.

Simple Hibernate Example on Inserting Employee details using MySql

>> Wednesday, May 25, 2011

Hibernate is a solution for object relational mapping and a persistence management solution or persistent layer. This is probably not understandable for anybody learning Hibernate.

What you can imagine is probably that you have your application with some functions (business logic) and you want to save data in a database. When you use Java all the business logic normally works with objects of different class types. Your database tables are not at all objects.

Hibernate provides a solution to map database tables to a class. It copies the database data to a class. In the other direction it supports to save objects to the database. In this process the object is transformed to one or more tables.

Difference between ServletContext and ServletConfig

>> Thursday, May 19, 2011

What is the difference between ServletConfig and ServletContext?
ServletContext and ServletConfig both are interfaces.ServletContext is one per application and within the application serveral Servlets will be defined. Each Servlet will be having a ServletConfig object. Even for jsp page.You can understand easily by the image given below.

Difference between ServletConfig and ServletContext_JavabynataraJ


Collections KeyPoints

The Main Collections KeyPoints in java

Collection is a group of objects.  java.util package provides important types of collections. There are two fundamental types of collections they are Collection and Map. Collection types hold a group of objects, Eg. Lists and Sets where as Map types hold group of objects as key, value pairs.
Eg. Hashtable, HashMap, TreeMap, and LinkedHashMap (LinkedList+HashTable). Explained in detail in last post, how to iterate HashMap.
Here the collections of classes and interfaces having some their own properties.They are


Hibernate Caching Techniques

>> Wednesday, May 18, 2011

Caching is a Temporary memory or buffer which resides at client side and stores the results sent by server. When client generates same request for multiple number of times, the first request generated results will be stored in cache and this result will be used across the multiple requests. This reduces the round trips between the client and server. Since the result will be collected from cache that is available at client side.
Hibernate supports for 2 levels of cache:
  1. Level one cache
  2. Level two cache.

What is the difference between sleep(), wait() and suspend()?

>> Wednesday, May 11, 2011

Thread.sleep() is used to suspend a thread execution for a specified time. or it sends the current thread into the "Not Runnable" state for some amount of time. The thread keeps the monitors it has aquired --

i.e. if the thread is currently in a synchronized block or method no other thread can enter this block or method. If another thread calls t.interrupt() it will wake up the sleeping thread.

Note that sleep is a static method, which means that it always affects the current thread (the one that is executing the sleep method). A common mistake is to call t.sleep() where t is a different thread; even then, it is the current thread that will sleep, not the t thread.

Creating a Connection object in mysql using Connection Pooling

>> Monday, May 9, 2011

Create a connection obj using Connection pooling in mysql.

Connection pooling is the maintenance of a group of database connections for reuse by applications on an application server. It is part of the JDBC 2.0 Optional Package API. Another part of the Optional Package API provides for the use of the Java Naming and Directory Interface (JNDI) and DataSource objects instead of JDBC 1.0 DriverManager objects to access relational data.

Daily Activities of RealTime Software Employee.

Daily Activities of a Real Time Software Employee.

1). Monitoring.

a. Mails - we should configure MS Outlook to our system.
b.Check mails u got from TeamLead or Client.
c.Check Development/TestServer/ProductServer mails
d.check Mails from project tracker.
e.Check mails  from issue/bug tracker.
f.Check logger fiels.

Object Serialization and Deserialization

>> Friday, May 6, 2011

Working with ObjectOutputStream class and ObjectInputStream Classes

Object Serialization and Deserialization_JavabynataraJ

When ever the object values need to be stored with in a file then ObjectOutputStream class is used. When ever the object values need to be retrieved from a file then ObjectInputStream class is used.

When ever the object values need to be stored with in a file or need to be retrieved from a file then class corresponding to that object must implement the interface Serializable.

8). Program for reading the data from Zipped file using java

>> Wednesday, May 4, 2011

Uncompress the data from a zipped file using java.


 To Convert the contents present in zip_hello file to the original data then the class InflatorInputStream is used.This class is used to convert unreadable format data to the readable format.


InflaterInputStream iis = new InflaterInputStream(fis);


While creating the object of this class it expects FileInputStream class object (fis) as an argument.

InflatorInputStream class is available in java.util.zip package.

This class implements a stream filter for uncompressing data in the "deflate" compression format. It is also used as the basis for other decompression filters, such as GZIPInputStream.

7). Program to Zipping the contents present with in the file.

>> Tuesday, May 3, 2011

Making a file into unreadable format.


To Zip the contents present with in a file the class DeflatorOutputStream is used.This class is defined with in the util package.

DeflaterOutputStream dos = new DeflaterOutputStream(fos);

The Object of DeflatorOutputStream class will expect FileOutputStream object as an argument.

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2014. All rights reserved.