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.

Leave a Reply