Member-only story

Java — 5 Coding Mistakes You Should Avoid

Ignoring Exceptions In Your Code

#[Pragmatic(Kiwi)]
2 min readAug 15, 2022

Many times we may stumble upon pieces of code with unhandled exceptions; these pieces of code may not have been troublesome at conception but can become in time as more features and changes pile up triggering unwanted effects, especially using the OOP paradigm.

Exceptions are thrown with a purpose and in most cases we need to address the issue that causes it.

Java NullPointerException

When You Collect And Remove Objects in Separate Loops

This is how you would do it wrong:

This may be not so obvious but there is a method on the Iterator object called remove that could do the job for us and make it cleaner.

Using For Loops When We Can Use Foreach Loops

This is more about the semantics of the code as foreach loops can help us give names and meanings to our code. Instead of our code looking like a…

--

--

No responses yet