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. Before the termination of the program, JVM executes the 'finally' block (if any).

  2. The 'finally' block can be used for writing the cleanup code.

  3. The 'finally' block must be followed by try or catch block.

  4. There can be multiple 'finally' blocks for a try block.

  5. The 'finally' block is not executed if the program exists.

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

This is a false statement. There can only be one finally block for each try block. Since the statement is false about 'finally' block in Java, it is the correct alternative.

Multiple choice
  1. Delete

  2. Exit

  3. Main

  4. Continue

  5. Next

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

Next is not a keyword in Java. Continue is a keyword in Java. Continue is used inside a loop to skip the current loop step and continue with the next loop step.

Multiple choice
  1. Deletion of characters from startIndex position to endIndex position

  2. Deletion of characters from startIndex position to endIndex-1 position

  3. Deletion of all the characters

  4. Deletion of the startIndex and endIndex characters only

  5. Deletion of a single character only

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

This is the correct because the number of characters are deleted upto endIndex-1.

Multiple choice
  1. char ch;

    BufferedReader br=new BufferedReader(new InputStreamReader(System.out)); ch=(char)br.read();|

  2. char ch;

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); ch=br.read();|

  3. char ch;

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); ch=(char)br.read();|

  4. char ch;

    BufferedReader br=new BufferedReader(System.in); ch=(char)br.read();|

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

The steps to read a character are as follows. char ch; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); ch=(char)br.read();

Multiple choice
  1. StringBuffer replace(int s,int e)

  2. StringBuffer replace(int s,String str)

  3. StringBuffer replace(int s,String str1,String str2)

  4. StringBuffer replace(int s,int e,String str)

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

The correct syntax of the replace() method is StringBuffer replace(int s,int e,String str) Replaces the characters in a substring of the given sequence with the given string 'str'.