Blog Archives

02: Tree structure – calculate average recursively & iteratively in Java

Q. Complete the following “TreeProcessingImpl” class ….. so that the unit tests shown below pass? Skeleton Code Unit Tests A. Solution 1: Solution 2: Using recursion for getAverage(…) and iteration for getSum(…) Key Points #1: Recursion can cause stack overflow exception if you don’t properly define an exit condition. …...



Prerequisite: if want to work with Maven & eclipse

Here are the basic steps as to how I set up “passing” project using maven & eclipse for the coding exercises. If you are using other IDEs or command line approach then you can ignore this prerequisite. Just create the relevant packages and copy the classes in the passing the test exercises.

Read more ›



Processing data from a file & sorting them

Q. Complete the following “DataProcessingImpl.java” class ….. so that the unit tests shown below pass? Following unit tests fail. You need to implement the logic to pass these tests. Solution: Key Points If you are using Java 7, … Read more ›...



Working with a given input string & character processing

Q. Complete the following StringProcessingImpl.java” class ….. so that the unit tests shown below pass? Unit test Solution Key points #1. The encode method is using the rot13 encoding that is used for hiding offensive material from accidental viewing, … Read more ›...



Working with monetary values

Q. Complete the following “MonetaryProcessingImpl.java” class … so that the unit tests shown below pass? Skeleton code The unit test that fails A. Code that passes the test cases Key Points Take note that test cases test for exceptions being thrown as well. … Read more ›...



Java Interview FAQs

800+ Java Interview Q&As

Top