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

Multiple choice java
  1. System.arraycopy(fromarray,frominden,toarray,toindex,count);

  2. System.arraycopy(toarray,toinden,fromarray,fromindex,count);

  3. System.arraycopy(fromarray,toarray,count);

  4. System.arraycopy();

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

System.arraycopy copies array elements from source to destination. The correct syntax requires: source array, starting position in source, destination array, starting position in destination, and number of elements to copy. Option A correctly shows this parameter order.

Multiple choice technology programming languages
  1. Used for Cloning or copying integer var

  2. Used for Cloning or copying float var

  3. Used for Cloning or copying String var

  4. Used for Cloning an array

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

The clone() method in Java is commonly used for creating copies of arrays. While arrays can also be cloned using other methods, the clone() method provides a straightforward way to duplicate array contents.

Multiple choice technology mainframe
  1. Operational exception

  2. Address exception

  3. Data exception

  4. Numeric exception

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

Multiple choice technology programming languages
  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 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).

Multiple choice technology programming languages
  1. ListResultSet

  2. ResultSet

  3. ScrollableResultSet

  4. ScrollableResult

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

Multiple choice technology programming languages
  1. Refresh();

  2. Flush();

  3. Fetch();

  4. Load()

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

Multiple choice technology programming languages
  1. Refresh();

  2. Flush();

  3. Fetch();

  4. Load()

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

Multiple choice technology
  1. execute(), exit()

  2. execute(), setProperties()

  3. execute(), setParameter()

  4. exit(), systemProperties()

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

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.