Untitled Quiz
59 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

How should the rear pointer be updated when inserting an element in a queue?

  • rear=(rear%1)+MAX_SIZE
  • rear=rear%(MAX_SIZE+1)
  • rear=rear+(1%MAX_SIZE)
  • rear=(rear+1)%MAX_SIZE (correct)
  • What will be the output of the given Java program that manipulates a LinkedList?

  • 2 5 8
  • 2 1 8 (correct)
  • 2 8 5
  • 8 5 1
  • Is PriorityQueue thread safe?

  • True (correct)
  • False
  • Which method is used to clear a specified bit in a data structure?

    <p>clear()</p> Signup and view all the answers

    Which method of the Date class checks if one date is before another date?

    <p>before()</p> Signup and view all the answers

    What happens when two threads try to access the same ArrayList simultaneously?

    <p>ConcurrentModificationException is thrown.</p> Signup and view all the answers

    What will be the output when adding elements to an ArrayList as shown in the Java program?

    <p>2</p> Signup and view all the answers

    Which data structure is typically used in Breadth First Traversal of a graph?

    <p>Queue</p> Signup and view all the answers

    What does a package in Java mainly consist of?

    <p>A collection of classes and interfaces</p> Signup and view all the answers

    Which keyword is essential for defining a package in Java?

    <p>package</p> Signup and view all the answers

    What option describes the main purpose of a package in Java?

    <p>To organize classes and interfaces</p> Signup and view all the answers

    How would you properly import all classes from a specific package in Java?

    <p>import packageName.*;</p> Signup and view all the answers

    Which is the automatically imported package in every Java program?

    <p>java.lang</p> Signup and view all the answers

    Which of the following packages contains the Scanner class used for input?

    <p>java.util</p> Signup and view all the answers

    What is indicated by the fully qualified name of a class in Java?

    <p>Class name and package name together</p> Signup and view all the answers

    Is it possible for two different packages in Java to have classes with the same name?

    <p>Yes, packages isolate classes</p> Signup and view all the answers

    How can you use a class from another package without importing it?

    <p>Use the fully qualified name of the class</p> Signup and view all the answers

    What is the primary purpose of the java.sql package?

    <p>Handling database operations</p> Signup and view all the answers

    Can a package include private classes?

    <p>Yes</p> Signup and view all the answers

    What does the CLASSPATH variable in Java specify?

    <p>Both B and C</p> Signup and view all the answers

    Which package in Java contains classes specifically for networking?

    <p>java.net</p> Signup and view all the answers

    What type of classes are contained within the java.util package?

    <p>Utility classes like Scanner and ArrayList</p> Signup and view all the answers

    Which method is used to initiate a thread in Java?

    <p>start()</p> Signup and view all the answers

    Which interface must be implemented to create a thread in Java?

    <p>Runnable</p> Signup and view all the answers

    What will occur if the run() method is invoked directly instead of the start() method?

    <p>The code will run in the current thread</p> Signup and view all the answers

    What is the primary function of the synchronized keyword in Java?

    <p>Prevents thread interference and memory consistency errors</p> Signup and view all the answers

    When a thread goes to sleep using Thread.sleep(), what happens?

    <p>The thread releases CPU but holds any locks it has</p> Signup and view all the answers

    Which method should be used to make one thread wait for another to complete?

    <p>join()</p> Signup and view all the answers

    Which method can be called to check if a thread is currently alive?

    <p>isAlive()</p> Signup and view all the answers

    What is the role of the yield() method in Java threads?

    <p>It pauses the thread to allow other threads of the same priority to execute</p> Signup and view all the answers

    What exception is raised if the sleep() method is interrupted?

    <p>InterruptedException</p> Signup and view all the answers

    How does the notifyAll() method function in thread management?

    <p>Wakes up all threads waiting on the object's monitor</p> Signup and view all the answers

    What will be the output of the Java program that adds elements to a TreeSet and prints it?

    <p>[1, 3, 4, 8, 9]</p> Signup and view all the answers

    How do you synchronize access to a HashMap?

    <p>Collections.synchronizedMap(new HashMap());</p> Signup and view all the answers

    What is the relation between HashSet and HashMap?

    <p>HashSet internally implements HashMap.</p> Signup and view all the answers

    Which method of the ArrayList class retrieves the current size of the list?

    <p>size()</p> Signup and view all the answers

    What will be the result of using max() method incorrectly, such as max(Comparator comp)?

    <p>It throws a compilation error.</p> Signup and view all the answers

    Which iterator is specifically designed to work only with List collections?

    <p>ListIterator</p> Signup and view all the answers

    What will the output be if we add multiple null entries in a TreeMap?

    <p>{1=null, 2=null, 3=null, 4=null, 5=null}</p> Signup and view all the answers

    Which method is used to remove duplicates from a List using HashSet?

    <p>new HashSet(duplicateList);</p> Signup and view all the answers

    How can we make all elements of a collection equal to a specified value?

    <p>fill()</p> Signup and view all the answers

    Which method is not implemented in HashSet to retrieve an object?

    <p>get()</p> Signup and view all the answers

    Which Java collection class has a fixed size when initialized using Arrays.asList()?

    <p>Collections type Lists</p> Signup and view all the answers

    What happens when invoking clear() on a Hashtable?

    <p>All elements are removed</p> Signup and view all the answers

    Which of the following statements about properties object is false?

    <p>It uses a linear data structure</p> Signup and view all the answers

    What is the primary purpose of the Comparator interface in the Java Collections Framework?

    <p>It defines a comparison function for ordering elements</p> Signup and view all the answers

    Which of these methods can be used to convert an object into a List?

    <p>singletonList()</p> Signup and view all the answers

    Which interface in the Java Collections Framework represents a collection of elements stored in sorted order?

    <p>SortedSet</p> Signup and view all the answers

    What is the primary difference between a HashSet and a LinkedHashSet?

    <p>LinkedHashSet maintains insertion order; HashSet does not</p> Signup and view all the answers

    Which class typically implements a Deque in the Java Collections Framework?

    <p>ArrayDeque</p> Signup and view all the answers

    What method is used to remove all elements from a collection in the Java Collections Framework?

    <p>clear()</p> Signup and view all the answers

    Which class is used to implement a Map interface in the Java Collections Framework?

    <p>LinkedHashMap</p> Signup and view all the answers

    What will be the output of a program that uses the Collections.sort() method on a list with unsorted integers?

    <p>The list will be sorted in ascending order</p> Signup and view all the answers

    What happens when two threads simultaneously modify a TreeSet?

    <p>A ConcurrentModificationException is thrown</p> Signup and view all the answers

    Which of the following interfaces represents a last-in, first-out (LIFO) stack of elements?

    <p>Stack</p> Signup and view all the answers

    What is the purpose of the toArray() method in the Java Collections Framework?

    <p>To convert a collection to an array</p> Signup and view all the answers

    Which of these methods can be used to obtain a synchronized (thread-safe) version of a collection?

    <p>Collections.synchronizedCollection()</p> Signup and view all the answers

    Which class is typically used to implement a Set in the Java Collections Framework?

    <p>HashSet</p> Signup and view all the answers

    What is the result of calling trimToSize() on an ArrayList?

    <p>The capacity of the ArrayList is decreased to its size</p> Signup and view all the answers

    Study Notes

    Question 1

    • The Collections Framework provides a unified architecture for representing and manipulating collections.

    Question 2

    • The List interface in the Java Collections Framework represents an ordered collection that can contain duplicate values.

    Question 3

    • The primary difference between a List and a Set is that a List allows duplicate elements, while a Set does not.

    Question 4

    • The ArrayList class is typically used to implement a List in the Java Collections Framework.

    Question 5

    • The Deque interface extends the List interface to provide more efficient insertions and deletions in the middle of the list.

    Question 6

    • The Map interface in the Java Collections Framework is used to store key-value pairs.

    Question 7

    • The HashMap class is typically used to implement a Map in the Java Collections Framework.

    Question 8

    • The TreeMap allows duplicate keys, while a HashMap does not.

    Question 9

    • The Set interface represents a collection of unique elements with no duplicates.

    Question 10

    • The HashSet class is typically used to implement a Set in the Java Collections Framework.

    Question 11

    • LinkedHashSet maintains insertion order, while HashSet does not.

    Question 12

    • The Collection interface represents a collection of elements with no specific order.

    Question 13

    • A Queue represents a single-ended queue, while a Deque represents a double-ended queue.

    Question 14

    • The ArrayDeque class is typically used to implement a Deque in the Java Collections Framework.

    Question 15

    • The Collections class allows you to create a synchronized (thread-safe) collection.

    Question 16

    • The SortedSet interface extends the Set interface and represents a collection of elements stored in a sorted order.

    Question 17

    • The Comparator interface in Java provides methods for comparing objects to enable ordering.

    Question 18

    • The TreeSet class implements the SortedSet interface.

    Question 19

    • The Stack interface represents a last-in, first-out (LIFO) stack of elements.

    Question 20

    • A Stack uses LIFO order, while a Queue uses FIFO order.

    Question 21

    • The add() method is used to add an element to a collection in the Java Collections Framework.

    Question 22

    • The toArray() method converts a collection to an array.

    Question 23

    • The Collections class provides methods to manipulate the size of a list and its elements.

    Question 24

    • The Iterator interface provides a way to iterate over a collection's elements.

    Question 25

    • The clear() method removes all elements from a collection.

    Question 26

    • The Map.Entry interface represents a key-value pair in a map.

    Question 27

    • The Collections.synchronizedCollection() method obtains a synchronized or thread-safe version of a collection.

    Question 28

    • HashSet does not maintain insertion order; LinkedHashSet does.

    Question 29

    • The Collections.synchronizedMap() method is used to make a synchronized map from an existing map.

    Question 30

    • The Collections.reverse() method reverses the order of elements in a list.

    Question 31

    • The ensureCapacity() method increases the capacity of an ArrayList object.

    Question 32

    • The output of the provided Java code snippet is [D, A, B, C].

    Question 33

    • A Collection in Java is a group of objects.

    Question 34

    • The singletonList() method converts an object into a List.

    Question 35

    • The output of the provided Java code snippet is 2.

    Question 36

    • The premise of equality for IdentityHashMap is reference equality.

    Question 37

    • The EMPTY_LIST is a static variable defined in Collections.

    Question 38

    • The addElement() method is used to add elements to a Vector at specific locations.

    Question 39

    • The output of the provided Java code is 1582.

    Question 40

    • Stack is LIFO; Queue is FIFO.

    Question 41

    • The output of the provided Java code is {3, 4}.

    Question 42

    • Front pointer points to the first element; rear pointer points to the last element

    Question 43

    • BlockingQueue is a sub-interface of Queue.

    Question 44

    • trimToSize() method is used to reduce the capacity of an ArrayList object.

    Question 45

    • Collections.sort(listObj) is used to sort elements of an ArrayList.

    Question 46

    • The java.util package contains all collection classes.

    Question 47

    • The keySet() method is used to obtain a set of all keys in a map.

    Question 48

    • Remote class methods are checkIP(), addLocation(), and AddServer().

    Question 49

    • The get() method of Map class is used to obtain an element with the specified key.

    Question 50

    • The elementCount data member of Vector stores the number of elements.

    Question 51

    • The output of the provided Java code snippet is {A=1, B=2, C=3}.

    Question 52

    • The java code sample will output the current time and date.

    Question 53

    • The worst case time complexity of accessing an element in ArrayList is O(1).

    Question 54

    • The ArrayList class implements a dynamic array.

    Question 55

    • The enqueue() and dequeue() methods are used to insert and delete items from a queue.

    Question 56

    • The LinkedList class implements all the standard functions on list data structure.

    Question 57

    • ConcurrentModificationException is thrown if two threads modify a TreeSet simultaneously.

    Question 58

    • The output of the provided Java code snippet is Test 10 and Test 10.

    Question 59

    • The Set interface and HashSet class do not maintain order.

    Question 60

    • The Enumeration interface is a legacy interface.

    Question 61

    • The output of the provided Java code snippet is false.

    Question 62

    • The key is hashed multiple times until the correct bucket is found.

    Question 63

    • The Collection interface is a basic interface that other interfaces inherit.

    Question 64

    • The previousIndex() method of ListIterator obtains the index of the previous element.

    Question 65

    • The output of the provided Java code snippet is [A, D, B, C].

    Question 66

    • The output of the provided Java code snippet is 12345.

    Question 67

    • The length() method calculates the number of bits required to hold a BitSet object.

    Question 68

    • RemoteException is a possible exception thrown by a remote method.

    Question 69

    • BitSet objects have an architecture similar to arrays.

    Question 70

    • The sort() method in the Array class sorts the array or its subset.

    Question 71

    • The output of the program is {A=3, B=2, C=8}.

    Question 72

    • The Enumeration interface is implemented by Hashtable and Dictionary classes.

    Question 73

    • The output of the following Java code snippet is 12345.

    Question 74

    • LinkedHashSet maintains insertion order and ensures uniqueness of elements.

    Question 75

    • The output of the program is false.

    Question 76

    • The output of the program is {A=1, B=2, C=3}.

    Question 77

    • Map class objects use keys to store values.

    Question 78

    • ArrayList and Vector can be used to create dynamic arrays.

    Question 79

    • The output of the Java program is 1852.

    Question 80

    • The output of the Java code snippet is [5, 8, 2, 3, 2].

    Question 81

    • The output of the provided Java code snippet is 2.

    Question 82

    • The shuffle() method randomizes elements.

    Question 83

    • The toArray() method is used to obtain a static array from ArrayList objects.

    Question 84

    • The put() method inserts a value and its key into a Map.

    Question 85

    • The clear() method removes all entries from a Map.

    Question 86

    • The output of the following Java program is "EMPTY".

    Question 87

    • The output depends on the program to be run.

    Question 88

    • If a key object already exists in a HashMap, the new object replaces the existing key-value pair.

    Question 89

    • List and Collection handle sequences.

    Question 90

    • Collections.synchronizedMap() is used for externally synchronizing HashMap.

    Question 91

    • Set does have the contains(Object o) method.

    Question 92

    • HashMap is not a concrete class; HashSet is a concrete class built upon HashMap.

    Question 93

    • The iterator() method can obtain an iterator to the set's start.

    Question 94

    • max(Comparator comp) is an incorrect method for max in Java.

    Question 95

    • The iterator() method is used to obtain an iterator to the start of a Collection.

    Question 96

    • The output of the program is [1, 3, 4, 8, 9].

    Question 97

    • The output of the program is 81432

    Question 98

    • The output of the program is 0

    Question 99

    • The getProperty() method retrieves elements from a Properties object.

    Question 100

    • Set has a contains(Object o) method.

    Question 101

    • HashSet is implemented on top of HashMap.

    Question 102

    • The return type of the hasNext() method of an iterator is Boolean.

    Question 103

    • The method iterator() is used to obtain an iterator to the start of a Collection.

    Question 104

    • The output of the following Java program is [1, 3, 4, 8, 9].

    Question 105

    • The output of the program is 58881.

    Question 106

    • The output of the following Java code is 0.

    Question 107

    • The getProperty() method is used to retrieve elements in the Properties object.

    Question 108

    • The put() method is used to add elements to a Map.

    Question 109

    • HashSet<String> listToSet = new HashSet<>(duplicateList); This line of code converts a List into a Set that removes duplicates.

    Question 110

    • The ListIterator can be used only with a List.

    Question 111

    • HashMap is not an ordered collection.

    Question 112

    • Arrays.asList() creates an unmodifiable List, limiting its capacity and preventing the addition or removal of elements.

    Question 113

    • dequeue() removes and returns the next item, whereas peek() only returns, but does not remove, the next item.

    Question 114

    • The size() method gets the current size of an ArrayList.

    Question 115

    • Stack, Hashtable, and Vector are legacy classes.

    Question 116

    • The initial capacity of HashSet is 16, and the load factor is 0.75.

    Question 117

    • The output of the Java program will be 2851.

    Question 118

    • The output will be 1582.

    Question 119

    • HashSet does not have a get(Object o) method.

    Question 120

    • LinkedList implements a linked list data structure.

    Question 121

    • The clear() method deletes all elements from the collection.

    Question 122

    • Collections.emptySet() returns an immutable set.

    Question 123

    • The output of the code will be [1=null, 2=null, 3=null, 4=null, 5=null].

    Question 124

    • The output is 6.

    Question 125

    • The Map object manages key-value associations.

    Question 126

    • The output of the program is 1582.

    Question 127

    • The get() method can be used to retrieve an element in a list.

    Question 128

    • The remove() method, or using an iterator, is used to eliminate an object from an ArrayList.

    Question 129

    • The output of the program is 2.

    Question 130

    • The output of the program will be 54321.

    Question 131

    • The next() method moves to the next element.

    Question 132

    • This question is missing from the data.

    Question 133

    • This question is missing from the data.

    Question 134

    • The set() method changes an element in a LinkedList.

    Question 135

    • The output of the Java program is [A, B, C].

    Question 136

    • The output of the java code is [3,2,6,8].

    Question 137

    • The output of the java code is {B=2, C=8}

    Question 138

    • HashSet is a class that implements Set.

    Question 139

    • SortedList is not a Java collection interface.

    Question 140

    • The fill() method sets all elements of a collection to a given value.

    Question 141

    • The Collection interface declares fundamental methods that are commonly used across collections.

    Question 142

    • SortedSet is an interface, and TreeSet is a class that implements it.

    Question 143

    • Map is not an interface for Collection.

    Question 144

    • The output of the program will be 285 1.

    Question 145

    • The output of this Java code will be a randomized order of the numbers (2, 1, 8, 5).

    Question 146

    • fill() method in Java's collections framework sets all elements of a list to a given value.

    Question 147

    • removeLast() is used to delete the last element of a LinkedList.

    Question 148

    • The add() method is not used in this context, but addFirst() is used to add to the front of a LinkedList.

    Question 149

    • The output of the java program is [AB, BC, CD].

    Question 150

    • Vector does not implement the Map interface.

    Question 151

    • HashMap, and Hashtable are Map implementations.

    Question 152

    • The get() method is used to obtain an element from BitSet

    Question 153

    • IllegalStateException can occur from a remove() method in a collection.

    Question 154

    • The add() method is used to add elements into a HashSet.

    Question 155

    • The output is 2.

    Question 156

    • The output is ["A", "D"].

    Question 157

    • Set interface requires unique elements

    Question 158

    • size() of ArrayList returns number of elements, and length() is not a valid method for ArrayList.

    Question 159

    • The rear pointer is updated using the formula rear=(rear+1)%MAX_SIZE to implement a circular queue.

    Question 160

    • The output of the program is 851.

    Question 161-166

    • These questions relate to the functionality of the Date class, and Set and Map interfaces.

    Question 167

    • Maps isn't a Java collection framework interface.

    Question 168-171

    • These questions deal with Java code packages.

    Question 172-176

    • These questions involve Java packages and their properties

    Question 177

    • The java.io package contains classes for handling input and output operations.

    Question 178

    • The syntax to create a package in Java is package packageName;.

    Question 179

    • Yes, two packages can have classes with the same name.

    Question 180

    • java.graphics is not part of the Java standard library.

    Question 181

    • Use the fully qualified class name to access a class in another package.

    Question 182-186

    • These questions cover the purpose and functionalities of various Java packages.

    Question 187-191

    • These questions involve Java threads and their properties.

    Question 192-201

    • These involve information about various Java threading concepts like wait, notify, join, sleep.

    Question 202-206

    • These questions deal with thread pools and concepts of concurrency.

    Question 127

    • binarySearch() is used for searching elements.

    Question 109

    • For removing duplicates from a List, converting it to a HashSet or using a Set interface is most efficient.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    More Like This

    Untitled Quiz
    19 questions

    Untitled Quiz

    TalentedFantasy1640 avatar
    TalentedFantasy1640
    Untitled Quiz
    55 questions

    Untitled Quiz

    StatuesquePrimrose avatar
    StatuesquePrimrose
    Untitled Quiz
    18 questions

    Untitled Quiz

    RighteousIguana avatar
    RighteousIguana
    Untitled Quiz
    50 questions

    Untitled Quiz

    JoyousSulfur avatar
    JoyousSulfur
    Use Quizgecko on...
    Browser
    Browser