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
-
Dispose
-
Close
-
Finalize
-
None of the above
C
Correct answer
Explanation
In VB.NET, the Finalize method is the destructor equivalent called by the garbage collector during object cleanup. Dispose (option A) is for deterministic resource cleanup via the IDisposable pattern. Close (option B) is typically for closing resources like files/connections but not the destructor.
-
ExecuteNonQuery & ExecuteScalar
-
ExecuteQuery & ExecuteScalar
-
ExecuteParameter
-
None of the above
A
Correct answer
Explanation
The Command object in ADO.NET has ExecuteNonQuery for INSERT/UPDATE/DELETE (returns affected rows), ExecuteScalar for single value queries, and ExecuteReader for multiple rows. ExecuteQuery and ExecuteParameter are not valid methods.
-
Java automatically works both within a web page and stand-alone.
-
You have to write separate pieces of Java if you want to run them in both a web page and stand-alone, although many
-
If you're careful, the same piece of Java can be used both as a stand-alone program and within a web page.
-
You run your Java first in a web page. A button then lets you save a local copy which you can run stand-alone
C
Correct answer
Explanation
Java's 'write once, run anywhere' design allows the same code to run as standalone application or applet if designed properly without platform-specific dependencies.
-
To maintain multiple contexts
-
To allow a Java program to do several things at the same time
-
Only to hold the seams in the programmer's trousers.
-
As a debugging tool to allow the programmer to trace back once a Java program has completed its operation
B
Correct answer
Explanation
Threads enable concurrent execution - a Java program can perform multiple tasks simultaneously like handling UI while processing data in background.
-
A Unix or Linux workstation which (in practice) would have a permanent link to the internet.
-
The applet in .class format
-
A licensed copy of the Java Development Kit, which comes with the appropriate rights for any programs you create
-
A Java-enabled web server
B
Correct answer
Explanation
Java applets are distributed as compiled .class files (bytecode) that browsers download and execute via JVM. Source code or JDK license is not required for users.
-
AddTick()
-
GetMonth()
-
GetHashCode()
-
AddMilliSeconds()
-
All the Above
B
Correct answer
Explanation
The question asks which is NOT a method of DateTime object. GetMonth() is not a valid DateTime method in C# - the correct method is Month property. AddTicks(), GetHashCode(), and AddMilliseconds() are actual methods.
-
String
-
Type
-
TimeSpan
-
int
-
None
C
Correct answer
Explanation
The difference between two DateTime values is stored in a TimeSpan object, which represents a time interval. String, Type, int, and None are not appropriate types for date differences.
-
gets
-
getstring
-
Both A and B
-
None of the Above
A
Correct answer
Explanation
The gets() function in C reads a single line from stdin into a char array until a newline. Note that gets() is deprecated and dangerous because it doesn't check buffer boundaries, leading to buffer overflows. Use fgets() instead in production code. There is no standard C function called getstring().
-
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
B
Correct answer
Explanation
GetROProperty retrieves the actual runtime property value of an object during test execution, reflecting the current state of the application. This differs from GetTOProperty which fetches property values from the Object Repository (test object definition), not the live application. SetROProperty is incorrect as it doesn't exist: RO properties are read-only runtime values.
-
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.