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
-
1 and 2
-
2 and 3
-
1 and 4
-
3 and 4
C
Correct answer
Explanation
There are two ways of creating a thread; extend (sub-class) the Thread class and implement the Runnable interface. For both of these ways you must implement (override and not overload) the public void run() method.
(1) is correct - Extending the Thread class and overriding its run method is a valid procedure.
(4) is correct - You must implement interfaces, and runnable is an interface and you must also include the run method.
(2) is wrong - Runnable is an interface which implements not Extends. Gives the error: (No interface expected here)
(3) is wrong - You cannot implement java.lang.Thread (This is a Class). (Implements Thread, gives the error: Interface expected). Implements expects an interface.
(5) is wrong - You cannot implement java.lang.Thread (This is a class). You Extend classes, and Implement interfaces. (Implements Thread, gives the error: Interface expected)
-
public class MyRunnable extends Runnable{public void run(){}}
-
public class MyRunnable extends Object{public void run(){}}
-
public class MyRunnable implements Runnable{public void run(){}}
-
public class MyRunnable implements Runnable{void run(){}}
C
Correct answer
Explanation
The class correctly implements the Runnable interface with a legal public void run()method.
Option 1 is incorrect because interfaces are not extended; they are implemented.
Option 2 is incorrect because even though the class would compile and it has a validpublic void run() method, it does not implement the Runnable interface, so the compiler would complain when creating a Thread with an instance of it.
Option 4 is incorrect because the run() method must be public.
-
java.lang.Runnable
-
java.lang.Thread
-
java.lang.Object
-
java.lang.ThreadGroup
-
none of the above
C
Correct answer
Explanation
these are the members of Object class
-
MethodDescriptor
-
ParameterDescriptor
-
Introspector
-
PropertyDescriptor
C
Correct answer
Explanation
This class analyses a bean and constructs a BeanInfo object that describes the component.
-
Event Source
-
Event Object
-
Event Listener
-
None of these
C
Correct answer
Explanation
This is an object, which is notified when an event occurs.
-
WindowListener
-
KeyListener
-
TextListener
-
ActionListener
C
Correct answer
Explanation
This interface in event listener interface defines one method to recognize when a text value changes.
-
getFontName()
-
getName()
-
getStyle()
-
getFamily()
D
Correct answer
Explanation
This method of Font class returns the name of the font family to which the invoking font belongs.
-
getItem()
-
getItemSelectable()
-
getStateChange()
-
none of these
B
Correct answer
Explanation
getItemSelectable() method can be used to obtain a reference to the ItemSelectable object that generate an event.
-
Adapter classes
-
Inner classes
-
Anonymous classes
-
Window classes
A
Correct answer
Explanation
Java Programming language provide Adapter classes that implement the corresponding listener interface containing more than one method.
-
getConnection()
-
createStatement()
-
executeQuery()
-
getQuery()
A
Correct answer
Explanation
The connection object is initialized using the getConnection() method.
-
translatePoint()
-
getClickCount()
-
isPopupTrigger()
-
getitem()
B
Correct answer
Explanation
getClickCount() method of MouseEvent obtains the number of mouse clicks for the event
-
getColumnClassName(int column)
-
getScale(int column)
-
isCaseSensitive(int column)
-
getColumnSize(int column)
-
isSearchable(int column)
D
Correct answer
Explanation
This is the correct answer because there is no method named getColumnSize(int column) in ResultSetMetaData interface. The correct method name is getColumnDisplaySize(int column), which indicates the designated column's normal maximum width in characters.
-
allProceduresAreCallable()
-
allTablesAreSelectable()
-
autoCommitFailureClosesAllResultSets()
-
dataDefinitionCausesTransactionCommit()
-
allTablesSelected()
E
Correct answer
Explanation
This is the correct option because there is no method named allTablesSelected() in DatabaseMetaData. The correct method is allTablesAreSelectable() and it retrieves whether the current user can call all the procedures returned by the method getProcedures or not.
-
getMaxTableLength()
-
getMaxTables()
-
getMaxCharLiteralLength()
-
getMaxUserLength()
-
getSchema()
C
Correct answer
Explanation
This is the correct answer because getMaxCharLiteralLength() is defined in the DatabaseMetaData interface and it retrieves the maximum number of characters the database allows for a character literal.
-
cancelRowUpdates()
-
deleteRow()
-
clearWarnings()
-
deleteColumn()
-
absolute(int row)
D
Correct answer
Explanation
This is the correct option because there is no method named deleteColumn() defined in ResultSet interface.