data structures and backend with java coursera week 1 quiz answers

Array - Practice quiz

1. Which of the following statements is true about arrays in Java?

  • Arrays can have elements of different data types.
  • Arrays are dynamic in size and can be resized during runtime.
  • Arrays in Java always start from index 0.
  • Arrays can have negative indices.

2. Which of the following is the correct way to declare and initialize a one-dimensional array in Java?

  • int[] arr = {1, 2, 3, 4, 5};
  • int arr[] = {1, 2, 3, 4, 5};
  • int arr[5] = {1, 2, 3, 4, 5};
  • int arr = {1, 2, 3, 4, 5};

3. Which of the following is an array utility class in Java?

  • ArrayUtils
  • ArrayHelper
  • ArrayUtil
  • ArrayHandler

4. What is the maximum number of dimensions that an array can have in Java?

  • 1
  • 2
  • 3
  • There is no maximum limit, it can have any number of dimensions.

5. How do you access an element in a two-dimensional array in Java?

  • arrayName[row][column]
  • arrayName[row, column]
  • arrayName[row][, column]
  • arrayName[column][row]

String - Practice quiz

6. What is the difference between String and StringBuffer classes in Java?

  • String is mutable, while StringBuffer is immutable.
  • String is immutable, while StringBuffer is mutable.
  • Both String and StringBuffer are mutable.
  • Both String and StringBuffer are immutable.

7. What is the purpose of the String Pool in Java?

  • To store Strings with the same value in a common memory area for better performance and memory utilization.
  • To store Strings with different values in a common memory area for better performance and memory utilization.
  • To store Strings in a separate memory area for better performance and memory utilization.
  • To store Strings in a dynamic memory area for better performance and memory utilization.

8. Which of the following is a difference between String in Java and String in C++?

  • In Java, Strings are mutable, while in C++, Strings are immutable.
  • In Java, Strings are immutable, while in C++, strings are mutable.
  • In Java, Strings are stored on the stack, while in C++, strings are stored on the heap.
  • In Java, Strings are stored on the heap, while in C++, strings are stored on the stack.

9. Which of the following is a method of the StringBuffer class in Java?

  • append()
  • concat()
  • reverse()
  • split()

10. Which of the following is a difference between StringBuffer and StringBuilder classes in Java?

  • StringBuffer is thread-safe, while StringBuilder is not thread-safe.
  • StringBuilder is thread-safe, while StringBuffer is not thread-safe.
  • Both StringBuffer and StringBuilder are thread-safe.
  • Both StringBuffer and StringBuilder are not thread-safe.

List - Practice quiz

11. What is the purpose of the Java Collections Framework?

  • To provide a set of classes and interfaces for working with collections of objects.
  • To provide a set of classes and interfaces for working with input/output operations.
  • To provide a set of classes and interfaces for working with threads and concurrency.
  • To provide a set of classes and interfaces for working with graphical user interfaces (GUI).

12. Which of the following interfaces in Java Collections Framework extends the Collection interface and allows duplicate elements?

  • List
  • Set
  • Map
  • Queue

13. What is the main difference between ArrayList and Vector in Java?

  • ArrayList is synchronized, while Vector is not.
  • Vector is resizable, while ArrayList is not.
  • ArrayList allows duplicate elements, while Vector does not.
  • Vector is thread-safe, while ArrayList is not.

14. Which of the following is not a valid implementation of the List interface in Java Collections Framework?

  • ArrayList
  • LinkedList
  • HashSet
  • Vector

15. Which of the following classes in Java Collections Framework represents a last-in, first-out (LIFO) stack of objects?

  • List
  • Set
  • Map
  • Stack

Map - Practice Quiz

16. Which of the following Java Map implementations allows null keys and values, and does not maintain the insertion order of elements?

  • HashMap
  • Linked HashMap
  • Weak HashMap
  • EnumMap

17. Which of the following Java Map implementations maintains the insertion order of elements and allows null keys and values?

  • LinkedHashMap
  • TreeMap
  • SortedMap Interface
  • NavigableMap Interface

18. Which of the following Java Map implementations is a concurrent map that is designed to be used in multi-threaded environments and provides thread-safe operations without the need for external synchronization?

  • HashMap
  • TreeMap
  • ConcurrentHashMap
  • WeakHashMap

19. Which of the following Java Map implementations is a specialized map that uses weak references to keys, allowing the keys to be garbage collected if they are not used anywhere else in the program?

  • HashMap
  • LinkedHashMap
  • WeakHashMap
  • TreeMap

20. Which of the following Java Map implementations is a specialized map that is designed to be used with enum keys only?

  • HashMap
  • LinkedHashMap
  • EnumMap
  • TreeMap

Set - Practice quiz

21. Which of the following Java Set implementations does not allow duplicate elements and does not maintain any specific order of elements?

  • HashSet
  • EnumSet
  • LinkedHashSet
  • SortedSet Interface

22. Which of the following Java Set implementations maintains the insertion order of elements and does not allow duplicate elements?

  • HashSet
  • EnumSet
  • LinkedHashSet
  • SortedSet Interface

23. Which of the following Java Set implementations is a specialized set implementation that is designed to be used with enum elements only?

  • HashSet
  • EnumSet
  • LinkedHashSet
  • SortedSet Interface

24. Which of the following Java Set implementations maintains the elements in sorted order based on their natural ordering or a specified comparator?

  • HashSet
  • EnumSet
  • LinkedHashSet
  • TreeSet

25. Which of the following Java Set implementations provides additional methods for navigating through the elements in a specific order?

  • HashSet
  • EnumSet
  • LinkedHashSet
  • NavigableSet Interface

Data Structures - Graded Quiz

26. Which of the following Java Set Interface implementations maintains a unique identifier for each element?

  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • All of the above

27. Which of the following Java Set Interface implementations maintains elements in sorted order based on their natural ordering?

  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Java EnumSet

28. Which of the following Java Set Interface implementations does not allow duplicate elements?

  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • All of these

29. Which of the following Java Set Interface implementations does not guarantee any specific order of elements?

  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Java EnumSet

30. Which of the following Java Set Interface implementations provides methods for navigating through elements in sorted order?

  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Java NavigableSet

31. Which of the following Java Set Interface implementations allows elements to be stored in a linked list, providing predictable iteration order?

  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Java EnumSet

32. Which of the following Java Set Interface implementations is backed by a hash table, providing constant-time performance for basic operations?

  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Java EnumSet

33. Which of the following Java Set Interface implementations maintains elements in a sorted order based on a custom comparator?

  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Java EnumSet

34. Which of the following Java Set Interface implementations allows only one null element?

  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Both A and B

35. Which of the following Java Set Interface implementations maintains elements in sorted order based on natural ordering of elements?

  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Java EnumSet

36. Which of the following Java Set Interface implementations allows elements to be stored in a red-black tree, providing guaranteed logarithmic time complexity for basic operations?

  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Java EnumSet

37. Which of the following Java Set Interface implementations allows elements to be stored in a hash table that is navigable and allows operations based on the closest match to a given value?

  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Java NavigableSet

38. Which of the following Java Set Interface implementations allows elements to be stored in a tree-based data structure, providing guaranteed O(log n) time complexity for basic operations?

  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Java EnumSet

39. Which of the following Java Set Interface implementations provides an iterator that allows elements to be accessed in a forward direction?

  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • All of the above

40. Which of the following Java Set Interface implementations maintains the insertion order of elements?

  • Java HashSet
  • Java TreeSet
  • Java SortedSet
  • Java LinkedHashSet

41. Which of the following Java Set Interface implementations allows elements to be accessed in ascending or descending order?

  • Java HashSet
  • Java TreeSet
  • Java NavigableSet
  • Both B and C

42. Which of the following Java Set Interface implementations allows elements to be stored in a hash table that supports map-like operations on keys?

  • Java HashSet
  • Java EnumSet
  • Java TreeSet
  • None of the above

Leave a Reply