Understanding DTO, VO, POJO and JavaBeans

Monday, February 8, 2010 12:41
Posted in category Articles

JavaBeans

A JavaBean is a class that follows the JavaBeans conventions as defined by Sun. Wikipedia has a pretty good summary of what JavaBeans are:

JavaBeans are reusable software components for Java that can be manipulated visually in a builder tool. Practically, they are classes written in the Java programming language conforming to a particular convention. They are used to encapsulate many objects into a single object (the bean), so that they can be passed around as a single bean object instead of as multiple individual objects. A JavaBean is a Java Object that is serializable, has a nullary constructor, and allows access to properties using getter and setter methods.

In order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behavior. These conventions make it possible to have tools that can use, reuse, replace, and connect JavaBeans.

The required conventions are:

  • The class must have a public default constructor. This allows easy instantiation within editing and activation frameworks.
  • The class properties must be accessible using get, set, and other methods (so-called accessor methods and mutator methods), following a standard naming convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties.
  • The class should be serializable. This allows applications and frameworks to reliably save, store, and restore the bean’s state in a fashion that is independent of the VM and platform.

Because these requirements are largely expressed as conventions rather than by implementing interfaces, some developers view JavaBeans as Plain Old Java Objects that follow specific naming conventions.

POJO

A Plain Old Java Object or POJO is a term initially introduced to designate a simple lightweight Java object, not implementing any javax.ejb interface, as opposed to heavyweight EJB 2.x (especially Entity Beans, Stateless Session Beans are not that bad IMO). Today, the term is used for any simple object with no extra stuff. Again, Wikipedia does a good job at defining POJO:

POJO is an acronym for Plain Old Java Object. The name is used to emphasize that the object in question is an ordinary Java Object, not a special object, and in particular not an Enterprise JavaBean (especially before EJB 3). The term was coined by Martin Fowler, Rebecca Parsons and Josh MacKenzie in September 2000:

“We wondered why people were so against using regular objects in their systems and concluded that it was because simple objects lacked a fancy name. So we gave them one, and it’s caught on very nicely.”

The term continues the pattern of older terms for technologies that do not use fancy new features, such as POTS (Plain Old Telephone Service) in telephony, and PODS (Plain Old Data Structures) that are defined in C++ but use only C language features, and POD (Plain Old Documentation) in Perl.

The term has most likely gained widespread acceptance because of the need for a common and easily understood term that contrasts with complicated object frameworks. A JavaBean is a POJO that is serializable, has a no-argument constructor, and allows access to properties using getter and setter methods. An Enterprise JavaBean is not a single class but an entire component model (again, EJB 3 reduces the complexity of Enterprise JavaBeans).

As designs using POJOs have become more commonly-used, systems have arisen that give POJOs some of the functionality used in frameworks and more choice about which areas of functionality are actually needed. Hibernate and Spring are examples.

Value Object

A Value Object or VO is an object such as java.lang.Integer that hold values (hence value objects). For a more formal definition, I often refer to Martin Fowler’s description of Value Object:

In P of EAA I described Value Object as a small object such as a Money or date range object. Their key property is that they follow value semantics rather than reference semantics.

You can usually tell them because their notion of equality isn’t based on identity, instead two value objects are equal if all their fields are equal. Although all fields are equal, you don’t need to compare all fields if a subset is unique – for example currency codes for currency objects are enough to test equality.

A general heuristic is that value objects should be entirely immutable. If you want to change a value object you should replace the object with a new one and not be allowed to update the values of the value object itself – updatable value objects lead to aliasing problems.

Early J2EE literature used the term value object to describe a different notion, what I call a Data Transfer Object. They have since changed their usage and use the term Transfer Object instead.

You can find some more good material on value objects on the wiki and by Dirk Riehle.

Data Transfer Object

Data Transfer Object or DTO is a (anti) pattern introduced with EJB. Instead of performing many remote calls on EJBs, the idea was to encapsulate data in a value object that could be transfered over the network: a Data Transfer Object. Wikipedia has a decent definition of Data Transfer Object:

Data transfer object (DTO), formerly known as value objects or VO, is a design pattern used to transfer data between software application subsystems. DTOs are often used in conjunction with data access objects to retrieve data from a database.

The difference between data transfer objects and business objects or data access objects is that a DTO does not have any behaviour except for storage and retrieval of its own data (accessors and mutators).

In a traditional EJB architecture, DTOs serve dual purposes: first, they work around the problem that entity beans are not serializable; second, they implicitly define an assembly phase where all data to be used by the view is fetched and marshalled into the DTOs before returning control to the presentation tier.


So, for many people, DTOs and VOs are the same thing (but Fowler uses VOs to mean something else as we saw). Most of time, they follow the JavaBeans conventions and are thus JavaBeans too. And all are POJOs.

DTO V/S VO

DTO - Data transfer objects are just data containers which is used to transport data between layers and tiers .It mainly contains of attributes ,You can even use public attributes without getters and setters .Data transfer objects do not contain any bussiness logic.

Analogy: Simple Registration form where you have attributes usename,password and email id . when you sumbit this form . In your servlet RegistrationServlet.java file you will get all the attributes from view layer to business layer where you pass the attributes to java beans and then to the DAO or the persistence layer . DTO’s helps in transporting the attributes from view layer to bussiness layer and finally to the persistence layer .

DTO was mainly used to get data transportd across the network efficiently , it may be even from JVM to another JVM .

DTOs are often java.io.Serializable – inorder to transfer data across JVM

VO - A Value Object [1,2] represents itself a fix set of data and is similar to a Java enum. A Value Object’s identity is based on their state rather than on their object identity and is immutable. A real world example would be Color.RED, Color.BLUE, SEX.FEMALE etc.

POJO V/S JavaBeans

  1. The Java-Beanness of a POJO is that it’s public attributes are all accessed via getters and setters that conform to the JavaBeans conventions. e.g. private String foo; public String getFoo(){…} public void setFoo(String foo){…};
  2. JavaBeans must implement Serializable and have a no-argument constructor. where as in POJO doesnot have these restrictions .
Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • blogmarks
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • Facebook
  • Live
  • Yahoo! Buzz

Sun Certified Java Programmer Books Review

Sunday, January 17, 2010 13:39
Posted in category Articles

In this post, I am going to make books review for Sun Java Certified Programmer

  1. SCJP Sun Certified Programmer for Java  Study Guide by Kathy Sierra and Bert Bates
  2. Programmer’s Guide to Java™ Certification
    A Comprehensive Primer, Second Edition Publisher: Addison Wesley
  3. SCJP Exam for J2SE 5:
    A Concise and Comprehensive Study Guide for The Sun Certified Java Programmer Exam

My vote goes for Kathy Seirra and Bert Bates’s book for Sun Certified Programmer for Java. I have scored a good percentage in SCJP exam by using this book.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • blogmarks
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • Facebook
  • Live
  • Yahoo! Buzz

Free Web-based Practice Exams with All Java Certifications till Jan 31 2010

Saturday, January 16, 2010 0:47
Posted in category Articles

Make your certification success 100% sure.

Sun Microsystem launched a limited time offer to give Free ePractice exam with the Certification voucher free.  Order by January 31, 2010.

  • Sun Java Associate Certification (PK-CERT-SCJA)
  • Sun Java Programmer Certification (PK-CERT-SCJP)
  • Sun Java Web Component Developer (PK-CERT-SCWCD)
  • Sun Java Enterprise Architect Certification (PK-CERT-SCEA)
  • Sun System Administrator Certification Part I (PK-CERT-SCSA1)
  • Sun System Administrator Certification Part II (PK-CERT-SCSA2)

For more detail, visit the following URL

http://www.sun.com/training/savings/cert_epractice.xml

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • blogmarks
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • Facebook
  • Live
  • Yahoo! Buzz

Top 10 JSF RIA Frameworks

Saturday, January 16, 2010 0:20
Posted in category Articles

Today, I am going to just publish the article that contains the most popular Java Web RIA frameworks mostly coupled with JSF. Then in my next article, I will discuss the most 5 promising framework for Java EE development.

  1. Jboss Richfaces
    Richfaces is known most popular, stable framework. It have full documentation plus great user community. Richfaces have built-in AJAX support for its own components and also for native JSF components.
  2. ICEfaces
    ICEfaces is an integrated Ajax application framework that enables Java EE application developers to easily create and deploy thin-client rich.
  3. Jboss Seam
    Jboss Seam is full stack Java EE application development. It fully compatible with JSF 1.2, integrated support for jBPM, Hibernate & Richfaces. It overcome many of the problems of JSF like URL bookmarking, post back  and simplified navigation.
  4. Woodstock
    Project Woodstock participants are developing the next generation of User Interface Components for the web, based on Java Server Faces and AJAX.
  5. Primefaces
    Primefaces have 70+ components, with stylish user interface. Prime faces give some unique components that other framework don’t have.
  6. Openfaces
    OpenFaces is a set of advanced Ajax-powered JSF components, an Ajax framework and a client-side validation framework. It have advance time scheduling component like google calendar have schedule.
  7. MyFaces Trinidad
    MyFaces Tomahawk extension component suite by apache. This component library was oracle’s donation to open source community of Java Web Development.
  8. NetAdvantage for JSF
    Netadvantage offers ajax based, next generation components.
  9. JSF-Flex
    Jsf-Flex component library aims to provide next generation flex component under the hood of JSF. JSF developer do not need to learn flex, its jsf-flex responsibility to provide flex user interface.
  10. MyFaces Tomahawk
    MyFaces Tomahawk extension component suite by apache.
ICEfaces is an integrated Ajax application framework that enables Java EE application developers to easily create and deploy thin-client rich…

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • blogmarks
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • Facebook
  • Live
  • Yahoo! Buzz

JetBrain’s IntelliJ IDEA goes Open Source

Saturday, October 17, 2009 15:29
Posted in category Java

Empowering Java Development, Now Java Developer Community have another leading IDE open sourced.

JetBrain's IntelliJ IDEA v9 Open Source

JetBrain's IntelliJ IDEA v9 Open Source

JetBrains has announced that, starting with the next release – version 9.0, it will offer its IntelliJ IDEA Java development environment as open source software. IntelliJ IDEA is to become available in two versions;  a free and open source Community Edition, and a commercial Ultimate Edition, which will apparently be similar to the current version. In various polls IntelliJ IDEA, has been voted the third most popular Java development environment after Eclipse and NetBeans.

The developers have chosen to release the Community Edition under the Apache 2.0 Licence, which they also use for several other of their open source projects. The free version is available for Windows, Mac OS X and Linux; it offers various re-factoring, code inspection/help and debugging features that IDEA developers are likely to be familiar with. Furthermore, the Community Edition is designed to support testing with TestNG and Junit, version control via CVS, Subversion and Git, and building with the Maven and Ant build tools. The Community Edition will be available to download as a preview from today. The vendor has set up an open source page for the project’s future community.

The Ultimate Edition also supports various web frameworks and additional programming languages, and offers more deployment functions than its free counterpart. On its website, JetBrains provides a comparison of the differences between the free and the Ultimate Edition. The commercial variant will cost just under 500 euros. A”Personal Licence” option costs just over 200 euros.

In past time, the commercial IDE joints goes open source or discontinued when NetBean & Eclipse free environment comes into the field. There were, JBuilder, OptimalJ and Oracle’s flagship java IDE JDeveloper but only the IntelliJ IDEA remained as seemingly the last viable commercial product, with market share about 10 percent.

Happy Java Development

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • blogmarks
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • Facebook
  • Live
  • Yahoo! Buzz

How to ban JSP scriptlet in JSF Facelet application.

Wednesday, September 9, 2009 14:08
Posted in category Java EE


Building JSF Scriplet-free Web Pages with Expression Language & JSTL

Scriptlets (embedded Java code in JSP) are considered to be hazardous from a maintenance standpoint. Especially in JSF development, they should be dumped. The JSP 2.0 specification allows developers to explicitly ban the use of scriptlets by making the following declaration in web.xml:


<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <scripting-invalid>true</scripting-invalid>
        <is-xml>true</is-xml>
    </jsp-property-group>
</jsp-config>
Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • blogmarks
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • Facebook
  • Live
  • Yahoo! Buzz

jBPM 4.1 Released with Signavio Integration

Thursday, September 3, 2009 19:24
Posted in category Java

On 1st September JBoss released jBPM 4.1 with some extra ordinary features & commitments. The most significant feature add is Signavio and Oryx collaboration that gives the web based BPMN graphical designer.

jBPM-4.1-Signavio

The web based PDL designer is now implicit part the of jBPM 4.1 package, no need to do anything extra.

Features added are below:

  • End-to-end demo: JBPM-2480
  • Improved installer to handle tomcat and more configuration options : JBPM-2409
  • Extended coverage of Continuous Integration and reduced the execution time
  • Tomcat support in the console : JBPM-2353
  • Fix process variables of type hibernate-long-id/hibernate-string-id : JBPM-2474
  • Tomcat continious integration : JBPM-2409
  • Domain model integration : JBPM-2474
  • And a bunch of bug fixes

More details in our JIRA.

Download it from sourceforge and enjoy it.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • blogmarks
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • Facebook
  • Live
  • Yahoo! Buzz

Quick Getting Started with jBPM 4.0 Tutorials

Sunday, July 19, 2009 14:12
Posted in category BPM

Recently I have been start working on jBPM, while I was learning jBPM 3, I heard the jBPM 4.0 first release after its beta and get attention.

While exploring jBPM 4.0, it feels much better and stronger to implement a BPM solution with so much powerful features of jBPM 4.0

The jBPM 4.0 release has not gone unnoticed and many Java BPM passionate developers  published their articles, how to get started with jBPM 4.0 I have also found some good & to the point jBPM 4.0 articles and now sharing with you. I will publish my own article after learning and implementing jBPM 4.0

Joram Barrez whats-new-series
jBPM4 Hello World
jBPM4: What’s new?
jBPM4: What’s new (part 2)?
jBPM4: What’s new (part 3)?

Jeff Yu published a great jBPM 4 intro in 3 parts:

Getting Started with jBPM 4.0 – (Part I )
Getting Started with jBPM 4.0 (Part II)
Getting Started with jBPM 4.0 (Part III)

Bernd Ruecker published a jBPM 4 showcase:

Ein kleiner jBPM 4 Showcase (In German)
English translation

Andries Inze published a demo on the Spring integration:

Spring jBPM4 CR1 Demo

JBPM 4 Installation  Tutorial:
JBPM 4 Installation Tutorial by MasterTheBoss

Do not forget to view The Official jBoss jBPM online documentation is much worthy.  Now jBoss jBPM 4 have separate user docs and developer docs.

jBPM 4 User Guide
jBPM 4 Developers Guide
jBPM 4 API Javadocs
jBPM 4 schemadocs

The next post I will try to publish, Integration of jBPM 4.0 with Eclipse, MyEclipse, jBoss and Tomcat.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • blogmarks
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • Facebook
  • Live
  • Yahoo! Buzz

Inside String Working in JVM

Sunday, July 12, 2009 17:11
Posted in category Articles, Java

Java Virtual Machine maintains an internal list of references for interned Strings ( pool of unique Strings) to avoid duplicate String objects in heap memory. Whenever the JVM loads String literal from class file and executes, it checks whether that String exists in the internal list or not. If it already exists in the list, then it  does not create a new String and it uses reference to the existing String Object. JVM does this type of checking internally for String literal but not for String object which it creates through ‘new’ keyword. You can explicitly force JVM to do this type of checking for String objects which are created through ‘new’ keyword using String.intern() method. This forces JVM to check the internal list and use the existing String object if it is already present.

So the conclusion is, JVM maintains unique String objects for String literals internally. Programmers need not bother about String literals but they should bother about String objects that are created using ‘new’ keyword and they should use intern() method to avoid duplicate String objects in heap memory which in turn improves java performance. see the following section for more information.

Have a look at the following code snippet.


		String s1 = new String("Java");
		String s2 = new String("Java");

		System.out.println(s1 == s2);//false
		System.out.println(s1.equals(s2));//true

		String t1= "JavaSE";
		String t2 = "JavaSE";

		System.out.println(t1 == t2); //true
		System.out.println(t1.equals(t2));//true

		String p1 = new String("JavaEE");
		p1 = p1.intern();//Forced to use string literal value, from String Pool
		String p2 = "JavaEE";
		p2 = p2.intern();//Forced to use string literal value, from String Pool

		System.out.println(p1 == p2);
		System.out.println(p1.equals(p2));

		String m = new String("JavaFX");
		m = m.intern();//Forced to use string literal value, from String Pool
		String n = new String("JavaFX");
		n = n.intern();//Forced to use string literal value, from String Pool

		System.out.println(m == n);//true
		System.out.println(m.equals(n));//true
Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • blogmarks
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • Facebook
  • Live
  • Yahoo! Buzz

Inside Implementing & Customizing Serialization in Java

Sunday, July 12, 2009 16:35
Posted in category Articles, Java

Implementing serialization in Java is pretty straight forward just a little step task. The class you want to be serialized just have to implements a marker Interface Serializable no override nothing extra work.

The JVM will take care of serialization and deserialization process automatically. Now you can write your object to any persistent technology e.g. database, file system or even over the network.

Serialization:   The process of writing bits and bytes of a java object to physical stream.

Deserialization: The process of reading bits and bytes from physical stream to construct a java object.

Implementing serialization straight forward or lightly may cause problems in future. Let’s discuss some issues that can be faces.

If you not implement serialVersionUID, when you are saving the object JVM automatically calculate serialVersionUID depending upon the various class factors. So when deserialization reading object back it again calculate the serialVersionUID  of the persistent object and to whom class it going to referenced. If class structure changed after saving object then a ClassCastException will be thrown.

Read the rest of this entry »

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • blogmarks
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • Facebook
  • Live
  • Yahoo! Buzz