In this article, let's learn about the serialization of the order of properties using the Jackson library in Java. The Jackson library is used for processing JSON data in Java. The @JsonPropertyOrder is an annotation to be used at the class level. It takes as property a list of fields that defines the order in which fields can appear in the string resulting from the object JSON serialization. The properties included in the annotation declaration can be serialized first(in defined order), followed by any properties not included in the definition. Steps to serialize the order of properties using the Jackson ... Read More
If there are fields in Java objects that do not wish to be serialized, we can use the @JsonIgnore annotation in the Jackson library. The @JsonIgnore can be used at the field level, for ignoring fields during the serialization and deserialization. In this article, we will learn how to ignore the fields during JSON serialization in Java using the Jackson library. Steps to ignore the fields during JSON serialization in Java: In order to use Jackson, you will need to add it to your project. If you use Maven, add the following dependency to your ... Read More
The Method Reference and Constructor Reference are part of Java 8's functional programming features, they used for refering to methods and constructors without executing them. They are often used in conjunction with functional interfaces, such as those defined in the java.util.function package. Method Reference A method reference is a shorthand representation of a lambda expression for calling a method. A method reference refers to a method without executing it. Method references can refer to static methods, instance methods, and constructors. Constructor Reference A constructor reference is a unique kind of method reference that is a reference to a constructor. ... Read More
Java HashMap is a hash table-based implementation of Java's Map interface. It is a collection of key-value pairs.In this article, we will learn to sort a map by values in Java. Following are the ways to sort a map by values in Java: Using Comparator Using Streams Using Comparator We can sort a map by values using a custom comparator. The comparator will compare the values of the map entries and sort them accordingly. Steps to sort a map by values using Comparator: Step 1: Create a HashMap and populate it with some key-value pairs. Step 2: ... Read More
The constructor chaining is a specific sequence of calling constructors when a user initializes an object in a certain way. This technique is used when multiple constructors are invoked one after another, based on the instance class. It is also closely related to inheritance, where the role of a subclass constructor is to call the constructor of its superclass. You can perform constructor chaining in two ways: Within the same class - where one constructor calls another constructor of the same class. Across different classes - where a subclass constructor calls ... Read More
Interfaces in Java are used for defining a contract that classes can implement. They can contain method signatures, default methods, static methods, and constants. we must implement the methods defined in the interface in the implementing class. Constructor in an Interface A Constructor is to initialize the non-static members of a particular class with respect to an object. An Interface in Java doesn't have a constructor because all data members in interfaces are public static final by default, they are constants (assign the values at the time of declaration). There are ... Read More
An enum is a special "class" that represents a group of constants (unchangeable variables, like final variables). For example, we have constants like week days, months, or set of languages etc. In Java, we can create an enum to represent these constants. In this article, we will learn how to lookup an enum by its string value in Java. Java Program to Lookup Enum by String Value lets learn how you can convert a string to its corresponding enum value using the following ways and also print the enum value: Using valueOf() Method Using EnumSet and stream() Using ... Read More
In this article, let's learn how to remove a sublist from an ArrayList in Java. The ArrayList class is a part of the Java Collections Framework. It is a resizable array and an implementation of the List interface. The ArrayList class is used when we want to store a list of elements in a dynamic array. Sub-list is a specific portion of an array list. Basically, it is a list of elements that are part of the original list but it is not the entire list itself. Using subList() and clear() method. ... Read More
Problem Statement The task is, given a string and a substring, you have to check if a substring is present in a string or not. Do not mind if the case of the string and substring is different, it should not matter. For example, if the string is "Hello World" and the substring is "hello", then the output should be true. Even if the substring is "HELLO" or "HeLLo", the output should be true. Solution To solve this problem, we will first convert the string and the substring to lowercase using the toLowerCase() method. The toLowerCase () method of the ... Read More
Problem Statement Here we have a string that contains integer values, our task is to sort those integer values in ascending order. For example, if the string is "31134", the sorted string should be "11334". Solution We can solve the above problem using multiple ways: Using char array Using Stream API Using Bubble Sort Using char array We will use the toCharArray() method of the String class to convert the string into a character array. Then we will sort the character array using the Arrays.sort() method. ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP