Administrator

Lokesh Gupta

A fun-loving family man, passionate about computers and problem-solving, with over 15 years of experience in Java and related technologies. An avid Sci-Fi movie enthusiast and a fan of Christopher Nolan and Quentin Tarantino.

Website: https://howtodoinjava.com

Github: https://github.com/lokeshgupta1981/

Twitter: @HowToDoInJAVA

LinkedIn: https://www.linkedin.com/in/lokeshgupta1981/

My Articles:

REST API Security Guide

Knowledge of how to secure REST APIs is as much necessary as writing the APIs themselves. Mostly REST APIs are HTTP protocol-based, and any user having an internet connection can access them, and so can bad users as well. It is crucial to write secure APIs to protect the business. …

JavaScript Equality (==) vs. Identity (===) Operators

If you have worked on javascript then you must have noticed the equality and identity operators to compare objects or values. Many developers do not understand the correct version they use in specific scenarios. The correct decision is based on the knowledge of how they work. Let’s understand. 1. Difference …

Jackson – Marshal and Unmarshal Java Objects to JSON

This Jackson tutorial will teach us to use Jackson ObjectMapper to read and write JSON data into Java Objects. 1. Setting Up Jackson To include Jackson library in our project, we should include jackson-databind dependency which internally pulls the other two needed dependencies i.e. jackson-annotations and jackson-core. We can find the latest …

Java Stack Implementation using Array

This tutorial gives an example of implementing a Stack data structure using an Array. The stack offers to put new objects on the stack (push) and to get objects from the stack (pop). A stack returns the object according to last-in-first-out (LIFO). Please note that JDK provides a default java …

Custom List Implementation in Java

We may need to design our own custom list implementation for a very specific requirement or simply as a coding question in a Java interview.

Java System Properties

Java maintains a Set of system properties that can be accessed in the runtime by executing programs. Each system property is a key-value pair. For example, one such system property is “java.version”=”1.7.0_09“. We can retrieve all the system properties via System.getProperties() or we can also retrieve individual property via System.getProperty(key) …

Guide to java.util.Date Class

Learn to create new date, get current date, parse date to string or format Date object using java.util.Date class. These use-cases are frequently required, and having them in one place will help in saving time for many of us.

Get Current Date and Time in Java

Java offers many useful ways to get current date or current time using Date, Calendar and newly introduced LocalDate, LocalDateTime and ZonedDateTime classes in Java 8 Date/Time API classes.

Java Multi-threading Evolution and Topics

One of our reader, Anant, asked this extremely good question to elaborate / list down all related topics that we should know about multi-threading including changes made in java 8.( Beginner level to Advance level). All he wanted to know was evolution of Multi-threading Framework in Java from Simple Runnable …

Difference between lock and monitor – Java Concurrency

You may have faced this question in your interview that what is the difference between lock and a monitor? Well, to answer this question you must have good amount of understanding of how java multi-threading works under the hood. Short answer, locks provide necessary support for implementing monitors. Long answer …

Difference between SOAP and REST

Although SOAP and REST- both help building applications based on SOA, yet they are pretty much different. Let us learn few differences.

SLF4j Vs Log4j – Which One is Better?

Which logging framework we should use in our new application? I have been asked this question multiple times, so I thought to write down my answer in this post so fellow developers can refer to it from time to time when needed. 1. SLF4j acts like abstract Logging API Simple …

Java – Difference Between Two Dates

Learn to find difference between two dates in days, months or any other time units – using Java 8 classes such as Duration, ChronoUnit and finally JodaTime.

Are Java Enums Really the Best Singletons?

We must have heard multiple times that enums are always the best choice for implementing singleton design pattern in java. Are they really the best? If it is then how is it better than other available techniques? Let’s find out. Writing a singleton implementation is always tricky. I already discussed …

Java Puzzle – Check if a String contains All Alphabets

1. What is a Complete String? A string is said to be complete if it contains all the characters from a to z. If it misses even a single character, it is considered an incomplete string. For example, the following string is a complete string. It contains all the characters …

Bridge Pattern (with Example)

Bridge pattern is about preferring composition over inheritance. Implementation details are pushed from a hierarchy to another object with a separate hierarchy.

Jersey Client: How to Set Cookie in Request?

In this example, we will learn to set cookies into HTTP requests invoked by the Jersey client. This example makes use of Invocation.Builder for setting cookies into outgoing REST calls. 1. Syntax The following is the syntax to set a cookie in a Jersey client request using the Cookie class …

Multiple Inheritance in Java

Multiple inheritance is a feature of some object-oriented computer programming languages in which an object or class can inherit characteristics and behavior from more than one parent object or parent class.

Jersey REST API Security Example

In this Jersey rest security example, we will learn to secure Jersey REST APIs with basic authentication. This will make mandatory every user to provide username/password to authenticate into portal. Also, user must have certain level of role as well. I have extended this example from my other example created …

Jersey + Google Gson Example

This tutorial explains how to use google Gson with Jersey 2.x. There are some other java libraries also capable of doing this conversion e.g. MOXy, Jackson or JSONP; but Gson stands among very few which do not require any pre-annotated java classes OR sourcecode of java classes in any way. …

Jersey + JSONP Example

This tutorial explains how to use JSONP JSON provider with Jersey 2.x. JSONP is also auto-discoverable just like what we discussed in Jersey MOXy example. Table of Contents JSONP maven dependencies/changes REST API code Model bean changes Manually adding JsonProcessingFeature JSONP maven dependencies/changes JSONP media module is one of the …

Jersey + MOXy JSON Example

This tutorial explains how to use MOXy JSON feature with Jersey 2.x. MOXy is the default JSON-Binding Provider in Jersey 2.x. Though I still personally prefer Jackson over MOXy for performance reasons. Table of Contents MOXy maven dependencies/changes REST API code Model bean changes Manually adding MoxyJsonFeature Customize behavior using …

Jersey-quickstart-archetype Hello World Example

In this example, we will create a jersey RESTful API web application using jersey-quickstart-webapp maven archetype in eclipse. Table of Contents Install remote archetypes in eclipse Create new maven project using jersey-quickstart-webapp Generated Files Run The Application Install remote archetypes in eclipse The very first step before creating actual maven …

Jersey: Case-insensitive @Path URLs

By default in JAX-RS, ALL URLs specified in @Path annotations are case-sensitive. Learn to support case-insensitive URLs using regex and ResourceConfig.

Getting Started with Jersey Client

Jersey 2 client API finds inspiration in the proprietary Jersey 1.x Client API. In this Jersey client example, we will learn to build client API and invode different REST methods and consule the API results.

Jersey exception handling – Jersey ExceptionMapper Example

In Jersey ExceptionMapper example, we will learn to handle custom exceptions using ExceptionMapper interface while developing Jersey RESTful web services. For demo purpose, I am modifying the sourcecode written for jersey download file example. Table Of Contents 1. Jersey custom exception with ExceptionMapper 2. How to throw exception from REST …

Jersey – Ajax Multi-File Upload Example

Learn to use Ajax with JAX-RS webservices (Jersey used in example) to upload multiple files with single button click. Also look at form based file upload example and file download example as well. Table of Contents Jersey maven multipart dependency Add MultiPartFeature Write Upload REST API HTML/Ajax code Demo of …

Jersey file download example – StreamingOutput

In this Jersey file download example, we will learn to write a Jersey rest api which will be able to stream or download file (e.g. PDF/Excel/Text files) to requesting client. I will be using javax.ws.rs.core.StreamingOutput class for building this JAX-RS API. Table of Contents 1. REST API to stream file …

Implement Phonetic Search with Soundex Algorithm

Have you ever wondered how spell checkers, in any word editor, suggest you a list of probable other words whenever you have any spelling mistake?? This is done using phonetic search. Soundex is a phonetic algorithm for indexing names by sound, as pronounced in English. The goal is for homophones …

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.