How Hashmap works in Java

How HashMap works in Java.


This is the famous interview question for the beginners as well as for experienced, So Let's see what it is all about.

Hashmap is very popular data structure and found useful for solving many problems due to O(1) time complexity for both get and put operation.
Before getting into Hashmap internals, Please read Hashmap basics and Hashcode.

Internal working of Get and Put operation.


Hashmap store objects in key-value pair in a table.
   1. Objects are stored by method hashmap.put(key, value) and
   2. Objects are retrieved by calling hashmap.get(key) method.

For detail explanation on hashmap get and put API, Please read this post How Hashmap put and get API works.

Put Operation


Hashmap works on principle of hashing and internally uses hashcode as a base, for storing key-value pair.
With the help of hashcode, Hashmap stores objects and retrieves it in constant time O(1).


Lets recap "Employee Letter Box" example, we saw in last post on Hashcode.


Quartz Scheduler Cron Trigger example in Java

Quartz Scheduler Cron Trigger example in Java.


Integration of Quartz scheduler with Spring boot. Java Quartz scheduler cron expression example. Spring quartz scheduler postgresql database example.
quartz scheduler cron trigger example in spring boot
Quartz scheduler cron trigger example in Spring Boot

Quartz Scheduler:  
  1. Quartz is a richly featured, open source Job scheduling library. 
  2. Quartz can be used to create simple or complex schedules for executing multiple jobs. 
  3. Using quartz library, job can be schedule which can be executed instantly or to be executed later point of time. 
  4. Quartz also accepts cron expression using which complex jobs can be scheduled like
    "Run job after every 5 minutes" or "Run job every week on monday at 3 PM" etc.

Spring boot:
  1. Spring boot is (Spring + Configuration) bundle which helps you to develop application faster.
  2. Spring boot take care of many configurations and helps developer focus on business. 
  3. It includes an embedded tomcat (or jetty) server.

Configure Quartz Scheduler In Web Application Java

Integrating Quartz Scheduler In Web Application Java.


Integration of Quartz scheduler with Spring boot. Java Quartz scheduler cron expression example. Spring quartz scheduler postgresql database example.

Configure quartz scheduler in web application in Java
Quartz Scheduler:  
  1. Quartz is a richly featured, open source Job scheduling library. 
  2. Quartz can be used to create simple or complex schedules for executing multiple jobs. 
  3. Using quartz library, job can be schedule which can be executed instantly or to be executed later point of time. 
  4. Quartz also accepts cron expression using which complex jobs can be scheduled like
    "Run job after every 5 minutes" or "Run job every week on monday at 3 PM" etc.

Spring boot:
  1. Spring boot is (Spring + Configuration) bundle which helps you to develop application faster.
  2. Spring boot take care of many configurations and helps developer focus on business. 
  3. It includes an embedded tomcat (or jetty) server.

Quartz Scheduler Tutorial In Java with Example.

Quartz Scheduler Tutorial In Java with Example.


Integration of Quartz scheduler with Spring boot. Java Quartz scheduler cron expression example. Spring quartz scheduler postgresql database example.

quartz scheduler tutorial in java
Quartz scheduler tutorial in Java 

Quartz Scheduler:  
  1. Quartz is a richly featured, open source Job scheduling library. 
  2. Quartz can be used to create simple or complex schedules for executing multiple jobs. 
  3. Using quartz library, job can be schedule which can be executed instantly or to be executed later point of time. 
  4. Quartz also accepts cron expression using which complex jobs can be scheduled like
    "Run job after every 5 minutes" or "Run job every week on monday at 3 PM" etc.


Spring boot:
  1. Spring boot is (Spring + Configuration) bundle which helps you to develop application faster.
  2. Spring boot take care of many configurations and helps developer focus on business. 
  3. It includes an embedded tomcat (or jetty) server.

Quartz Scheduler + Spring Boot Example

Quartz Scheduler + Spring Boot Example.


Integration of Quartz scheduler with Spring boot. Java Quartz scheduler cron expression example. Spring quartz scheduler postgresql database example.

Quartz Scheduler:  
  1. Quartz is a richly featured, open source Job scheduling library. 
  2. Quartz can be used to create simple or complex schedules for executing multiple jobs. 
  3. Using quartz library, job can be schedule which can be executed instantly or to be executed later point of time. 
  4. Quartz also accepts cron expression using which complex jobs can be scheduled like
    "Run job after every 5 minutes" or "Run job every week on monday at 3 PM" etc.
Spring boot:
  1. Spring boot is (Spring + Configuration) bundle which helps you to develop application faster.
  2. Spring boot take care of many configurations and helps developer focus on business. 
  3. It includes an embedded tomcat (or jetty) server.

Insertion Sort in Java

Insertion Sort in Java


Insertion sort is simple sorting algorithm that sorts the complete array by picking one element at a time and shifting it at its right place.

Lets understand above line in more details with the help of an example. Given a array of integers, Sort it using Insertion sort.  

Lets understand what is the input and the expected output.

Linear Search Algorithm in Java

Linear Search Algorithm in Java OR
Sequential Search Algorithm in Java

Linear search is a searching algorithm which sequentially searches element in an array.

In this algorithm, elements of array is scanned one by one and check if it is matching with element to search and if found return true else return false.

Lets understand the problem statement graphically and it will be more clear,  



How Binary search Algorithm works in Java

How Binary search Algorithm works in Java.

Binary search is a technique for searching an element from sorted array.

Let's understand Binary Search Algorithm with the help of an example, 
You will be given a sorted array and an element, find whether element is present in array or not.
 

Binary Search in Java

Binary Search in Java.

Binary search is a technique for searching an element from sorted array.

Let's understand Binary Search with the help of an example,
You will be given a sorted array and an element, find whether element is present in array or not.
Lets understand the problem statement graphically and it will be more clear,  
 

Find element in a sorted array

Binary Search in Sorted Array OR
Given a sorted array, Search a given element in array.


Searching an element in a sorted array.
You will be given a sorted array and an element, you need to find whether element is present in array or not.

Lets understand the problem statement graphically and it will be more clear,