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

How to Load a Text File into Spark

Loading text files in Spark is a very common task, and luckily it is easy to do. Below are a few examples of loading a text file (located on the Big Datums GitHub repo) into an RDD in Spark. If you have looked at the Spark Documentation you will notice that they do not include

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

How to Create a Fat Jar with Maven

A fat jar or uber jar is a jar that contains the classes of your current project as well as all of the classes on which it depends. For example, if your application requires Joda-Time, your jar file will contain all the classes of your current project, as well as all the classes of Joda-Time.

read more