Computer Knowledge
Java Core Classes and Threads
1,935 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
-
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()
-
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.
-
suspend()
-
destroy()
-
resume()
-
stop()
A,C,D
Correct answer
Explanation
In Java's Thread class, suspend(), resume(), and stop() are final methods and therefore cannot be overridden by subclasses. These methods are also deprecated in modern Java. The destroy() method is not final, so it can technically be overridden, though it's also deprecated.
-
Heap memory
-
classes
-
objects
-
variables
C
Correct answer
Explanation
In Java, threads acquire locks at the object level using intrinsic locks (monitor locks). Each object has an associated monitor that threads can lock or unlock. Threads do not lock heap memory, classes themselves, or individual variables - they lock objects to achieve synchronization.
-
IllegalMonitorStateException
-
IllegalThreadStateException
-
IllegalLockStateException
-
InvalidLockException
A
Correct answer
Explanation
The wait(), notify(), and notifyAll() methods must be called from within a synchronized context (i.e., while holding the object's lock). Invoking these methods without acquiring the lock results in IllegalMonitorStateException at runtime.
-
sleep()
-
join()
-
activeCount()
-
none
B
Correct answer
Explanation
sleep() and activeCount() are static methods of the Thread class - you call them directly on Thread.sleep() or Thread.activeCount(). join() is an instance method that you call on a specific thread object. 'none' is incorrect since join() is indeed not static.
-
wait()
-
notify()
-
notifyAll()
-
start()
A,B,C
Correct answer
Explanation
wait(), notify(), and notifyAll() are defined in the Object class, not the Thread class - they're available on every object in Java for inter-thread communication. start() IS a method of Thread class that begins execution.
-
Thread.MAX_PRIORITY
-
Thread.NORM_PRIORITY
-
Thread.LOW_PRIORITY
-
Thread.MIN_PRIORITY
A,B,D
Correct answer
Explanation
Thread defines three priority constants: MAX_PRIORITY (10), MIN_PRIORITY (1), and NORM_PRIORITY (5). LOW_PRIORITY doesn't exist - it's a distractor mixing 'LOW' with the correct constant name MIN_PRIORITY.
-
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 it using various character encoding techniques (URL encoding, Unicode, double encoding, etc.) to represent blocked characters in ways the filter doesn't recognize. Being hard-coded (A) doesn't make it weak. POST method handling (C) isn't specifically problematic for black lists. Black lists don't match good patterns (D) - they block bad ones.