Popular items


Everyone makes mistakes

Blogpost by: Sui Wai Chan
From: Friday 15 August 2014

This time my blog entry will be a bit more technical. It’s about certain mistakes a beginner Java programmer makes. And not only beginners, also people who live and breathe Java make (these) mistakes.

I found this top ten list of mistakes which everyone makes, at one time or another. Although quite an old list, I still find it useful and recognizable. I’ve cut down the full explanation to only the example code where applicable. You should read the full article for all information about spotting and fixing the problems here.

Do you recognize any of these mistakes?

10. Accessing non-static member variables from static methods

This takes me back to the days I started programming Java…

9. Mistyping the name of a method when overriding

Why is the method not called…

8. Comparison assignment

Don’t confuse “=” with “==”. Can you explain why the code below produces “false”?

7. Comparing two objects

Why does it say “Different” after running this program…?

6. Confusion over passing by value, and passing by reference

This specific problem is one I encountered myself last week. I’ve written some example code replicating the problem. You can download the code here:  cardetailprocessor »

It contains a CarDetailProcessor class containing a main method which can be executed. We expected the code to print out a nice list containing each entry, but somehow….

5. Writing blank exception handlers

Make sure you always log / print the Exception.  Even if you don’t need to do anything with the Exception. If you DO run into any problems and haven’t written any error messages, it will be difficult to find out the cause of the error.

4. Forgetting that java is zero-indexed

Don’t tell me you’ve never gotten an “ArrayOutOfBoundsException” notification?

3. Preventing concurrent access to shared variables by threads

Don’t think single-threaded processors don’t have problems modifying the same data at the same time. Don’t cut corners and make your variables private and use synchronized accessor methods!

2. Capitalization errors

Let us not give ourselves and others a headache and use naming conventions

1. Null pointers

Probably by far the number 1 error a programmer gets. Your compiler won’t spot it but you most certainly will be made aware at runtime… Can you spot the problem below?

« Back to Blogs
Tags: Java

Sui Wai Chan

Java Developer

» More information

Add your reply


They chose Onetrail