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
B
Correct answer
Explanation
Sensors in Android are NOT uniquely identified by integer IDs. They are identified by sensor type constants (like Sensor.TYPE_ACCELEROMETER) and an integer handle that can vary between devices. Multiple sensors of the same type exist, requiring additional identification beyond a simple unique integer ID.
-
Operational exception
-
Address exception
-
Data exception
-
Numeric exception
C
Correct answer
Explanation
When an arithmetic operation is attempted on non-numeric data (like trying to do math on a text field or alphabetic character), it causes a 'Data Exception' (decimal data exception or 0Cx exception in IBM mainframe terminology). Operational exceptions relate to program interrupts, Address exceptions to invalid memory access.
-
Method with ActionResult keyword
-
All methods
-
All methods except non-public methods
-
All of the above
C
Correct answer
Explanation
By default, the controller treats all public methods as potential action methods. Non-public methods (private, protected) are not considered actions. Special attributes like [NonAction] can also exclude public methods from being actions.
-
[Private]
-
[NonAction]
-
[Internal]
-
[Protected]
B
Correct answer
Explanation
The [NonAction] attribute prevents a public method in a controller from being invoked by a URL request, even though it's public. [Private] and [Protected] are access modifiers for class members, not MVC-specific attributes. [Internal] limits visibility to the assembly but doesn't prevent URL routing.
-
Exec
-
Execute
-
CacheMetadata
-
beginExec
B
Correct answer
Explanation
In custom activities derived from CodeActivity, the Execute method contains the execution logic. This is where you implement the activity's primary behavior. For NativeActivity, you override Execute differently, and CacheMetadata is for runtime metadata registration, not execution logic. Exec and beginExec are not valid WF4.0 method names.
-
Using InArgument Name
-
Using context.GetValue(InArgumentName)
-
InArgumentName.Get(context)
-
InArgument.Get()
B,C
Correct answer
Explanation
To access InArgument values within a custom activity's Execute method in WF 4.0, you have two correct approaches: either use context.GetValue(inArgument) or call inArgument.Get(context). Both methods require the ActivityContext parameter to resolve the argument's value at runtime. Simply referencing the argument by name or calling Get() without context will not work.
-
ExecuteDataSet()
-
ExecuteScalar()
-
ExecuteReader()
-
ExecuteNonQuery()
D
Correct answer
Explanation
ExecuteNonQuery is specifically designed for SQL commands that don't return row data - INSERT, UPDATE, DELETE, DDL statements. It returns only the count of affected rows. ExecuteReader returns rows, ExecuteScalar returns a single value, ExecuteDataSet returns a DataSet.
B
Correct answer
Explanation
onreadystatechange is a PROPERTY (event handler) of XMLHttpRequest, not a method. You assign a function to it: xhr.onreadystatechange = function() { ... }. It's called when the readyState changes, but you don't invoke it as a method like xhr.onreadystatechange().
-
When browser is closed
-
When the page reloads as well.
-
Only when you navigate out of the page.
-
All Of the Above
D
Correct answer
Explanation
The onUnload event fires when a document is unloaded from the browser window. This occurs in three scenarios: when the browser window closes, when the page reloads (including refresh), and when the user navigates away from the page (clicking links, back/forward buttons). Therefore, all listed conditions are correct.
-
session.contains() method to determine if an instance belongs to the session cache.
-
session.contains() method to determine if an instance belongs to the data base
-
Both are correct
-
none of the above
A
Correct answer
Explanation
In Hibernate, the session.contains() method checks whether a given instance is present in the first-level cache (session cache), not whether it exists in the database. To check database existence, you would use a query or get() method. The statement correctly identifies this.
-
Remove the object and its collections from the first level cache
-
Remove the object and its collections from the second level cache
-
Remove the object and its collections from the data base
-
None of the above
A
Correct answer
Explanation
The session.evict() method removes a specified object and its associated collections from the first-level cache (session cache). This is useful when you want to detach an object from the session without closing it. It does NOT remove from the second-level cache (that's a different concept) or from the database (that would be a delete operation).
-
ListResultSet
-
ResultSet
-
ScrollableResultSet
-
ScrollableResult
D
Correct answer
Explanation
The session.createQuery("Query").scroll() method returns a ScrollableResult, which allows you to scroll through query results both forward and backward. This is different from scroll() on a Criteria query which returns ScrollableResults. Note the singular 'Result' versus 'Results'.
-
Refresh();
-
Flush();
-
Fetch();
-
Load()
A
Correct answer
Explanation
The refresh() method re-loads an object and all its collections from the database, overwriting any changes made in memory. This is particularly useful when database triggers initialize or modify properties after a save operation. It ensures your in-memory object reflects the actual database state.
-
Refresh();
-
Flush();
-
Fetch();
-
Load()
A
Correct answer
Explanation
The refresh() method re-loads an object and all its collections from the database, overwriting any changes made in memory. This is particularly useful when database triggers initialize or modify properties after a save operation. It ensures your in-memory object reflects the actual database state.
-
execute(), exit()
-
execute(), setProperties()
-
execute(), setParameter()
-
exit(), systemProperties()
C
Correct answer
Explanation
The StreamTransformation interface requires two mandatory methods: execute() contains the main transformation logic (input to output), and setParameter() receives runtime configuration from the XI pipeline. Options A, B, and D incorrectly include exit() or systemProperties(), which are not part of the interface.