Java Collections interview questions and answers

Here is the list of Java Collections interview questions. These questions have been asked over time and are still being asked in interviews. It is good to go through them to understand the various concepts in Collections. Java Collections Interview Questions and Answers What is a HashSet and how does it work internally in Java? … [Read more…]

Top 15 Core Java Interview Questions

Here is a list of core java interview questions.  These are questions that touch the basics of Java language. And it is good to know them even if you are not attending an interview. Q) Describe the contract of equals() and hashCode(). Why is it important that if you implement one, then you must implement … [Read more…]

Just-In-Time (JIT) Compiler

1. Overview The Just-In-Time (JIT) compiler, which is commonly referred as JIT Compiler, is a part of Java Runtime Environment (JRE). JIT improves the performance of Java applications at runtime. In computing JIT compilation, which is also known as “Dynamic Translations” is compilation done during execution of a program. The traditional Java compiler compiles high-level Java … [Read more…]

Difference Between List, Set and Map in Java

List vs Set vs Map

1. Overview List, Set and Map in java are the most used interfaces of the collection framework. Collection framework has several interfaces and classes which are widely used in most java application. For storing data in collections, List, Set and Map are most often used interfaces. A difference between these interfaces is one of the … [Read more…]

Binary Search

Binary search example

Problem We have sorted array of some elements, and we have to find index of given element using Binary search (better than O(n) time complexity). Solution Here we are going to use Binary Search.  We can have two cases : Element exists in given array Element does not exist in given array Element exists in … [Read more…]

Comparison method violates its general contract!

Comparison method violates its general contract, error can be very painful to debug. I recently encountered this issue in one of the production servers and it was only sometimes the error was thrown. Here I would discuss some cases that can lead to such an error. Stacktrace Possible Coding Mistakes Example 1: In the below … [Read more…]

Static and Default Methods in Interface – Java 8

Introduction Java 8 introduces concept of “Default Methods” and “Static Methods” for interfaces, which allows developers to enhance existing interface used in their applications without breaking prior implementations of that interface. “Default Methods” and “Static Methods” are one of new features of Java 8 which is used extensively in core Java framework packages especially in collections. … [Read more…]

Java 9 new features

Java 9 is scheduled to be released in July 2017.  The Feature Extension Complete milestone was achieved in late December,. We will have a look at the new features in Java 9. Java 9 Features Module System (Jigsaw Project) JShell Collection Factory methods Private Methods in Interfaces Reactive Streams Multi Resolution Images API Process API … [Read more…]

Java 8 new features

In this article we are going to discuss the most important features of Java 8.  I would be discussing these features with examples. Functional Interfaces Functional interfaces are interfaces with exactly one method. They can have an annotation with @FunctionalInterface. A very good example of Function Interface is that of the Comparable. It has exactly … [Read more…]

Java Generics interview questions

Java Generics concepts

Here is a list interview questions that may be asked in interviews. Java Generics as a feature is one of the most controversial features added to Java Language. As a programmer, it is very important that the basic concepts of Generics should be very clear.  I have prepared a list of basic interview questions that … [Read more…]