Home » Core Java

Core Java

Jackson vs Gson: A Deep Dive

This is a tutorial about Jackson vs Gson. Specifically, we will do a quick comparison of the libraries Gson and Jackson for serialization of a Java object to its JSON representation and deserialization of JSON string back to an equivalent Java object. We will talk about the benefits of each and see which library to use when. 1. Maven Dependencies ...

Read More »

Thread.sleep Java Example

In this article, we’ll discuss about thread.sleep in Java along with some examples. We’ll start by explaining some details on threads, the importance of sleep method, and then we will use examples of the sleep method. 1. What is a thread in Java Threads are lightweight processes that allow concurrent execution of multiple activities. It allows us to perform synchronous ...

Read More »

Apache Ant Command Line Arguments Example

1. Introduction In this example, we will explain Apache Ant Command Line Arguments. In software development, the term building usually means the conversion of source code and other artifacts, like images or configuration files, into another artifact. For example source code might be compiled into a JAR file, or you may create a new standalone application. The build result can be shared ...

Read More »

Jackson Bidirectional Relationships

In this example, we will go through the Infinite Recursion (StackOverflowError) problem, when working with Bidirectional Relationships in Jackson model classes. We will also see different techniques to serialize and deserialize such entities. If you are new to Jackson, it is good to go through this primer on ObjectMapper before proceeding with this example. 1. What is a Bidirectional Relationship? ...

Read More »

Java Socket Programming

This article talks about sockets and socket programming with java examples. It begins with the basics and explains with an example of how they work. 1. Introduction Java Socket Programming finds itself very useful for peer-to-peer communication between two Java programs running different JVM. It works on a typical request/response model where-in a java program called client invokes another program ...

Read More »

Jackson Exceptions – Problems and Solutions

1. Introduction In this example, we shall go through the most common Jackson API exceptions encountered while working for serialization and deserialization. We will see what caused the exception to be thrown and how to fix it. Let’s dive deep. Table Of Contents 1. Introduction 2. InvalidDefinitionException: No Creators, like default constructor, exist 3. MismatchedInputException: Out of START_ARRAY token 4. ...

Read More »

Jackson Annotation Examples

This example is a deep dive into Jackson Annotations. It covers almost all the annotations with code examples. We will learn how to use the existing annotations, create our custom annotations and finally how to completely disable Jackson annotations. If you are new to the Jackson API for JSON serialization and deserialization, check out this article on Introduction to Jackson ...

Read More »

Java LocalDate Example

LocalDate class in Java 8 date time API represents a local date without time zone details. It is located in the java.time.LocalDate object. In this article, we shall look at some of the commonly used methods of LocalDate with some examples. 1. What is LocalDate LocalDate is an immutable thread-safe date-time object that represents a date, often viewed as year-month-day. ...

Read More »

Dependency Injection Java Example

In this article, we will examine Dependency Injection in Java and some dependency injection examples. 1. Introduction In a previous article, we explored the topic of Inversion of Control and how this design principle is appropriately suited for creating loosely coupled software applications. The IoC principle states that certain tasks typically performed by a class – for example, creating objects ...

Read More »

How to initialize an ArrayList in Java

In this article we will explain how to initialize an ArrayList in Java through example. 1. Introduction ArrayList is a part of the Collection Framework and is present in java.util package. It provides us dynamic arrays in Java. Though, it may be slower than standard arrays but can be helpful in programs where lots of manipulation in the array is needed. ...

Read More »