Java Collections | Functional Interfaces | Streams | SQL | Programming
Duration: 20 Minutes
Experience: 2–6 Years
This assessment evaluates a candidate’s practical understanding of Java Collections, Java 8 Streams, Functional Programming, SQL fundamentals, and problem-solving skills.
Section A – Java OCP Style MCQs (5 Questions)
Question 1 – HashSet & equals()/hashCode()
What is the output?
import java.util.*;
class Employee {
int id;
Employee(int id){
this.id=id;
}
}
public class Test {
public static void main(String[] args){
Set<Employee> set = new HashSet<>();
set.add(new Employee(1));
set.add(new Employee(1));
System.out.println(set.size());
}
}
A. 0
B. 1
C. 2
D. Compilation Error
Question 2 – Stream Execution
import java.util.*;
public class Test {
public static void main(String[] args){
List<Integer> list =
Arrays.asList(1,2,3,4);
list.stream()
.filter(i ->{
System.out.print(i);
return i%2==0;
});
}
}
Output?
A.
1234
B.
24
C.
No Output
D.
Compilation Error
Question 3 – Functional Interface
import java.util.function.Predicate;
public class Test {
public static void main(String[] args){
Predicate<String> p =
s -> s.length()>5;
System.out.println(
p.test("Java8"));
}
}
Output?
A.
true
B.
false
C.
Compilation Error
D.
Runtime Exception
Question 4 – Comparator
import java.util.*;
public class Test {
public static void main(String[] args){
List<String> list =
Arrays.asList(
"Java",
"Spring",
"AWS");
list.sort(
Comparator.comparingInt(String::length));
System.out.println(list);
}
}
Output?
A.
[AWS, Java, Spring]
B.
[Spring, Java, AWS]
C.
[Java, Spring, AWS]
D.
Compilation Error
Question 5 – Collectors
import java.util.*;
import java.util.stream.*;
public class Test {
public static void main(String[] args){
List<String> list =
Arrays.asList(
"Java",
"Spring",
"AWS");
String result =
list.stream()
.collect(
Collectors.joining("-"));
System.out.println(result);
}
}
Output?
A.
JavaSpringAWS
B.
Java-Spring-AWS
C.
Java,Spring,AWS
D.
Compilation Error
Section B – SQL Challenge
Question 6
Table
| EMP_ID | NAME | DEPT | SALARY |
|---|---|---|---|
| 1 | John | IT | 5000 |
| 2 | Mary | HR | 7000 |
| 3 | Steve | IT | 6500 |
| 4 | David | HR | 4500 |
| 5 | Tom | IT | 8000 |
Query
SELECT NAME
FROM EMPLOYEE
WHERE SALARY >
(
SELECT AVG(SALARY)
FROM EMPLOYEE
);
What is returned?
A.
John
Mary
B.
Mary
Steve
Tom
C.
Steve
Tom
D.
All Employees
Section C – Programming Questions
Question 7 – Frequency Count
Write a Java program to print the frequency of every character in a String.
Example
banana
Expected Output
b = 1
a = 3
n = 2
Bonus:
Solve using Java 8 Streams.
Question 8 – Collections
Given
List<Integer> list =
Arrays.asList(7,3,9,1,8,5,9,8);
Using Java 8:
- Remove duplicates
- Print numbers greater than 5
- Sort in ascending order
Expected Output
7
8
9
Question 9 – Programming Logic
Write a Java program to find the first non-repeated character in a String.
Example
success
Expected Output
u
Bonus:
Solve using Java 8 Streams.
Answer Key & Detailed Explanations
Question 1
Correct Answer: C
Explanation
HashSet uses both equals() and hashCode() to determine object uniqueness.
Since Employee overrides neither method, each new Employee(1) is considered a different object.
Size = 2
Interview Follow-up
How would you modify the class so the size becomes 1?
Expected Answer: Override both equals() and hashCode().
Question 2
Correct Answer: C
Explanation
Streams are lazy.
A pipeline containing only intermediate operations (filter) does nothing until a terminal operation (such as forEach, collect, count, findFirst) is invoked.
Since no terminal operation exists, the lambda is never executed.
Key Concept
Intermediate operations are lazy.
Terminal operations trigger execution.
Question 3
Correct Answer: B
Explanation
"Java8"
Length = 5
Predicate:
s -> s.length() > 5
5 > 5
is false.
Question 4
Correct Answer: A
Explanation
String lengths:
AWS 3
Java 4
Spring 6
Sorted by length:
AWS
Java
Spring
Question 5
Correct Answer: B
Explanation
Collectors.joining("-") concatenates elements using - as the delimiter.
Output:
Java-Spring-AWS
Question 6
Correct Answer: B
Explanation
Average salary
(5000+7000+6500+4500+8000)/5
=6200
Employees earning more than 6200:
- Mary
- Steve
- Tom
Question 7 – Sample Solution
String input="banana";
Map<Character,Long> result =
input.chars()
.mapToObj(c->(char)c)
.collect(Collectors.groupingBy(
c->c,
LinkedHashMap::new,
Collectors.counting()));
result.forEach(
(k,v)->System.out.println(k+" = "+v));
Concepts Tested
- Streams
- groupingBy
- counting
- LinkedHashMap
- Character manipulation
Question 8 – Sample Solution
Arrays.asList(7,3,9,1,8,5,9,8)
.stream()
.distinct()
.filter(n->n>5)
.sorted()
.forEach(System.out::println);
Output
7
8
9
Question 9 – Sample Solution
Traditional
String input="success";
for(char c:input.toCharArray()){
if(input.indexOf(c)==input.lastIndexOf(c)){
System.out.println(c);
break;
}
}
Java 8
Character first =
input.chars()
.mapToObj(c->(char)c)
.collect(Collectors.groupingBy(
c->c,
LinkedHashMap::new,
Collectors.counting()))
.entrySet()
.stream()
.filter(e->e.getValue()==1)
.map(Map.Entry::getKey)
.findFirst()
.get();
Output
u
Evaluation Guide
| Score | Recommendation |
|---|---|
| 9/9 | Excellent – Strong Java 8 Developer |
| 7–8 | Good – Proceed to Technical Interview |
| 5–6 | Average – Needs Further Evaluation |
| Below 5 | Not Recommended |
Interviewer’s Notes
This set intentionally tests concepts that candidates frequently misunderstand:
- Difference between object identity and logical equality (
equals()/hashCode()). - Lazy evaluation in Streams.
- Functional Interfaces (
Predicate). - Sorting with
Comparator. - Stream collectors (
joining,groupingBy,counting). - SQL subqueries and aggregate functions.
- Ability to solve problems using both traditional Java and Java 8 Streams.
A strong candidate should not only identify the correct answer but also explain why Java behaves that way and discuss the time and space complexity of the programming exercises.