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
  1. 8

  2. 7

  3. 6

  4. 5

  5. 4

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

This is the correct choice because there are 5 constructors of ConcurrentHashMap class. These are :- 1) ConcurrentHashMap():- Creates a new, empty map with a default initial capacity (16), load factor (0.75) and concurrencyLevel (16), 2) ConcurrentHashMap(int initialCapacity):- Creates a new, empty map with the specified initial capacity and with default load factor (0.75), and concurrencyLevel (16), 3) ConcurrentHashMap(int initialCapacity, float loadFactor):- Creates a new, empty map with the specified initial capacity and load factor and with the default concurrencyLevel (16), 4) ConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel):- Creates a new, empty map with the specified initial capacity, load factor and concurrency level, 5) ConcurrentHashMap(Map m):- Creates a new map with the same mappings as the given map.

Multiple choice
  1. 6

  2. 5

  3. 4

  4. 3

  5. 2

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

This is the correct answer, as there are 5 constructors of LinkedHashMap class. These are:- LinkedHashMap():- constructs an empty insertion-ordered LinkedHashMap instance with the default initial capacity (16) and load factor (0.75), LinkedHashMap(int initialCapacity):- constructs an empty insertion-ordered LinkedHashMap instance with the specified initial capacity and a default load factor (0.75), LinkedHashMap(int initialCapacity, float loadFactor):-  constructs an empty insertion-ordered LinkedHashMap instance with the specified initial capacity and load factor. LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder):- constructs an empty LinkedHashMap instance with the specified initial capacity, load factor and ordering mode, and LinkedHashMap(Map<? extends K,? extends V> m):-  constructs an insertion-ordered LinkedHashMap instance with the same mappings as the specified map.

Multiple choice
  1. putAll(map : m)

  2. Get(key : K)

  3. isEmpty()

  4. removeLast()

  5. Put(key : K, Value : V)

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

This is incorrect, as removeLast()method is not present in the map interface, it is present in LinkedList class.This method removes the last element from the list.

Multiple choice
  1. procedural

  2. object oriented

  3. web development

  4. event driven

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

Java is fundamentally an object-oriented programming language. It supports core OOP principles like encapsulation, inheritance, and polymorphism through classes and objects. While Java can incorporate procedural and event-driven elements, its primary paradigm is object-oriented.

Multiple choice
  1. Java. lang

  2. Java. io

  3. Java. awt

  4. Java. applet

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

The java.lang package is automatically imported into every Java program without requiring an explicit import statement. It contains fundamental classes like Object, String, Math, and System that are essential for basic Java operations. Packages like java.io, java.awt, and java.applet require explicit imports.

Multiple choice
  1. illegal args

  2. illegal argument

  3. illegal arguments

  4. illegal arg

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

IllegalArgumentException is thrown when a method receives an argument that is inappropriate or invalid. The correct exception name uses the singular form 'argument' rather than plural, matching Java's naming convention for this standard exception.

Multiple choice
  1. join

  2. stop

  3. enumerate

  4. yield

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

The join() method causes the current thread to wait until the thread on which it is called completes execution. This is a fundamental thread synchronization mechanism in Java that ensures one thread waits for another to finish before proceeding.

Multiple choice
  1. two

  2. one

  3. four

  4. three

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

The skip() method in Java's java.io package takes exactly one argument - a long value specifying the number of bytes to skip. This method is used in input/output streams to skip over a specified number of bytes without reading them.

Multiple choice
  1. IO

  2. File Not Found

  3. Class Not Found

  4. Interrupted

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

FileInputStream throws FileNotFoundException (a subclass of IOException) when attempting to open a file that doesn't exist. This is a checked exception that must be handled or declared when working with file input streams.

Multiple choice
  1. Get Count ()

  2. Get Items Count

  3. Items.Count ()

  4. Get Item Count ()

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

In Visual Basic and similar GUI frameworks, the getItemCount() method returns the number of items in a ListBox or similar control. This allows you to programmatically determine how many items are currently in the list.