Programming Articles - Page 2440 of 3366

What is the most efficient way to deep clone an object in JavaScript?

Abdul Rawoof
Updated on 26-Aug-2022 11:57:23

1K+ Views

In JavaScript, objects are the collection of a key value pairs. The properties of the object are the keys and is denoted with a string. The value of the key is the value of the property of the given object. In JavaScript, the objects can be copied to other by many ways in which some of them are discussed below. Using spread operator(…), Using assign() function and Using JSON.parse() and JSON.stringify() functions. Using the Json.parse() and Stingify() methods Among the above mentioned three ways, for an object to be deep cloned, JSON.stringify() and JSON.parse() functions are used. ... 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

How to check whether a particular key exist in javascript object or array?

Abdul Rawoof
Updated on 26-Aug-2022 11:59:20

11K+ Views

In JavaScript an object is found to be in the form of key value pairs. The keys of the objects are known as properties of the given object and is represented using a string. The property of the object can have a value which can be of any data type. For example, if an employee object is created then it has the properties like employee name, employee id, employee age, salary etc. These are the properties of the employee object which are called keys. The values of these properties will be different for different employees. In case of array, the ... 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

How can we decode a JSON object in Java?

raja
Updated on 04-Jul-2020 06:27:24

3K+ Views

A JSON is a lightweight, text-based and language-independent data exchange format. A JSON can represent two structured types like objects and arrays. We can decode a JSON object using JSONObject and JSONArray from json.simple API. A JSONObject works as a java.util.Map whereas JSONArray works as a java.util.List.In the below example, we can decode a JSON object.Exampleimport org.json.simple.*; import org.json.simple.parser.*; public class JSONDecodingTest {    public static void main(String[] args) {       JSONParser parser = new JSONParser();       String str = "[ 0 , {\"1\" : { \"2\" : {\"3\" : {\"4\" : [5, { \"6\" : { \"7\" : 8 } } ] } ... Read More

Difference between print() and println() in Java

Nitin Sharma
Updated on 18-Sep-2019 14:23:00

6K+ Views

As we know in Java these both methods are primarily used to display text from code to console. Both these methods are of PrintStream class and are called on static member 'out' of 'System' class which is a final type class.The following are the important differences between print() and println().Sr. No.Keyprint()println()1Implementationprint method is implemented as it prints the text on the console and the cursor remains at the end of the text at the console.On the other hand, println method is implemented as prints the text on the console and the cursor remains at the start of the next line ... Read More

Difference between notify() and notifyAll() in Java

Nitin Sharma
Updated on 02-Mar-2020 10:15:56

7K+ Views

Both notify and notifyAll are the methods of thread class and used to provide notification for the thread.But there are some significant differences between both of these methods which we would discuss below.Following are the important differences between notify and notifyAll.Sr. No.KeynotifynotifyAll1NotificationIn case of multiThreading notify() method sends the notification to only one thread among the multiple waiting threads which are waiting for lock.While notifyAll() methods in the same context sends the notification to all waiting threads instead of single one thread.2Thread identificationAs in case of notify the notification is sent to single thread among the multiple waiting threads so ... Read More

Difference Between LinkedList and LinkedHashSet in Java

Aishwarya Naglot
Updated on 21-Apr-2025 19:15:46

2K+ Views

LinkedList and LinkedHashSet are two important classes of Java's Collection framework. They are used to store groups of items, but they work in different ways and have their own unique features. What is a LinkedList in Java? Java LinkedList is a linear data structure that is used to store the same type of elements. It is a part of the Java Collections Framework, and it implements the List as well as the Deque interfaces. It has a dynamic size, which means it can grow and shrink as needed. Example The following is an example of how we write code for ... Read More

Advertisements