
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7442 Articles for Java

4K+ Views
When we have a JSON object and want to change a specific field name for some reason, we can use the Jackson library in Java.The Jackson Annotation @JsonProperty The Jackson Annotation @JsonProperty is used on a property or method during the serialization or deserialization of JSON. It takes an optional 'name' parameter, which is useful in case the property name is different from the key name in JSON. By default, if the key name matches the property name, the value is mapped to the property value. If the key name is different, we can use the @JsonProperty annotation to ... Read More

2K+ Views
The Jackson is a library for Java and it has very powerful data binding capabilities and it also provides a framework to serialize custom java objects to JSON and deserialize JSON back to Java object. Ignoring Null and Empty Fields Using Jackson The Jackson library provides @JsonInclude annotation, which controls the serialization of a class as a whole or its individual fields based on their values during serialization. The @JsonInclude annotation contains below two values: Include.NON_NULL: Indicates that only properties with not null values will be included in JSON. Include.NON_EMPTY: Indicates ... Read More

334 Views
Pretty printing JSON is a process of formatting our JSON data to make it more readable and good-looking.The prettyPrint() Method of Flexjson We will be using the Flexjson library to pretty print JSON in Java. The Flexjson library is a lightweight library that is used for serializing as well as deserializing Java objects to and from JSON. A JSONSerializer is the main class for performing the serialization of Java objects to JSON and by default, performs a shallow serialization. We can pretty-print JSON using the prettyPrint(boolean prettyPrint) method of JSONSerializer class. Syntax of prettyPrint() The syntax of the prettyPrint() method ... Read More

5K+ Views
Deserializing a JSON to a Java object means converting a JSON string into a Java object.The deserialize() Method of the Flexjson Library We will be using the Flexjson library to deserialize a JSON to a Java object in Java. The Flexjson library is a lightweight library that is used for serializing as well as deserializing Java objects to and from JSON. A JSONDeserializer is the main class for performing deserialization of JSON to Java objects. We can deserialize a JSON string to a Java object using the deserialize(String json, Class type) method of JSONDeserializer. Syntax of deserialize() Method The syntax of the ... Read More

2K+ Views
While parsing a JSON String to or from a Java object, by default, Gson tries to create an instance of the Java class by calling the default constructor. In the case of Java, if a class doesn’t contain a default constructor or we want to do some initial configuration while creating Java objects, we need to create and register our own instance creator. Custom Instance Creator Using Gson Custom instance means creating a new instance that is not the default. In this instance, we can add whatever properties we want. There are many libraries that create custom instances. In this ... Read More

190 Views
The java.util.EnumMap class is a specialized Map implementation for use with enum keys. Following are the important points about EnumMap −All of the keys in an enum map must come from a single enum type that is specified, explicitly or implicitly, when the map is created.Enum maps are maintained in the natural order of their keys.EnumMap is not synchronized. If multiple threads access an enum map concurrently, and at least one of the threads modifies the map, it should be synchronized externally.Following are the constructors of the EnumMap class −Sr.NoConstructor & Description1EnumMap(Class keyType)This constructor creates an empty enum map with the specified ... Read More

401 Views
Compare two strings using compareTo() method in Java. The syntax is as follows −int compareTo(Object o)Here, o is the object to be compared.The return value is 0 if the argument is a string lexicographically equal to this string; a value less than 0 if the argument is a string lexicographically greater than this string; and a value greater than 0 if the argument is a string lexicographically less than this string.ExampleLet us now see an example − Live Demopublic class Demo { public static void main(String args[]) { String str1 = "Strings are immutable"; ... Read More

474 Views
In this article, we will learn how to count the number of elements in a stream using the counting() method in Java Streams. Java Streams provide an efficient way to process data collections, and the Collectors.counting() method is useful for counting the number of elements in a stream. The counting() method is a static method of the Collectors class, which is part of the java.util.stream package. It returns a long value representing the number of elements in the stream. Counting the Number of Elements in the Stream The following are the steps to count the number of elements in the ... Read More

1K+ Views
In this article, we will learn the findAny() method with examples in Java. The findAny() method in Java Streams is a tool that is used for fetching an arbitrary element from a stream. It provides a quick and easy way to retrieve any element without writing any conditions. This method returns a container that may or may not contain a non-null value, which is called an Optional object. What is the findAny() Method? The findAny() method retrieves any element from the stream, and the result is wrapped in an Optional object. If the stream is empty, the Optional object will ... Read More

612 Views
An Iterator is used for cycling through a Collection of objects. Whereas a List is an Interface which is used for storing an ordered collection of elements. Both classes are part of the Java Collections Framework.Converting an Iterator to a List in Java Sometimes we need to convert an Iterator to a collection. In this article, we will learn how to convert an Iterator to a List in Java using multiple ways. Those are: Using a while loop Using Iterator.forEachRemaining() Using Stream API Let's understand each of them in ... Read More