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
-
Start()
-
Thread(…)
-
Run()
-
Both (1) and (3)
A
Correct answer
Explanation
In Java and Android threading, calling the start() method of a Thread class tells the system to initiate a new thread of execution, creating a separate background process or thread path. The run() method merely executes code in the current thread.
-
HideSelection
-
StackTrace
-
Text
-
None of these
B
Correct answer
Explanation
StackTrace is a list of the pending method calls at the point at which the exception was detected.
-
Message
-
TargetSite
-
InnerException
-
StackTrace
C
Correct answer
Explanation
InnerException property returns the exception object reference to a nested exception.
-
OutOfMemoryException
-
XmlException
-
InvalidOperationException
-
None of these
A
Correct answer
Explanation
OutOfMemoryException is the representative of the classes that extends exception results when there is not enough memory to carry out an operation.
-
HelpLink
-
InnerException
-
Message
-
None of these
C
Correct answer
Explanation
Message property of exception is a string that contains a description of the error, suitable for displaying to users.
-
For getting the input
-
For printing the output
-
For accessing any particular variable
-
None of the above
A
Correct answer
Explanation
Explanation: Console.ReadLine() is used to get the input from the user and Console. WriteLine() is used to print the output to the screen.
-
Its very first method
-
Its very last method
-
Its middle method
-
None of the above
D
Correct answer
Explanation
Explanation: The very first method the compiler looks for is the Main method in the program.
-
It is used for concurrency issue in the application.
-
It makes sure that no race condition in the application code.
-
This technique does not maintain the thread safety in the application.
-
This technique allows the developer to delay the instantiation of the object until it is first called upon.
-
Both (1) and (3).
E
Correct answer
Explanation
These are the correct statements.
B
Correct answer
Explanation
We must execute the javac command to compile a java program(.java extension file). The syntax is as follows:
javac <filename>
-
Only A
-
Only B
-
Both A and B
-
Neither A nor B
A
Correct answer
Explanation
Byte code is always generated by the Java compiler. This byte code is platform independent.
-
student is the name of a structure.
-
result is the name of a method.
-
result is a form of a datatype.
-
student is the name of a method.
B
Correct answer
Explanation
Here, student may be a class or an object but result is the method.
-
Student s[];
-
Student s[]=new Student[4];
-
Student s[][]=new Student[5][];
-
Student s[][]=new Student[5][3];
A
Correct answer
Explanation
The declaration Student s[] is incorrect. All the other array declarations are correct.
-
switch(exp)
{
case value1: statement_1;
case value2: statement_2;
……………………
case valuen: statement_n;
[default: statements ;]
}
-
switch(exp)
{
case value1: statement_1;
case value2: statement_2;
……………………
case valuen: statement_n;
default: statements ;
}
-
switch(exp)
{
case value1: statement_1;
case value2: statement_2;
……………………
case valuen: statement_n;
}
-
switch(exp)
{
case value1; statement_1;
case value2; statement_2;
……………………
case valuen; statement_n;
[default: statements ;]
}
A
Correct answer
Explanation
The correct syntax is as follows:
switch(exp)
{
case value1: statement_1;
case value2: statement_2;
……………………
case valuen: statement_n;
[default: statements ;]
}
The default statement is optional.
-
private
-
public
-
transient
-
unserialize
-
none of the above
C
Correct answer
Explanation
This is the correct answer. If a data member is made transient, it will not be serialized.
-
Adaptive collectors
-
Copying collectors
-
Tracing collectors
-
Destructor algorithm
-
The train algorithm
D
Correct answer
Explanation
Destructor is a method in Java, not an algorithm.