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 technology web technology
  1. All of these.

  2. b. (C) & (E)

  3. c. (A), (C) & (E)

  4. d. (B),(C) & (D)

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

Java reserves goto and const as keywords but doesn't use them. 'inner' was reserved for potential inner class support but ultimately wasn't used (inner classes use different syntax). Union, boolean, and synchronized are used keywords.

Multiple choice technology programming languages
  1. if ( i > 10) { throws new IndexOutOfBoundsException("Index is out of bound!"); }

  2. if ( i > 10) { throw new IndexOutOfBoundsException("The value of index i=" + " is out of bound!" ); }

  3. if ( i > 10) { throw "Index is out of bound!"; }

  4. None of the ABove

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

Java exceptions are objects thrown using the 'throw' keyword with 'new' to instantiate the exception class. Option B shows correct syntax: 'throw new IndexOutOfBoundsException(...)' creates the exception object and throws it. Option A uses 'throws' (a declaration keyword, not for throwing) and has a typo. Option C tries to throw a string literal directly, which isn't valid - only Throwable objects can be thrown.

Multiple choice technology
  1. True

  2. False

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

Java has robust built-in support for multithreaded programming through the Thread class, Runnable interface, and synchronized keyword. The language was designed from the ground up to support concurrent programming, making it one of the core strengths of the Java platform.

Multiple choice technology packaged enterprise solutions
  1. Session.load();

  2. Session.get();

  3. Session.fetch();

  4. None of the above

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

In Hibernate, Session.get() immediately hits the database and returns null if the record does not exist. Session.load() returns a proxy and throws an exception later if the entity is missing, making get() safer when existence is uncertain.

Multiple choice technology programming languages
  1. a) Yes

  2. b) No

  3. c) can't say

  4. d) None of the above

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

Hibernate requires choosing one inheritance strategy per hierarchy. You cannot mix table-per-class (union subclass) and table-per-subclass (joined subclass) within the same hierarchy. Each persistent hierarchy must use a single strategy.

Multiple choice technology programming languages
  1. im.name = "Done";

  2. Item otherObject = new Item(“Done”); itemList.set(49, otherObject);

  3. ((Item)itemList.get(49)).name = “Done”;

  4. None of above is correct as they are not changing 50th element.

Reveal answer Fill a bubble to check yourself
A Correct answer
Multiple choice technology programming languages
  1. a) By using the insert="false" and update="false" attributes.

  2. b) By using the isinsert="false" and isupdate="false" attributes.

  3. c) By using the isinsert="no" and isupdate="no" attributes

  4. d) None

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

In Hibernate, making a property read-only from the application side (while still loading it from the database) is achieved by setting insert="false" and update="false" in the mapping XML or annotations. This tells Hibernate to retrieve the property value when loading objects but never include it in INSERT or UPDATE statements. Option A correctly states this. Options B and C use incorrect attribute names (should be 'insert' and 'update', not 'isinsert' and 'isupdate'), making them invalid.

Multiple choice technology programming languages
  1. a) Session.load();

  2. b) Session.get();

  3. c) Session.fetch();

  4. d) None of the above

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

Session.get() is the better choice when you're uncertain whether a row exists. The get() method returns null if no matching row is found, allowing you to handle the absence gracefully. In contrast, Session.load() assumes the row exists and throws an ObjectNotFoundException if it doesn't, which would cause an uncaught exception in your code. Option B is correct. Options C and D are incorrect because there's no Session.fetch() method in standard Hibernate, and load() would cause an exception.

Multiple choice technology programming languages
  1. a) bag has index column

  2. b) bag permits duplicate element values

  3. c) bag does not permits duplicate element values

  4. d) None

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

To solve this question, the user needs to have knowledge about the concept of a bag data structure. A bag is a collection of unordered elements that may contain duplicates.

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

a) bag has index column: This statement is incorrect. A bag is an unordered collection, which means it does not have an index column. Items in a bag are stored in any order.

b) bag permits duplicate element values: This statement is correct. A bag allows duplicate elements to be added to it. For example, a bag can contain two or more items with the same value.

c) bag does not permit duplicate element values: This statement is incorrect. A bag permits duplicate elements to be added to it. Therefore, this statement is false.

d) None: This option is incorrect because option B is correct.

The Answer is: B

Multiple choice technology programming languages
  1. a) refresh();

  2. b) flush();

  3. c) fetch();

  4. d) 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 the current state in the Session. This is particularly useful when database triggers initialize or modify properties after the initial save - refresh() retrieves those trigger-generated values. Option A correctly identifies refresh(). Option B (flush) synchronizes the Session state to the database (writes to DB, not reads from it). Options C and D are incorrect because there's no standard fetch() method, and load() retrieves only if already in Session or throws exception.