Found 9150 Articles for Object Oriented Programming

Difference between Arrays and Collection in Java

Nitin Sharma
Updated on 17-Sep-2019 10:34:05

14K+ Views

In order to store multiple values or objects of the same type, Java provides two types of data structures namely Array and Collection.The following are the important differences between Arrays and Collection.Sr. No.KeyArraysCollection1SizeArrays are fixed in size i.e once the array with the specific size is declared then we can't alter its size afterward.The collection is dynamic in size i.e based on requirement size could be get altered even after its declaration.2Memory ConsumptionArrays due to fast execution consumes more memory and has better performance.Collections, on the other hand, consume less memory but also have low performance as compared to Arrays.3Data ... Read More

Ways to create a Set in JavaScript?

Ayush Gupta
Updated on 18-Sep-2019 12:01:15

152 Views

A set is an abstract data type that can store certain values, without any particular order, and no repeated values. It is a computer implementation of the mathematical concept of a finite set. Unlike most other collection types, rather than retrieving a specific element from a set, one typically tests a value for membership in a set.Ways to create a set in js−1. Using empty Set constructorlet mySet = new Set(); mySet.add(1); mySet.add(1); console.log(mySet)OutputSet { 1 } 2. Passing an iterable to the constructorThe set constructor accepts an iterable object(list, set, etc) using which it constructs a new set.Examplelet mySet ... Read More

What are javascript sets?

Ayush Gupta
Updated on 18-Sep-2019 11:57:00

203 Views

A set is an abstract data type that can store certain values, without any particular order, and no repeated values. It is a computer implementation of the mathematical concept of a finite set. Unlike most other collection types, rather than retrieving a specific element from a set, one typically tests a value for membership in a set.You should use sets, whenever you want to store unique elements in a container for which the order doesn't matter and you mainly want to use it to check for membership of different objects. Sets are also useful when you want to perform operations ... Read More

What is the use of OBJECT.assign() in javascript?

Ayush Gupta
Updated on 17-Sep-2019 08:55:08

278 Views

The Object.assign() method is used to copy the values of all of the object's own properties(enumerable only) from one or more source objects to a target object. It will return the target object.Exampleconst targetObj = { a: 1, b: 2 }; const sourceObj = { b: 4, c: 5 }; const returnedTarget = Object.assign(targetObj, sourceObj); console.log(targetObj); console.log(returnedTarget); console.log(returnedTarget === targetObj); console.log(sourceObj);Output{ a: 1, b: 4, c: 5 } { a: 1, b: 4, c: 5 } true { b: 4, c: 5 }Note −sourceObj did not change.returnedTarget and targetObj are the same.The Object.assign() method only copies enumerable and own properties from ... Read More

Async/Await Functions in JavaScript

Arnab Chakraborty
Updated on 23-Aug-2022 06:52:12

947 Views

Handling asynchronous tasks is essential for network programming. In JavaScript most cases, we ask for data that are not synchronous to our system. To handle asynchronous systems, we can use Async and Await functions in JavaScript. The async keyword which is used with a function will qualify a javascript function as an asynchronous function. Async Function The async functions are very similar to the normal functions in javascript. The syntax is like below− From the syntax, it is clear that only the ‘async’ keyword is added to the function signature. Syntax async function name(param1, param2, ...paramN) { ... Read More

Multiple inheritance in JavaScript

Arnab Chakraborty
Updated on 23-Aug-2022 06:39:00

6K+ Views

JavaScript is a partially object-oriented language. To work with this, the object-oriented nature needs to be understood. In this article, we are going to focus on the multiple inheritance concept inside JavaScript. An object can be inherited from multiple other objects, i.e. the object has common property from other parent objects not only a single parent. In JavaScript, this can be achieved by merging properties from different properties into one single object. Let us see the overall syntax which represents how multiple properties can be merged. SyntaxLet us consider a function syntax like the below − function multiple(...arguments) { ... Read More

How can we merge two JSON objects in Java?

raja
Updated on 04-Jul-2020 05:40:36

17K+ Views

A JSON is a lightweight data-interchange format and the format of JSON is a key with value pair. The JSONObject can parse a text from a String to produce a map-like object and supports java.util.Map interface. We can use org.json.simple.JSONObject to merge two JSON objects in Java.We can merge two JSON objects using the putAll() method (inherited from interface java.util.Map) in the below program.Exampleimport java.util.Date; import org.json.simple.JSONObject; public class MergeJsonObjectsTest {    public static void main(String[] args) {       JSONObject jsonObj = new JSONObject(); // first json object       jsonObj.put("Name", "Adithya");       jsonObj.put("Age", 25);     ... Read More

Method Chaining in JavaScript

Arnab Chakraborty
Updated on 23-Aug-2022 06:34:35

8K+ Views

Method or function chaining is a popular method in JavaScript that is used to write more concise and readable code. In this article, we shall discuss the method of chaining tactics in JavaScript and also discuss how it works In some JavaScript programs written with JQuery or some other packages, sometimes we call multiple functions one after another on the same line. This can be explained by a simple example as shown below − Syntax ob = ob.method_1().method_2().(some more methods).method_n() Example Without using the method of chaining. HTML Console ... Read More

Eradicating Memory Leaks in Javascript

Ayush Gupta
Updated on 17-Sep-2019 08:15:58

181 Views

The main cause for leaks in garbage collected languages are unwanted references. To understand memory leaks, let us see how the memory freeing(garbage collection) works.Mark-and-sweep algorithm −This algorithm reduces the definition of "an object is no longer needed" to "an object is unreachable". This algorithm assumes the knowledge of a set of objects called roots. In JavaScript, the root is the global object. Periodically, the GC starts from these roots, find all objects that are referenced from these roots, recursively. Starting from the roots, the GC will thus find all reachable objects and collect all non-reachable objects.Types of memory leaks1. ... Read More

Practical Uses for Closures in Javascript?

Arnab Chakraborty
Updated on 22-Aug-2022 13:55:39

723 Views

In JavaScript, the closure is an environment which helps us to access an outer function’s scope from an inner function. In JavaScript, when a function is created, the closure also created. In other words, we can say closure is a way which allows functions that is present inside outer functions to access the outer function’s scope. In this article we are focusing on some practical uses of Closures in JavaScript. Syntax function outerFunction(){ function updateProperty(){ } return updateProperty() } ... Read More

Advertisements