The class ________ provides methods to work with SSL sockets.

  • SSLSocketFactory
  • SocketFactory
  • SocketSSL
  • SocketSecurity
The correct class to work with SSL sockets in Java is SSLSocketFactory. It provides methods for creating secure SSL sockets, making it an essential class for implementing secure socket communication.

Consider a scenario where you have to implement a complex mathematical function involving various arithmetic operations. How would you manage operator precedence to ensure accurate calculations?

  • Adjust the order of operations based on trial and error until the calculations are correct.
  • Rely on the default operator precedence in Java, as it always follows the mathematical conventions.
  • Use a series of if-else statements to manually control the execution order of operations.
  • Use parentheses to specify the order of operations, ensuring that higher precedence operations are enclosed within inner parentheses.
In Java, operator precedence follows the standard mathematical rules. However, to ensure accuracy in complex expressions, it's crucial to use parentheses to explicitly define the order of operations. Relying solely on default precedence may lead to unexpected results. Option 3 and 4 are not recommended approaches and can introduce errors.

Which of the following stream operations is a terminal operation?

  • collect()
  • filter()
  • forEach()
  • mapToDouble()
In Java Streams API, a terminal operation is an operation that produces a result or a side-effect. The collect() method is a terminal operation that collects the elements of a stream into a new collection or performs some other final action. Options 1 to 3 are intermediate operations, which transform or filter the elements but do not terminate the stream.

When an array element, such as arr[2][3], is accessed, Java uses ________ to locate it in memory.

  • column-major order
  • linear search
  • random access
  • row-major order (or row-major indexing)
In Java, when you access an element in a two-dimensional array like arr[2][3], the system uses row-major order (or row-major indexing) to locate it in memory. This means it first traverses rows and then columns to find the desired element efficiently.

What is the worst-case time complexity of Linear Search?

  • O(1)
  • O(log n)
  • O(n)
  • O(n^2)
The worst-case time complexity of Linear Search is O(n), where 'n' is the number of elements in the data. In the worst scenario, the search may have to check every element in the list to find the target, making it a linear time algorithm.

Which exception might be thrown when opening a file for reading?

  • FileNotFoundException
  • FileOpenException
  • FileReadException
  • IOException
When opening a file for reading in Java, the FileNotFoundException might be thrown if the specified file does not exist or cannot be found. This exception is a subclass of IOException and is commonly used to handle file-related errors during file input operations. Other exceptions like FileReadException and FileOpenException are not standard Java exceptions.

What does the Future interface represent in Java concurrency?

  • A class for creating threads in Java
  • A class for handling exceptions thrown by threads
  • A class for storing past execution results
  • A representation of a result that is yet to be computed
The Future interface in Java represents a result that is yet to be computed. It is used in concurrency to obtain the result of asynchronous operations. It allows you to check if the computation is complete, cancel the computation, and retrieve the result when it becomes available. This is commonly used with the Executor framework to manage concurrent tasks.

In Flexbox, how would you align all items to the center of the container both vertically and horizontally?

  • Apply justify-content: center and align-items: center.
  • Apply margin: auto to all flex items.
  • Set display: flex; and align-content: center.
  • Use text-align: center on the container element.
To align all items both vertically and horizontally in a Flexbox container, you can use justify-content: center to center items horizontally and align-items: center to center them vertically. This combination ensures that items are centered in the container along both axes.

The text-indent property in CSS is used to adjust ________.

  • letter spacing
  • line height
  • text alignment
  • the first line of a block of text
The "text-indent" property in CSS is used to adjust the indentation of the first line of a block of text. It specifies the amount by which the first line of a block-level element should be indented from the left margin.

What is the primary purpose of the float property in CSS?

  • To apply text styles such as font size and color.
  • To create flexible grid layouts.
  • To make text italic.
  • To position an element to the left or right, allowing content to flow around it.
The primary purpose of the float property in CSS is to position an element to the left or right within its containing element. This allows other content to flow around it, which is commonly used for creating multi-column layouts or wrapping text around images.