Java Fundamentals Quiz

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

What is the return type of the equals() method in the String class?

  • char
  • All of the mentioned
  • boolean (correct)
  • int

What will be the output of the given Java program?

  • Compile error
  • Runtime error
  • Not Equal (correct)
  • Equal

What type of exception is ArithmeticException in Java?

  • Built-in exception class
  • Unchecked exception (correct)
  • Checked exception
  • Custom exception

Which keyword is used to implement an interface in Java?

<p>IMPLEMENTS (B)</p> Signup and view all the answers

Which package is automatically imported in a Java program?

<p>java.lang (C)</p> Signup and view all the answers

Which of the following is a checked exception in Java?

<p>IOException (B)</p> Signup and view all the answers

What is a package in Java?

<p>All of the above (D)</p> Signup and view all the answers

What will happen if a NullPointerException is thrown in the following code?

<p>A runtime exception is thrown and the program crashes (B)</p> Signup and view all the answers

What is the purpose of the catch block in the following code?

<p>To handle ArithmeticException (D)</p> Signup and view all the answers

How can a custom exception be created in Java?

<p>All of the above (D)</p> Signup and view all the answers

What is the difference between a process and a thread?

<p>A thread is a part of a process (B)</p> Signup and view all the answers

What will be the output of the following code?

<p>ArithmeticException caught (C)</p> Signup and view all the answers

What is a key difference between a process and a thread?

<p>A thread is a unit of execution that shares memory and resources with other threads in the same process (B)</p> Signup and view all the answers

What is the output of the following code? String str = 'Hello'; str.replace('H', 'J'); System.out.println(str);

<p>Hello (B)</p> Signup and view all the answers

What is true about interfaces in Java?

<p>1, 2, 3, and 4 (D)</p> Signup and view all the answers

Which of the following is NOT a characteristic of a process?

<p>It shares memory and resources with other processes. (C)</p> Signup and view all the answers

What is a characteristic of a thread?

<p>It shares memory and resources with other threads. (C)</p> Signup and view all the answers

What is NOT a characteristic of an interface in Java?

<p>An instance of an interface can be created. (A)</p> Signup and view all the answers

What is the purpose of setting the priority of a thread?

<p>To set the priority of a thread (D)</p> Signup and view all the answers

What is the purpose of multiple catch clauses in Java?

<p>To catch different types of exceptions in the same block (D)</p> Signup and view all the answers

What does 'java'.substring(1) return?

<p>ava (C)</p> Signup and view all the answers

How can threads be synchronized in Java?

<p>Using synchronized methods and synchronized block (A)</p> Signup and view all the answers

What is the difference between a checked and an unchecked exception in Java?

<p>Checked exceptions must be caught or declared in the method signature, while unchecked exceptions do not have to be caught or declared (D)</p> Signup and view all the answers

Which method is used to create a new thread in Java?

<p>start() (A)</p> Signup and view all the answers

What is the output of the program when the demo method is called?

<p>ab cd ef gh ij kl ab cd (D)</p> Signup and view all the answers

What is the purpose of the Throwable class in Java?

<p>To catch and handle exceptions (D)</p> Signup and view all the answers

What is the result of attempting to compile and run the program in Question 1?

<p>false, true (C)</p> Signup and view all the answers

Which keyword is used to handle exceptions in Java?

<p>all of the above (D)</p> Signup and view all the answers

What is the type of the array elements in the given program?

<p>char (A)</p> Signup and view all the answers

What is the purpose of the split method in the given program?

<p>To split a string into substrings (D)</p> Signup and view all the answers

Flashcards are hidden until you start studying

Use Quizgecko on...
Browser
Browser