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
-
Import Table
-
SheetImport
-
ImportSheet
-
ImportDataTable
C
Correct answer
Explanation
The ImportSheet method in QTP's DataTable object imports a sheet from an external Excel file into the runtime Data Table. The syntax is DataTable.ImportSheet(filename, sheetSource, sheetDest). ImportTable and SheetImport are not valid methods.
-
Wait
-
WaitProperty
-
Exist
-
Sync
D
Correct answer
Explanation
The Sync method (applied to Browser objects) waits for the browser to complete the current navigation before proceeding. This ensures the page is fully loaded. Wait is a time delay, WaitProperty checks object properties, and Exist checks for object presence.
-
GetCellData(Row ,Col)
-
GetData(Row,Col)
-
GetRowValue(Roeid,Colname)
-
None of the Above
A
Correct answer
Explanation
The GetCellData(Row, Col) method retrieves data from a specific cell in an HTML Table object in QTP. You pass row and column indices as parameters. GetData and GetRowValue are not standard QTP table methods.
-
SetROProperty
-
GetROProperty
-
GetTOProperty
-
GetVisibleText
-
public void run()
-
public void start()
-
public void exit()
-
public final void setAccess()
-
public final void setPriority(int priNbr)
-
public final int getPriority()
A,B,E,F
Correct answer
Explanation
The methods run(), start(), setPriority(int), and getPriority() are standard methods defined in the java.lang.Thread class used to manage thread execution and priorities. Methods exit() and setAccess() do not exist in the Thread class, making them incorrect.
-
Open
-
Begin Transaction
-
Execute
-
Commit Transaction
C
Correct answer
Explanation
In ADO.NET, the DbConnection class (such as SqlConnection or OleDbConnection used in VB.NET) features methods like Open(), BeginTransaction(), and Close(). The Execute() method does not belong to the Connection object; execution is instead handled by a Command object (SqlCommand.ExecuteNonQuery, etc.). Note that Commit is on the transaction object, but Execute is definitely not on the connection.
-
Deserialization
-
Serialization
-
Interface
-
None of the Above
B
Correct answer
Explanation
Serialization is the process of converting the state of an object into a byte stream so that it can be saved to a file or transmitted over a network. Deserialization is the reverse process, which reconstructs the object from the byte stream.
-
Message
-
StackTrace
-
Source
-
Line number
B
Correct answer
Explanation
The StackTrace property provides a string representation of the frames on the call stack at the time of the current exception, including line numbers when debugging symbols are available. The Message property only contains the error description text. Source refers to the application name, and there is no built-in 'Line number' property.
-
The running application crashes`
-
The exception is simply ignored and the object is garbage collected
-
The exception is simply ignored, but the object is not garbage collected
-
If a Runtime Exception is thrown in the finalize method
B
Correct answer
Explanation
In Java, if an uncaught exception (such as a RuntimeException) is thrown during the execution of the finalize method, the exception is ignored, the finalization of the object terminates, and the object remains eligible for garbage collection. The application does not crash.
-
The method must return a type of either IEnumerator or Ienumerable
-
The method must return a type of IComparable
-
The method must explicitly contain a collection
-
A and B
A
Correct answer
Explanation
In C#, the foreach statement can iterate over any type that implements IEnumerable or returns an IEnumerator. The method does not need to return IComparable, nor does it need to explicitly contain a collection internally, as long as the returned type supports the iteration pattern.
-
By invoking the free method on the object
-
By calling system.gc() method
-
By setting all references to the object to new values (say null).
-
Garbage collection cannot be forced. The programmer cannot force the JVM to free the memory used by an object.
D
Correct answer
Explanation
The correct answer is D. Garbage collection cannot be forced. The programmer cannot force the JVM to free the memory used by an object. The JVM will automatically free the memory used by an object when it is no longer referenced by any other object.
Option A is incorrect because there is no free method in Java.
Option B is incorrect because calling system.gc() only requests the JVM to run the garbage collector, but it does not guarantee that the garbage collector will actually free the memory used by the object.
Option C is incorrect because setting all references to the object to new values (say null) will only prevent the JVM from garbage collecting the object, but it will not actually free the memory used by the object.
The memory used by an object will only be freed when the object is no longer referenced by any other object. This is the principle of garbage collection.
-
Writing the object to a Stream
-
Reading the Object from a Stream
-
Adding the Object to a collection
-
All of the above
A
Correct answer
Explanation
Serialization is the process of converting an object's state into a byte stream so that it can be written to memory, a database, or a file. Reading the object back from a stream to reconstruct its state is called deserialization, not serialization.
-
character streams
-
byte streams
-
Both (A) and (B)
-
None of the Above
C
Correct answer
Explanation
Java I/O uses two parallel hierarchies: byte streams (InputStream/OutputStream) for binary data and character streams (Reader/Writer) for text. Byte streams handle raw I/O (images, files, network). Character streams handle text with proper encoding (unicode, localization). Both types are fundamental to Java's I/O architecture.
-
toNumber()
-
conString()
-
valueOf()
-
None of the Above
C
Correct answer
Explanation
In Java, the valueOf() method is commonly used to convert String representations to Number types (Integer.valueOf(), Long.valueOf(), Double.valueOf(), etc.). Options like toNumber() and conString() are not standard Java methods for this purpose.
-
Open
-
BeginTransaction
-
Execute
-
CommitTransaction
C
Correct answer
Explanation
A Connection Object in VB.NET provides methods for managing database connections: Open() to establish a connection, BeginTransaction() to start a transaction, and CommitTransaction() to commit changes. Execute() is not a Connection method - it belongs to Command Objects which are used to execute SQL commands once a connection is established.