What are Lambdas in Java?

In general a lambda expression is an anonymous function, which means for some combination of inputs, there is a specific output. In the context of Java, a lambda expression is a kind of anonymous method with a more compact constructor syntax. Lambdas in Java are first class citizens, and can be passed as method parameters

read more

How to Decode URLs in Hive

Decoding URLs and strings can be a common task, especially when working with web data. This is easy to do in a language like Java or Python, but what about in Hive? Luckily, this is fairly easy as well. Decoding URLs in Hive with Reflection The first and easiest approach is to use the reflect()

read more

How to Generate a UUID in Java

UUID stands for Universally Unique Identifier. UUIDs are used as IDs (to identify) unique objects or records. An easy way to generate UUIDs in Java is to use the java.util.UUID class. Different variants and variant-versions exist for UUID objects. The methods of this class generally manipulate the Leach-Salz variant, although the constructors allow the creation

read more

How to Create a Max Heap using an Array in Java

A Heap/Binary Heap is a data structure that takes the form of Binary Tree. Heaps are commonly used to implement priority queues (check out the PriorityQueue class in Java). Priority queues are great ways to identify the highest (or lowest) priority items in a collection. A Max Heap is a binary tree data structure in

read more

How to Create a Hash Table in Java (Chaining Example)

Knowing how to create a hash table is helpful when using built-in HashTable and HashMap implementations in various languages. Questions about hash tables are commonly asked in programming interviews, and often people are asked to create an implementation from scratch. Below is an example of how to create a hash table in Java using “chaining”

read more

How to Code a Recursive Fibonacci Sequence

A Fibonacci Sequence is a sequence of numbers in which the first and second numbers in the sequence are 0 and 1 respectively, and additional numbers in the sequence are calculated by adding the previous two. The first few numbers in the Fibonacci Sequence look like this: 0, 1, 1, 2, 3, 5, 8, 13,

read more

How to Code an Iterative Fibonacci Sequence

A Fibonacci Sequence is a sequence of numbers in which the first and second numbers in the sequence are 0 and 1 respectively, and additional numbers in the sequence are calculated by adding the previous two. The first few numbers in the Fibonacci Sequence look like this: 0, 1, 1, 2, 3, 5, 8, 13,

read more

How to GZip a File in Java

One of the most common compression algorithms out there is gzip. Therefore you are likely to need to compress files using gzip at some time or another. Below is an example of doing this in Java. First create a FileInputStream from the file to be compressed. The data is read, and a compressed version of

read more

How to Sum Array of Ints in Java

Aggregating data in an array is a common programming task. This can easily be done in Java by initializing a variable to hold the summed value, looping over the elements in the array, and adding these values to the total. The sumArray method below is a good example of how to sum the values in

read more

Creating JSON with JSON.simple (Java)

JSON is a popular way to represent and transfer data. Creating JSON with JSON.simple (a Java library from Google) is very easy. JSON.simple also performs very well compared to other Java JSON libraries when parsing a variety of file sizes (see results of performance tests here). Below is a simple example of building a JSON

read more