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
-
getErrorCode()
-
getNextException()
-
getPreviousException()
-
getSQLState()
-
setNextException(SQLException ex)
C
Correct answer
Explanation
There is no method named getPreviousException() in java database programming. So, this answer is true.
-
isDeleted()
-
Deleted()
-
rowDeleted()
-
hasDeleted()
-
isRowDeleted()
C
Correct answer
Explanation
This is the correct choice because rowDeleted() method is present in ResultSet interface and it retrieves whether a row has been deleted or not.
-
isValid(int timeout)
-
isReadable()
-
isWritable()
-
isInvalid(int timeout)
-
isPrepared()
A
Correct answer
Explanation
isValid(int timeout) method is present in the Connection interface and it returns true if the connection has not been closed and is still valid. So, this answer is correct.
C
Correct answer
Explanation
There are 8 constructors of SQLTimeoutException class in java. These are:-
1) SQLTimeoutException():- Constructs a SQLTimeoutException object
2) SQLTimeoutException(String reason):- Constructs a SQLTimeoutException object with a given reason
3) SQLTimeoutException(String reason, String SQLState):- Constructs a SQLTimeoutException object with a given reason and SQLState
4) SQLTimeoutException(String reason, String SQLState, int vendorCode):- Constructs a SQLTimeoutException object with a given reason, SQLState and vendorCode
5) SQLTimeoutException(String reason, String SQLState, int vendorCode, Throwable cause):- Constructs a SQLTimeoutException object with a given reason, SQLState, vendorCode and cause
6) SQLTimeoutException(String reason, String SQLState, Throwable cause):- Constructs a SQLTimeoutException object with a given reason, SQLState and cause
7) SQLTimeoutException(String reason, Throwable cause):- Constructs a SQLTimeoutException object with a given reason and cause
8) SQLTimeoutException(Throwable cause):- Constructs a SQLTimeoutException object with a given cause
So, this is the correct answer.
-
nextIndex()
-
addAll()
-
IndexOf()
-
listIterator()
-
subList(startindex,endindex)
A
Correct answer
Explanation
nextIndex() method is present in the ListIterator interface in Java collections.
-
remove()
-
element()
-
Pop()
-
poll()
-
exit()
C
Correct answer
Explanation
pop() method returns and removes the top element of stack.
-
poll()
-
search(o:Object)
-
empty()
-
exit()
-
Pop()
-
addFirst()
-
setFirst()
-
setLast()
-
indexOf(e:Element)
-
lastIndexOf(e:element)
A
Correct answer
Explanation
addFirst() method is used to add element to the head of the list.
-
Frequency(c : collection, o : object)
-
Reverse(List)
-
Sort(List)
-
Both 1 and 2
-
All of the above
E
Correct answer
Explanation
All the methods given are static and present in collections class.
-
Min(c:Collection)
-
Shuffle(list)
-
Frequency(c :collection, o :object)
-
Copy(destination,source)
-
Merge(c:collection,c1:collection)
E
Correct answer
Explanation
There is no method named Merge(c:collection,c1:collection) in the collections class.
-
elementAt(index)
-
firstElement()
-
removeElementAt(int)
-
setSize(int)
-
removeFirst()
E
Correct answer
Explanation
removeFirst() method is not present in Vector class.
-
removeAllElements()
-
element()
-
removeLast()
-
get(index : int)
-
set(index,element)
B
Correct answer
Explanation
removeAllElements() method is present in the Vector class.
-
This class is thread-safe.
-
The object of this class can be modified.
-
It contains some particular sequence of characters.
-
All of the above
-
Both (1) and (3)
-
Garbage collection can be decided by the user.
-
The finalise() method is guaranteed to run once for the garbage collection.
-
Garbage collection works for the automatic memory management.
-
Both (1) and (2)
-
Both (2) and (3)
-
These variable are used to save an object into a file.
-
The thread will read the most recent updated value by using volatile variable.
-
It is used to create variables and methods that will exist independently of any instances created for the class.
-
Volatile variables are used in asynchronous medium.
-
Both (2) and (4)