Thursday, December 18, 2008

Online Image Manipulators

Today, I was just googling for the online image manipulators and found this blog entry worth keeping track of. Thanks for the info. Just to copy the most relevant information from that page:

A list of free online image editors:

* Snipshot
* Picnik
* FotoFlexer
* Pixer.us
* Pixlr
* Phixr
* WebPicTool
* Splashup
* Resizr
* Photoshop Express
* Imageeditor.net

Thursday, May 15, 2008

JNDI and OC4J

Got stuck into something and considered it interesting to keep a note of. If you are a J2EE developer and using Oracle Application server (OC4J) then the following information may be useful.

In OC4J if you have user created threads (not implicit threads of Servlet etc) and you want to do a JNDI lookup in that thread, then an OC4J start-up option needs to be set, otherwise the lookup would fail. The option is "-userThreads" and can be set using EM console (OC4J -> Administration -> Server Properties -> Start-parameters: OC4J Options).

Here is the detail of all such available OC4J options.

Tuesday, April 8, 2008

IoC and DI

Good read on IoC and DI

http://martinfowler.com/bliki/InversionOfControl.html
http://martinfowler.com/articles/injection.html

Something that cleared my thought process (an excerpt from one of the articles)
Inversion of Control is a key part of what makes a framework different to a library.

Tuesday, February 12, 2008

Autoboxing and Equality

Tiger(JDK 5) has introduced a lot of features and in turn lots more to dig into. Here I want to explain the issues that arise due to equality comparisons and Autoboxing/Auto-unboxing.

Since, equality operator (==) can be used with reference variables and primitive types, the first question is what happens when we equate reference wrapper variable with its corresponding primitive type.

int i = 1;
Integer iObj = new Integer(i);
System.out.println(i==iObj);


Here, the iObj will be unboxed to a primitive type and the result of the expression would be similar to the comparison of int value with iObj.intValue().

If we equate two reference wrapper variables it is not the value comparisons but object comparison.

Also, JLS recommends that the same wrapper objects should be returned on autoboxing for lower values of the integer primitives. This accounts for some of the unusual behaviour of the equality expressions.

The program and the output below self-explains the issues

package autoboxing;

public class EqualityTest {

public static void main(String[] args) {
// any arbitrary value
int i = 236459;
Integer iObj = new Integer(i);

/*
* if wrapper object is equated with primitive
* types wrapper object would be converted to
* primitive type and then compared
*/

if(i == iObj) {
System.out.println("Integers are equal: " + i);
}

for(int loop = -128; loop < Integer.MAX_VALUE; loop++) {
Integer iObj1 = loop;
Integer iObj2 = loop;

/*
* this is a reference equality check and not value
* comparison
*/
if(iObj1 == iObj2) {

} else {
System.out.println("Integers are not equal: " + loop);
break;
}
}

for(int loop = -128; loop < Integer.MAX_VALUE; loop++) {
Integer iObj1 = new Integer(loop);
Integer iObj2 = new Integer(loop);

/*
* this is a reference equality check and not value
* comparison
*/
if(iObj1 == iObj2) {

} else {
System.out.println("Integers are not equal: " + loop);
break;
}
}
}
}


Output:
Integers are equal: 236459
Integers are not equal: 128
Integers are not equal: -128

Thursday, January 24, 2008

Calling non-public methods

A very small and simple hack to call non-public methods in Java.

Problem
~~~~~~~
A non-public method of a class has to be called from another class. Both the classes are in different packages.

package apipackage;
public class APIClass {
void methodA() {
System.out.println("methodA Called");
}
}

package clientpackage;
public class ClientClass {
void methodACaller() {
...
...
...
}
}


Fill in the dotted lines to call methodA of APIClass.

Solution
~~~~~~~~
package clientpackage;
// import statements
public class ClientClass {
void methodACaller() {
apipackage.APIClass apiObject = new apipackage.APIClass();
Method methodA = apipackage.APIClass.class.getDeclaredMethod("methodA", null);
methodA.setAccessible(true); // this makes it possible to invoke methodA
methodA.invoke(apiObject, null);
}
}

One important thing to remember is to call "getDeclaredMethod" and not "getMethod" to obtain the Method object.

From Java docs:
"getMethod returns a Method object that reflects the specified public member method of the class"

/*
This would not work
Method methodA = apipackage.APIClass.class.getMethod("methodA", null);
*/