Found 9150 Articles for Object Oriented Programming

What is setInterval() method in JavaScript?

vineeth.mariserla
Updated on 05-Aug-2019 11:53:58

370 Views

setInterval()This is one of the many timing events. The window object allows code to execute at every certain interval of time. This object has provided SetInterval() to repeat a function for every certain amount of time. It takes two parameters as arguments. One is the function and the other is the time that specifies the interval after which the function should be repeated.syntaxwindow.setInterval(function, milliseconds, param1, param2, ...));This method can also take other parameters and can add it to the function.Example-1In the following example, setInterval() method is defined and a time interval of 3000 millisecs or 3 seconds is declared. Therefore the function provided ... Read More

Java program to verify whether a given element exists in an array

Maruthi Krishna
Updated on 31-Jul-2024 17:29:29

1K+ Views

Given an array and one of its element as an input, write a Java program to check whether that element exists in given array or not. You can find any element from an array using search algorithms. In this article, we will use linear search and binary search algorithms. Using Linear Search Algorithm In this approach, follow the steps below to verify whether a given element exists in an array − Iterate through the array using for loop. Compare each element with the required element. If found return the index. Example The following Java program shows how ... Read More

Can we make Array volatile using volatile keyword in Java?

Maruthi Krishna
Updated on 02-Jul-2020 13:22:36

2K+ Views

The volatile modifier indicates the JVM that the thread accessing a volatile variable should get data always from the memory. i.e. a thread should not cache the volatile variable.Accessing a volatile variable synchronizes all the cached copied of the variables in the main memory. Volatile can only be applied to instance variables, which are of type object or private. A volatile object reference can be null.Examplepublic class MyRunnable implements Runnable {    private volatile boolean active;    public void run() {       active = true;       while (active) { // line 1         ... Read More

Importance of StringReader class in Java?

raja
Updated on 23-Nov-2023 09:13:26

318 Views

The StringReader class is s subclass of a Reader class and it can be used to read the character stream in the form of a string which acts as a source to StringReader. The StringReader class overrides all the methods from a Reader class. The important methods of StringReader class are skip(), close(), mark(), markSupported(), reset() and etc. Syntax Public class StringReader extends Reader Example import java.io.StringReader; import java.io.IOException; public class StringReaderTest { public static void main(String[] args) { String str = "Welcome to Tutorials Point"; StringReader strReader = new StringReader(str); ... Read More

What is setTimeout() Method in javascript?

vineeth.mariserla
Updated on 05-Aug-2019 11:10:33

460 Views

 setTimeout()This is one of the many timing events. The window object allows the execution of code at specified time intervals. This object has provided SetTimeout() to execute a function after a certain amount of time. It takes two parameters as arguments. One is the function and the other is the time that specifies the interval after which the function should be executed.syntaxwindow.setTimeout(function, milliseconds);Example-1In the following example, the time passed to the setTimeout() function is 2 seconds. Therefore the function will be executed after two secs and display the output as shown.Live Demo wait 2 seconds.    setTimeout(function(){   ... Read More

ArrayIndexOutOfBounds Vs ArrayStoreException in Java?

Maruthi Krishna
Updated on 02-Aug-2019 14:40:57

393 Views

An array is a data structure/container/object that stores a fixed-size sequential collection of elements of the same type. The size/length of the array is determined at the time of creation.The position of the elements in the array is called as index or subscript. The first element of the array is stored at the index 0 and, the second element is at the index 1 and so on.Creating an arrayIn Java, arrays are treated as referenced types you can create an array using the new keyword similar to objects and populate it using the indices as −int myArray[] = new int[7]; ... Read More

Can you change size of Array in Java once created?

Maruthi Krishna
Updated on 02-Jul-2020 12:43:37

8K+ Views

An array is a data structure/container/object that stores a fixed-size sequential collection of elements of the same type. The size/length of the array is determined at the time of creation.The position of the elements in the array is called as index or subscript. The first element of the array is stored at the index 0 and, the second element is at the index 1 and so on.Each element in an array is accessed using an expression which contains the name of the array followed by the index of the required element in square brackets.For example, if an array of 6 ... Read More

Can we store objects in an array in Java?

Maruthi Krishna
Updated on 02-Jul-2020 12:45:01

11K+ Views

Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms. Following are the important terms to understand the concept of Array.Element: Each item stored in an array is called an element.Index: Each location of an element in an array has a numerical index, which is used to identify the element.Storing Objects in an arrayYes, since objects are also considered as datatypes (reference) in Java, you can create an array of the type of a particular class ... Read More

"extends" keyword in JavaScript?

Manisha Patil
Updated on 23-Aug-2022 13:37:33

1K+ Views

In JavaScript, you may extend both classes and objects with the extends keyword. It is frequently used to build classes that are children of other classes. In addition to built-in objects, customized classes can also be subclass using the extends keyword. The classes serve as the blueprint for a real-world item so that we may easily change, access, and utilise them in programming. It is specified to establish an abstract data type to hold a specific sort of information together with the methods for manipulating that information. You use the extends keyword to use class inheritance. Any constructor with the ... Read More

What are the drawbacks of the arrays in Java?

Maruthi Krishna
Updated on 02-Aug-2019 14:16:04

2K+ Views

Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms. Following are the important terms to understand the concept of Array.Element − Each item stored in an array is called an element.Index: Each location of an element in an array has a numerical index, which is used to identify the element.The size of the array will be determined at the time of creation.Disadvantages of arraysDeleting or inserting − You cannot insert a new element at the ... Read More

Advertisements