Java Reflection API provides support for querying information about a class at run-time. This information includes the list of public as well as private members (methods) available for the class, the various public operations it supports etc. This section will guide you in making use of the Reflection API. Suppose we have the following test [...]
Archive | August 21st, 2007
Using the Jar Utility
August 21, 2007
Jar stands for Java Archive file and it is used to compress and archive one or more files. It is equivalent to Zip file in Window operating system. A typical jar file contains Java class files in addition to source files as well as resource files, like images and properties. Let us see how to [...]
Storing Application Data using Preferences API
August 21, 2007
Applications can now make use of the Java Preferences API for storing and retrieving Application related data. The location where the Data gets stored is implementation specific. Two levels of Preferences come into picture, one is the User Preferences for storing user information and the other is the System Preferences that deals with information common [...]
Threads Synchronization
August 21, 2007
Synchronization is done in order to protect a segment of code from being accessed by more than a single Thread at any particular instance of time. In Java, synchronization is achieved with the use of synchronized keyword. Synchronization can be applied to methods as well as to a block of code. The following code shows [...]
Overriding the toString() method in Object class
August 21, 2007
The toString() method in the Object class is used to display some information regarding any object. If any code needs some information of an object of a class, then it can get it by using this method. The toString() method of an object gets invoked automatically, when an object reference is passed in the System.out.println() [...]
Externalizable Interface in Java
August 21, 2007
Serialization is the process of giving persistence storage to Java objects so that they can be restored at a later time. Classes can be made persistent in Java by implementing the Serializable interface. Serializable is a marker interface meaning that it has no methods within it. Any Serializable class can be passed on to ObjectOutputStream.writeObject(object) [...]
Enhanced for-loop for User-defined objects
August 21, 2007
Enhanced For-loop is a new syntax for traversing over a collection of objects and it was introduced from Java 5.0. Let us see how Enhanced for-loop operates on user-defined Objects. The following example shows the syntax of using enhanced for-loop on a Collection object, 1 2 3 4 5 6 7 8 List<character> letters = [...]
Singleton Pattern – Design Patterns in Java/J2EE
August 21, 2007
Situations often will demand for the existence of only one object for a particular class in an Application. For example, the existence of only one Database Connection for a particular session, one object referencing the set of Global properties being shared across the various modules, etc. Such classes are candidates to be designated as Singleton [...]
Template method Pattern – Design Patterns in Java/J2EE
August 21, 2007
A Template method pattern provides a skeleton for performing any sort of algorithm or an operation, and it allows the sub-classes to re-define part of the logic. Let us directly get into an example to clarify things in a much better manner. For example, if we wish to write a String Decorator class, which decorates [...]
State Pattern – Design Patterns in Java/J2EE
August 21, 2007
State pattern falls under the category of Behavioural patterns. Assume that we have an object and its behavior is largely dependent on the state of its internal variables. Consider the following example, Person.java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 package tips.pattern.state; [...]






August 21, 2007
0 Comments