Core Concepts

Java Virtual Machine Startup

In the last post we had a brief idea about the memory model of the Java Virtual Machine. We also came across certain terms like the Creation, Linking, Loading and Initialization of classes. In this post we will try to improve our understanding of all these terms. At the Java Virtual Machine Startup The JVM starts up by creating an initial class and loads it using the bootstrap class loader (we will learn about the class loader in another post). Some implementation of the JVM allow us to pass the name of the initial class using the command line. The JVM then links this initial class. L...
Read More

Seed in Random Number Generation

Random Numbers Randomization is an awesome concept. Efficiency of most of the algorithms are proportional to how randomly the algorithm is implemented. Talking about one the best sort algorithms - Quick Sort. The efficiency depends on the choice of pivot and it is wise to choose a pivot randomly to get an even distribution of elements around it. Of course no one can beat my bad luck if my randomly chosen pivot misbehaves. But still you will be luckier and have a better running time and upper bound on the running time of this algorithm. This is not the only algorithm where randomization ...
Read More

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-5b30b8268ee7c438848281/]   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