JDeveloper 11.1.1.0.2 Released!
Over the weekend the latest bug fix release of JDeveloper 11g (11.1.1.0.2 or Build 5205) was released on OTN. Go and get it while it's hot.
« January 2009 | Main | May 2009 »
Over the weekend the latest bug fix release of JDeveloper 11g (11.1.1.0.2 or Build 5205) was released on OTN. Go and get it while it's hot.
One of the first questions that come up with the JDev /ADF 11.1.1.0.2 release is how to upgrade your WebLogic 10.3 to it. Here is my solution:
Enjoy.
Note: You will find the Uninstaller either as $WLSHOME/wlserver_10.3/uninstall/uninstall.sh or %WLSHOME%\wlserver_10.3\uninstall\uninstall.cmd. On a headless server (like a Linux or Unix-based system) you may need to set the DISPLAY variable to an X Server like VNC or Xming. (Assuming that $WLSHOME or %WLSHOME% is your home directory for the WebLogic Server 10.3. installation.)
After some years of Java development, one should expect that all lessons are learned and good code is the norm. Yes, really, but this isn't the case. As I work in different projects and reading many books, I am still surprised how often you will find the same ways for doing things wrong.
One of the easiest errors you can do, is to create unnecessary objects. Yes, honestly. There is one famous class in the whole Java environment that can only have two real values. These values are provided as constant values and the only reasonable ones everybody should use as objects of this class. I am talking of the Boolean class. True and false are the only instance and are provided as constant values Boolean.TRUE and Boolean.FALSE. Unfortunately, this class also has a public constructor Boolean(boolean value). This constructor leads to really unnecessary code new Boolean(true) or new Boolean(false). If you see this in your code, it is time to speak with the author and introduce some code inspection tools like FindBugs or PMD.
In JDK 1.0 times, StringBuffer was a reasonable approach to boost performance for String concatenation. It still is an alternative, but StringBuilder is a better one. The worst thing you can do is to concatenate string literals (aka constant strings) with StringBuffer.append(). Because you are working with literals use the + operator. It gives the compiler the chance to optimize the concatenation during compile time and not to leverage the effect to the runtime.
It is really tempting to use the "size" methods of the collection classes (anything like size(), length(), rowCount(), etc.). But before you use them in a loop condition like for(int i = 0; i < array.size(); ++i), take a step back and think about it again. Do you just iterate over it to find something? Or do you modify it in the loop? If the content of the collection will not be modified you should use a construct like for(int i = 0, size = array.size(); i < size; ++i). This is much faster, especially when the method is synchronized.
Very often, in a loop you find code to access the same object through the same method more then once. This makes your code hard to read, less maintainable, and slower. Imagine this method call is synchronized, what an avoidable bottleneck. Of course, you check the method before writing the code, but this does not help for ever. The next version of the API might use a synchronized method. Anyway, to improve the readability, maintainability and performance of the loop, you can introduce a temporary variable, call the method and use the variable throughout the loop. Here is some code:
// Bad
for (int i = 0, size = array.size(); i < size; ++i) {
doSomething(array.get(i));
doSomethingElse(array.get(i));
}// Better
for (int i = 0, size = array.size(); i < size; ++i) {
Object obj = array.get(i);
doSomething(obj);
doSomethingElse(obj);
}
Sure, these two line loop isn't really challenging, but image loops with more lines and line lengths with more then 80 characters...
Another classic. Use of JDBC in a server environment is much different than in a simple demo environment. You should avoid the DriverManager API (for example, not allowed in Java EE) as this does not allow you to provide connection pools as with a DataSource and very often the wrong class loader is used.
Although some JDBC drivers support implicit closing of JDBC resources it is still a recommended practice to close the JDBC resources in the right order at the right place in your code and explicitly. The right order is ResultSet, PreparedStatement, Statement, and Connection. The right place for issuing this code is the finally clause of your try-catch-finally block. Do not reinvent the wheel for this, use the Apache Commons DbUtils library.
The usage of the ClassLoader in Java is very often the only way to get resources loaded. Using the correct ClassLoader is essential for a perfect running application. The best way to use the correct ClassLoader is by using the Context ClassLoader. You can access it through Thread.currentThread.getContextClassLoader()
You can write the worst code in every programming language. If you write your code, always ask yourself, whether you have seen this code before, if so, try to refactor both pieces to common code and find ways to put custom code in it. Repetition is boring and introduces errors and problems.
This is just the tip of the iceberg. You can get much more interesting points to check your code against from very good references:
This page contains all entries posted to Olaf Heimburger's Blog in April 2009. They are listed from oldest to newest.
January 2009 is the previous archive.
May 2009 is the next archive.
Many more can be found on the main index page or by looking through the archives.