Recently I was working on a project where we were working with a third party in order to process different Office files. This third-party had both a production tenant as well as a development tenant as can be common with these types of integrations. The development tenant was much less stable than the production tenant and, at least it felt like, it would go down quite often. At this point it was just a gut feel from our interactions on and off with the service so we wanted to quantify it. As we considered ways we could check whether the…

Photo by Sarah Kilian on Unsplash

At some point in your coding career you may be unlucky enough to encounter code that looks somewhat like the following:

try {
int i = 0;
while (true) {
} catch (ArrayIndexOutOfBoundsException ignored) {

Likely what this code is doing doesn’t immediately jump out at you, especially compared to a similar function that performs the same function written like this:

for (Item item : items) {

Not only is the first function more code, it is harder to grok and actually less performant. The unfortunate thing is that apparently some developers that write code…

Photo by Glenn Carstens-Peters on Unsplash

Java has been around for a long time. In its long history, certain conventions have been created. An official set of conventions, reasonably called The Java Language Specification, stands as the official language conventions. These conventions cover both appearance and grammatical conventions.

The first item to cover is that of the package structure. Packages form a hierarchical organization of components separated by periods. Components are written in lowercase letters and rarely digits. Packages should begin with the organization’s domain name with the components reversed (ex:, org.apache, etc.) Two exceptions to this are the java and javax packages. Package components…

Photo by Martin Adams on Unsplash

There are a number of sayings that have grown in popularity in the technical industry:

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil

Donald E. Knuth

We follow two rules in the matter of optimization:
Rule 1: Don’t do it.
Rule 2: (for experts only) Don’t do it yet — that is, not until you have a perfectly clear and unoptimized solution

M. A. Jackson

It’s pretty clear that there are major concerns with optimizing applications early. A root of a lot of these concerns is that when…

Photo by Marc-Olivier Jodoin on Unsplash

Java provides the Java Native Interface (JNI) that allows Java programs to call into native methods written in native programming languages such as C, C++, or Rust. Historically this capability has been used for three different things:

  1. The ability to call into platform-specific features such as registries.
  2. Access to existing native code so that you don’t need to re-implement it.
  3. For writing performance-critical parts of your application.

As stated above it is valid to use native methods to access platform-specific functionality although that is seldom needed. …

Photo by Faye Cornish on Unsplash

Java provides a very powerful capability in its reflection system. Reflection allows us to have extreme flexibility when calling classes, their constructors, and methods. These classes that we are interacting with may not even exist at the time that our reflexive code is written. This flexibility is not free, however; there are downsides to its use. Some of these are the following:

  • You lose out on compile time checks. Issues that would be exposed at compile-time when coded in non-reflexive style turn into runtime issues when coded via the reflexive APIs.
  • Related to the above, static code analysis tools have…
Photo by Namroud Gorguis on Unsplash

This topic of today is focussed on flexibility. When defining parameters, return types, or variables it is encouraged to define them as the interface that the concrete types implement. So instead of something like:

LinkedHashSet<String> stringSet = new LinkedHashSet();

we should instead implement something like:

Set<String> stringSet = new LinkedHashSet();

What writing our code like this allows us to do is change out the implementation of our variables as long as they meet the same interfaces. So maybe instead of using a LinkedHashSet like defined in the first example we could change it to a HashSet without having to change…

Photo by Christopher Bill on Unsplash

Types in Java come in two flavors, primitive types (int, long, etc) and reference types (String, List, etc). Each primitive type has a corresponding reference type called a boxed primitive. Java does have autoboxing and unboxing which can abstract away the difference between these types but not completely as we will see. Let’s look at a few examples of where we can get in trouble with using primitives and reference types together.

To start off we need to consider the main differences between primitive and reference types:

  1. Primitives identity and values are the same. …
Photo by Jeswin Thomas on Unsplash

This chapter dives into a fun computer science based topic. When we have a need to represent numbers that include a decimal point we will often reach for either a float or a double. These primitive types facilitate the representations of approximate floating point values over various magnitudes. A key part of the previous sentence is that it's an approximation. We must not use floats or doubles when we need exact answers, especially when dealing with numbers.

Let’s briefly go over why this is the case. The goal of floating point types is to allow the representation of any number…

Photo by Alfons Morales on Unsplash

This chapter dives into a problem that many developers will find themselves falling into at one time or another, that is of reinventing the wheel. As developers we often want to get into the details of something rather than learn how to use someone else’s code. This being said, by taking this stance, we often are doing ourselves a disservice.

Let’s look at an example. Let’s consider the following code. This code’s job is to pick a random number up to a given limit:

static Random rnd = new Random();static int random(int upperLimit) {
return Math.abs(rnd.nextInt()) % n;

Kyle Carter

I'm a software architect that has a passion for software design and sharing with those around me

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store