9 most common mistakes by Java programmers

As you know that Java is one of the most popular general purpose programming languages and many programmers use Java daily basis. The language is easy to learn, but there have many different kinds of mistakes that every programmer does. So, let's find out the 9 most common mistakes in Java development.

1. Missing closing braces

Most common mistakes by Java programmer is the missing closing braces. The closing braces are often missed due to improper indentation of the code, or due to putting the open brace without closing it immediately.

2. Forget to free up resources

Similar like braces, most of the time when a programmer opens a file or network connection, they forgot to free the resource once you are done using it.

3. Missing break in switch case

Java creates very embarrassing issues, and sometime novice programmers added more fuel by missing a break in switch case. Because of missing break, the code does not cause compile error, but it runs wrongly.

4. Excessive garbage allocation

When a programmer create lot of short-lived objects, that may cause excessive garbage allocation. The garbage collector works continuously, removing unneeded objects from memory, which impacts applications' performance in a negative way.

5. Confused about 0 and 1 based index system

Like other languages, array index in Java are based on 0, which means the first element in the array starts at the index 0. However, sometimes programmer mistakenly treat the first element at index 1.

6. Accessing non-static members from static methods

Programmers are often making this mistake, because they don't fully understand the differences between static and non-static stuffs in Java. This mistake mostly happens in the static method main () where one attempts to access an instance variable or method.

7. Neglecting existing libraries

Java has innumerable amount of libraries. You can do almost everything the existing libraries. But, many programmers try to reinvent the wheel without searching for the library with the particular feature.

8. Memory leaks

Java uses automatic memory management, but it doesn't mean that a beginner should not be aware of how memory is used in the application. Memory leaks in Java can happen in various ways, the most common reason is everlasting object references. Because the garbage collector can't remove objects from the heap while there are still references to them.

9. Ignoring exceptions

Many beginners are too lazy to write the code for handling exceptions. It seems to be harmless if the code runs fine without exceptions. But, in case the exceptions occurred, the code can fail silently which create difficulties to find the problem.

Hope this list may help you to minimize your mistakes while working on Java. Please share your common mistakes in the comment below. Thanks so much!

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.