Computer Knowledge
Java Core Classes and Threads
1,473 Questions
Java core classes and threads form the foundation of object oriented programming and are crucial for IT officer and programming exams. This includes concepts like string mutability, collections, and multithreading. Solve these questions to test your practical coding and theoretical knowledge.
String and StringBuffer classesThread execution methodsJava collections frameworkCharacter streams input outputVariable serialization rules
Java Core Classes and Threads Questions
-
Vector
-
ArrayList
-
Hashtable
-
HashMap
A
Correct answer
Explanation
Vector is a legacy class (introduced in JDK 1.0) that implements a synchronized resizable array as part of the List interface. Every method in Vector is synchronized, making it thread-safe but slower than non-synchronized alternatives. ArrayList is the unsynchronized modern alternative. Hashtable is synchronized but implements Map, not List. HashMap is unsynchronized and also implements Map.
-
Boxing and UnBoxing
-
Generics
-
Enhanced for
-
Iterator
A,B,C
Correct answer
Explanation
Java 1.5 (Tiger) introduced autoboxing/unboxing for automatic primitive-wrapper conversion, generics for type-safe collections, and the enhanced for-loop for cleaner iteration. The Iterator interface existed since Java 1.2, so it was not a new feature in Java 1.5. The claimed answer correctly identifies A, B, and C.
B
Correct answer
Explanation
Static methods belong to the class itself, not to any instance, so they cannot access instance members (non-static fields or methods) without an object reference. Attempting to do so results in a compilation error. The statement is False, making the claimed answer correct.
-
Wait
-
notify
-
notifyAll
-
Sleep
A,B,C
Correct answer
Explanation
Java's Object class provides wait(), notify(), and notifyAll() for inter-thread communication using the monitor pattern. These methods must be called within synchronized code. The sleep() method pauses a thread but is not used for communication. The claimed answer A, B, C is correct.
B
Correct answer
Explanation
IOException and its subclasses are CHECKED exceptions in Java, meaning they must be declared or caught. Only RuntimeException and Error subclasses are unchecked. The statement that IOException is unchecked is False, making the claimed answer correct.
-
String
-
StringBuffer
-
Both
-
None
B
Correct answer
Explanation
StringBuffer is mutable and more efficient for multiple concatenations in loops because it modifies a single buffer. String is immutable - each concatenation creates a new object. For repeated concatenation, StringBuffer (or StringBuilder in newer Java) is preferred. The claimed answer B is correct.
-
String Buffer
-
String
-
both
-
none
A
Correct answer
Explanation
In Java, StringBuffer is mutable and modifies the existing character sequence without creating new objects, whereas String is immutable, meaning each concatenation creates a new String object, which degrades performance during multiple operations.
-
sizeOf ()
-
size()
-
getSize()
-
No such method in java to find size of an object directly.
D
Correct answer
Explanation
Java does not provide any built-in method like sizeof(), size(), or getSize() to directly find the size of an object. The size of an object in memory is implementation-dependent and not exposed through standard APIs. While Java provides methods to find the size of collections and arrays, there is no direct way to get the memory footprint of an object instance.
-
a Keyword
-
a method
-
a special identifier
-
none
D
Correct answer
Explanation
'delete' is not a keyword in Java, unlike in C++ where it is used for memory deallocation. Java does not expose manual memory management through keywords - it uses automatic garbage collection instead. 'delete' has no special meaning in Java syntax or standard libraries.
-
Because the validation settings are hard coded.
-
Susceptible to bypass using various forms of character encoding
-
Because it's difficult to implement a black list filter that also takes into account data sent using the POST method
-
Because it is typically implemented using regular expressions to match known good data patterns
B
Correct answer
Explanation
Black list validation is weak because attackers can bypass filters using character encoding variations like URL encoding, Unicode, or hex encoding. White list validation is more secure because it only allows known-good patterns. Hard coding (A) and POST method handling (C) aren't fundamental weaknesses, and black lists don't use regex patterns (D).
-
Because the validation settings are hard coded.
-
Susceptible to bypass using various forms of character encoding
-
Because it's difficult to implement a black list filter that also takes into account data sent using the POST method
-
Because it is typically implemented using regular expressions to match known good data patterns
B
Correct answer
Explanation
Blacklist validation is weak because attackers can easily bypass it using various character encoding techniques like URL encoding, Unicode variations, or hex encoding. Since blacklists try to block specific bad patterns, they inevitably miss novel attack vectors. Whitelist validation (allowing only known good patterns) is much more secure.
-
valuator()
-
reset()
-
execute()
-
findForward()
C
Correct answer
Explanation
In Apache Struts framework, actions typically extend an Action class and override the execute() method to handle business logic and request processing. The other options are not standard required methods for the base Action class.
-
a interface with single method
-
A interface with no methods
-
A final interface
-
there is nothing like marker interface
B
Correct answer
Explanation
A marker interface is an interface with no methods or fields, serving only to mark a class for special handling (e.g., Serializable, Cloneable, Remote). It conveys metadata to the JVM or compiler through the interface's presence alone.
-
dpMoveCursor()
-
dpNext()
-
dpNextRow()
-
dpMoveNext()
B
Correct answer
Explanation
The dpNext() method is the standard RFT API call to advance the datapool cursor to the next row. Other options like dpMoveCursor(), dpNextRow(), or dpMoveNext() are not valid RFT methods.
-
The class that extends javax.faces.validator.Validator and validates the given input
-
The class that implements javax.faces.validator.Validator and validates the given input
-
The class that extends javax.faces.validate.Validator and validates the given input
-
The class that implements javax.faces.validate.Validator and validates the given input
B
Correct answer
Explanation
JSF Validators are classes that implement the javax.faces.validator.Validator interface and validate the given input. The Validator interface defines a validate method that must be implemented. Note that it's an interface (implement), not an abstract class (extend), and the package is validator, not validate.