Posts

Showing posts from April, 2009

Working with Java Reflection

Java reflection gives flexibility of controlling java application's behavior runtime. This tutorial explains using java reflection to load, instantiate and access member dynamically. Some simple and straight forward steps to use reflection are 1. Load class and get reference to Class Object [ using default class loader or custom one ]get required class properties using Class Object such as constructor, methods, fields etc 2. Instantiate class either using specific constructor or default one. 3. Invoke methods using object reference. Here , class MyCar is being accessed using reflection by TestRefelction class. MyCar package reflectionproject; public class MyCar { /** * private memebrs */ private String modelName; private String color; public static String parkingSlot; /** * default constructor */ public MyCar() { } public MyCar(String modelName, String col

JAXB By Example

Java Architecture for XML Binding makes developer's life easier .Extended markup language (XML) is standard for exchanging data in between different applications across the network and Java provides a platform for building portable applications . JAXB API provides easier and standard way of accessing XML in java application. It is just two steps process Bind the Schema , binding xml schema to set of Java classes Unsharshaling / marshaling , XML to Java or Java to XML Following are step by step processing of using JAXB 1. Sample department XML Schema, save in the file named dept.xsd. Put in current directory. <br /><?xml version="1.0" encoding="windows-1252" ?><br /><xsd:schema xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://jaxb.demo" targetnamespace="http://jaxb.demo" elementformdefault="qualified"><br /><xsd:element name="order"><br /><xsd:complextype>

Oracle Coherence Cache Mangement

Oracle has got Coherence Cache management product by acquiring Tangasole. Coherence provides data management and cacheing service. It is not just simple caching service. It provides much more than it, such as  Distributed replicated  reliable scalable  clustered  automatic load balanced  consistent  indexed  in-memory  data management.   Using Coherence, you can have distributed cache management over clustered network. IT provides several implementations , such as  Local Cache  Replicated Cache Partitioned Near Cache  The most interesting feature is ease of installation and implementation. Installation of coherence is only one step process, just include jars in path.   Following are few step to install, implement and test it [ Only basic implementation ] 1. Installation Download and unzip step up  archive from Oracle Coherence home page 2.  Update Classpath Include coherence.jar in  your CLASS_PATH, you will find this jar at  coherence_home/lib/ 3. Implement

Singleton Vs Static Class

"Singleton designing pattern deals with a pattern in which instantiation of object is under control and restrict count by one by making constructor as private " "A Static mean a class that has only static members" A Singleton class is supposed to have one and only one instance while a static class is never instantiated . The singleton pattern has several advantage over the static class pattern A Singleton can extend class and implement interfaces, while a static class can not. A singleton can be initiated lazily or asynchronously while a static class is generally initialized when it is first loaded A singleton class can be extended and its methods overridden , We can not override static methods with non static method

Markers - Interfaces with no Methods defined

You might have come across many interfaces ,which doesn't have any methods defined. most common example is java. io . Serializable Class The interface with no defined methods act like "Markers". They just tell the compiler that the object of classes implementing the interface with no defined methods need to be treated differently. For example  java.io.Serializable java.lang.Clonable java.util.EventListener Markers are also known as "Tag" interface since they tag all the derived classes into  a category based on their purpose.