Category: Java core

Convert Java object to JSON

Convert Java object to JSON

This tutorial shows 2 ways for converting Java objects to JSON. This kind of conversion is normally done via third-party libraries as it’s not supported by the JDK itself and...

Java - Convert InputStream to String

Java – Convert InputStream to String

This tutorial shows several ways to convert an InputStream to a String in Java. 1- BufferedReader The common way for generating a String out of an InputStream is through using...

Java - Convert InputStream to File

Java – Convert InputStream to File

This tutorial shows several ways to convert InputStream to File in Java. 1- Common way The common way for converting InputStream to File is through using OutputStream. You can’t directly...

Java - Convert List to Array

Java – Convert List to Array

This tutorial shows several ways to convert a List to Array in Java. 1- toArray() List provides a utility method called toArray() which accepts an empty array and populates it...

Java - Convert Array to List

Java – Convert Array to List

This tutorial shows several ways to convert Array to List in Java. 1- Arrays.asList You can convert an Array to List using Arrays.asList() utility method. This method accepts an array...

Java - Convert List to Map

Java – Convert List to Map

This tutorial shows the different ways to convert a List to Map in Java. 1- Java 7 & before With Java 7 and older releases, the only way to convert...

StringBuilder VS StringBuffer

StringBuilder VS StringBuffer

Since String is immutable, it is very costly to use it when constructing a dynamic character string due to the fact that a new memory location will be allocated at...

Java try-with-resources

Java try-with-resources

Java 7 supports a new statement called try-with-resources which extends the behavior of the traditional try/catch block for the sake of automatic resource management, since Java 7 developers are able...

Define an abstract property in java

Define an abstract property in java

Abstract keyword is normally applied on classes and methods in order to delegate the implementation of some behavior to subclasses. Java doesn’t support abstract properties, if you try to mark...

Static keyword in java

Static keyword in java

Every instance of a class has its own state and behavior, whenever the state of a particular instance is modified, other instances are not affected. In java, a static keyword...

How to use Enums in java

How to use Enums in java

In this article, we provide several examples on the usage of Enums in java. 1. Overview of Enum Enum is a java type/class which holds a fixed set of related...

How to create an immutable class in java

How to create an immutable class in java

An object is immutable if its state cannot change after construction, immutable objects don’t expose any way for other objects to modify their state, the object’s fields are initialized only...

Working with hashcode() and equals() in java

Working with hashcode() and equals() in java

By default, the java super class java.lang.Object provides 2 important methods: equals() and hashcode() for comparing objects, these methods become very useful when implementing large business which requires interactions between several classes. In...