Found 7442 Articles for Java

When can we use a JSONStringer in Java?

Aishwarya Naglot
Updated on 22-Apr-2025 14:33:12

531 Views

A JSONStringer provides a convenient way of producing JSON text, and it can strictly follow to JSON syntax rules. Each instance of JSONStringer can produce one JSON text. A JSONStringer instance provides a value method for appending values to the text and a key-method for adding keys before values in objects. We have array () and endArray() methods that create and bind array values, and object() and endObject () methods that create and bind object values. It is part of the org.json library. It is generally used in Android and lightweight Java programs. In this article, we will learn when to use a JSONStringer in Java. When to use ... Read More

How can we sort a JSONArray in Java?

Aishwarya Naglot
Updated on 22-Apr-2025 16:27:02

9K+ Views

In this article, we will learn how to sort a JSON array in Java. But first, let’s understand what JSON is. If you do not have knowledge about JSON, you can refer to the tutorial JSON Overview. Now, let's see different ways to sort a JSON array in Java. Ways to sort a JSON array in Java Following are different ways to sort a JSON array in Java - Sort JSON array Without any Dependency Using org.json library: Methods are getJSONArray() and getJSONObject() Using Gson library: Methods ... Read More

How can we convert a list to the JSON array in Java?

Aishwarya Naglot
Updated on 22-Apr-2025 14:25:07

33K+ Views

Converting a list to a JSON array is one of the common tasks in Java. Let's see how to convert a list to a JSON array in Java. If you do not know what JSON is, then you can read the JSON tutorial. The following are various ways to convert a list to a JSON array in Java: Manual construction of JSON array Using Jackson library Using Gson library Using org.json library Let's learn the process of each of them one by ... Read More

Differences between wait() and join() methods in Java

Nitin Sharma
Updated on 18-Sep-2019 14:16:47

3K+ Views

In multithreading when we deal with threads there comes the requirement of pause and start a thread for this Threading provides two methods wait and join which are used for the same.The following are the important differences between wait() and join().Sr. No.Keywait()join()1Declarationwait() method is defined in Object class and hence the wait() method is declared in java.lang package.join() method, on the other hand, is also defined in java.lang package but in Thread class.2Usagewait() method is primarily used for the inter-thread communication.On the other hand join() is used for adding sequencing between multiple threads, one thread starts execution after first thread ... Read More

What is the differences between TreeMap, HashMap and LinkedHashMap in Java?

Nitin Sharma
Updated on 18-Sep-2019 14:36:22

1K+ Views

HashSet and ArrayList both are one of the most important classes of the Java Collection framework.The following are the important differences between TreeMap, HashMap and LinkedHashMap.Sr. No.KeyTreeMapHashMapLinkedHashMap1Ordering of elementsThe elements inserted in TreeMap are sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.In case of HashMap it does not guarantees as to the order of the map also it does not guarantee that the order will remain constant over time.LinkedHashMap follows the insertion order of elements and also maintaining an order of elements inserted into ... Read More

What is the differences between HashMap and HashTable in Java

Nitin Sharma
Updated on 18-Sep-2019 14:35:37

910 Views

HashMap and HashTable both are one of the most important classes of Java Collection framework. Both HashMap and HashTable stores the data in key value pair and at the time storing data hashing is used to hash the key and the resulting hash code is used as the index at which the value is stored within the table. But still, there are many differences between both these classes which we would discuss below.The following are the important differences between HashMap and HashTable.Sr. No.KeyHashMapHashTable1IntroductionHashmap is the advanced version of HashTable and is introduced as a new class in JDK 1.2.HashTable on ... Read More

Difference between throw and throws in Java

Nitin Sharma
Updated on 18-Sep-2019 14:29:22

11K+ Views

Both throw and throws are the concepts of exception handing in which throw is used to explicitly throw an exception from a method or any block of code while throws are used in the signature of the method to indicate that this method might throw one of the listed type exceptions.The following are the important differences between throw and throws.Sr. No.Keythrowthrows1DefinitionThrow is a keyword which is used to throw an exception explicitly in the program inside a function or inside a block of code.Throws is a keyword used in the method signature used to declare an exception which might get ... Read More

Difference between Thread.start() and Thread.run() in Java.

Nitin Sharma
Updated on 18-Sep-2019 14:28:24

6K+ Views

As we know that start() and run() are the two important methods of multithreading and one is used to create a new thread while other is used to start executing that thread.Following are the important differences between Thread.start() and Thread.run().Sr. No.Keystart()run()1Implementationstart method of thread class is implemented as when it is called a new Thread is created and code inside run() method is executed in that new Thread.While if run method is executed directly than no new Thread is created and code inside run() will execute on current Thread and no multi-threading will take place.2Definitionstart method is defined in thread ... Read More

Difference between String and Character array in Java.

Nitin Sharma
Updated on 18-Sep-2019 14:27:27

6K+ Views

On technical groud, we can say that both a character array and string contain the sequence of characters and used as a collection of characters. But there are significant differences between both which we would discuss below.The following are the important differences between String and Character array.Sr. No.KeyStringCharacter array1ImplementationString is implemented to store sequence of characters and to be represented as a single data type and single entity.Character Array on the other hand is a sequential collection of data type char where each element is a separate entity.2Internal implementationString internal implementation makes it immutable in nature.Character array is mutable in ... Read More

Difference between Singly linked list and Doubly linked list in Java

Nitin Sharma
Updated on 18-Sep-2019 14:25:53

4K+ Views

Both Singly linked list and Doubly linked list are the implementation of Linked list in which every element of singly-linked list contains some data and a link to the next element, which allows to keep the structure. On the other hand, every node in a doubly-linked list also contains a link to the previous node.The following are the important differences between a Singly linked list and Doubly linked list.Sr. No.KeySingly linked listDoubly linked list1ComplexityIn singly linked list the complexity of insertion and deletion at a known position is O(n)In case od doubly linked list the complexity of insertion and deletion ... Read More

Advertisements