Category Archives: Java Basics

Exception handling in ScheduledExecutorService

Java’s ScheduledExecutorService allows you to schedule Runnable tasks without having to worry too much about creating Threads. But how do we handle this exception? We have a few options.

Execute Around idiom in Java

The Execute Around idiom is a pattern that allows you to wrap an action with some standard setup / tear down steps. Examples might include: Execute within a lock: acquire the lock, do the action, release the lock Resource handling: acquire the resource, do the action, close the resource Execute as a user: switch to read more »

Reverse order a Stream in Java

How do you reverse order a Stream in Java? There’s no obvious Stream.reverse() method. Is this an oversight in the API? Is there a workaround?

Testing for SimpleDateFormat thread safety

Declaring an instance of SimpleDateFormat as a constant (static final class member) is usually bad. But then again, it’s a very obvious thing to do.

Currency and BigDecimal

When deciding how to represent numbers (decimal or otherwise) we must first know if we are dealing with approximate or exact numbers.

Bean introspection

Have a naming convention or don’t. But if you do have one, don’t stick some obscure fudge in there. Hacks and fudges will catch up with you and bite you in the bottom.