Top 5 Mistakes Most Java Programmers Make (Guest Post)

By January 14, 2013All 3 Comments

    This article was originally posted by Michael Dorf at LearnComputer blog.

    Everyone makes mistakes. Even the best programmer will have errors in their code every now and then, and no matter whether you’re a beginner or a master there are always going to be some frustrating errors or mistakes that you make that will come back to haunt you days, weeks, or months later in the production cycle. Don’t let programming mistakes come back to bite you down the line- take a look at some of the most common mistakes even experienced Java programmers make in their programs and remember to think of them next time you’re faced with a thorny issue you can’t pin down!

    5. Mistyped Override Function Name

    This is by far one of the most common and most frustrating errors that happens now and again. Take a look at the following code block:

    public class MyWindowListener extends WindowAdapter {
            public void WindowDeactivate(WindowEvent e) {

    That code will compile just fine. However, absolutely nothing will happen when the user minimizes the window, because that should be “WindowDeactivated” instead of “WindowDeactivate”. If the function is misspelled, the compiler will have no idea and won’t catch it, and you’ll be left trying to figure out why your code block isn’t working. Better yet, often the typo is hard to spot, and you’ll be left scratching your head, sure that “WindowDeactivated” is running- (and it is, your code just doesn’t override it!). If you’re having problems with overrides, the first thing you should do is check and double-check your function names- chances are there’s a missing or added letter somewhere that shouldn’t be!

    4. Passing By Value vs. Passing By Reference

    This is another sticky one to spot, especially because it’s often the case that it’s not entirely clear as to when exactly you’re passing by value and when you’re passing by reference and why that matters.

    Passing by value is when you use a primitive data type like an int, float, char, or double and pass it to a function. When this happens, a copy of that data type is sent to the function instead of the actual data itself. When the function performs any modification to the value, only the copy is being touched: unless the new value is put as a return value, nothing will have happened to the original data.

    When you pass an object like a vector, string, or array, however, you are passing by reference- that means you are actually passing the data type to the function, and any modifications made to the object are permanent even without the use of a return statement since the function is using the original data.

    Quite often these two differences cause strange problems when you think you’re dealing with one and you’re in fact dealing with the other- if you’re seeing strange value changing errors, take a look at your functions: chances are something’s passing differently than you’d expect it to!

    3. Not Writing Exception Handlers

    This isn’t technically an error, but it’s most certainly a very bad programming practice that can lead to mistakes that can be harder to spot. Don’t write blank exception handlers! If you don’t have any error messages, mistakes can’t be caught easily and you’ll have no idea what’s going on. Even if it’s just a short, unique string that you can match against the specific handler, make sure you have some sort of error message string for your exception handlers so you can more easily and quickly find and catch bugs later. A second or two of work writing exception handlers can save minutes or hours later trying to find out a mistake later!

    2. Comparing (== vs .equals)

    Though this is more often a beginner’s mistake, it’s amazing how often it pops up in code from more experienced developers as well, especially from developers coming from different languages who aren’t entirely comfortable working in Java’s syntax yet. The == operator only compares two references- i.e. whether the two object references point to the same object. The equals function actually compares the two values for equality:

    String string1 == “string1”; String string2 == “string1”;

    Those two strings will fail the == operator, because they do not reference the same object. You can only compare them using the equals operator- don’t forget this when working and using Java to compare different values!

    1. Capitalization Errors

    This is the most common mistake that most Java programmers make, and it’s also the mistake that seems the most unlikely to make and the easiest to spot. Most experienced Java programmers reading this will swear up and down they would never mistakenly capitalize something or forget to capitalize something, but just as many of them will attest to the fact that they’ve done this a time or two. It’s sometimes extremely difficult to discover when you’ve done this, as our minds tend to read over capitalization errors, especially in long programs with long function names. If you’re finding strange errors regarding a function you know is there, always, always check the capitalization- it’s possible you forgot, and it’ll save hours of heartache looking for the problem!


    Everyone makes mistakes, and every programmer will likely make all of these more than once. The trick, however, is to recognize that these are common problems and to look for them when you get misbehaving code – it’ll help in the long run to have a bit of an educated guess as to where the problem in your code might lie!

    * The views expressed in this article are those of the author and do not necessarily represent the views of, and should not be attributed to, Jelastic or its technology and distribution partners.


    Leave a Reply

    Your email address will not be published.