Posts

Static Import In Java 5

Constant Interface Anti pattern is a real hot topic of discussion in java, after browsing the web for hours I am not sure whether to use it or avoid it. Constant Interface is a interface which defines some public static final constants. And when we need those constants we can implement the Interface and uses the defined constants or we can access the static constants as InterFaceName.ConstantName. The book Effective Java by Joshua Bloch discusses this problem he calls it "Constant Interface Anti pattern." Poor use of interfaces and  Exposes Implementation Detail are some of the issues why author advocates to avoid it. public interface Constants {       public static final double PI = 3.14159;       public static final double PLANCK_CONSTANT = 6.62606896e-34;   }     public class Calculations implements Constants {       public double getReducedPlanckConstant() {         return PLANCK_CONSTANT / (2 * PI);     }   } Java 5 comes with a Static Import concept. We can solve the...

Liquibase Incremental Database Changes

LiquiBase is used for managing, tracking and applying database changes. It uses XML file for storing incremental changes to data base.These xml file stores both Database structures(DDL) and codes.LiquiBase is an open source (LGPL) Library The following are some of the features which attract LiquiBase a lot 1) It is Open Source 2) It is Database independent 3) Supports rolling back changes 4) Supports merging of changes from multiple developers The XML file which contains input to Liquibase is called databaseChangeLog File. The following is a example of a empty databaseChangeLog file <databaseChangeLog         xmlns=" http://www.liquibase.org/xml/ns/dbchangelog/1.8 "         xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "         xsi:schemaLocation=" http://www.liquibase.org/xml/ns/dbchangelog/1.8         http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.8.xsd "> </databaseChangeLog> The following fragment is a changeset, the...

Google Using Yahoo Libraries?

It seems that google is also using Yahoo Libraries. YUI is a product from yahoo, YUI stands for Yahoo User Interface. To know more about YUI visit http://developer.yahoo.com/yui/ . Google seems to be using yui for layout, as it seems like by the following URL, http://ajax.googleapis.com/ajax/libs/yui/2.6.0/build/yuiloader-dom-event/yuiloader-dom-event.js Clearly It seems like YUI is hosted on google server too. YUI is a great tool, it provides tools for creating rich web application and ajax tools.

Java Annotation

Annotations on Annotations(Meta Annotation) J2SE 5.0 provides four annotations in the java.lang.annotation package that are used only when writing annotations:     @Documented—Whether to put the annotation in Javadocs     @Retention—When the annotation is needed     @Target—Places the annotation can go     @Inherited—Whether subclasses get the annotation These four annotations are used while creating custom Annotations and are called Meta Annotations. The Target annotation The target annotation indicates the targeted elements of a class in which the annotation type will be applicable. It contains the following enumerated types as its value:      @Target(ElementType.TYPE)—can be applied to any element of a class      @Target(ElementType.FIELD)—can be applied to a field or property      @Target(ElementType.METHOD)—can be applied to a method level annotat...

Java Annotation

Annotation in Java is there to make programmers life a bit easy. Annotation-based development relieves Java developers from the pain of cumbersome configuration. Advantages of using Annotations Annotations are attached to Classes and can be processed via reflection. It is much easier to see the Annotations as they are defined in Java code and no need to refer external configurations (like XML). Compiler will do static type checking for Annotation uses. Compile time the proper uses of annotation will be done. Here are some rules-of-thumb when defining an annotation type: Annotation declaration should start with an 'at' sign like @, following with an interface keyword, following with the annotation name. Method declarations should not have any parameters. Method declarations should not have any throws clauses. Return types of the method should be one of the following: primitives String Class enum array of the above types The following shows example of decel...

3 Column Page Design using YUI

The Yahoo! User Interface Library (YUI) is a collection of Java script and CSS, which helps  for building rich interactive web applications quickly.  The CSS components provide a collection of CSS which when used correctly helps us to produce nice and complex layouts. The following ★reset.css normalizes margins, padding, etc. ★fonts.css sets font baseline & even scaling ★grids.css defines classes for preset height and widths of div html elements ★base.css Base is an optional CSS file that complements YUI's core CSS foundation (Reset, Fonts, and Grids). While Reset removes and neutralizes the inconsistent default styling of HTML elements, Base applies a consistent style foundation for common HTML elements across A-grade browsers In the following example I have created a Three column page structure using YUI CSS Framework. <html> <head> <title>Reworked with YUI Grids CSS</title>   <link rel="stylesheet" type="text...

Invoking EJB deployed on a remote machine

Invoking EJB deployed on a remote machine In case we are calling remote ejb( ejb deployed on remote machines), The JNDI lookup might lookup like, Properties env = new Properties();   env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");   env.put(Context.PROVIDER_URL, " 10.227.16.72:1099 ");     env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");    Context ctx = new InitialContext(env); If we are calling local ejb then we can simply create InitialContext without any parameters. Like, Context ctx = new InitialContext(); Using ENC JNDI to access EJBs  IF we want to use ENC JNDI then the , in the lookup method the name of the JNDI passed is prefixed with java:comp/env/ so, if we wish to use ENC JNDI and access ejb Sidd The JNDI name will look like java:comp/env/ejb/Fibo. It is a good practice to use ENC JNDI, sin...