Iterative Binary Search Example

Binary Search is a classic algorithm used to find an item in an ordered list/array of items. This list/array of items must be ordered for binary search to work. The basic idea of Binary Search is to: Take the midpoint between the smallest and largest elements. Determine if item being searched for is smaller or

read more

How to Exclude Fields using Gson

There are a lot of great Java libraries for working with JSON. One of these is Google’s Gson, which has the goal of providing simple toJson() and fromJson() methods to convert Java objects to JSON and vice-versa. Often when serializing objects into JSON you will want to exclude certain object fields. There a couple of

read more

Creating JSON with Gson

There are a lot of great Java libraries for working with JSON. One of these is Google’s Gson, which has the goal of providing simple toJson() and fromJson() methods to convert Java objects to JSON and vice-versa. By default, the toJson() method will serialize all fields in the current class (and all super classes). Below

read more

Java Binary Search Tree Implementation

The Binary Search Tree is commonly used data structure in Computer Science. Below is a complete binary search tree implementation, including the standard methods used to find, insert, and delete nodes from the tree. In addition are methods to print tree structure as well as track of the number nodes (so the tree size can

read more

Simple Apache Avro Example using Java

Apache Avro is a popular data serialization system that relies on schemas. The official Avro documentation can be found here: http://avro.apache.org/docs/current/. This post walks through an example of serializing and deserializing data using Avro in Java. Maven is not necessary for working with Avro in Java, but we will be using Maven in this post.

read more

How to Break from Nested Loop in Java

In Java, we can break/exit from the current loop with the break statement. But what if we want to break an outer loop from a nested loop? In Java we can name our loops using labels. By using labels we can specify which loop we would like to break out of (also called “breaking to

read more

Get the MD5 Hash Code of a File with Java

Getting the hash code of a file is a common programming task. MD5 is a very popular and commonly used hashing algorithm. Getting the MD5 hash code of a file with Java can be easily done, and is shown in the code below:

The code above does several things: Creates a MessageDigest object that

read more

Create an MD5 Hash Code from a String in Java

Creating a hash codes from strings is a common programming task. MD5 is a very popular and commonly used hashing algorithm. Creating an MD5 hash code from a String in Java can be easily done, and is shown in the code below:

The code above is does several things: Creates a StringBuilder object to

read more

Generating Fake Data in Java with jFairy

Generating fake data can be a common need when developing applications or loading test data into a database. jFairy is a great fake data generator library built in Java that is very easy to use. jFairy allows you to build data sets containing diverse types of data including names, addresses, telephone numbers, dates, large integers,

read more