Java Quizz

Home Java Quizz

Java Quizz

Dive into our tech quiz zone and put your technical skills to the test! Our quizzes cover a wide array of technical topics, perfect for sharpening your knowledge and challenging your understanding. Compete with others, see your rankings, and boost your technical proficiency. Start quizzing today!

1 / 56

1. Which one of the following classes is best suited for storing timestamp values of application events in a file?

2 / 56

2. Consider the following program and predict its output:
public class Test {
public static void main(String[] args) {
String str = null;
switch (str) { // #1
case "null":
System.out.println("null string"); // #2
break;
}
}
}

3 / 56

3. Which method is used to start a thread in Java?

4 / 56

4. What is the output of the following code?

int[] arr = {1, 2, 3, 4, 5};
System.out.println(arr[2]);

5 / 56

5. What is the purpose of the Stream.flatMap method?

6 / 56

6. What is the output of the following program?
public class Question {
T t;
public static void main(String[] args) {
Question q =
new Question(); // 1
q.t = new Float(1); // 2
System.out.println(q.t);
}
}

7 / 56

7. What does the following lambda expression represent?

() -> {}

8 / 56

8. What is the output of the following program?

public class Question {
public static void main(String[] args) {
Question q = new Question();
List l = new ArrayList();
l.add(20);
l.add(30);
q.m1(l);
}
private void m1(List l) {
m2(l); // 1
}
private void m2(List l) {
l.set(1, l.get(0)); // 2
System.out.println(l);
}
}

9 / 56

9. Which of the following is a checked exception?

10 / 56

10. Which of these collectors is used for grouping elements of a Stream?

11 / 56

11. Which of these is a terminal operation in the Stream API?

12 / 56

12. Which of the following are valid ChronoField values for LocalDate?

13 / 56

13. Consider the following program and predict the output:
public class Test {
public static void main(String[] args) {
String s = new String("5");
System.out.println(1 + 10 + s + 1 + 10);
}
}

14 / 56

14. Which one of the following options correctly describes the behavior of this program?

15 / 56

15. Which of the following is a valid lambda expression?

16 / 56

16. What is the main purpose of the Stream.sorted method?

17 / 56

17. In which of the following type of ResultSet, the cursor can only move forward in the result set?

18 / 56

18. What will be the output of the following code?

String str = "Hello";
str.concat(" World");
System.out.println(str);

19 / 56

19. Which of the following statements are true?

20 / 56

20. What type of operation is Stream.filter?

21 / 56

21. Consider the following program and predict the output:
class MyThread extends Thread {
public MyThread(String name) {
this.setName(name);
start();
System.out.println("in constructor " + getName());
}

@Override
public void start() {
System.out.println("in start " + getName());
}

public void run() {
System.out.println("in run " + getName());
}
}

public class ThreadTest {
public static void main(String[] args) {
new MyThread("oops");
}
}

22 / 56

22. Which of the following state(s) is/are NOT legitimate thread state(s)? (Select all that apply.)

23 / 56

23. Which method is used to compare two strings, ignoring case considerations?

24 / 56

24. Consider the following program:
public class StrEqual {
public static void main(String[] args) {
String s1 = "hello";
String s2 = new String("hello");
String s3 = "hello";
if (s1 == s2) {
System.out.println("s1 and s2 equal");
} else {
System.out.println("s1 and s2 not equal");
}
if (s1 == s3) {
System.out.println("s1 and s3 equal");
} else {
System.out.println("s1 and s3 not equal");
}
}
}
Which one of the following options provides the output of this program when executed?

25 / 56

25. Given
List list = new ArrayList(); // 1
list.add(new Integer(2)); // 2
list.add(new Object()); // 3
Which line will generate a compile-time error?

26 / 56

26. Lambda expressions can be used with the Java Collections API primarily in ...

27 / 56

27. Which method is used to transform each element of a Stream using a provided function?

28 / 56

28. Which of the following statements correctly describes the behavior of this program?

29 / 56

29. What will be the output of the below statements?
public class Test {

public static void main(String[] args) {
String s1 = "abc";
StringBuffer s2 = new StringBuffer(s1);
System.out.println(s1.equals(s2));
}
}

30 / 56

30. Which of the following are valid ChronoUnit values for LocalTime?

31 / 56

31. What is the output of the following code?
try {
int a = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Exception caught");
} finally {
System.out.println("Finally block");
}

32 / 56

32. Which method is used to start the execution of a thread?

33 / 56

33. What will be the output of the below statements?
public class Test {

public static void main(String[] args) {
String s1 = null;
System.out.println(s1); //line 2
System.out.println(s1.toString()); //line 3
}
}

34 / 56

34. Consider the following program and predict the output:

class MyThread implements Runnable {

@Override
public void run() {
System.out.println(Thread.currentThread().getName());
}
}

public class ThreadTest {
public static void main(String arg[]) {
Thread thread = new Thread(new MyThread());
thread.run();
thread.run();
thread.start();
}
}

35 / 56

35. Which of the following is correct about PreparedStatement?

36 / 56

36. Consider the following program and choose the right option:

class MyThread extends Thread {
public void run() {
System.out.println("Running");
}
}

public class ThreadTest {
public static void main(String args[]) throws InterruptedException {
Runnable r = new MyThread(); // #1
Thread myThread = new Thread(r); // #2
myThread.start();
}
}

37 / 56

37. What is the result of applying the Stream.reduce operation?

38 / 56

38. What is the purpose of the join() method in Java threads?

39 / 56

39. What is the purpose of the wait() method in Java threads?

40 / 56

40. Which of the following correctly declares an array of integers in Java?

41 / 56

41. You cannot use ... inside lambda expressions.

42 / 56

42. Which of the following keywords is used to manually throw an exception?

43 / 56

43. Which method is used to transform each element of a Stream using a provided function?

44 / 56

44. Which of the following methods can be used to make a thread pause execution for a specific amount of time?

45 / 56

45. Consider this code segment?
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("EEEE", Locale.US);
System.out.println(formatter.format(LocalDateTime.now()));

Which of the following outputs matches the string pattern "EEEE" given in this code segment?

46 / 56

46. Which of the following is correct about setFetchSize(int)?

47 / 56

47. How can synchronization be achieved in Java threads?

48 / 56

48. Which of the following type of JDBC driver, uses database native protocol?

49 / 56

49. What is the main advantage of multithreading in Java?

50 / 56

50. Which of the following is correct about Statement class of JDBC?

51 / 56

51. Consider the following program and predict the output:

class MyThread extends Thread {
@Override
public void run() {
System.out.println("In run method; thread name is: " + Thread.currentThread().getName());
}
}

public class ThreadTest {

public static void main(String args[]) {
Thread myThread = new MyThread();
myThread.run(); // #1
System.out.println("In main method; thread name is: " + Thread.currentThread().getName());
}
}

52 / 56

52. Consider the following program and choose the correct answer:

class MyThread extends Thread {

public MyThread(String name) {
this.setName(name);
}

@Override
public void run() {
try {
sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
play();
}

private void play() {
System.out.print(getName());
System.out.print(getName());
}
}

public class ThreadTest {
public static void main(String args[]) throws InterruptedException {
Thread tableThread = new MyThread("Table");
Thread tennisThread = new MyThread("Tennis");
tableThread.start();
tennisThread.start();
}
}

53 / 56

53. Select all the classes that extend the String class

54 / 56

54. What is the default priority of a thread in Java?

55 / 56

55. What does the Stream.peek method do?

56 / 56

56. What is the maximum number of threads that can be created in a Java program?

Your score is

0%