The ________ class in Java creates an immutable sequence of characters.

  • CharArray
  • String
  • StringBuffer
  • StringBuilder
In Java, the String class creates an immutable sequence of characters. This means that once a string is created, its content cannot be changed. The other options, StringBuilder, StringBuffer, and CharArray, are used for mutable character sequences.

A private constructor prevents the class from being instantiated outside of the class and is commonly used in ________.

  • Abstraction
  • Inheritance
  • Polymorphism
  • Singleton Pattern
A private constructor is commonly used in the Singleton design pattern. The Singleton pattern ensures that a class has only one instance, and the private constructor prevents external instantiation. It is not typically used for inheritance, polymorphism, or abstraction.

A two-dimensional array int[][] arr is essentially an array of ________ in Java.

  • arrays
  • arrays of arrays
  • arrays of integers
  • integers
In Java, a two-dimensional array int[][] arr is essentially an array of arrays. It means that each element of arr is itself an array, which can hold integers or other data types. This concept allows you to create tables or matrices of data.

The _______ block in a Java class is executed before constructors.

  • finalize
  • instance
  • main
  • static
In Java, the static block is executed before constructors. Static blocks are used for performing class-level initialization tasks. They run when the class is loaded, and they are executed only once. Constructors, on the other hand, are used to initialize instance variables and are called when an object is created.

What is the purpose of the flatMap() method in the Stream API?

  • To collect the elements of the stream into a list
  • To filter elements based on a given predicate
  • To flatten a stream of streams into a single stream
  • To perform an operation on each element in the stream
The flatMap() method in the Stream API is used to flatten a stream of streams into a single stream. It is particularly useful when you have a stream of elements, and each element is itself a stream (e.g., a stream of lists). flatMap() will merge all these sub-streams into one, providing a single stream of elements. This is different from map(), which produces a stream of streams.

What will be the result of the expression 7 ^ 3 in Java?

  • 0
  • 10
  • 3
  • 4
In Java, the ^ operator is the bitwise XOR operator. It performs a bitwise XOR operation on the binary representations of the two operands. In this case, 7 in binary is 0111, and 3 in binary is 0011. Performing XOR, we get 0100, which is 4 in decimal. So, the result is 4.

Can method overloading be achieved by changing only the return type of methods?

  • No, method overloading can only be achieved by changing both the method name and return type.
  • No, method overloading is not possible by changing only the return type; the method name and/or parameters must also differ.
  • Yes, as long as the method name and parameters are the same, changing the return type is sufficient for method overloading.
  • Yes, method overloading can be achieved solely by changing the return type, even if the method name and parameters are the same.
Method overloading is based on the method name and parameters, not the return type. Therefore, simply changing the return type of methods with the same name and parameters does not constitute method overloading in Java. Different parameters are required to overload methods.

The ______ class in JavaFX is used to create a simple timeline animation.

  • AnimationTimer
  • KeyFrame
  • Timeline
  • TranslateTransition
In JavaFX, the Timeline class is used to create a simple timeline animation. It allows you to define keyframes and specify changes in properties over time, making it suitable for animations. The other options are also related to animations but serve different purposes.

Consider a scenario where you need to write a log file and ensure that each log entry is written to disk immediately for audit compliance. Which classes and/or methods would you use to implement this?

  • FileWriter and BufferedWriter classes
  • FileOutputStream class and flush() method
  • PrintWriter class and sync() method
  • RandomAccessFile class and write() method
In this scenario, to ensure that each log entry is written to disk immediately, you can use the PrintWriter class with the sync() method. This combination ensures that data is flushed and written to disk immediately. The other options do not provide the same level of immediate disk writing.

How is operator overloading achieved for the String class in Java?

  • By defining custom methods for concatenation
  • By using the '+' operator for String concatenation
  • By using the '+' operator with custom type conversion
  • Java does not support operator overloading for the String class
Operator overloading is not supported for the String class in Java. Instead, Java provides a convenient way to concatenate strings using the '+' operator, but it doesn't involve operator overloading. You can use custom methods for string manipulation, but it's not true operator overloading.