Low level difference between Slice and Splice methods in Javascript

Ayush Gupta
Published on 16-Sep-2019 10:27:01
The basic difference between slice and splice is −splice() changes the original array on which it is called and returns the removed item(s) in an array as a new array object.slice() doesn't change the original array and also returns the array sliced.Example// splice changes the array let arr = [1, ... Read More

Difference between JavaScript deepCopy and shallowCopy

Ayush Gupta
Published on 16-Sep-2019 10:27:01
Shallow copy and deep copy are language agnostic. Shallow copies duplicate as little as possible. A shallow copy of a collection is a copy of the collection structure, not the elements. With a shallow copy, two collections now share the individual elements.Examplelet innerObj = {    a: 'b',    c: ... Read More

Radix sort in Javascript?

Ayush Gupta
Published on 16-Sep-2019 10:27:01
The radix sort algorithm distributes integers into buckets based on a number's significant digit or value (the radix). The radix is based on the number system of the values of the arrays. Let us look at how it can be implemented −Examplefunction radixSort(arr) {    // Find the max number ... Read More

Merge sort vs quick sort in Javascript

Ayush Gupta
Published on 16-Sep-2019 10:27:01
Merge sort is a sorting technique based on divide and conquer technique. It has a worst-case time complexity of Ο(n log n). But this comes with an added cost in terms of space as this algorithm takes an extra O(n) memory.Now let's look at how we're going to implement this ... Read More

Is JavaScript a pass-by-reference or pass-by-value language?

Ayush Gupta
Published on 16-Sep-2019 10:27:01
Javascript is a pass by value language. But for objects, the value is their reference. So for example, if you pass an int to a function as parameter and increment its value in the function, its value will not be updated in the caller's context −Examplelet i = 0; function ... Read More

Can we throw an Unchecked Exception from a static block in java?

Krishna Kasyap
Published on 16-Sep-2019 10:27:01
A static block is a block of code with a static keyword. In general, these are used to initialize the static members. JVM executes static blocks before the main method at the time of class loading.Example Live Demopublic class MyClass {    static{       System.out.println("Hello this is a static ... Read More

How do you throw an Exception without breaking a for loop in java?

Krishna Kasyap
Published on 16-Sep-2019 10:27:01
Whenever an exception occurred in a loop the control gets out of the loop, by handling the exception the statements after the catch block in the method will get executed. But, the loop breaks.Example Live Demopublic class ExceptionInLoop{    public static void sampleMethod(){       String str[] = {"Mango", "Apple", ... Read More

Can we to override a catch block in java?

Krishna Kasyap
Published on 16-Sep-2019 10:27:01
DescriptionWhen a piece of code in particular method throws an exception, and is handled using try-catch pair. If we are calling this method from another one and, the calling line is wrapped within try-catch pair. Now, how can I override the catch block by the catch block of the calling ... Read More

How to get Exception log from a console and write it to external file in java?

Krishna Kasyap
Published on 16-Sep-2019 10:27:01
There are several logging frame works available to log your data in to files. You can also define your own method.Example − Using I/O packageFollowing Java program has an array storing 5 integer values, we are letting the user to choose two elements from the array (indices of the elements) ... Read More

Does code form Java finally block

Krishna Kasyap
Published on 16-Sep-2019 10:27:01
The finally block follows a try block or a catch block. A finally block of code always executes, irrespective of occurrence of an Exception.The return statement in the method too does not stop the finally block from getting executed.ExampleIn the following Java program we are using return statement at the ... Read More
1 2 3 4 5 6 7 ... 2506 Next
Advertisements