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

Multiple choice technology testing
  1. Import Table

  2. SheetImport

  3. ImportSheet

  4. ImportDataTable

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology testing
  1. GetCellData(Row ,Col)

  2. GetData(Row,Col)

  3. GetRowValue(Roeid,Colname)

  4. None of the Above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. public void run()

  2. public void start()

  3. public void exit()

  4. public final void setAccess()

  5. public final void setPriority(int priNbr)

  6. public final int getPriority()

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. Open

  2. Begin Transaction

  3. Execute

  4. Commit Transaction

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. Message

  2. StackTrace

  3. Source

  4. Line number

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. The running application crashes`

  2. The exception is simply ignored and the object is garbage collected

  3. The exception is simply ignored, but the object is not garbage collected

  4. If a Runtime Exception is thrown in the finalize method

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. The method must return a type of either IEnumerator or Ienumerable

  2. The method must return a type of IComparable

  3. The method must explicitly contain a collection

  4. A and B

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. By invoking the free method on the object

  2. By calling system.gc() method

  3. By setting all references to the object to new values (say null).

  4. Garbage collection cannot be forced. The programmer cannot force the JVM to free the memory used by an object.

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. Writing the object to a Stream

  2. Reading the Object from a Stream

  3. Adding the Object to a collection

  4. All of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. character streams

  2. byte streams

  3. Both (A) and (B)

  4. None of the Above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. Open

  2. BeginTransaction

  3. Execute

  4. CommitTransaction

Reveal answer Fill a bubble to check yourself
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.