Administrator

Lokesh Gupta

Lokesh Gupta is a Java developer with more than 20 years of experience and the founder of HowToDoInJava, which he started in 2012. He has worked on Java and Spring applications at Hewitt Associates, Hughes Systique, Adobe and Bank of America. The site has over 1,600 tutorials on Java, Spring Boot, Hibernate, testing and TypeScript. Every example is run and verified before it is published, and the source code is on GitHub.

Website: https://howtodoinjava.com

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

Twitter: @HowToDoInJAVA

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

My Articles:

Resize an Array in Java with Arrays.copyOf() and ArrayList

Java arrays have a fixed length, so we resize an array by copying it into a new one with Arrays.copyOf(). Learn the default values, the alias trap, inserting with System.arraycopy(), resizing 2D arrays and when an ArrayList fits better.

Java Core & Fundamentals Tutorial

Java tutorial for beginners on Java 25. Install the JDK, run a first program and follow a 12-step learning path plus an index of every Java topic.

Setting Up SLF4J with Logback, Log4j2 and JUL

A logging facade is an abstraction API that application code logs against, while a separate logging framework does the actual logging. SLF4J (Simple Logging Facade for Java) is the facade for logging frameworks such as Java Util Logging (JUL), Logback and Log4j2. We use the SLF4J API in the application …

Java Logging with Mapped Diagnostic Context (MDC)

A Mapped Diagnostic Context (MDC) is a per-thread map of key/value pairs that a logging framework adds to log messages, so we can distinguish the interleaved log output of different requests. Log output is interleaved when a server handles multiple clients at nearly the same time. 1. Stamping Requests with …

Masking Sensitive Data with Logback

Masking sensitive data in logback logs is done by partially or fully replacing the client-sensitive data or NPI (nonpublic personal information) with some arbitrary encoded text. For example, the SSN information can be replaced with all star characters or we can remove the complete SSN information from the logs. 1. …

Logback HTMLLayout

Logback HTMLLayout outputs events in an HTML table. The content of the table columns is specified using a conversion pattern in the encoder property. 1. HTMLLayout Sample Configuration For quick reference, this is the configuration file we will be referring. It logs into c:/temp/logs/applicationLogs.html file and rolls-over daily. 2. Dependencies …

Logback RollingFileAppender

Logback RollingFileAppender appends log events into a file with the capability to rollover (archive the current log file and resume logging in a new file) based on a particular schedule, such as daily, weekly, monthly or based on log file size. For quick reference, this is configuration file we will …

Logback Console Appender

Logback ConsoleAppender appends on the console though System.out or System.err print streams. In this Logback tutorial, learn about default configured console logging and how to apply custom configuration. 1. Dependencies Logback requires three modules in the application runtime i.e. logback-core, logback-classic and slf4j-api. The logback-classic module has implemented the SLF4J …

Omit Lombok @Getter and @Setter

Learn to add default accessor methods (getter and setter) using Lombok and omit these methods for specific requirements. 1. Default Behavior Lombok provides two annotations to add getter and setter methods to a POJO. @Getter – can be applied on any field and class. When applied on a field, lombok …

Lombok Serialize and Deserialize @Builder Class

Lombok @Builder generates a builder for our class, and Gson serializes and deserializes such a class without extra configuration, whereas Jackson serializes it directly but needs @Jacksonized or @JsonDeserialize to deserialize it. Serialization converts a Java object to JSON, and deserialization converts the JSON back to a Java object. We …

Lombok @Builder

Lombok’s @Builder annotation is a useful technique to implement the builder pattern that aims to reduce the boilerplate code. In this tutorial, we will learn to apply @Builder to a class and other useful features. Ensure you have included Lombok in the project and installed Lombok support in the IDE. …

Log4j2 – Maven and Gradle Configuration

Learn to configure Log4j2 using Maven and Gradle dependencies. 1. Log4j Modules The main modules of interest are given below. We can read the complete list of modules and their dependencies at this link. 2. Maven Dependencies An example of log4j2 configuration with SLF4J using Maven. We can check the …

Log4j2 with SLF4J Configuration

Learn to configure Log4j2 logging with SLF4J APIs. We will look at required dependencies, sample configuration and a demo to use the log statements. Read More: SLF4j Vs Log4j – Which One is Better? 1. Log4j2 and SLF4j Binding Dependencies To make Log4j2 work with SLF4J, we need to include …

Log4j2 JDBCAppender

Learn to configure the Log4j2 provided JDBCAppender that writes log events to a relational database table using standard JDBC. The JDBCAppender obtains the database connection from a configured connection factory or JNDI datasource. Then it uses the provided column configuration to insert a new row in the log table, everytime …

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.