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
D
Correct answer
Explanation
This is the correct choice because there are 5 constructors of ConcurrentHashMap class. These are :- 1) ConcurrentHashMap():- Creates a new, empty map with a default initial capacity (16), load factor (0.75) and concurrencyLevel (16), 2) ConcurrentHashMap(int initialCapacity):- Creates a new, empty map with the specified initial capacity and with default load factor (0.75), and concurrencyLevel (16), 3) ConcurrentHashMap(int initialCapacity, float loadFactor):- Creates a new, empty map with the specified initial capacity and load factor and with the default concurrencyLevel (16), 4) ConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel):- Creates a new, empty map with the specified initial capacity, load factor and concurrency level, 5) ConcurrentHashMap(Map m):- Creates a new map with the same mappings as the given map.
B
Correct answer
Explanation
This is the correct answer, as there are 5 constructors of LinkedHashMap class. These are:- LinkedHashMap():-
constructs an empty insertion-ordered LinkedHashMap instance with the default initial capacity (16) and load factor (0.75), LinkedHashMap(int initialCapacity):- constructs an empty insertion-ordered LinkedHashMap instance with the specified initial capacity and a default load factor (0.75), LinkedHashMap(int initialCapacity, float loadFactor):- constructs an empty insertion-ordered LinkedHashMap instance with the specified initial capacity and load factor.
LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder):- constructs an empty LinkedHashMap instance with the specified initial capacity, load factor and ordering mode, and LinkedHashMap(Map<? extends K,? extends V> m):- constructs an insertion-ordered LinkedHashMap instance with the same mappings as the specified map.
-
boolean containsKey(object)
-
containValue(object)
-
getKey(object)
-
KeysSet(object)
-
removeKey(object)
A
Correct answer
Explanation
This is the correct answer, as containsKey(object) method is present in the map interface in java collections framework. This method returns true if this map contains a mapping for the specified key.
-
putAll(map : m)
-
Get(key : K)
-
isEmpty()
-
removeLast()
-
Put(key : K, Value : V)
D
Correct answer
Explanation
This is incorrect, as removeLast()method is not present in the map interface, it is present in LinkedList class.This method removes the last element from the list.
-
procedural
-
object oriented
-
web development
-
event driven
B
Correct answer
Explanation
Java is fundamentally an object-oriented programming language. It supports core OOP principles like encapsulation, inheritance, and polymorphism through classes and objects. While Java can incorporate procedural and event-driven elements, its primary paradigm is object-oriented.
-
Java. lang
-
Java. io
-
Java. awt
-
Java. applet
A
Correct answer
Explanation
The java.lang package is automatically imported into every Java program without requiring an explicit import statement. It contains fundamental classes like Object, String, Math, and System that are essential for basic Java operations. Packages like java.io, java.awt, and java.applet require explicit imports.
-
illegal args
-
illegal argument
-
illegal arguments
-
illegal arg
B
Correct answer
Explanation
IllegalArgumentException is thrown when a method receives an argument that is inappropriate or invalid. The correct exception name uses the singular form 'argument' rather than plural, matching Java's naming convention for this standard exception.
-
join
-
stop
-
enumerate
-
yield
A
Correct answer
Explanation
The join() method causes the current thread to wait until the thread on which it is called completes execution. This is a fundamental thread synchronization mechanism in Java that ensures one thread waits for another to finish before proceeding.
-
Window Activated
-
window Closed
-
Window Opened
-
Window Closing
-
To String ()
-
Get Source ()
-
Get String ()
-
None of the above
B
Correct answer
Explanation
The skip() method in Java's java.io package takes exactly one argument - a long value specifying the number of bytes to skip. This method is used in input/output streams to skip over a specified number of bytes without reading them.
D
Correct answer
Explanation
In programming languages like Java or C-sharp, standard input reader methods such as ReadLine() return null when the end of the stream or file is reached and no more data is available.
-
IO
-
File Not Found
-
Class Not Found
-
Interrupted
B
Correct answer
Explanation
FileInputStream throws FileNotFoundException (a subclass of IOException) when attempting to open a file that doesn't exist. This is a checked exception that must be handled or declared when working with file input streams.
-
Get Count ()
-
Get Items Count
-
Items.Count ()
-
Get Item Count ()
D
Correct answer
Explanation
In Visual Basic and similar GUI frameworks, the getItemCount() method returns the number of items in a ListBox or similar control. This allows you to programmatically determine how many items are currently in the list.