
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7442 Articles for Java

602 Views
instanceof operator is used to check the type of object passed. Following rules explain the usage of instanceof operator in Java.instanceof operator returns true for the object if checked against its class type.instanceof operator returns false for the object if checked against its type which is not in its hierarchy.instanceof operator returns true for the child object if checked against parent object type.instanceof operator returns true for the complete object hierarchy up to the Object class.instanceof operator returns false for the null value.instanceof operator returns false for the parent object if checked against child object type.Following example showcases the above ... Read More

11K+ Views
In Java, we use inheritance to allow the creation of a hierarchical classification of classes and objects. As the name suggests, inheritance is the ability of a class to inherit members of another class. The class whose properties are inherited is called a superclass whereas the class that inherits a superclass is called a subclass. We use the extends keyword to inherit the class. There are several types of inheritance in Java such as single and multilevel. In this article, we will specifically explore the multiple inheritance. Multiple Inheritance in Java In the terminology of object-oriented programming, multiple inheritance is ... Read More

4K+ Views
Jagged array is a multidimensional array where member arrays are of different size. For example, we can create a 2D array where first array is of 3 elements, and is of 4 elements. Following is the example demonstrating the concept of jagged array.Example Live Demopublic class Tester { public static void main(String[] args){ int[][] twoDimenArray = new int[2][]; //first row has 3 columns twoDimenArray[0] = new int[3]; //second row has 4 columns twoDimenArray[1] = new int[4]; int counter = ... Read More

4K+ Views
Jagged array is a multidimensional array where member arrays are of different size. For example, we can create a 2D array where first array is of 3 elements, and is of 4 elements. Following is the example demonstrating the concept of jagged array.Example Live Demopublic class Tester { public static void main(String[] args){ int[][] twoDimenArray = new int[2][]; //first row has 3 columns twoDimenArray[0] = new int[3]; //second row has 4 columns twoDimenArray[1] = new int[4]; int counter = ... Read More

3K+ Views
Collections can be iterated easily using two approaches.Using for-Each loop − Use a foreach loop and access the array using object.Using Iterator − Use a foreach loop and access the array using object.DifferencesConcurrentModificationException − Using for-Each loop, if an object is modified, then ConcurrentModificationException can occur. Using iterator, this problem is elliminated.Size Check − Using for-Each, size check is not required. Using iterator if hasNext() is not used properly, NoSuchElementException can occur.Performance − Performance is similar for both cases.Following is an example of using above ways.Example Live Demoimport java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Tester { public ... Read More

3K+ Views
Collections can be iterated easily using two approaches.Using for-Each loop − Use a foreach loop and access the array using object.Using Iterator − Use a foreach loop and access the array using object.DifferencesConcurrentModificationException − Using for-Each loop, if an object is modified, then ConcurrentModificationException can occur. Using iterator, this problem is elliminated.Size Check − Using for-Each, size check is not required. Using iterator if hasNext() is not used properly, NoSuchElementException can occur.Performance − Performance is similar for both cases.Following is an example of using above ways.Example Live Demoimport java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Tester { public ... Read More

516 Views
Often, you will want to cycle through the elements in a collection. For example, you might want to display each element. The easiest way to do this is to employ an iterator, which is an object that implements either the Iterator or the ListIterator interface.Iterator enables you to cycle through a collection, obtaining or removing elements. ListIterator extends Iterator to allow bidirectional traversal of a list, and the modification of elements.Before you can access a collection through an iterator, you must obtain one. Each of the collection classes provides an iterator( ) method that returns an iterator to the start ... Read More

516 Views
Often, you will want to cycle through the elements in a collection. For example, you might want to display each element. The easiest way to do this is to employ an iterator, which is an object that implements either the Iterator or the ListIterator interface.Iterator enables you to cycle through a collection, obtaining or removing elements. ListIterator extends Iterator to allow bidirectional traversal of a list, and the modification of elements.Before you can access a collection through an iterator, you must obtain one. Each of the collection classes provides an iterator( ) method that returns an iterator to the start ... Read More

435 Views
isInstance method is equivalent to instanceof operator. The method is used in case of objects are created at runtime using reflection. General practice says if type is to be checked at runtime then use isInstance method otherwise instanceof operator can be used. See the example below −Example Live Demopublic class Tester{ public static void main(String[] args) throws ClassNotFoundException { Integer i = new Integer(10); System.out.println(usingInstanceOf(i)); System.out.println(usingIsInstance(i)); } public static String usingInstanceOf(Object i){ if(i instanceof String){ return "String"; } ... Read More

435 Views
isInstance method is equivalent to instanceof operator. The method is used in case of objects are created at runtime using reflection. General practice says if type is to be checked at runtime then use isInstance method otherwise instanceof operator can be used. See the example below −Example Live Demopublic class Tester{ public static void main(String[] args) throws ClassNotFoundException { Integer i = new Integer(10); System.out.println(usingInstanceOf(i)); System.out.println(usingIsInstance(i)); } public static String usingInstanceOf(Object i){ if(i instanceof String){ return "String"; } ... Read More