Home » Archives for Anirudh Bhatnagar » Page 2

Author Archives: Anirudh Bhatnagar

Anirudh is a Java programmer with extensive experience in building Java/J2EE applications. He has always been fascinated by the new technologies and emerging trends in software development. He has been involved in propagating these changes and new technologies in his projects. He is an avid blogger and agile enthusiast who believes in writing clean and well tested code.

Java ObjectInputStream and ObjectOutputStream Example

In this example we will see how we can use Java’s ObjectInputStream and ObjectOutputStream classes to serialize objects and store them as a file or any other storage accessible by Output Stream; read them again, deserialize it into an object and use it. ObjectOutputStream Example So, first we will see how to write an object into a File using FileOutputStream ...

Read More »

Java File Descriptor Example

In this post we will discuss Java FileDescriptor class and its use case. Before we see an example, first lets try to understand what is File Descriptor and why it is used. Whenever a file is opened, the operating system creates an entry to represent this file and stores its information. Each entry is represented by an integer value and ...

Read More »

Java StreamTokenizer Example

In this example we will see how to use Java StreamTokenizer class to parse an input stream into tokens. We can use this class to break the InputStream object or an object of type Reader into tokens based on different identifiers, numbers, quoted strings, and various comment styles. The use of InputStream as the input parameter is deprecated, so we ...

Read More »

Java DecimalFormat Example

In this example, we will see how we can use the Java DecimalFormat class to format decimal numbers. 1. Java DecimalFormat – Introduction  This class is useful when we want to format the decimal numbers in the following ways: As per a defined specific string pattern: We can specify a pattern string to define the display of the decimal. ...

Read More »

Java List Remove Object Example

In this example we will discuss how to remove objects from a java.util.List. There are 2 methods described in the Java API to do so : E remove(int index) We can use index of list to remove the object. boolean remove(Object o)   We can pass the object itself which needs to be removed. For this method to work for ...

Read More »

Java List to Array Example

In this example, we will see how to convert a List (java.util.List) in Java into an array. java.util.List has two methods to do so : T[] toArray(T[] a) – returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified ...

Read More »

Java List Contains Method Example

In this example we will discuss the java.util.List.contains method and see how to use it. The method signature in the Java interface List is : boolean contains(Object o). As per the Java documentation, it returns true if and only if this list contains at least one element’s equals method returns true for object which we are searching for. Lets see ...

Read More »

Java Array to List Example

In this example I will show you how to convert an array into a java.util.List. We will use the java.util.Arrays class to convert an Object Array into a List of Objects. Lets see the example: 1) Object Array to List. A List can only store objects and not the primitives. So, lets how we can convert an array of objects into ...

Read More »