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
-
Faster performance
-
Methods are synchronised
-
Thread-safety
-
Multithreading
A
Correct answer
Explanation
StringBuilder is not thread-safe - its methods are NOT synchronized, which eliminates synchronization overhead. StringBuffer is thread-safe with synchronized methods, making it slower. The main advantage of StringBuilder is faster performance in single-threaded environments.
-
HttpServletRequest
-
HttpServletResponse
-
ServletConfig
-
ServletContext
B
Correct answer
Explanation
To solve this question, the user needs to know that the getWriter() method returns an object of type PrintWriter, which can be used to generate output. The user must also know which class defines this method.
The getWriter() method is used to return an object of type PrintWriter, which can be used to generate output. This method is defined in the HttpServletResponse class.
Therefore, the correct answer is:
The Answer is: B. HttpServletResponse
-
It loads the Java code into the database.
-
It publishes Java methods in CardValidation.java
-
It loads the metadata related to the Java class file into the database.
-
It loads the Java class file into the Java pool in the database instance.
A
Correct answer
Explanation
The loadjava utility loads Java source code, class files, and resources into an Oracle database. When given a .java file, it compiles and loads the Java code into the database schema. It does not publish methods (that requires separate publication) nor does it specifically load metadata only into Java pool.
A
Correct answer
Explanation
Yes, Java transformation is a valid transformation type in Informatica PowerCenter. It allows developers to write custom transformation logic using Java code, providing flexibility for complex data transformations that might be difficult to achieve using built-in transformations. The Java transformation can include imports, use Java libraries, and implement custom business logic.
-
extern
-
volatile
-
transient
-
this
B,C,D
Correct answer
Explanation
Java keywords are reserved words with special meaning. 'volatile' is used for variables in multithreading, 'transient' marks fields not to be serialized, and 'this' refers to the current instance. 'extern' is a C/C++ keyword, not used in Java.
-
The member variable called length
-
The method length() returns the number of characters.
-
The member variable called size
-
The method size() returns the number of characters.
B
Correct answer
Explanation
In Java, String objects use the length() method to return the character count, not a member variable. This is because String is a class - not a primitive or struct - so it encapsulates its data and exposes methods like length() rather than public fields. Option D's size() method doesn't exist for String.
-
One must override the method ReceiveMessage
-
One must override the method InitializeMethod
-
Both A) and B)
-
One must override the method ProcessMessage
-
Load ( )
-
Fill( )
-
DataList
-
DataBind
B
Correct answer
Explanation
The Fill() method is used to populate a DataSet with data from a data source in ADO.NET. It executes the query and retrieves rows into the DataSet. Load() is not a standard DataAdapter method, DataList is a UI control, and DataBind is for web controls.
-
RowUpdating, AfterUpdate
-
BeforeUpdate, RowUpdating
-
RowUpdating, RowUpdated
-
BeforeUpdate, AfterUpdate
-
BeforeUpdate, RowUpdated
C
Correct answer
Explanation
The DataAdapter in ADO.NET fires two events for each row during database updates: RowUpdating (before the update action) and RowUpdated (after the update completes). These events allow developers to intervene in the update process for validation, logging, or error handling. The prefix 'Row' is consistent for both events.
-
Application.Exit();
-
System.Environment.Exit(0)
-
System.Environment.Exit(1)
-
All the above
D
Correct answer
Explanation
All listed methods can terminate a C# application. Application.Exit() informs all message loops to terminate, which is suitable for Windows Forms. System.Environment.Exit(0) and System.Environment.Exit(1) terminate the process immediately and return exit codes to the operating system, representing success and failure respectively.
-
ReadAllLine()
-
ReadAllBytes()
-
ReadAllTexts()
-
WriteAllLine()
-
WriteAllTexts()
B
Correct answer
Explanation
In the C# System.IO.File class, ReadAllBytes() is a valid built-in method. The other options are incorrect because they use incorrect naming: the correct framework methods are plural ReadAllLines(), singular ReadAllText(), plural WriteAllLines(), and singular WriteAllText(). C# is case-sensitive and strict about method signatures.
-
Set
-
Property Object
-
Count
-
ChildObjects
D
Correct answer
Explanation
The ChildObjects method in QTP retrieves all child objects within a parent container that match specified description criteria. It returns a collection of objects that can be iterated through programmatically. Property objects are used for defining descriptions, Set assigns object references, and Count returns the number of items.
-
ExecuteNonQuery & ExecuteScalar
-
ExecuteQuery & ExecuteScalar
-
ExecuteParameter
-
None
A
Correct answer
Explanation
In ADO.NET, the SqlCommand class provides methods like ExecuteNonQuery (for INSERT, UPDATE, DELETE) and ExecuteScalar (for single-value lookups). ExecuteQuery and ExecuteParameter are not standard ADO.NET command object methods.
-
Data
-
Message
-
StackTrace
-
Source
C
Correct answer
Explanation
The StackTrace property provides a detailed call stack that shows the sequence of method calls that led to the exception, including the exact line numbers where the exception originated. This is precisely what a developer needs to locate the problematic code. The Message property only contains a description of the error, while Data contains arbitrary additional information, and Source indicates the application name - none provide the specific line location like StackTrace does.
A
Correct answer
Explanation
Vector is synchronized, making it thread-safe for multi-threaded environments, whereas ArrayList is not synchronized and therefore not thread-safe. This is a fundamental difference in Java collections, where ArrayList offers better performance when synchronization is not required.