Java Support Interview Questions and Answers
Ques 26. What is the 'java.lang.Math' class in Java, and how is it used?
'java.lang.Math' is a utility class in Java that provides mathematical functions. It includes methods for basic arithmetic, trigonometry, logarithms, exponentiation, and more. The methods are static and can be used without creating an instance of the 'Math' class.
Example:
Example:
double result = Math.sqrt(25.0); // calculates the square root
Ques 27. Explain the 'java.util.Collections' class in Java.
'java.util.Collections' is a utility class that provides static methods for operating on collections (e.g., lists, sets, and maps). It includes methods for sorting, shuffling, searching, and synchronizing collections.
Example:
Example:
ListmyList = new ArrayList<>();
Collections.addAll(myList, 'Java', 'Python', 'C++');
Collections.sort(myList); // sorts the list
Ques 28. What is the purpose of the 'java.util.concurrent' package in Java?
The 'java.util.concurrent' package in Java provides a framework for concurrent programming. It includes classes and interfaces for thread management, concurrent collections, synchronization utilities, and high-level concurrency abstractions.
Example:
Example:
ExecutorService executor = Executors.newFixedThreadPool(5);
executor.submit(() -> System.out.println('Hello, concurrent world!'));
executor.shutdown();
Ques 29. Explain the concept of 'immutable objects' in Java.
Immutable objects are objects whose state cannot be modified after they are created. Once an immutable object is created, its state remains constant throughout its lifetime. String, Integer, and BigDecimal are examples of immutable classes in Java.
Example:
Example:
final class ImmutableClass {
private final int value;
public ImmutableClass(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
Ques 30. What is the 'Java Virtual Machine (JVM)' and its role in Java?
The JVM is a virtual machine that enables a computer to run Java programs. It interprets Java bytecode and translates it into machine code for the host system. The JVM provides platform independence, as Java programs can run on any device that has a compatible JVM installed.
Example:
No specific example, as the JVM itself is not directly programmable.
Most helpful rated by users: