Core Concepts

A Generic toString in Java

Alternative to Java's toString() method: A generic toString in java For the impatient readers who know the problem I am trying to solve and need the code can scroll down to the Source code section. If you are still reading then, let us describe the problem in hand. Problem Statement Have you ever faced an issue where you included a POJO(Plain Old Java Object) in your source code and tried to print it's state in the logs or may be on the console. But unlike your expectations you ended up with some ugly object references which gives no good representation of the data you require. This t...
Read More

Interview Question – Static variables

Introduction This question was asked in a recent java interview in Goldman Sachs, this isn't complicated but candidates might get confused solving it. This is about static blocks and static variables initialization, so I publish this article under the heading Interview Question - Static variables. To get updates on the other articles in the series, please use the Subscribe feature on the right panel. Problem Statement What would be the result when the below code is executed? [crayon-594bb1443e1d6569922458/]   Solution What is the approach for solving this question? Remember your b...
Read More

Comparable and Comparator – a detailed discussion

Introduction This article is in response to a question asked on one of the groups I am a member of. What is the difference between Comparable and Comparator interfaces in Java. Why there are two interfaces if what they do is provide a method to compare. This might not seem to be a topic worth discussion for people who are experts in java, but yeah for many of my friends out there, it might help. Purpose of the article The article will describe in detail the difference between the interfaces Comparable and Comparator and also define the usages of both of them. One thing we need to underst...
Read More