Home | Examples | Supported Classes | Collections | What about MyClass | Documentation | Download Latest Release | SourceForge Project Page | SVN code

What is Joperties?

Joperties is an extension to the Properties class in Java. It exists in order to solve a common problem when dealing with Java properties.

Which problem / What is Properties?

In case you are unfamiliar with Java Properties, this is the definition from the Java API documentation: "The Properties class represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and its corresponding value in the property list is a string."

And exactly therein lays the problem. All properties must be of type String. It is very common for Java programs to want to persist some properties of different type, let's say a color. In that case it is up to the developer to write the color in a String format and also be responsible for restoring this String format to a Java Color object. Of course in this case, the problem is easily solved since the class Color provides the toString() method which formats the color as a String and the decode() method which does the opposite. But what about other types where such a conversion is not easy and trivial?

What about Serialization?

Java already provides a way to represent Objects as Strings and persist them to a stream through the mechanism of Serialization. This method has several downsides but the most obvious for use with the Properties class is that the Serialized form of an Object is not human readable. Properties are used as an "in-between" persistence method in place of full-blown methods like Hibernation or plain Serialization where the information that is persisted is usually written in a file that can be read and modified by users. It is used to store just that: Properties. The Serialization method cannot be used because of that. A user must be able to modify the Properties by opening a file in a text editor and changing the contents.

What is the solution?

Joperties is a very useful alternative since it provides a well-known mechanism (by extending the Properties class) and by introducing automatic transformation between String and Object behind the scenes so that the developer doesn't have to worry about conversion and error checking. For examples, check out the examples page.

▲ Top