Those familiar with the java.util.Comparator interface of the Java API
realize its capabilities for sorting a collection of objects based on an
attribute of the objects in the collection. This works well when there is
only a single field in which sorting is required. When more complex sorting
is necessary, the limitations of sorting on a single field become obvious.
What about the situation in which a user desires the functionality to sort
selectively on any field in object collection? This article describes an
implementation of the Comparator interface that along with the reflection API
allows an object to be sorted dynamically on any of its publicly accessible
fields.
Problem Statement
Let's describe the problem a bit more specifically. A collection of employee
Transfer Objects (EmployeeTO class) exists. (For a description of the
Transfer Object design pattern co... (more)
Individuals just starting out with Java and object-oriented (OO) programming
often feel overwhelmed by not only having to learn a new language syntax but
also having to comprehend the unfamiliar concepts of OO programming. For
those individuals, building a strong foundation on the key OO concepts is a
great place to start. For seasoned developers, a refresher on these topics is
always beneficial.
Objects
The most basic concept in an OO language is that of an object. In OO
languages, objects represent real everyday items such as an automobile,
radio, or dog. Objects can contain b... (more)