Main Content RSS FeedRecent Articles

Java: Performance Issue with Serialization »

Java serialization allows us to marshal and unmarshal objects. It is a mechanism automatically, at runtime, converts class objects into metadata so instances can be serialized with the least amount of programmer work.

In some of my Java applications, RMI is used quite frequently. Serialization is the mechanism used by RMI to pass objects between JVMs, either as arguments in a method invocation from a client to a server or as return values from a method invocation. In this case, objects are marshalled and unmarshalled a lot between the RMI client and server. Serialization is slow especially for large object since

  • Serialization depends on reflection
  • Serialization has a verbose data format
  • It is easy to send more data than is required

To turn off serialization on a certain field of an object, I tag that field of the class of our object with the Java’s “transient” keyword. This, to low-level parts of the Java virtual machine, is an indication that the transient variable is not part of the persistent state of an object.

E.g.

public class MyClass implements Serializable 
{
  private String saveMe;
  private transient String dontSaveMe;
}
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Technorati

Spring Web Flow: State Machine for Your Web Application »

Spring Web Flow is the project in the Spring Portfolio that focuses on providing the infrastructure for building and running rich web applications. As a Spring project, Web Flow builds on the Spring Web MVC framework to provide:

  • A domain-specific-language for defining reusable controller modules called flows
  • An advanced controller engine for managing conversational state
  • First-class support for using Ajax to construct rich user interfaces
  • First-class support for using JavaServerFaces with Spring

The Web Flow module is a MVC extension that allows you to define Controllers using a domain-specific-language. This language is designed to model user interactions that require several requests into the server to complete, or may be invoked from different contexts.

In short, it is like a state machine for your web application. If you web application has a clear defined state transition navigation pattern for the user, then you should consider using Spring Web Flow.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Technorati

Java: Web Application Testing using jWebUnit »

This is another alternative to Selenium.

jWebUnit provides a high-level API for navigating a web application combined with a set of assertions to verify the application’s correctness. This includes navigation via links, form entry and submission, validation of table contents, and other typical business web application features.

image

Sample unit test written using jWebUnit

public void testMainPageLinks() {
       beginAt(“/mainPage”);
       assertLinkPresent(“addLink”);
       clickLink(“addLink”);
       assertTitleEquals(“Widget Add Page”);
       beginAt(“/mainPage”);
       assertLinkPresentWithText(“Edit Widget”);
       clickLinkWithText(“Edit Widget”);
       assertTitleEquals(“Widget Edit Page”);
}
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Technorati

Apache UIMA: Unstructured Information Management Architecture »

UIMA is a framework and SDK for developing software systems that analyze large volumes of unstructured information in order to discover knowledge that is relevant to an end user.

As quoted from the website, an example UIM application might ingest plain text and identify entities, such as persons, places, organizations; or relations, such as works-for or located-at. UIMA enables such an application to be decomposed into components, for example “language identification” -> “language specific segmentation” -> “sentence boundary detection” -> “entity detection (person/place names etc.)”.

UIMA is a component framework for analysing unstructured content such as text, audio and video. It comprises an SDK and tooling for composing and running analytic components written in Java and C++, with some support for Perl, Python and TCL.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Technorati

Java: Structural Analysis using SA4J »

This is a good tool to perform analysis on your Java application.

As quoted from the website, Structural Analysis for JavaTM (SA4J) is a technology that analyzes structural dependencies of Java applications in order to measure their stability. It detects structural “anti-patterns” (suspicious design elements) and provides dependency web browsing for detailed exploration of anti-patterns in the dependency web. SA4J also enables “what if” analysis in order to assess the impact of change on the functionality of the application; and it offers guidelines for package re-factoring.

This technology runs on several versions of Windows®, Linux®, and Sun Solaris.

image

It can perform

  • Stability Analysis
  • Antipattern Detection
  • Dependency Web Browsing
  • Package Analysis
  • “What if” Analysis
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Technorati

Design of a Java Application Framework Part 2 - DAO Layer using Hibernate »

This is the sequel of my previous post on the AppFuse source code, a good MVC framework. Thanks to Matt Raible and the team for this wonderful framework.

By reading the code, I can understand the framework better in order to use it correctly.

For AppFuse, for the data access layer you can use Hibernate, iBATIS or JPA. Here I am going through the Hibernate code.

All the DAO interface shall implement the GenericDao interface.

 
/**
 * Generic DAO (Data Access Object) with common methods to CRUD POJOs.
 *
 * <p>Extend this interface if you want typesafe (no casting necessary) DAO’s for your
 * domain objects.
 *
 * @param <T> a type variable
 * @param <PK> the primary key for that type
 */
public interface GenericDao <T, PK extends Serializable> {
 
    /**
     * Generic method used to get all objects of a particular type. This
     * is the same as lookup up all rows in a table.
     * @return List of populated objects
     */
    List<T> getAll();
 
    /**
     * Generic method to get an object based on class and identifier. An
     * ObjectRetrievalFailureException Runtime Exception is thrown if
     * nothing is found.
     *
     * @param id the identifier (primary key) of the object to get
     * @return a populated object
     * @see org.springframework.orm.ObjectRetrievalFailureException
     */
    T get(PK id);
 
    /**
     * Checks for existence of an object of type T using the id arg.
     * @param id the id of the entity
     * @return - true if it exists, false if it doesn’t
     */
    boolean exists(PK id);
 
    /**
     * Generic method to save an object - handles both update and insert.
     * @param object the object to save
     * @return the persisted object
     */
    T save(T object);
 
    /**
     * Generic method to delete an object based on class and id
     * @param id the identifier (primary key) of the object to remove
     */
    void remove(PK id);
    
    /**
     * Gets all records without duplicates.
     * <p>Note that if you use this method, it is imperative that your model
     * classes correctly implement the hashcode/equals methods</p>
     * @return List of populated objects
     */
    List<T> getAllDistinct();
    
 
    /**
     * Find a list of records by using a named query
     * @param queryName query name of the named query
     * @param queryParams a map of the query names and the values
     * @return a list of the records found
     */
    List<T> findByNamedQuery(String queryName, Map<String, Object> queryParams);
}

In this interface, common CRUD methods are defined. The interface accepts 2 parameters, which is the type variable and the PK for that type.

And GenericDaoHibernate class implements GenericDao interface

Read the rest

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Technorati

Library of Free Data Models »

In every application, no matter Java, .NET or PHP, most probably you need to interact with databases. For every domain your application is used for, the database design is definitely different, though basic database design principles are still the same. Every domain requires different database models and unless you are the domain expert, most of the time you need to spend time to study the domain and the business requirements.

DatabaseAnswers.org has a vast collection of free data models for different domains. It can serve as a starting point for our application database design. You can then customize the database design to your specific requirements.

As quoted from the owner

My intention is to provide a wide range of ‘Kick Start’ Models that anyone can use as a starting-point, and could extend cleanly and logically, with appropriate reference to the Business Rules.
It is not my intention to provide Models that can be used off-the-shelf to meet the requirements of a large commercial organisation.
After all, that is one of the things I do for a living !!!
None of the Models is the complete and final solution in its area, but any of them can be added to easily and quickly to meet a specific requirement. The logic in each Model is correct and contains the minimum Entities for the area being modeled. It is easy to create a complex Model by combining these Kick-Start Models because they all follow the same design approach and standards.

Here are the top 20 models

  1. Libraries and Books
  2. Inventory Control for Retail Stores
  3. Hotel Reservations
  4. Video Rentals
  5. School Management
  6. Clients and Fees
  7. CD Collections
  8. Customers and Invoices
  9. Payroll
  10. Apartment Rentals
  11. Customers and Services
  12. ERP
  13. Car Sales
  14. Customers and Addresses
  15. Driving Schools
  16. Health and Fitness Clubs
  17. Hospital Admissions
  18. Inventory of Files in Boxes
  19. Sports Clubs
  20. Airline Reservations
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Technorati

m2eclipse: Maven Eclipse Plugin »

This is a very good Maven Eclipse plugin

image

Maven Integration for Eclipse provides tight integration for Maven into the IDE and providing the following features:

  • Launching Maven builds from within Eclipse
  • Dependency management for Eclipse build path based on Maven’s pom.xml
  • Resolving Maven dependencies from the Eclipse workspace without installing to local Maven repository
  • Automatic downloading of the required dependencies from the remote Maven repositories
  • Wizards for creating new Maven projects, pom.xml or to enable Maven support on plain Java project
  • Quick search for dependencies in Maven remote repositories
  • Quick fixes in the Java editor for looking up required dependencies/jars by the class or package name

It has also good integration with Mylyn.

Good for reading

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Technorati

Java: Open-ESB »

Open ESB implements an Enterprise Service Bus (ESB) runtime using Java Business Integration as the foundation. This allows easy integration of web services to create loosely coupled enterprise class composite applications.

 

image

It hosts a set of pluggable component containers, which integrate various types of IT assets. These pluggable component containers are interconnected with a fast, reliable, in-memory messaging bus called the Normalized Message Router (NMR) also referred to as the JBI Bus. Service containers adapt IT assets to a standard services model, based on XML message exchange using standardized message exchange patterns (MEP) based on abstract WSDL. This improves interoperability and allows a mix-and-match of technologies from various vendors.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Technorati

Java: Google Collections »

The Google Collections Library  is a suite of new collections and collection-related goodness for Java 5.0.

This library is a natural extension of the Java Collections Framework you.

The major new types are:

  • BiMap. A Map that guarantees unique values, and supports an inverse view.
  • Multiset. A Collection that may contain duplicate values like a List, yet has order-independent equality like a Set. Often used to represent a histogram.
  • Multimap. Similar to Map, but may contain duplicate keys. Has subtypes SetMultimap and ListMultimap providing more specific behavior.

There are also more than a dozen collection implementations, mostly of the interfaces above, but not all. ReferenceMap, for example, is a ConcurrentMap implementation which easily handles any combination of strong, soft or weak keys with strong, soft or weak values.

Static utility classes include:

  • Comparators. Natural order, compound, null-friendly, ad-hoc . . .
  • Iterators and Iterables. Element-based equality, cycle, concat, partition, filter with predicate, transform with function . . .
  • Lists, Sets and Maps. A plethora of convenient factory methods and much more.
  • PrimitiveArrays: “boxing”/”unboxing” of primitive arrays
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Technorati

Copying Values Between HashMap and Hashtable »

What is the problem with the following code?

String userName = null;
 
if (……) {
    userName = <some value>;
}
Map<String,String> hm = new HashMap<String,String>();
hm.put(“username”, userName);
.....
 
Map<String,String> ht = new Hashtable<String,String)(hm);

There is a bug in this code. What the the userName remains NULL when you are copying the value to the Hashtable. Hashtable does not allow NULL as part of the value, and depending on the platform and JDK that you are using, you may or may not see any errors at all, and the program will just exit by itself.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Technorati

Oracle: Alter Password Policy »

Whenever an Oracle user is created, the default profile is DEFAULT is none is specified. To set the login attempts to unlimited, run the following to change the DEFAULT profile.

alter profile DEFAULT LIMIT FAILED_LOGIN_ATTEMPTS UNLIMITED;

Make the password unavailable for 90 days

ALTER PROFILE new_profile 
   LIMIT PASSWORD_REUSE_TIME 90 
   PASSWORD_REUSE_MAX UNLIMITED;

Set default password values

ALTER PROFILE app_user 
   LIMIT PASSWORD_REUSE_TIME DEFAULT
   PASSWORD_REUSE_MAX UNLIMITED;

 

Limited login attempts and password lock time

ALTER PROFILE app_user LIMIT
   FAILED_LOGIN_ATTEMPTS 5
   PASSWORD_LOCK_TIME 1;

 

Limited concurrent sessions

ALTER PROFILE app_user LIMIT SESSIONS_PER_USER 5; 

 

Removing profile limits

ALTER PROFILE app_user LIMIT IDLE_TIME DEFAULT;

 

 

Changing password lifetime and grace period

ALTER PROFILE app_user2 LIMIT
   PASSWORD_LIFE_TIME 90
   PASSWORD_GRACE_TIME 5;
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Technorati

Design of a Java Application Framework Part 1 - Model Layer »

I have been using AppFuse in several projects. It is a excellent framework which implemented a proper MVC architecture.

In order to better understand the framework, I spent sometime browsing through the source code.

In Part I of this articles I am going to show you the model layer.

For all the model classes in AppFuse, it has to extends BaseObject, which has the abstract methods toString, equals and hashCode. Note that BaseObject implements Serializable

 

/**

 * Base class for Model objects. Child objects should implement toString(),

 * equals() and hashCode().

 */

public abstract class BaseObject implements Serializable {