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 programming languages
  1. IllegalStateException

  2. NumberFormatException

  3. IllegalArgumentException

  4. ClassCastException

Reveal answer Fill a bubble to check yourself
A,B,C Correct answer
Explanation

To answer this question, the user needs to know what each exception represents and which exceptions are most commonly thrown by API developers or application developers, rather than by the JVM.

A. IllegalStateException: This exception is usually thrown when the state of an object is not as expected. An IllegalStateException is typically thrown by an application or API developer when an object is not in the right state to perform a particular operation.

B. NumberFormatException: This exception is thrown when a program attempts to convert a string to a numeric value, but the string is not a valid number. An application or API developer might throw a NumberFormatException when expecting a string to contain an integer, but the string actually contains letters or other non-numeric characters.

C. IllegalArgumentException: This exception indicates that a method has been passed an illegal or inappropriate argument. An application or API developer might throw an IllegalArgumentException when a parameter passed into a method does not meet the expected criteria.

D. ClassCastException: This exception is thrown when an attempt is made to cast an object to a subclass of which it is not an instance. An application or API developer might throw a ClassCastException when trying to cast an object to a type that it is not compatible with.

Based on these explanations, the exception that is most typically thrown by an API developer or an application developer rather than being thrown by the JVM is C. IllegalArgumentException.

Therefore, the answer is: C. IllegalArgumentException.

Multiple choice technology programming languages
  1. MyThread foo

  2. MyThread bar

  3. foo bar

  4. foo bar baz

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

The anonymous inner class constructor implicitly invokes the MyThread superclass constructor, printing MyThread. Calling the t.start() method then executes the overridden run() method defined in the anonymous subclass body, printing foo instead of the original superclass bar implementation.

Multiple choice technology programming languages
  1. notify();

  2. wait(long msecs);

  3. interrupt();

  4. synchronized();

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

notify() and wait(long) are methods defined in the java.lang.Object class, which serves as the root class for all Java objects. interrupt() is a method of the java.lang.Thread class, and synchronized is a Java keyword used for locking blocks or methods rather than a method itself.

Multiple choice technology programming languages
  1. getCust

  2. isColorado

  3. addSize

  4. putDimensions

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

JavaBeans getter naming: boolean properties use 'is' prefix (isColorado), other types use 'get' prefix (getCust). The method must be public and non-void. addSize and putDimensions don't follow getter patterns - add suggests collection manipulation, put is not a valid prefix.

Multiple choice technology programming languages
  1. LinkedList

  2. TreeMap

  3. HashMap

  4. HashSet

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

To solve this question, the user needs to know the characteristics of different Java classes and their features.

  • LinkedList: This class provides an implementation of the List interface using a doubly-linked list. It allows duplicate elements and maintains the order of insertion. However, accessing an element in a LinkedList is slower than accessing an element in an array.

  • TreeMap: This class provides a red-black tree-based implementation of the SortedMap interface. It does not allow duplicate keys but allows duplicate values. It maintains the order of elements based on their natural ordering or a Comparator. Accessing an element in a TreeMap is slower than accessing an element in an array.

  • HashMap: This class provides a hash table-based implementation of the Map interface. It does not allow duplicate keys or values. It does not maintain the order of elements. Accessing an element in a HashMap is almost as fast as accessing an element in an array.

  • HashSet: This class provides a hash table-based implementation of the Set interface. It does not allow duplicate elements. It does not maintain the order of elements. Accessing an element in a HashSet is almost as fast as accessing an element in an array.

Based on the given features, the class that provides all the specified features is:

The Answer is: D, HashSet.

Multiple choice technology web technology
  1. stringName.charAt(0);

  2. stringName.substring(1);

  3. stringName.charAt(1);

  4. stringName.charAt(2);

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

JavaScript strings are zero-indexed, meaning the first character is at position 0. The charAt() method returns the character at a specified index. To get the first character, use charAt(0). substring(1) would return from position 1 to the end.

Multiple choice technology web technology
  1. popUp(PageURL,WindowName,settings);

  2. window.launch(PageURL,WindowName,settings);

  3. window.close(PageURL,WindowName,settings);

  4. window.open(PageURL,WindowName,settings);

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

The standard JavaScript method for opening a new browser window or tab is window.open(). Other options like window.launch() or popUp() are not built-in JavaScript window methods, and window.close() is used to close an existing window.

Multiple choice technology web technology
  1. stringVariable.substring(subString)

  2. stringVariable.find(subString)

  3. stringVariable.indexOf(subString)

  4. stringVariable.indexOf(charAt(0))

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

The indexOf() method searches for a substring within a string and returns the index of the first occurrence, or -1 if not found. The syntax is string.indexOf(substring). Options A and B use incorrect method names (substring, find), and option D incorrectly nests charAt(0) inside indexOf.

Multiple choice technology programming languages
  1. Using delete operator

  2. Using destructor

  3. Garbage collection is an automatic process & cant be forced.

  4. None of the above

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

Garbage collection in languages like Java is an automatic process managed by the runtime environment. While you can suggest garbage collection using methods like System.gc(), you cannot force or guarantee when it will actually occur. The JVM decides based on memory needs and heuristics.

Multiple choice technology web technology
  1. Use the Java method

  2. AtSetValue(PropertyName, Value)

  3. Use the Property-Set method

  4. {PropertyName INPUT}

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

The Property-Set method is the standard way to update properties in PEGA activity steps. Java methods are not the recommended approach, AtSetValue is not a standard PEGA method, and {PropertyName INPUT} is a reference syntax, not an update method. Property-Set ensures proper clipboard manipulation and rule compliance.

Multiple choice technology web technology
  1. Property-Map-Value calls a Rule-Obj-MapValue once, and Property-Map-ValuePair calls it twice

  2. Property-Map-Value can call a Rule-Obj-MapValue and pass a single row input, and Property-Map-Value-Pair can call a Rule-Obj-Map Value and pass two row inputs

  3. Property-Map-Value can call a Rule-Obj-MapValue and pass a single row input, and Property-Map-Value-Pair can call a Rule-Obj-Map Value and pass a single row input and single column input

  4. Property-Map-Value can call a Rule-Obj-MapValue and pass a single row input, and Property-Map-Value-Pair can call a Rule-Obj-Map Value and pass multiple row inputs

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

This is a duplicate of question 146856. The Property-Map-Value method takes a single row input to evaluate a 1D map value, whereas Property-Map-ValuePair takes both a row input and a column input to evaluate a 2D map value.