0% found this document useful (0 votes)
5 views8 pages

Java Developer Assessment

This document outlines a technical assessment for a Senior Java Developer position, consisting of four sections: Core Concepts, Output Prediction, Code Completion, and Design. The assessment is timed at 20 minutes and includes multiple-choice questions, coding tasks, and design questions, with a total score of 100 points. Candidates are instructed to write clean, compilable code and manage their time effectively while adhering to closed-book rules.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

Java Developer Assessment

This document outlines a technical assessment for a Senior Java Developer position, consisting of four sections: Core Concepts, Output Prediction, Code Completion, and Design. The assessment is timed at 20 minutes and includes multiple-choice questions, coding tasks, and design questions, with a total score of 100 points. Candidates are instructed to write clean, compilable code and manage their time effectively while adhering to closed-book rules.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Java Developer Technical Assessment

Senior Level | 5–6 Years Experience | 20-Minute Exam

Candidate Name Date Position Interviewer

Java Developer

Instructions
• Total time: 20 minutes. Manage your time carefully.
• This assessment has 4 sections: Core Concepts (MCQ), Output Prediction, Code Completion, and
Design.
• Write clean, compilable Java code. Clearly explain design decisions where asked.
• Each section is weighted — prioritize accordingly.
• Do not use external resources. This is a closed-book assessment.

Score Summary
Section Topic Points Score

Section A Core Concepts (MCQ) 20

Section B Predict the Output 20

Section C Code Completion / Fix 40

Section D Design & Architecture 20

TOTAL 100

Section A — Core Concepts (20 points | ~5 minutes)


Circle the best answer for each question.

Q1. Java Memory Model 4 pts ~1 min

What is stored in the Java Heap memory?

• A) Local variables and method call frames


• B) Class metadata and static variables (Metaspace)
• C) Object instances and arrays
• D) Thread stacks

Java Developer Assessment | Confidential | Page 1 of 8


Correct Answer:

Q2. Concurrency — volatile vs synchronized 4 pts ~1 min

Which statement about the volatile keyword is correct?

• A) volatile ensures atomicity for compound operations like i++


• B) volatile guarantees visibility of writes to all threads but NOT atomicity
• C) volatile is equivalent to using synchronized(this)
• D) volatile prevents a variable from being garbage collected

Correct Answer:

Q3. Generics & Type Erasure 4 pts ~1 min

What does Java's type erasure mean for generics at runtime?

• A) Generic type parameters are preserved and available via reflection


• B) Generic type information is removed at compile time; List<String> becomes List at runtime
• C) Generics are only available for classes in the [Link] package
• D) Type erasure only applies to wildcard generics (?)

Correct Answer:

Java Developer Assessment | Confidential | Page 2 of 8


Q4. Java 8+ — Stream Terminal Operations 4 pts ~1 min

Which of the following is a terminal operation on a Java Stream?

• A) filter()
• B) map()
• C) flatMap()
• D) collect()

Correct Answer:

Q5. Exception Hierarchy 4 pts ~1 min

Which exception type does NOT need to be declared in a method signature or caught?

• A) [Link]
• B) [Link]
• C) [Link]
• D) [Link]

Correct Answer:

Section B — Predict the Output (20 points | ~4 minutes)


Write the exact console output for each snippet, or explain the error.

QB1. String Immutability & Pool 10 pts ~2 min

Java Developer Assessment | Confidential | Page 3 of 8


String a = "hello";
String b = "hello";
String c = new String("hello");
[Link](a == b); // (i)
[Link](a == c); // (ii)
[Link]([Link](c)); // (iii)
[Link]([Link]() == [Link]()); // (iv)

Output (i) through (iv) + Explanation:

QB2. Autoboxing & Integer Cache 10 pts ~2 min

Integer x = 127;
Integer y = 127;
Integer p = 128;
Integer q = 128;
[Link](x == y); // (i)
[Link](p == q); // (ii)
[Link]([Link](q)); // (iii)

Output (i) through (iii) + Explanation:

Section C — Code Completion & Bug Fix (40 points | ~8 minutes)


Complete or fix the code as instructed. Write clean, production-quality Java.

QC1. Thread-Safe Singleton (Hands-On) 15 pts ~3 min

The following Singleton implementation has a concurrency bug in a multi-threaded environment. Identify the
problem and rewrite it using the correct thread-safe pattern.

Java Developer Assessment | Confidential | Page 4 of 8


// BUGGY CODE
public class Config {
private static Config instance;
private Config() {}
public static Config getInstance() {
if (instance == null) {
instance = new Config();
}
return instance;
}
}

(a) State the bug:

Bug Explanation:

(b) Rewrite using the double-checked locking pattern with volatile:

Fixed Code:

(c) Name one alternative thread-safe approach (e.g., Initialization-on-demand holder):

Alternative:

QC2. Java Streams — Write from Scratch 15 pts ~3 min

Java Developer Assessment | Confidential | Page 5 of 8


Given the following Employee class, complete the method body using Java Streams API:

public class Employee {


private String name;
private String department;
private double salary;
// assume getters are present
}

Write a method that, given List<Employee> employees, returns a Map<String, Double> where the key is the
department name and the value is the average salary of employees in that department. Only include departments
where the average salary exceeds 70,000.

public Map<String, Double> avgSalaryByDept(List<Employee> employees) {

// YOUR CODE HERE

Complete Implementation:

QC3. Fix the Deadlock 10 pts ~2 min

The code below can cause a deadlock. Identify why and provide ONE concrete fix.

public class BankAccount {


private double balance;
public synchronized void transfer(BankAccount target, double amount) {
synchronized (target) {
[Link] -= amount;
[Link] += amount;
}
}
}

(a) Explain the deadlock scenario (when does it occur?):

Deadlock Explanation:

Java Developer Assessment | Confidential | Page 6 of 8


(b) Provide a fix:

Fixed Code / Strategy:

Section D — Design & Architecture (20 points | ~3 minutes)

QD1. Design Pattern Choice 10 pts ~1.5 min

You are building a notification service that sends alerts via Email, SMS, and Push Notification. New channels will
be added in future. The caller should not need to know the underlying channel implementation.

(a) Which design pattern(s) would you apply and why?

Design Pattern + Justification:

(b) Sketch the key interface(s) and class relationships (class names + arrows are sufficient):

Sketch:

Java Developer Assessment | Confidential | Page 7 of 8


QD2. SOLID Principle Violation 10 pts ~1.5 min

Review the following class signature:

public class OrderService {


public void placeOrder(Order o) { ... }
public void sendConfirmationEmail(Order o) { ... }
public void saveToDatabase(Order o) { ... }
public void generateInvoicePDF(Order o) { ... }
}

(a) Which SOLID principle is violated?

Principle + Reason:

(b) How would you refactor this? (Brief class names / responsibilities only)

Refactored Design:

— End of Assessment —
Total Score: ___ / 100 Pass Mark: 70 / 100 Result: PASS / FAIL

Interviewer Signature: ____________________________ Date: ________________

Java Developer Assessment | Confidential | Page 8 of 8

You might also like