Java multithreading interview questions Set 5

Categories: Java 8(JDK1.8)

Define FutureTask class in Java?

Java FutureTask class provides a base implementation of the Future interface. The result can only be obtained if the execution of one task is completed, and if the computation is not achieved then get method will be blocked. If the execution is completed, then it cannot be re-started and can't be canceled.

Syntax

public class FutureTask<V> extends Object implements RunnableFuture<V>


What is the Collection framework in Java?

Collection Framework is a combination of classes and interface, which is used to store and manipulate the data in the form of objects. It provides various classes such as ArrayList, Vector, Stack, and HashSet, etc. and interfaces such as List, Queue, Set, etc. for this purpose.


What are the main differences between array and collection?

Array and Collection are somewhat similar regarding storing the references of objects and manipulating the data, but they differ in many ways. The main differences between the array and Collection are defined below:

a) Arrays are always of fixed size, i.e., a user can not increase or decrease the length of the array according to their requirement or at runtime, but In Collection, size can be changed dynamically as per need.

b) Arrays can only store homogeneous or similar type objects, but in Collection, heterogeneous objects can be stored.

c) Arrays cannot provide the ?ready-made? methods for user requirements as sorting, searching, etc. but Collection includes readymade methods to use.


What is the difference between Set and Map?

The differences between the Set and Map are given below.

a) Set contains values only whereas Map contains key and values both.

b) Set contains unique values whereas Map can contain unique Keys with duplicate values.

c) Set holds a single number of null value whereas Map can include a single null key with n number of null values.


Explain various interfaces used in Collection framework?

Collection framework implements various interfaces, Collection interface and Map interface (java.util.Map) are the mainly used interfaces of Java Collection Framework. List of interfaces of Collection Framework is given below:

1. Collection interface: Collection (java.util.Collection) is the primary interface, and every collection must implement this interface.

Syntax:

public interface Collection<E>extends Iterable  

Where <E> represents that this interface is of Generic type

2. List interface: List interface extends the Collection interface, and it is an ordered collection of objects. It contains duplicate elements. It also allows random access of elements.

Syntax:

public interface List<E> extends Collection<E>  

3. Set interface: Set (java.util.Set) interface is a collection which cannot contain duplicate elements. It can only include inherited methods of Collection interface

Syntax:

public interface Set<E> extends Collection<E>  


 What is the difference between ArrayList and Vector?

No.ArrayListVector

1)ArrayList is not synchronized.Vector is synchronized.

2)ArrayList is not a legacy class.Vector is a legacy class.

3)ArrayList increases its size by 50% of the array size.Vector increases its size by doubling the array size.

4)ArrayList is not ?thread-safe? as it is not synchronized.Vector list is ?thread-safe? as it?s every method is synchronized.


What is the difference between ArrayList and LinkedList?

No.ArrayListLinkedList

1)ArrayList uses a dynamic array.LinkedList uses a doubly linked list.

2)ArrayList is not efficient for manipulation because too much is required.LinkedList is efficient for manipulation.

3)ArrayList is better to store and fetch data.LinkedList is better to manipulate data.

4)ArrayList provides random access.LinkedList does not provide random access.

5)ArrayList takes less memory overhead as it stores only objectLinkedList takes more memory overhead, as it stores the object as well as the address of that object.


What is the difference between Iterator and ListIterator?

Iterator traverses the elements in the forward direction only whereas ListIterator traverses the elements into forward and backward direction.

No.IteratorListIterator

1)The Iterator traverses the elements in the forward direction only.ListIterator traverses the elements in backward and forward directions both.

2)The Iterator can be used in List, Set, and Queue.ListIterator can be used in List only.

3)The Iterator can only perform remove operation while traversing the collection.ListIterator can perform ?add,? ?remove,? and ?set? operation while traversing the collection.


What is the difference between Iterator and Enumeration?

No.IteratorEnumeration

1)The Iterator can traverse legacy and non-legacy elements.Enumeration can traverse only legacy elements.

2)The Iterator is fail-fast.Enumeration is not fail-fast.

3)The Iterator is slower than Enumeration.Enumeration is faster than Iterator.

4)The Iterator can perform remove operation while traversing the collection.The Enumeration can perform only traverse operation on the collection.


What is the difference between List and Set?

The List and Set both extend the collection interface. However, there are some differences between the both which are listed below.

a) The List can contain duplicate elements whereas Set includes unique items.

b) The List is an ordered collection which maintains the insertion order whereas Set is an unordered collection which does not preserve the insertion order.

c) The List interface contains a single legacy class which is Vector class whereas Set interface does not have any legacy class.

d) The List interface can allow n number of null values whereas Set interface only allows a single null value.


What is the difference between HashSet and TreeSet?

The HashSet and TreeSet, both classes, implement Set interface. The differences between the both are listed below.

a) HashSet maintains no order whereas TreeSet maintains ascending order.

b) HashSet impended by hash table whereas TreeSet implemented by a Tree structure.

c) HashSet performs faster than TreeSet.

d) HashSet is backed by HashMap whereas TreeSet is backed by TreeMap.


Top Blogs
Java Retention Policy, SOURCE,CLASS,RUNTIME Published at:- Meaning Of Java Published at:- Java Programming in Python Published at:- Applications of Java Programming Published at:- Java Explaination Published at:- History of Java Published at:- Tools You Will Need Published at:- Local Environment Setup Published at:- Popular Java Editors Published at:- Basic Syntax in Java Published at:- Java Identifiers Published at:- Java Modifiers Published at:- Inheritance Published at:- Object and Classes In Java Published at:- Classes in Java Published at:- Source File Declaration Rules Published at:- Java Package Published at:- Constructors Published at:- No argument Constructors Published at:- Basic Datatypes In Java Published at:- Java - Modifier Types Published at:- Java - Basic Operators Published at:- The Relational Operators Published at:- The Bitwise Operators Published at:- The Logical Operators Published at:- The Assignment Operators Published at:- Miscellaneous Operators Published at:- Precedence of Java Operators Published at:- Java - Loop Control Published at:- Java - Decision Making Published at:- Java - Numbers Class Published at:- Java In Character Class Published at:- Escape Sequences In Java Published at:- Character Methods In Java Published at:- Java In Strings Class Published at:- String Length In Java Published at:- Concatenating Strings In Java Published at:- Creating Format Strings In Java Published at:- Java - Arrays Published at:- Creating Arrays In Java Published at:- Java - Date and Time Published at:- Getting Current Date and Time Published at:- Date Comparison Published at:- Simple DateFormat Format Codes Published at:- Sleeping for a While Published at:- Gregorian Calendar Class Published at:- Java - Regular Expressions Published at:- Java - Methods Published at:- Method Calling Published at:- Passing Parameters by Value In Java Published at:- Method Overloading In Java Published at:- The finalize( ) Method In Java Published at:- Java - Files and I O Published at:- Standard Streams In Java Published at:- File Input Stream Published at:- File Output Stream In Java Published at:- Directories in Java Published at:- Java - Exceptions Published at:- Exception Hierarchy In Java Published at:- Java Programming Language Published at:- JDK in Java Published at:- History of Java Programming Language Published at:- Difference Between C++ vs Java vs Python Published at:- How JVM Works – JVM Architecture? Published at:- JVM Memory Published at:- Difference between Byte Code and Machine Code Published at:- How is Java platform independent? Published at:- Java is platform-independent but JVM is platform dependent Published at:- Java Basic Syntax Published at:- Data types in Java Published at:- Primitive data type vs. Object data type in Java with Examples Published at:- Java Identifiers Published at:- Operators in Java Published at:- Variables in Java Published at:- Types of Variables in Java Published at:- Differences between the Instance variable Vs. the Static variables Published at:- Scope of Variables In Java Published at:- Differences between JDK, JRE and JVM Published at:- Similarities and Difference between Java and C++ Published at:- Setting up the environment in Java Published at:- Packages In Java Published at:- Decision Making in Java (if, if-else, switch, break, continue, jump) Published at:- Loops in Java Published at:- Java while loop with Examples Published at:- Java do-while loop with Examples Published at:- Components of do-while Loop Published at:- Continue Statement in Java Published at:- Break statement in Java Published at:- Define Java Methods Published at:- Java Method Parameters Published at:- Return Values In JAva Published at:- Define of Java Scope Published at:- Meaning of Java Recursion Published at:- What is OOP in Java ? Published at:- Java Class Attributes Published at:- Java Class Methods Published at:- Static vs. Non-Static Java Published at:- Java Constructors Published at:- Java Encapsulation Published at:- Java Packages Published at:- Java Inheritance Published at:- Java Polymorphism Published at:- Java - Abstraction Published at:- Java - Interfaces Published at:- Declaring Interfaces In Java Published at:- Java - Overriding Published at:- Java - Packages Published at:- Java - Data Structures Published at:- Java - Data Structures Published at:- The Collection Interfaces In Java Published at:- Generics In Java Published at:- Java - Serialization Published at:- Java - Networking Published at:- Java - Sending Email Published at:- Java - Multithreading Published at:- Java - Applet Basics Published at:- Java - Documentation Comments Published at:- Comments in Java Published at:- Java Interview Questions Set 1 Published at:- Java Interview Questions Set 2 Published at:- Java Interview Questions Set 2 Published at:- Java Interview Questions Set 3 Published at:- Java Interview Questions Set 4 Published at:- Java Interview Questions Set 5 Published at:- Java Interview Questions Set 6 Published at:- Java Interview Questions Set 7 Published at:- Java Interview Questions Set 8 Published at:- Java Interview Questions Set 9 Published at:- Java Interview Question Set 10 Published at:- Java Interview Question Set 11 Published at:- Java interview Question Set 12 Published at:- Java Interview Question Set 13 Published at:- Java Interview Questions Set 10 Published at:- Java Interview Question Set 12 Published at:- Java Interview Question Set 13 Published at:- Java Interview Question Set 14 Published at:- Java Interview Question Set 15 Published at:- Java Multithreading Interview Questions Set 1 Published at:- Java multithreading interview questions Set 2 Published at:- Java multithreading interview questions Set 3 Published at:- Java Multithreading Interview Set 4 Published at:- Java multithreading interview questions Set 5 Published at:- Java collections interview questions Set 6 Published at:- Java collections interview questions Set 7 Published at:- Java Interview Question Set 8 Published at:- Java Interview Question Set 1 Published at:- Java Interview Question Set 10 Published at:- Java Interview Question Published at:- Java Interview Question Published at:- Java Interview Question Published at:- Java Interview Question Published at:- Java Interview Question Published at:- Java Interview Question Published at:- Java Interview Question Published at:- JavaScript Interview Questions Published at:- Javascript Interview Question Published at:- Javascript Interview Question Published at:- JavaScript Interview Question Set 1 Published at:- JavaScript Interview Question Set 2 Published at:- JavaScript Interview Question Set 3 Published at:- JavaScript Interview Question Set 4 Published at:- Python Interview Question Set 6 Published at:- How to Optimize Java Apps on Kubernetes Published at:- When and Why Java is utilized for Application Improvement Published at:- Scanner nextLine() ,nextInt() ,nextDouble() method in Java with Examples Published at:- java toUpperCase() and toLowerCase() example Published at:- pushing value at last in java | how to add element at the end of array in java Published at:- Write a program for group words by first character of given string | Java 8 Stream Example Published at:- Write a Java 8 program to calculate the age of a person in years given their birthday Published at:- Write a Java 8 program to calculate the age of a person in years given their birthday Years Months Days Published at:- Write a Java 8 program to print the first 10 odd numbers Published at:- Filter employees by age in Java 8 Lamda steam Published at:- Write a Java 8 program to get the last element of an array string/object Published at:- Filter employees by age set senior if age is greater than 30 in Java 8 Lamda steam Published at:- How to increment salary by 2%, 5%, etc. Using java Published at:- Write a program to find the only duplicate count list in the List Published at:- Write a program to append char in char ex-input- {A, B, C} output->[A_X, B_Y, C_Z] Published at:- Write a program to sum an array without using the sum method Published at:- Write a program to sum an array Published at:- Drop all while condition not meet dropWhile(),dropWhile(Predicate<T> predicate) Published at:- Find the maximum value in a list of integers using Stream & Method Reference Published at:- How to sort a list of strings by length using Lambda expressions Published at:- How to filter and collect a list of strings that start with a specific letter using Java 8 Stream Published at:- Write a Java program To create a map from a array of strings where the key is the string and the value is its length Published at:- How to count the number of occurrences of a given word in a list of strings using Java 8 Published at:- How to remove all duplicates from an array of integers in Java using Java 8 Published at:- How to find next, previous, tomorrow ,yesterday date using Java 8 Published at:- How to iterate and modify values in a Map using Java 8 Published at:- How to print keys & values of a Map using Java 8 Published at:- count of each character in a String using Java 8 Published at:- Write a Program to find the Maximum element in an array Published at:- How to check if list is empty in Java 8 using Optional Published at:- Find duplicate elements with its count using Java 8 Published at:- Find Last duplicate character of given string using Java 8 Published at:- Given a list of integers, separate odd and even numbers Published at:- java 8 using lambda expression and stream api | Java 8 Programs using Lambda Expression and Stream Published at:- 26 Java 8 Programs using Lambda Expression and Stream Published at:- Java 8 Stream String Null Or Empty Filter Published at:- sum ,min ,max etc example using reduce method using Java 8 Stream API Published at:- Find first repeated character in a string Published at:- Sort highest salary in each department Published at:- Grouping Employees by City and Age Published at:- Finding the Count of Male and Female Employees Published at:- Printing Names of All Departments from Employee Class using Java Published at:- Printing Employee Details by Age Criteria using Java Published at:- Finding Maximum Age of Employee using Java Published at:- Printing Average Age of Male and Female Employees using Java Published at:- Printing the Number of Employees in Each Department using Java Published at:- Java Class subclass interview coding questions Published at:- Child and Parent overridden methods Throws RuntimeException Published at:- Child and Parent overridden methods Throws checked exception Published at:- Find Customer staring with +91 mobile number Published at:- Sorting the Employees Salary in Each Department in Descending Order Published at:- Sorting the Employees Salary in Each Department in Ascending Order Published at:-
R4R.co.in Team
The content on R4R is created by expert teams.