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
  1. A method is called on that object

  2. A member variable is set for that object

  3. A text string is assigned to the object.

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

In object-oriented programming, sending a message to an object is the mechanism by which an operation is invoked. This results in the execution of a method defined within that object's class.

Multiple choice
  1. must be initialized

  2. cannot be deleted

  3. cannot be changed

  4. None of the above

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

Immutability in Java means that once a String object is created, its internal state (the sequence of characters) cannot be changed.

Multiple choice
  1. the Java Virtual Machine

  2. code in a try block

  3. calls from a try block to other methods

  4. All of the above

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

Exceptions can be thrown by the JVM (e.g., NullPointerException), by explicit throw statements in code, or by methods called within a try block.

Multiple choice
  1. System.out()

  2. out.write.Text()

  3. System.out.println()

  4. System.printText()

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

System.out.println() is the standard method used to print text to the console in Java.

Multiple choice
  1. public void main(String args[])

  2. public void static main(String args[])

  3. public static void main(String args[])

  4. public static void main()

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

The standard entry point for a Java application is public static void main(String args[]) (or String[] args). It must be public so the JVM can access it, static so it can be called without instantiating the class, void because it returns no value, and must accept an array of Strings as arguments.

Multiple choice
  1. myArray.size

  2. myArray.size()

  3. myArray.length

  4. myArray.length()

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

In Java, arrays are objects that expose a public, final field named 'length' to store the number of elements. Because it is a field and not a method, you access it without parentheses, unlike the length() method used for Strings or the size() method used for Collections.

Multiple choice
  1. Collections

  2. Throwable

  3. List

  4. Collection

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

The Collection interface (java.util.Collection) is the root interface of the collection hierarchy, from which List, Set, and Queue inherit. Note that 'Collections' is a utility class containing static methods, not an interface.

Multiple choice
  1. String[] running = new String[10];

  2. String[] running = String[10];

  3. String[10] running = new String[];

  4. String running = String[10];

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

To declare and instantiate an array of ten Strings in Java, you use the syntax 'String[] running = new String[10];'. This correctly specifies the array type, variable name, and allocates space for 10 String references.

Multiple choice
  1. stop

  2. break

  3. return

  4. done

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

The 'return' keyword is used in Java to immediately exit from a method and optionally pass back a value to the caller. The 'break' keyword is used to exit loops or switch statements, not methods.