Found 9150 Articles for Object Oriented Programming

Difference Between Daemon Threads and User Threads In Java

Nitin Sharma
Updated on 18-Sep-2019 12:10:14

1K+ Views

As we know java is a language that supports multi threading and on the basis of nature threads in java are classified into two types Daemon thread and User thread.The following are the important differences between Daemon Threads and User Threads.Sr. No.KeyDaemon ThreadsUser Threads1NatureDaemon thread is low in priority i.e JVM does not care much about these types of threads.User threads are recognized as high priority thread i.e. JVM will wait for any active user thread to get completed.2CPU availabilityIt is not guaranteed that Daemon thread always gets CPU usage whenever it requires due to its low priority.User thread always ... Read More

Difference between concat() and + operator in Java

Aishwarya Naglot
Updated on 10-Oct-2024 12:46:11

2K+ Views

Java provides two ways to append strings and make them one. These two methods are namely the concat() method and + operator to join strings together, but there are some important differences between how they work. The concat() method is a bit more specific and limited, while the + operator is more flexible. So, even though they do the same thing, understanding how and when to use each one can help in writing more efficient or cleaner code in Java. Concat() Vs + operator The following are the important differences between the concat method and the + operator. ... Read More

How can we encode a JSON object in Java?

raja
Updated on 04-Jul-2020 05:58:28

3K+ Views

A JSONObject is a subclass of java.util.HashMap where no order is provided. We can also use the strict ordering of elements as well with the help of the JSONValue.toJSONString(map) method i.e. by the implementation of java.util.LinkedHashMap.We can encode a JSON object in the below two examples.Example import java.util.*; import org.json.simple.JSONObject; public class JSONEncodingTest {    public static void main(String[] args) {       Map dataMap = new HashMap();       dataMap.put("Name", "Adithya");       dataMap.put("Age", new Integer(25));       dataMap.put("Salary", new Double(25000.00));       dataMap.put("Employee Id", new Integer(115));       dataMap.put("Company", "TutorialsPoint");       JSONObject ... Read More

How can we parse a nested JSON object in Java?

Aishwarya Naglot
Updated on 22-Apr-2025 16:28:52

15K+ Views

Sometimes, we need to parse a nested JSON object, which means an object inside another object. In this article, let's learn about how to parse a nested JSON object in Java. If you don't know about JSON, refer JSON overview. Parsing a Nested JSON Object in Java? We can achieve this using some of the popular Java libraries. Those are listed below: Using org.json library : We will use jsonObject.getJSONObject method to parse a nested JSON object. Using Gson library : We will use JsonParser.parseString(json).getAsJsonObject(). Using Jackson library : In this, We will use ObjectMapper.readTree(json) method. Now, ... Read More

Convert a JSON object to XML format in Java?

Aishwarya Naglot
Updated on 21-Apr-2025 18:54:40

7K+ Views

In this article, we will learn how to convert a JSON object into XML format in Java. But first, let’s understand what JSON and XML are. JSON is a lightweight data-interchange format, and the format of JSON is like a key-value pair. XML (Extensible Markup Language) is also a way to store data, but unlike JSON, it uses tags to make the proper structure. Why Do we Convert JSON to XML? There can be multiple situations where we would need to convert JSON to XML. Here are some of the reasons: XML is ... Read More

Convert a JSON String to Java Object using the json-simple library in Java?

Aishwarya Naglot
Updated on 21-Apr-2025 19:35:29

2K+ Views

In this article, we will learn how to convert a JSON string to a Java object using the json.simple library. JSON stands for JavaScript Object Notation. It's a simple format that stores data in key-value pairs. It is used for sharing data between a server and a web app. To learn more about JSON, you can refer to the JSON tutorial. In Java, we can use a library called json.simple to handle JSON data. So, using this, we can easily convert a JSON string into a Java object. Why Convert JSON String to Java Object? There are many reasons to ... Read More

How to construct a JSON object from a subset of another JSON object in Java?

Aishwarya Naglot
Updated on 21-Apr-2025 19:33:12

3K+ Views

In this article, we will learn how to construct a JSON object from a subset of another JSON object in Java. If you are not familiar with JSON and its usage in Java, you can refer to our JSON Overview tutorial. JSON Object From a Subset of Another Object There is more than one way to construct a JSON object from a subset of another JSON object in Java. Some of the popular libraries that we can use are - Using org.json library Using Gson library Using ... Read More

How can we merge two JSON arrays in Java?

Aishwarya Naglot
Updated on 22-Apr-2025 18:35:33

8K+ Views

In this article, we will be learning how to merge two JSON arrays in Java. Let's understand step by step. First, if you are not familiar with JSON, refer JSON overview. How to Merge Two JSON Arrays in Java? There are multiple ways to merge two JSON arrays in Java. Some of them are: Using org.json library: We will use JSONArray.put() method to merge two JSON arrays. Using Gson library: We will use JsonArray.add() method to merge two JSON arrays. Using Jackson library: We will use ObjectMapper.createArrayNode() ... Read More

How can we convert a map to the JSON object in Java?

raja
Updated on 04-Jul-2020 05:51:35

9K+ Views

The JSON is a lightweight, text-based and language-independent data exchange format. The JSON can represent two structured types like objects and arrays. An object is an unordered collection of key/value pairs and an array is an ordered sequence of values. We can convert a Map to JSON object using the toJSONString() method(static) of org.json.simple.JSONValue. It has two important static methods: writeJSONString() method to encode an object into JSON text and write it out, escape() method to escape the special characters and escape quotes,  \, /, \r, , \b, \f, \t.Exampleimport java.util.*; import org.json.simple.JSONValue; public class ConvertMapJSONTest {    public static void main(String[] args) {       ... Read More

How to remove all the elements from a set in javascript?

Ayush Gupta
Updated on 18-Sep-2019 12:03:47

451 Views

The Set class in JavaScript provides a clear method to remove all elements from a given set object. This method can be used as follows −Examplelet mySet = new Set(); mySet.add(1); mySet.add(2); mySet.add(1); mySet.add(3); mySet.add("a"); console.log(mySet) mySet.clear(); console.log(mySet)OutputSet { 1, 2, 3, 'a' } Set { }You can also individually remove the elements by iterating over them.Examplelet mySet = new Set(); mySet.add(1); mySet.add(2); mySet.add(1); mySet.add(3); mySet.add("a"); console.log(mySet) for(let i of mySet) {    console.log(i)    mySet.delete(i) } console.log(mySet)OutputSet { 1, 2, 3, 'a' } Set { }

Advertisements