Raja has Published 469 Articles

What are the advantages of private methods in an interface in Java 9?

raja

raja

Updated on 21-Feb-2020 04:59:01

568 Views

In Java 9, an interface can also have private methods. Apart from static and default methods in Java 8, this is another significant change as it allows the re-usability of common code within the interface itself.In an interface, there is a possibility of writing common code on more than one default method that leads to code duplication. ... Read More

How to add/insert additional property to JSON string using Gson in Java?

raja

raja

Updated on 19-Feb-2020 10:28:54

9K+ Views

The com.google.gson.JSonElement class represents an element of Json. We can use the toJsonTree() method of Gson class to serialize an object's representation as a tree of JsonElements. We can add/ insert an additional property to JSON string by using the getAsJsonObject() method of JSonElement. This method returns to get the element as JsonObject.Syntaxpublic ... Read More

How to convert an array to JSON Array using JSON-lib API in Java?

raja

raja

Updated on 19-Feb-2020 07:46:28

522 Views

A Java array is an object which stores multiple variables of the same type, it can hold primitive types and object references whereas JSONArray is an ordered sequence of values. Its external text form is a string wrapped in square brackets with commas separating the values, an internal form is an object having get() and opt() methods for ... Read More

How can we implement a JSON array using Streaming API in Java?

raja

raja

Updated on 18-Feb-2020 10:47:33

1K+ Views

The JsonGenerator interface can be used to write the JSON data to an output source in a streaming way. We can create or implement a JSON array using the writeStartArray() method of JsonGenerator, this method writes the JSON name/start array character pair within the current object context. The writeStartObject() method writes ... Read More

How can we sort a JSONObject in Java?

raja

raja

Updated on 18-Feb-2020 10:07:15

6K+ Views

A JSONObject is an unordered collection of a key, value pairs, and the values can be any of these types like Boolean, JSONArray, JSONObject, Number and String. The constructor of a JSONObject can be used to convert an external form JSON text into an internal form whose values can be retrieved with ... Read More

How to create a class and object in JShell in Java 9?

raja

raja

Updated on 17-Feb-2020 13:36:48

397 Views

JShell is a new java shell tool released in java 9. It is the first official REPL (Read-Evaluate-Print-Loop) application. This tool helps in executing and evaluating simple java programs and logics such as statements, loops, expressions, and etc. Java REPL provides a simple programming environment in the command prompt. It ... Read More

How to deserialize a JSON string using @JsonCreator annotation in Java?

raja

raja

Updated on 17-Feb-2020 08:18:20

978 Views

The @JsonProperty annotation can be used to indicate the property name in JSON. This annotation can be used for a constructor or factory method. The @JsonCreator annotation is useful in situations where the @JsonSetter annotation cannot be used. For instance, immutable objects do not have any setter methods, so they need their initial ... Read More

JShell in Java 9?

raja

raja

Updated on 17-Feb-2020 05:05:11

229 Views

JShell is a new concept introduced in Java 9 version. It provides Java with REPL (Read-Eval-Print-Loop) ability. By using JShell, we can test the java-based logic and expressions without compiling it. REPL acts as an immediate feedback loop and has a great effect on productivity in that particular language.Step 1: Open Command Prompt ... Read More

How to define the naming conventions for JSON field names in Java?

raja

raja

Updated on 14-Feb-2020 06:58:38

2K+ Views

The FieldNamingPolicy can be used to define a few standard naming conventions for JSON field names and it can be used in conjunction with GsonBuilder to configure a Gson instance to properly translate Java field names into the desired JSON field names. We can use the setFieldNamingPolicy() method of GsonBuilder to configure a specific naming policy ... Read More

What is the use of underscore keyword in Java 9?

raja

raja

Updated on 13-Feb-2020 10:29:35

2K+ Views

In earlier versions of Java, the underscore ("_") has used as an identifier or to create a variable name. Since Java 9, the underscore character is a reserved keyword and can't be used as an identifier or variable name. If we use a single underscore character as an identifier, the program ... Read More

Advertisements