jdeveloper voice

Saturday, July 01, 2006

java hacks

When I was preparing to the Sun Certifed Java Programmer (the official name is "Sun Certified Programmer for the Java 2 Platform 1.4") exam I came across many tricky questions. Let's look at the following:


class Dog {
public static String sayHello() {
return "Whow...";
}
}

public class DogTest {
public static void main(String[] args) {
Dog dog = null;
System.out.println(dog.sayHello());
}
}


What is the output?

Everything goes fine and the "Whow..." will be printed. The NullPointerException won't occur. The key is the sayHello() static modifier.

Static methods are linked at compile time as opposed to the runtime linking of instance methods. Compiler doesn't use the value of reference variable at all in this situation. It uses the type of the reference variable only for the purpose of compile time linking.

Friday, June 30, 2006

JMX sucks

Do you like JMX? I don't. It gets me nothing special. For me (simply puts) it is "technology" for accessing some information and invoking operations on mbeans via standard api. The only advantage (not always as you will see) is the ability to use diffrent consoles as a ui view of the mbeans. When I started my journey with JMX I thought it is something more sophisticated.

Let's suppose that you added some jmx-related stuff to your web application. Now, you want to see it. Do you use jmx console that you must run in some specific way other than clicking through application? Maybe you, but I would like to access the information the same way I access application's functionality (for example by login to application to admin account and selecting the admin tab). Of course I must embedded jmx's html console to my application, but it isn't compact with my look and feel, so I write the ui with jmx statistics by myself. And I wonder what JMX gets me?

spring's api wrapping

What I don't like about Spring Framework is its api wrapping of existing libraries with spring-specific one. For example HibernateTemplate. I would prefer working with hibernate api directly and I know I can. Thanks to it, I needn't learn the next api and can work with hibernate utilizing its api without any mediator between. Of course in mentioned situation I loose spring's exception hierarchy related to orm frameworks, but always can translate them using aop (or use try-catch inside method, but it's not recommened). But is it important? How often we change orm frameworks. Not so often.