Java Backend Screening Test – Set 4

Java 8 | Generics | Enums | String Pool | Date API | SQL | Programming

Duration: 20 Minutes

Experience: 3–8 Years

This assessment evaluates Java fundamentals frequently encountered in enterprise applications, including Generics, Enums, String handling, Date/Time API, SQL, and problem-solving skills.


Section A – Java OCP Style MCQs (5 Questions)


Question 1 – String Immutability

What is the output?

public class Test {

    public static void main(String[] args) {

        String s = "Java";

        s.concat("8");

        System.out.println(s);

    }

}

A. Java

B. Java8

C. 8Java

D. Compilation Error


Question 2 – String Pool

public class Test {

    public static void main(String[] args) {

        String s1 = "Java";

        String s2 = "Java";

        String s3 = new String("Java");

        System.out.println(
                (s1 == s2) + " "
                + (s1 == s3));

    }

}

Output?

A.

true true

B.

true false

C.

false false

D.

Compilation Error


Question 3 – Generics

import java.util.*;

public class Test {

    public static void main(String[] args) {

        List<String> list = new ArrayList<>();

        list.add("Java");

        Object obj = list.get(0);

        System.out.println(obj);

    }

}

Output?

A.

Java

B.

Compilation Error

C.

Runtime Exception

D.

null


Question 4 – Enum

enum Status {

    NEW,
    PROCESSING,
    COMPLETED

}

public class Test {

    public static void main(String[] args) {

        Status status =
                Status.valueOf("NEW");

        System.out.println(status);

    }

}

Output?

A.

NEW

B.

new

C.

Compilation Error

D.

IllegalArgumentException


Question 5 – Java 8 Date API

import java.time.LocalDate;

public class Test {

    public static void main(String[] args) {

        LocalDate date =
                LocalDate.of(2026,7,31);

        System.out.println(
                date.plusDays(5));

    }

}

Output?

A.

2026-08-05

B.

2026-07-36

C.

Compilation Error

D.

Runtime Exception


Section B – SQL Challenge

Question 6

Table

EMP_IDNAMESALARY
1John5000
2Mary7000
3Steve6500
4David4500
5Tom8000

Query

SELECT *
FROM EMPLOYEE
WHERE SALARY =
(
SELECT MAX(SALARY)
FROM EMPLOYEE
);

Which statement is correct?

A. Returns Tom

B. Returns Mary

C. Returns John

D. Compilation Error


Section C – Programming Questions


Question 7 – Remove Duplicate Characters

Write a Java program to remove duplicate characters from a String while preserving the original order.

Example

programming

Expected Output

progamin

Bonus:

Solve using Java 8 Streams.


Question 8 – Map Sorting

Given

Map<String,Integer> map = Map.of(
"Java",5,
"Spring",8,
"AWS",7,
"Docker",6);

Write a Java 8 program to print the entries in descending order of value.

Expected Output

Spring=8
AWS=7
Docker=6
Java=5

Question 9 – Programming Logic

Write a Java program to determine whether two Strings are rotations of each other.

Example

ABCD

CDAB

Output

true

Example

ABCD

ACBD

Output

false

Answer Key & Detailed Explanations


Question 1

Correct Answer: A

Explanation

String objects are immutable.

The concat() method returns a new String, but the returned value is ignored.

s.concat("8");

does not modify s.

Output

Java

Interview Follow-up

How would the output change if StringBuilder were used instead?


Question 2

Correct Answer: B

Explanation

String s1 = "Java";
String s2 = "Java";

Both references point to the same object in the String Pool.

new String("Java")

always creates a new object on the heap.

Therefore

s1 == s2   → true

s1 == s3   → false

Interview Follow-up

  • Difference between == and equals()
  • What does intern() do?

Question 3

Correct Answer: A

Explanation

list.get(0) returns a String.

Assigning it to an Object reference is valid because String is a subclass of Object.

Output

Java

Interview Follow-up

Why is the following not allowed?

List<Object> list =
new ArrayList<String>();

(Expected answer: Generics are invariant.)


Question 4

Correct Answer: A

Explanation

Status.valueOf("NEW") performs an exact lookup using the enum constant name.

Output

NEW

If "new" were used instead, an IllegalArgumentException would be thrown because the lookup is case-sensitive.


Question 5

Correct Answer: A

Explanation

LocalDate is immutable.

LocalDate.of(2026,7,31)

plus five days becomes

2026-08-05

The API automatically handles month boundaries.


Question 6

Correct Answer: A

Explanation

The subquery

SELECT MAX(SALARY)
FROM EMPLOYEE

returns

8000

The outer query returns the employee whose salary is 8000.

Output

Tom

Question 7 – Sample Solution

Traditional

String input = "programming";

Set<Character> seen = new LinkedHashSet<>();

for(char c : input.toCharArray()){
    seen.add(c);
}

StringBuilder sb = new StringBuilder();

for(char c : seen){
    sb.append(c);
}

System.out.println(sb);

Java 8

String result =
input.chars()
     .distinct()
     .collect(StringBuilder::new,
              StringBuilder::appendCodePoint,
              StringBuilder::append)
     .toString();

Complexity

Time: O(n)

Space: O(n)


Question 8 – Sample Solution

map.entrySet()
   .stream()
   .sorted(Map.Entry
           .<String,Integer>comparingByValue()
           .reversed())
   .forEach(System.out::println);

Concepts Tested

  • Streams
  • EntrySet
  • Comparator
  • Method References
  • Sorting

Question 9 – Sample Solution

String s1 = "ABCD";
String s2 = "CDAB";

boolean result =
s1.length() == s2.length()
&& (s1 + s1).contains(s2);

System.out.println(result);

Explanation

A rotation of a string will always be a substring of the original string concatenated with itself.

Example

ABCDABCD

contains

CDAB

Complexity

Time: O(n)

Space: O(n)


Evaluation Guide

ScoreRecommendation
9/9Excellent – Strong Java Backend Developer
7–8Good – Recommended for Technical Round
5–6Average – Needs Deeper Evaluation
Below 5Not Recommended

Interviewer’s Notes

This set evaluates concepts that frequently appear in production code:

  • String immutability and the String Pool
  • == vs equals()
  • Generic type safety and invariance
  • Enum behavior and valueOf()
  • Java 8 Date/Time API immutability
  • Aggregate SQL functions
  • Ordered duplicate removal
  • Sorting Maps with Streams
  • Rotation detection algorithms

For strong candidates, ask follow-up questions about why these APIs behave as they do, discuss alternative implementations, and ask for the time and space complexity of the programming solutions.

Leave a Reply

Your email address will not be published. Required fields are marked *