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 web technology
  1. Session.contains() method to determine if an instance belongs to the session cache.

  2. Session.contains() method to determine if an instance belongs to the data base

  3. Both are correct

  4. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

To solve this question, the user needs to have knowledge about the Session object in Hibernate.

The Session.contains() method is used to check if a particular object is associated with the current Hibernate session or not.

Option A is correct because the Session.contains() method is used to determine if an instance belongs to the session cache.

Option B is incorrect because the Session.contains() method does not determine if an instance belongs to the database. Instead, it checks whether the instance is associated with the current Hibernate session or not.

Option C is incorrect because only option A is correct.

Option D is incorrect because option A is the correct answer.

Therefore,

The Answer is: A.

Multiple choice technology web technology
  1. remove the object and its collections from the first level cache

  2. remove the object and its collections from the second level cache

  3. remove the object and its collections from the data base

  4. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The evict() method removes an object and its associated collections from the first-level cache (Session cache). It does NOT affect the second-level cache or delete from the database - it just detaches from the session.

Multiple choice technology web technology
  1. ListResultSet

  2. ResultSet

  3. ScrollableResultSet

  4. ScrollableResult

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

To understand what session.createQuery("Query").scroll() returns, the user needs to know about Hibernate and its query methods.

Hibernate is an ORM (Object-Relational Mapping) library that provides an interface between Java classes and SQL databases. It provides several query methods to interact with the database, including session.createQuery().

session.createQuery("Query").scroll() method is used to iterate over a large number of objects without loading them all into memory at once. It returns a ScrollableResults object that can be used to scroll through the results one at a time.

Now, let's go through each option and explain why it is right or wrong:

A. ListResultSet: This option is incorrect because there is no such class as ListResultSet in Hibernate.

B. ResultSet: This option is incorrect because session.createQuery("Query").scroll() does not return a ResultSet object. Hibernate uses a different interface called ScrollableResults for scrolling through large datasets.

C. ScrollableResultSet: This option is incorrect because there is no such class as ScrollableResultSet in Hibernate.

D. ScrollableResult: This option is correct. session.createQuery("Query").scroll() returns a ScrollableResult object that can be used to scroll through the results one at a time.

Therefore, the answer is: D. ScrollableResult.

Multiple choice technology web technology
  1. refresh();

  2. flush();

  3. fetch();

  4. load()

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Session.refresh() re-loads the entity and its collections from the database, overwriting current state. This is useful when database triggers or other external processes modify data. flush() syncs to DB, load() may return a proxy, and fetch() doesn't exist.

Multiple choice technology programming languages
  1. By mapping the property with access="onlyfield" in Hibernate metadata

  2. By mapping the property with access="variable" in Hibernate metadata

  3. By mapping the property with access="field" in Hibernate metadata

  4. none of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Mapping a property with access="field" tells Hibernate to use reflection to access the entity instance variables directly, bypassing getters and setters. Options like 'onlyfield' and 'variable' are not valid Hibernate access strategies.

Multiple choice technology programming languages
  1. On session close session.load() Emp Object unavailable to access.

  2. On session close session.createCriteria() Emp unavailable to access.

  3. None

  4. a & b

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

session.load() can return a proxy and may not hit the database until you access the object's properties. If the session is closed before accessing properties, you cannot load the data (throws LazyInitializationException). session.createCriteria() immediately executes the query and returns fully initialized objects that remain accessible after session closes.

Multiple choice technology
  1. to update the screen input in working document

  2. to specify the next event to be executed

  3. to update the working document

  4. to update the working document with the results of service

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The Out parameter in a service event captures the output returned from the service execution and updates the working document with those results. Option A incorrectly references screen input which is unrelated to service events. Option B describes flow control, not data passing. Option C is partially correct but incomplete - it doesn't specify that the update contains service results.

Multiple choice technology
  1. to update the working document with the results of service

  2. to update the screen input in working document

  3. to specify the next event to be executed

  4. to format the working document

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In client events, which handle user interaction, the Out parameter is responsible for updating screen-related input data in the working document. Option A describes service events, not client events. Option C refers to flow control. Option D is not the standard terminology for client event Out parameters.

Multiple choice technology databases
  1. Trap it with a Handler

  2. Propagate it to the Calling Environment

  3. A & Then B

  4. B & Then A

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Exception handling involves first trapping the exception with a handler in the EXCEPTION block, then optionally propagating it to the calling environment if the handler cannot resolve it. This two-step approach (handle then propagate if needed) is the standard pattern.

Multiple choice technology web technology
  1. log.debug

  2. log.info

  3. log.error

  4. System.out.println

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

For debugging purposes, log.debug is the most appropriate choice as it provides fine-grained diagnostic information that can be enabled in development and disabled in production without performance impact. The info level is for significant application events, error for problems requiring attention, and System.out.println bypasses the logging framework entirely.

Multiple choice technology life sciences
  1. Session.Close()

  2. Session.discard()

  3. Session.Abandon()

  4. Session.Exit()

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In ASP.NET, the Session.Abandon() method is the standard way to destroy a user's session and release its resources. Alternative methods like Session.Close(), Session.discard(), or Session.Exit() do not exist as valid session termination APIs in the framework.

Multiple choice technology web technology
  1. OnItemChanged();

  2. OnFieldChanged();

  3. OnPropertyChanged();

  4. All of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

OnPropertyChanged() is the standard method called when a property value changes in data binding scenarios. This method implements INotifyPropertyChanged and notifies the UI that bound data has changed, triggering UI updates. OnItemChanged and OnFieldChanged are not standard Silverlight/WPF patterns.