Java Programming Tips


How to Write a MapReduce Program in Java

This tutorial provides a step by step tutorial on writing your first hadoop mapreduce program in java. This tutorial uses gradle build system for the mapreduce java project. This program requires a running hadoop installation. Quick Introduction to MapReduce MapReduce is a programming framework which enables processing of very large sets of data using a […]

Random Alphanumeric Generator in Java

The following Java example program generates a cryptographically secure random alphanumeric string. If cryptographic security is not a requirement, the SecureRandom class can be replaced with Random class for a much faster implementation. The following function can be used to generate random strings with a specified length. It is also possible to specify a subset […]

How to Pick a Random Character in Java

The following Java program can be used to generate a random character in Java. There are three functions in the program. getRandomCharacter() returns a random character in the ASCII printable character set. getRandomAlphabet() returns a random alphabet in english (a – z). getRandomAlphaNum() returns a random alphanumeric character (0 – 9 & a – z). […]

How to Read HDFS File in Java

Hadoop distributed file system (HDFS) can be accessed using native Java API provided by hadoop Java library. The following example uses FileSystem API to read an existing file in an hdfs folder. Before running the following Java program, ensure that the following values are changed as per your hadoop installation. Modify the HDFS_ROOT_URL to point […]

How to Pick a Random Number in Java

Random numbers have a wide range of programming uses such as in games, encrypting data etc. Java has multiple classes for generating random numbers. Deciding which one to use depends a lot on the program requirements. Here are some of the Random generator classes and their primary purpose, java.util.Random – This is the simplest implementation […]