Core Concepts

Introduction to Functional Interface – Java8

What is Functional Interface? A functional interface is any interface which contains only one abstract method. A functional interface can have one or more default and static methods. Also, there is an annotation in Java @FunctionalInterface which is used to annotate the functional interfaces. It is not a mandate for functional interfaces to carry this annotation. There are many predefined functional interfaces in Java which belong to the package java.util.function What is the significance of these interfaces? These interfaces as we know declare a method which can be implemented and us...
Read More

Introduction to Lambda Expressions – Java8

What are Lambda Expressions? Lambda expressions are another way of writing inline unnamed code block which performs a simple function. Not a direct analogy but if you recall anonymous classes in Java they are a way of writing inline classes. On similar lines Lambda expressions are a way to write method body inline. They can be considered as anonymous methods, there is no need to formally define these methods but the code in the lambda expression is the body of the method. Lambda Expression Example If I want to write a print method which prints the content of a List of strings which is pa...
Read More

Explaining the ThreadLocal

Introduction to ThreadLocal Java supports multi threading and provides many high level APIs to avoid running into the issues associated with multi threading. One of the concepts we discussed previously is called synchronization. You can read about synchronization in this blog post. Here are few scenarios I would like to draw your attention: Thread Safety - classic case for using ThreadLocal Not all the classes in the Java library are thread safe, also the user defined classes are mostly not thread safe. At many places on the web you will find posts related ThreadLocal  with one example o...
Read More

Explain Exception Handling in Java

This is one of the hottest Java Interview Questions for entry level and mid level software developers in Java. The question is mostly asked as "Explain Exception Handling in Java" but the wordings may change. Defining an Exception An exception indicates a problem that a reasonable application may wish to recover from. On a more formal note, "When a program violates the semantic constraints of the Java Programming Language, the JVM signals error to the program as an Exception. Many programming languages abruptly terminates programs in such scenarios but Java has a cleaner way of handling t...
Read More

Details of Class Loading in JVM

Have you ever seen a ClassNotFoundException or a NoClassDefFoundError? Did you ever face a situation where you are trying to cast and assign it to a compatible reference but it throws a ClassCastException ? Or did you face issues where you never understood where to put the jars in your application? Ever did any hot deployment on a running Application Server and wondered how the new changes get reflected without a server restart? Ever got confused with the process of Class Loading in JVM? If you didn't face any of these, then you are extremely lucky or you are yet to start development :)...
Read More

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