Author Archive


Reading a Text File in Java

Java has an extensive API for file handling. The following code illustrates how Java File API can be used to read text files. This example shows line by line reading of the file content. This example also assumes that a text file with the name input.txt is present in the C:\ drive. If you are […]

Struts 2 NetBeans Tutorial

Introduction Struts 2 is an excellent MVC Web application framework for developing enterprise Java web applications. It enables rapid development of Web applications and handles most of the plumbing required in large Web applications. This tutorial shows how NetBeans IDE can be used to build Struts 2 applications. Usually Struts2 applications are developed as Maven […]

Creating a Random BigInteger in Java

Java provides a custom class named BigInteger for handling very large integers (numbers which require more than 64 bits). BigInteger provides a constructor using which you can create a random BigInteger value. public BigInteger(int numBits, Random rnd) Constructs a randomly generated BigInteger, uniformly distributed over the range 0 to (2^numBits – 1), inclusive. The uniformity […]

Using BigInteger in Java

For handling numbers, Java provides built-in types such as int and long. However these types are not useful for very large numbers. When you do mathematical operations with int or long types and if the resulting values are very large, the type variables will overflow causing errors in the program. Java provides a custom class […]

Creating an Inline Array in Java

The usual way of creating an array in Java is given below. In this example, we create a String array containing primary color names, public class InlineArrays { public static void main(String[] args) { String[] colors = {"red","green","blue"}; printColors(colors); } public static void printColors(String[] colors) { for (String c : colors) { System.out.println(c); } } […]