JDBC performance tuning with optimal fetch size

Tuning performance using fetch size is an old technique some of you might already be using this configuration; some may know about it but may not have implemented. Recently I have implemented in my current project, would like to share my experience. In a typical production environment database and application will be running on different physical server. Even if you have high-end server class machine the network traffic between application and database server is one of the key factor of your application performance. Read more of this post

Debugging Applet code using Eclipse

For last one month I involved in an applet development work. Its been hard to debug and fix issues in applet code as I have to use System.out.println() to see debugging information, it is very hard and time consuming, often I have to redeploy applet code when after adding a few more System.out.println. Felt my development time is wasted so started looking around solution to debug applet code. I came across an article in IBM site to debug java code remotely using eclipse. Read more of this post

Difference between Thread.sleep() and Object.wait()

One of my favorite interview question is: What is the difference between sleep() and wait() method? The only commonality between these two method is both halts the current thread execution. The purpose and usage are entirely different. Read more of this post

Back to Basics: Statement vs. Prepared Statement

“What is the difference between Statement and Prepared Statement?” this is one of my favorite interview question. Most of the interviewee will say “Statement is not precompiled, prepared statements are precompiled, hence prepared statement will faster than statement”. My next question would be “What do you mean precompile”, the answer will be “the SQL gets compiled and reused”. My last question would be “In which layer the statement gets compiled? (like DB, JDBC, Java Apps.)”, most of them will answer JDBC. Since the answers are abstract, it could be interpreted in either way. Though the prepared statement concept are there for while very few provides in-depth answer. I did googling, the answers are scattered in various sites let me consolidate and give you a comprehensive view. Read more of this post

Why multiple inheritance is not allowed in Java

For long time I had a question “why Sun introduced Interface concept instead of C++ style of multiple inheritance?”. I did googling but many articles and forums talks about difference between abstract class and Interface not why Interface concept required in Java. After extensive search and analysis I came to know the reason behind the Interface concept in Java. Read more of this post

Advantages of ThreadLocal in Java

ThreadLocal is one of the rarely used class in Java. I found it is one of the powerful class in Java on multi-threaded programming. In multi-threaded program generally we use session object to track the current users information.

Read more of this post

What is the better approach to implement Singleton pattern?

Singleton is one of the frequently used and easily understandable design pattern. Most of the tutorials and books give example of making the constructor as private and exposing a static method which will provide single instance. The common example they use is Runtime class of JRE.

Is making constructor as private is the only way to implement singleton pattern? Is that the best way to implement singleton pattern?

Read more of this post

Java: How to stop a thread?

Sun deprecated Thread.stop() because it is unsafe. They didn’t provide any direct alternative for this operation; instead they are making us to reinvent the wheel. Here I am sharing my style of safe thread stop implementation. Read more of this post

Volatile and doubled checked locking in Java

During my Java training, I read about volatile keyword, but didn’t get clear understanding. Recently when I wrote a singleton class using double checked locking, PMD code reviewer gave a warning not to use volatile. Later I started exploring on double checked locking issue, here is my observation.

Read more of this post

Importance of specifying initial capacity while instantiating ArrayList and HashMap

ArrayList and HashMap are a few of the most frequently used data structures in Java development. So I would like to talk about the importance of instantiating these classes with initial capacity. Let me explain how the ArrayList works internally, so that you get a good insight. HashMap works almost the same way an ArrayList works, so I haven’t covered the details of that separately. But all the tips given below are applicable for HashMap as well.

Read more of this post

Java serializable interface

I was trying to understand the concept behind the java serialization.

I know java serialization is required when you want to save state of an object outside JVM. My thinking was why don’t Sun make all classes as Serializable by default? Why Serializable interface required to persist an object?

Read more of this post