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. 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. Both are activated with the command line

  2. They both are found in the Comment Class

  3. A single team made both of them in the same year

  4. JavaDoc is a form of commenting

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

Javadoc is a specialized tool in Java used to generate API documentation in HTML format directly from comments in the source code. Therefore, Javadoc is a structured form of commenting.

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.

Multiple choice
  1. another_variable_name

  2. Int

  3. myIdentifier

  4. variabletrackinghowmanyuserslogin

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

Java variable names should follow lowerCamelCase, starting with a lowercase letter and capitalizing the first letter of each subsequent word. 'myIdentifier' is the correct choice, whereas 'another_variable_name' uses snake_case and 'Int' starts with an uppercase letter.

Multiple choice
  1. public static int main(String args)

  2. public static void main(String arg)

  3. public static final main()

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

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

The standard entry point for any standalone Java application is the main method, which must be declared as 'public static void main(String[] args)'. This signature specifies that the method is accessible from anywhere, does not require an instance of the class to run, returns nothing, and accepts an array of String arguments.

Multiple choice

Which of the following is NOT a common refactoring technique?

  1. Extract method.

  2. Inline method.

  3. Move method.

  4. Rename method.

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

Inlining a method involves copying the code from the method into the caller, effectively removing the method from the codebase. This is generally not considered a good refactoring technique as it can lead to code duplication and make it harder to maintain.

Multiple choice

Which of the following is NOT a common refactoring pattern?

  1. Extract method.

  2. Move method.

  3. Inline method.

  4. Encapsulate field.

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

Inlining a method involves copying the code from the method into the caller, effectively removing the method from the codebase. This is generally not considered a good refactoring pattern as it can lead to code duplication and make it harder to maintain.

Multiple choice

Which of the following is NOT a common refactoring technique for improving the performance of a software application?

  1. Loop unrolling.

  2. Inlining.

  3. Method overriding.

  4. Data structure conversion.

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

Method overriding is not typically used for improving performance. It is a technique used in object-oriented programming to allow a subclass to provide its own implementation of a method inherited from a superclass.