Skip to main content

Posts

Showing posts from February, 2008

Java Data Objects

JDO has nothing to do with where methods are executed. JDO simply specifies how the fields of a petent object should be managed in-memory, being transparently stored to and retrieved from an underlying datastore. With JDO, methods are invoked on persistent object by an application, as per any regular in-memory Java object. JDO has many implementations. Visit the following link to know about the available implementations. http://db.apache.org/jdo/impls.html

valiateCharacterSetAscii

The method below replaces all the non ASCII printable characters in the ArrayList provided as argument with null. public static ArrayList valiateCharacterSetAscii(ArrayList fileContents){ ArrayList tmpList = new ArrayList (); String str = ""; for(int j=0; j < str =" fileContents.get(j);" resultantstring = "" i="0;i =33 && charCode <=126))) resultantString += str.charAt(i); else resultantString += null; } tmpList.add(resultantString); } return tmpList; }

Accessing static variables

Although a static method can't access instance variables, it can access static variables. A common use of static variables is to define "constants". Examples from the Java library are Math.PI or Color.RED. They are qualified with the class name, so you know they are static. Any method, static or not, can access static variables. Instance variables can be accessed only by instance methods.

Why declare a method static

Static methods can be called without using the class reference (object). Following are the two reasons, one can use static methods: Documentation Anyone seeing that a method is static will know how to call it (see below). Similarly, any programmer looking at the code will know that a static method can't interact with instance variables, which makes reading and debugging easier. Efficiency A compiler will usually produce slightly more efficient code because no implicit object parameter has to be passed to the method.