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. It is immutable

  2. Simplifies strng manipulations

  3. Simplifies concurrent multithreaded programming

  4. None of the above

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

System.String is immutable, which makes it inherently thread-safe. Multiple threads can access and read the same String object simultaneously without locks or synchronization, unlike StringBuilder which requires explicit coordination in multithreaded environments.

Multiple choice technology programming languages
  1. Convert.ToString() handle null values but ToString() don't

  2. ToString() output as per format supplied

  3. Convert.ToString() only handle null values

  4. ToString() handle null values but Convert.ToString() don't

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

The critical difference is null handling: calling ToString() on a null reference throws NullReferenceException, while Convert.ToString(null) returns null without throwing. Convert.ToString() also handles various type conversions via IConvertible, while ToString() is the instance method for string representation.

Multiple choice technology programming languages
  1. StringBuilder is more efficient when there is a large amount of string manipulation

  2. Strings are immutable, so each time a string is changed, a new instance in memory is created.

  3. StringBuilder is mutable; when you modify an instance of the StringBuilder class, you modify the actual string, not a copy

  4. Strings are mutable in .Net

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

System.String is immutable - every operation creates a new string object in memory. StringBuilder is mutable - modifications happen in-place on the same instance. Therefore, the statement "Strings are mutable in .Net" is false, making D the correct choice for the incorrect statement. Options A, B, and C all describe actual differences correctly.

Multiple choice technology programming languages
  1. HashTable

  2. ArrayList

  3. SortedList

  4. All of above

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

HashTable (and its generic version Dictionary) is designed specifically for key-value access where each key must be unique. ArrayList and SortedList store elements without requiring unique keys - ArrayList is a dynamic array and SortedList maintains sorted order but allows duplicates.

Multiple choice technology web technology
  1. Declare as null

  2. Declare as Null and Call the dispose method

  3. Call GC.SupressFinalize method for the object

  4. None of the above

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

For objects that are no longer needed and implement IDisposable, you should set the reference to null AND call the Dispose() method to release unmanaged resources promptly. Setting to null helps the garbage collector by removing the reference, while Dispose releases resources like file handles or database connections immediately rather than waiting for finalization.

Multiple choice technology web technology
  1. if(stringValue == null)

  2. if(string.IsNullOrEmpty(stringValue))

  3. if(stringValue == DbNull.value)

  4. None of the above

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

When checking database values stored in an ADO.NET DataSet, missing database values are represented by DBNull.Value, not C# null. Thus, comparing the value to DBNull.Value is correct. Note that the option text contains a typo 'DbNull.value' instead of 'DBNull.Value', but it represents the correct concept.

Multiple choice technology web technology
  1. Request.Form;

  2. Request.QueryString;

  3. Request_Get("");

  4. $GET[]
  5. $_GET[];
Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

PHP uses the $_GET[] superglobal array to retrieve data from forms submitted via the GET method. This is a built-in associative array that automatically contains all data sent through the URL query string. Option B uses ASP syntax, while option D is missing the underscore prefix.

Multiple choice technology web technology
  1. $_REQUEST[]
  2. $_GET[]
  3. $_POST[]
  4. $_SESSION[]
Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

$_REQUEST[] is the correct variable that can retrieve values from both GET and POST methods. It's a superglobal array that contains data from $_GET, $_POST, and $_COOKIE. While $_GET and $_POST work for their specific methods, $_REQUEST combines them for convenience.

Multiple choice technology programming languages
  1. An Error is a subclass of Throwable

  2. An Error is a subclass of Exception

  3. Error indicates serious problems that a reasonable application should not try to catch.

  4. An Error is a subclass of IOException

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

In Java, Error is a direct subclass of Throwable, not Exception. Error represents serious problems like OutOfMemoryError or StackOverflowError that applications should not attempt to catch or recover from, as they typically indicate fatal JVM-level issues. Option B is incorrect because Error and Exception are siblings under Throwable.

Multiple choice technology programming languages
  1. Compile error : No method name like lastEntry()

  2. null

  3. NullPointerException

  4. 0

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

The NavigableMap interface does have a lastEntry() method, so this is not a compile error. However, calling lastEntry() on an empty ConcurrentSkipListMap returns null, not a NullPointerException. The code compiles and runs, outputting null. Option B is correct.

Multiple choice technology programming languages
  1. Compile error : No method name like floorKey()

  2. null

  3. NullPointerException

  4. 2

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

The floorKey(k) method returns the greatest key less than or equal to k. The map contains keys 1,2,4,5,6 (sorted order). floorKey(3) looks for the largest key <= 3, which is 2. The method exists in NavigableMap, so no compile error. The map has entries, so result is not null. Output is 2.

Multiple choice technology programming languages
  1. Compile error : No method name like floorKey()

  2. null

  3. NullPointerException

  4. 2

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

This is a duplicate of question 161465 with identical code and options. The floorKey(3) method returns the greatest key less than or equal to 3. The map contains keys 1,2,4,5,6, so floorKey(3) returns 2. The method exists and the map has entries, so output is 2.

Multiple choice technology programming languages
  1. Locale loc = Locale.getLocale();System.out.println(loc.getDisplayCountry()+ “ “+ df.format(d));

  2. Locale loc = Locale.getDefault();System.out.println(loc.getDisplayCountry()+ “ “ + df.format(d));

  3. Locale bc = Locale.getLocale();System.out.println(loc.getDisplayCountry()+ “ “+ df.setDateFormat(d));

  4. Locale loc = Locale.getDefault();System.out.println(loc.getDispbayCountry()+ “ “+ df.setDateFormat(d));

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

Locale.getDefault() is the correct method to retrieve the system's current locale, and loc.getDisplayCountry() returns the country name. The df.format(d) method is the standard way to format a Date object. Other options are incorrect because getLocale() and setDateFormat() do not exist in their respective classes.

Multiple choice technology programming languages
  1. Enables you to cycle through a collection in the forward direction only, for obtaining or removing elements

  2. just for loop

  3. while loop

  4. It is an class for storing objects

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

An Iterator in Java provides a uniform way to access elements of a collection sequentially, allowing both retrieval and removal of elements during iteration. It differs from simple loops (options B, C) which are control flow constructs, not a dedicated interface for traversing collections. Option D incorrectly describes it as a storage class rather than an access mechanism.