Category: Java core

Hashtable VS HashMap

Hashtable VS HashMap

Hashing objects like HashMap and Hashtable are mostly used for storing and caching data as a key/value pairs inside the memory. In this tutorial, we list the major similarities and...

Java – Convert File to byte[]

Java – Convert File to byte[]

This tutorial shows several ways to convert a File object to a byte[] array in Java. 1- Traditional way The traditional conversion way is through using read() method of InputStream as...

Java – Convert byte[] to File

Java – Convert byte[] to File

This tutorial shows several ways to convert a byte[] array to File in Java. 1- Traditional way The traditional way of doing the conversion is through using FileOutputStream as the...

Convert JSON to Java Object

Convert JSON to Java Object

This tutorials shows 2 ways for converting a JSON string to a Java object. 1- Gson Gson is the most popular library for converting JSON string to Java objects. With Gson, you...

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...