Blog Archives

02: 9 Java Collection interview Q&As on choosing the right data structure

Choosing the right data structure is vital to get the job done with proper space vs performance trade-offs. Q1. What are the common data structures, and where would you use them? A1. Deterministic Data Structures like Arrays, … Read more ›...



02: Java 8 Streams, lambdas, intermediate vs terminal ops, and lazy loading with simple examples

A stream is an infinite sequence of consumable elements (i.e a data structure) for the consumption of an operation or iteration. Any Collection<T> can be exposed as a stream. It looks complex, but once you get it, it is very simple. The operations you perform on a stream can either...



03: Understanding Big O notations

Q. Have you seen job advertisements requiring Java candidates to work in real-time or high volume transaction processing systems? If you are applying for such jobs, you can be quizzed on Big O notation. Here are some basics to brush up on. … Read more ›...



04: 7 Java Collection Quizzes

Q1. When is an object needs to implement the Comparable interface? a) When adding it to a HashSet. b) When adding it to a TreeSet. c) When adding it to a LinkedHashSet. … Read more ›...



05: 4 Sorting objects in Java interview Q&As

Sorting objects in Java interview Q&As especially understanding Comparable & Comparator interfaces in Java for natural & custom sorting respectively. Q1. If I mention the interface names Comparable or Comparator, what does come to your mind? … Read more ›...



06: HashMap & HashSet and how do they internally work? What is a hashing function?

HashMap & HashSet are not only one of the frequently used data structures, but also one of the popular interview topics. Q1. How does a HashMap store data? A1. As key/value pairs. You can store and retrieve values with the keys. … Read more ›...



07: Java Iterable Vs Iterator differences and know how

Q1. What are the differences between Iterator<T> Vs Iterable<T>?
A1. The “Iterable” was introduced to be able to use in the “foreach” loop. A class implementing the Iterable interface can be iterated over. For example,

Hence, it can be used in the foreach loop

The Iterable interface has one method iterator()

So,

Read more ›



08: If Java did not have a stack or map, how would you ….

Q1 If Java did not have a Stack implementation, how would you go about implementing your own? A1 1) Determine the backing data structure (e.g. array, linked list, etc). 2) Determine the methods that need to be implemented like pop( ), … Read more ›...



09: When to use which Java data structure? and why?

List, Set, Map, and Queue(access the ends FIFO or LIFO) are the basic Java data structure interfaces for which there are different implementations to cater for different usage patterns. Java data structure interview questions are very popular, … Read more ›...



10: 8 Java Maps & Caching Data in Java Interview Q&As

Q1. What is the purpose of a Map interface in Java collection API? A1. A map is a set of associations between pairs of objects. One is known as a “key” and the other is known as a “value”. It is used very frequently in programming in case where for...



17 FAQ Java Collection interview Q&As

Java Collections interview questions and answers and Java String class interview Q&As are must know as you can’t write any decent Java application without these 2 APIs. This post focuses on Java Collection interview Q&As on differences between X and Y based on the Java Collection Framework (i.e. … Read...



Java 8: Different ways to sort a collection of objects in pre and post Java 8

The object we are going to sort is a Person. Option 1: Writing your own Comparator implementation. This can be done as an anonymous inner class instead of a separate class. The test class Option 2: The Option 1 is not bad, … Read more ›...



Sorting a Map by values instead of keys

This post is motivated by ““Sorting a list or array of numbers by frequency of occurrences in Java”

Sorting a Map by Keys

Sorting a map by its keys is straightforward

Sorting a Map by its Values –

Read more ›



800+ Java Q&As & tutorials

Top