Found 9150 Articles for Object Oriented Programming

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

How to use finally on promise with then and catch in Javascript?

Arnab Chakraborty
Updated on 04-Apr-2023 11:27:04

2K+ Views

Javascript asynchronous programming uses a promise object which does not block the execution of the current flow but informs the compiler that there is something that is not completed yet, and whenever it completes it returns a signal to the system. There are mainly two possibilities. Either the promise object will complete successfully, or it will stop by returning an exception. To handle exceptions coming from promise objects the catch() methods are used. In try-catch methods also we can use another block named ‘finally’. This will execute no matter what is done previously. For promises also we can use the ... 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

How to return the response from an asynchronous call in Javascript?

Arnab Chakraborty
Updated on 23-Aug-2022 07:33:53

445 Views

Asynchronous programming is fairly common in javascript network programming. In this approach, we can download, or perform some time-dependent jobs without locking thecurrent execution flow. Which performs asynchronously as compared to our program, which can be done using async functions in javascript. In this article, we will discuss the techniques to return the response from an asynchronous call in javascript. Before entering into the concept, let us see in which cases it becomes confusing to developers when asynchronous execution calls are taken into action. Let us see the following situation. Syntax function aTrivialFunction() { ajaxCall(..., function onSuccess(result) ... Read More

Class Keyword in JavaScript

Ayush Gupta
Updated on 18-Sep-2019 13:14:06

231 Views

JavaScript classes, introduced in ES6, are syntactical sugar over JavaScript prototype-based inheritance. Classes are in fact "special functions". You can define classes in JavaScript using the class keyword using the following syntax −class Person {    // Constructor for this class    constructor(name) {       this.name = name;    }    // an instance method on this class    displayName() {       console.log(this.name)    } }This is essentially equivalent to the following declaration −let Person = function(name) {    this.name = name; } Person.prototype.displayName = function() {    console.log(this.name) }This class can also be written as ... 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

Mixins in JavaScript

Arnab Chakraborty
Updated on 23-Aug-2022 07:22:32

3K+ Views

Multiple-inheritance is not supported by Javascript by default. But sometimes we need to mix multiple object properties into a single object. Object property sharing can be done using mixins. In this article, we shall cover what are mixins in JavaScript. The definition of mixins can be stated as mixins is a class that contains methods that can be used by other classes without inheriting from that class. The methods in mixin provide certain behavior which is not used alone but can be used to add these behaviors to other classes. Mixin: A Simple Example See the following example where we ... Read More

Advertisements