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:

Chain of Responsibility Design Pattern

The Chain of Responsibility is known as a behavioral pattern. The main objective of this pattern is that it avoids coupling the sender of the request to the receiver, giving more than one object the opportunity to handle the request. The core logic defined by GoF is : “Gives more …

Spring 3: Timer Tasks

Timer is a utility class which is used to schedule tasks for both one time and repeated execution in spring applications. Timer is dependent on system clock

Test Spring Security Auth with JUnit

Learn to test Spring security authentication using JUnit testcase using InMemoryDaoImpl. Also learn to build fully populated authentication object programmatically and then use it in application. SecurityContextHolder Spring security is based on security context, which is kind of static in nature. This essentially means that your do not need to …

Spring View Layer Security using JSP Taglibs

So far in previous tutorials, we have learned about securing your application behind login form, custom user detail service and even method level security also. All these security implementations were on controller or model layer of MVC. Its time to add security in view layer. It is mostly needed when …

Spring Method Security with @PreAuthorize and @Secured

Spring framework has made securing your application so much easy that you only need to use some basic configurations CORRECTLY, and that’s it !! This security can be applied to multiple levels in your web application. Spring’s basic support is for these levels: URL level security Method level security Entity …

Basic Auth with Spring Security

Learn about default basic authentication commissioned by Spring security and customize its configurations such as password encodings.

Log4j Logging Levels

Learn about Log4j log levels. Log4j2 log levels example. Learn about log4j logging level order and how log level works in this log4j tutorial.

Log4j2 XMLLayout

Log4j2 comes with multiple options to create and format log files created by the framework. It can create simple log files, HTML log files or even XML log files also. In this tutorial, we will see the example for configuring log4j to produce logs in XML format. To create a …

Java NullPointerException

Java NullPointerException (NPE) is an unchecked exception and extends RuntimeException. NullPointerException doesn’t force us to use a try-catch block to handle it. NullPointerException has been very much a nightmare for most Java developers. It usually pop up when we least expect them. I have also spent a lot of time …

Comparing Performance of Java Loops

This Java article compares the performance of an ArrayList iteration using simple for-loop, enhanced for-loop, list iterator and stream API.

Java Suppressed Exceptions with Examples

Suppressed exceptions, as name suggest, are exceptions thrown in the code but were ignored somehow. If you remember try-catch-finally block execution sequence and how they return any value or exceptions, you will recall that exceptions thrown in finally block are suppressed if an exception is thrown in try block also. …

Object level lock vs Class level lock in Java

In Java, a synchronized block of code can only be executed by one thread at a time. Also, java supports multiple threads to be executed concurrently. This may cause two or more threads to access the same fields or objects at same time. Synchronization is the process which keeps all …

Java – Internal Caching in Wrapper Classes

1. Object Creation is Expensive We know to create objects in java using the new keyword. A new instance created in Java allocates the memory in the heap, so creating new objects is considered an expensive operation. To avoid this expensive object creation process, many of the frameworks have been …

Java Interview Questions and Answers

Read all the Java interview questions and answers in this article to refresh your concepts and possibly have some new ones added to the list.

Maven Enforce Minimum Java Version

Many times, we need to enforce that java build process should halt immediately if deployment environment does not have not a specific operating system, or it does not contain a minimum required java version. If you are using maven for build process, then these limitations can be easily be configured …

Maven ant plugin – Generate build.xml from pom.xml

Suppose you had created and maintained your project from maven for long time, but now you have instructions to move it to ant build environment. Well, it does not look easy, but it really is very much. All you need to use if maven ant plugin which is specifically only …

Prototype Pattern

The prototype design pattern is used in scenarios where an application needs to create a number of instances of a class that have almost the same state or differ very little.

Maven – Local Repository Location

Learn where is maven local repository location? Learn how to change maven local repository location. Change repo location in windows 7, windows 10 & linux.

Create Maven Web Application and Import into Eclipse

Learn to create a Maven web project in Eclipse, which we should be able to import into the Eclipse IDE for further development. To create an Eclipse-supported web project, we will need to create a normal Maven web application and then make it compatible with the Eclipse IDE. Step 1: …

Maven – Create Java Project with Non/Interactive Mode

Learn to create a Java application project with maven, using interactive and non-interactive modes from the command prompt. 1. Using Maven Non-interactive Mode In non-interactive mode, Maven creates a blank Java project with all default options applicable for the selected Maven template. To create this, type the below command. This …

Installing Maven on Windows

Learn to install Maven on a Windows operating system. In this maven installation guide, we are installing Maven on a Windows 11 machine. The steps are the same for a Windows 10 machine as well. 1. Windows Environmant Variables Maven is a build and dependency management tool for Java applications …

JStack – Java Thread Dump Analyzer

A thread dump is a list of all the Java threads that are currently active in a Java Virtual Machine (JVM). There are several ways to take thread dumps from a JVM. It is highly recommended to take more than 1 thread dump while analyzing any problem such as deadlock …

Java Read XML using SAX Parser

In this tutorial, learn to read or parse XML document using Java SAX parser API for XML example. Learn to parse XML elements to java objects.

30+ Awesome Programming Quotes

I found these programming quotes on the internet and found them too good to share with you all. Enjoy !! Java: write once, run away! -Brucee If Java had true garbage collection, most programs would delete themselves upon execution. – Robert Sewell There are two ways of constructing a software …

Java XPath – How to Get Attribute Value

Learn to parse an XML document and read the value of an attribute using XPath in Java. We can read the attribute value for all its occurrences in the document, or only for selected nodes in the XML. 1. XPath Expression for Attributes In XPath, the ‘@’ is used to …

Java Strict Date Validation – SimpleDateFormat.setLenient()

All of us have come across situations when we have to parse user input for validation. Other fields such as text or numeric are rather easy, but Java date validation is a little bit difficult, and a small error can leave the application in an unstable state. 1. Java Date …

Spring MVC Interceptor Example – XML and Annotation Java Config

In this Spring tutorial, we will learn to use spring mvc interceptor in spring mvc applications. This tutorial is very short to focus only on spring interceptor configuration and usage. Interceptors, as we know, are special web programming constructs which gets invoked every time when a certain pre-configured web request …

Java Regex Password Validation Example

Password validation is the need of almost all applications today. There are various ways to validate passwords from writing everything manually to using third-party available APIs. In this password validation tutorial, we are building a password validator using regular expressions. 1. Regex for Validating the Passwords ((?=.*[a-z])(?=.*d)(?=.*[@#$%])(?=.*[A-Z]).{6,16}) The above regular …

JUnit JUnitCore Example

In any application, which is being built incrementally, often it is desired that we should be able to run only certain tests whenever a new feature is introduced. This can be achieved using JUnitCore class of JUnit framework. JUnitCore is an inbuilt class in JUnit package and it is based on facade …

Regex Meta Characters (with Examples)

A regular expression defines a search pattern for strings. This pattern may match one or several times or not at all for a given string. The abbreviation for regular expression is regex. Regular expressions can be used to search, edit, and manipulate text. Regex meta characters are special symbols that …

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.