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:

Spring SimpleMappingExceptionResolver Example

In some badly coded applications, when an unknown exception occurs the application server usually displays the evil exception stack trace to the user in the webpage itself. In this case, users have nothing to do with this stack trace and complain that your application is not user-friendly. Moreover, it can …

Spring MVC ResourceBundleViewResolver Configuration Example

In previous examples, we learned about XmlViewResolver and InternalResourceViewResolver view templates. In this post, we will learn about ResourceBundleViewResolver templates. ResourceBundleViewResolver loads view beans from a resource bundle in the classpath root. Note that ResourceBundleViewResolver can also take advantage of the resource bundle capability to load view beans from different …

Spring MVC Internationalization (i18n): Step by Step Guide

Internationalization (i18n) is the process of designing a software application so that it can potentially be adapted to various languages and regions without engineering changes. Localization is the process of adapting internationalized software for a specific region or language by adding locale-specific components and translating text. Spring framework is shipped …

Spring MessageSourceAware Example

If you want to access i18n resources bundles for different locales in your Spring application, then that a class must implement MessageSourceAware interface. After implementing MessageSourceAware interface, spring context will automatically inject the MessageSource bean’s reference into the class via ‘setMessageSource(MessageSource messageSource)‘ setter method which your class needs to implement. …

Spring HandlerInterceptor Example

Spring HandlerInterceptor allows creating interceptors in Spring or Boot applications to handle requests pre- and post-controller methods.

Maven: Create Java Source Folders in Eclipse

This is a very strange problem but this is the fact that when you create a maven web application using “-DarchetypeArtifactId=maven-archetype-webapp” then Java source folders are not created. Rather a ‘/resources‘ folder is created. Files placed in ‘/resources‘ folder are placed in your classpath when a jar or war file …

Spring AOP Annotation Config Example

In Spring AOP annotation example, learn to create an @Aspect (e.g. LoggerAspect) to log the execution time of methods within our application.

Spring BeanPostProcessor Example

Spring BeanPostProcessor allows for custom modification of new bean instances created by spring bean factory. Spring AOP classes use bean post-processors

Spring: Reading an Internal or External Resource

Learn different ways to load resources or files (e.g. text files, XML files, properties files, or image files) into the Spring application context. Spring ResourceLoader provides a unified getResource() method to retrieve an external resource by the resource path. 1. Spring Resource Interface The Spring Resource is a general interface …

Spring static factory-method example

In Spring framework, if you want to create a bean by invoking a static factory-method, whose purpose is to encapsulate the object-creation process in a static method then you could use factory-method attribute. Read More : Spring FactoryBean Static factory method example If you want to create different EmployeeDTO objects …

Spring FactoryBean with Example

In Spring, FactoryBean creates beans that cannot be created using the ‘new’ keyword and involve complex initialization or configuration.

Copying a Directory in Java

Learn to copy a directory into a new location in Java. Learn to apply FileFilter to include or exclude subdirectories and specific files.

Java File Checksum – MD5 and SHA-256 Hash Examples

A checksum hash is an encrypted sequence of characters obtained after applying specific algorithms and manipulations on user-provided content. In this Java hashing tutorial, we will learn to generate the checksum hash for the files. 1. Why Generate a File’s Checksum? Any serious file provider provides a mechanism to have …

Making a File Read-Only in Java

Learn to make a file read-only in Java. A read-only file can be opened for reading, but we cannot modify or delete the file contents.

Copying a File in Java

Copying a file from one place to another in Java is a common task. Learn to copy files using Java NIO, Commons-IO and Guava APIs.

Guide to Java BufferedWriter

Learn to create BufferedWriter with default, configure custom internal buffer sizes and write characters data into a file using it.

Guide to Java BufferedReader

Learn to create and operate the BufferedReader instance, set default buffer size and read from a file and system console with examples.

Creating a New File in Java

Learn to create a new file using different techniques including NIO Files and Path, IO File, File OutputStream, and open-source libraries.

Java MappedByteBuffer

Learn about Java memory-mapped files and learn to read and write content from a memory mapped file with the help of RandomAccessFile and MemoryMappedBuffer. 1. Java Memory-mapped IO If you know how java IO works at lower level, then you will be aware of buffer handling, memory paging and other …

Java NIO Vectored IO

Java NIO Channels provide an important new capability known as scatter/gather (referred to in some circles as vectored I/O). Scatter/gather is a simple yet powerful concept. Scatter/gather is a technique through which bytes can be read from a stream into a set of buffers (vectors) with a single read() invocation …

Java NIO Channel Tutorial

Channels are the second major addition to java.nio after buffers which we have learned in my previous tutorial in detail. Channels provide direct connection to the I/O services. A Channel is a medium that transports data efficiently between byte buffers and the entity on the other end of the channel …

Java NIO Buffer Tutorial

Java Buffer classes are the foundation upon which java.nio is built. In this tutorial, we will take a closer look at the buffers. We will discover the various buffer types, and learn how to use them. We’ll then see how the java.nio buffers relate to the Channel classes of java.nio.channels. …

Java Binary Semaphore (+Example)

A binary semaphore is a synchronization primitive that can hold only two values, typically 0 and 1. We use binary semaphore to manage access to a shared resource by multiple threads in a concurrent environment. Conceptually, a binary semaphore can be thought of as a lock that allows only one …

Java Locks (with Examples)

Java provides another mechanism for the synchronization of blocks of code based on the Lock interface and classes that implement it (such as ReentrantLock). In this tutorial, we will see a basic usage of Lock interface to solve printer queue problem. 1. Lock Interface A java.util.concurrent.locks.Lock is a thread synchronization …

Creating Threads Using java.util.concurrent.ThreadFactory

The factory design pattern is one of the most used design patterns in the java. It is one of creational patterns and can be used to develop an object in demand of one or several classes. With this factory, we centralize the creation of objects. The centralization of creation logic …

Java ThreadLocal Example: When and How to Use?

Today, one of the most critical aspects of a concurrent application is shared data. When you create a thread that implements the Runnable interface and then starts various Thread objects using the same Runnable object. All the threads share the same attributes that are defined inside the runnable object. This …

Restarting threads using UncaughtExceptionHandler

1. UncaughtExceptionHandler Java applications have two kind of exceptions – checked exceptions and unchecked exceptions. Checked exceptions must be specified in the throws clause of a method or caught inside them. Unchecked exceptions don’t have to be specified or caught. When a checked exception is thrown inside the run() method …

How Java IO Works Internally?

Learn how Java IO operations are mapped at the machine level; and what all things the hardware does all the time when application is running.

Guide to Java Servlets

Servlets are Java classes that conform to the Java Servlet API, which allows a Java class to respond to requests. Although servlets can respond to any type of request, they are most commonly written to respond to web-based requests. A servlet must be deployed to a Java servlet container in …

TestNG – Parallel Test Execution

TestNG parallel execution of tests, classes and suites. Learn to run multiple tests in different threads or a single test in multiple threads.

TestNG @Factory with Examples

Learn about the TestNG @Factory annotation that allows the tests to be created at runtime depending on provided datasets or conditions. 1. When to use TestNG @Factory? Sometimes we may need to run a set of tests with different data values. To achieve this we may define a separate set …

TestNG Dependent Tests with Examples

TestNG allows a test method to be dependent on a single or a group of test methods so that dependent tests are executed before the given test.

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.