What is the role of parameters in a Java method?
To provide input values to the method.
To declare variables within the method.
To define the method's return type.
To control the method's visibility.
What will the following Java code snippet print to the console?
for (int i = 1; i <= 3; i++) { System.out.print(i + " "); }
The code will result in a compilation error.
123
1 2 3
3 2 1
What is the core principle behind Object-Oriented Programming (OOP) in Java?
Data security
Code reusability
Faster execution speed
Improved memory management
What is the time complexity of the get() method for an ArrayList?
get()
O(log n)
O(n log n)
O(n)
O(1)
What is the fundamental difference between Java and JavaScript?
Java is a scripting language, while JavaScript is a compiled language.
They are essentially the same; the names are interchangeable.
Java is primarily used for client-side web development, while JavaScript is used for server-side applications.
Java is a statically-typed language, while JavaScript is dynamically-typed.
Which keyword is used to define a method in Java?
define
method
void
function
What is the result of the expression '10 % 3' in Java?
3
0
3.33
1
Which of the following is a characteristic of unchecked exceptions in Java?
The compiler requires you to handle them explicitly.
They typically represent recoverable situations.
They are derived directly from the 'Error' class.
They are not required to be declared in a method's 'throws' clause.
What is the primary purpose of exception handling in Java?
To improve the performance of Java applications.
To provide a mechanism for handling unexpected events during program execution.
To completely prevent runtime errors from occurring.
To enforce strict coding standards and prevent compilation errors.
What is the primary purpose of a constructor in Java?
To control access to class members
To initialize object attributes
To define methods
To declare variables