Log4j2 LevelRangeFilter Example

Learn to use log4j LevelRangeFilter filter which returns the onMatch result if the level in the LogEvent is in the range of the configured min and max levels, otherwise it returns onMismatch value. LevelRangeFilter Configuration In given log4j2.xml file, we have used to LevelRangeFilter to filter log levels in such …

Log4j2 Multiple Appenders Example

Given log4j2.xml is reference to configure multiple appenders such as console appender and file appenders. This also configure the dynamic log root path. Log4j2 Multiple Appenders – XML Configuration Sample log4j2 configuration is given blow. It does following things: Uses dynamic log root path where log files will be created. …

Spring Boot Log4j2.xml Example

Spring boot log4j2.xml configuration example of configuring log4j2 with spring boot2 project and adding logging support to the application.

Appending to a File in Java

Learn to append the data to a file in Java using Standard IO’s BufferedWritter, PrintWriter, FileOutputStream and NIO Files classes.

Java 10 Features and Enhancements

After Java 9 release, Java 10 came very quickly. Unlike it’s previous release, Java 10 does not have that many exciting features, still it has few important updates which will change the way you code, and other future Java versions.

Java Version – Time-Based Release Versioning

Starting from Java 10, Oracle has adapted time based version-string scheme [JEP 322]. The new time-based model has replaced the feature-based, multi-year release model of the past. Unlike the old releases, the new time-based releases will not be delayed and features will be released every six months, with no constraints …

Java Comments

Inside a Java program, we can write a special text that will be ignored by the Java compiler — known as the comment. Comments allow us to exclude code from the compilation process (disable it) or clarify a piece of code to yourself or other developers. Learn everything about Java comments, …

Java Variables

In traditional programming languages, such as Java, a variable is a placeholder for storing a value of a particular type: a string, a number, or something else. This Java tutorial discusses what a variable is and the types of variables. Also, look at the example of how to declare a variable in Java. We …

Difference between JDK, JRE and JVM in Java

JDK, JRE and JVM is very common words when developers talk about java applications and their development environments. Let’s find out the differeneces between these words.

Python string endswith() example

Python string.endswith() is used to check the end of a string for specific text patterns e.g. domain name extensions and so on.

Python String startswith()

Python string.startswith() method is used to check the start of a string for specific text patterns e.g. URL schemes and so on.

Python String split()

Python example to split string into tokens using the delimiters in the string. Learn to split string using single or multiple delimiters in python.

Python OrderedDict

Learn the differences between a dictionary and OrderedDict, and also how to create, update and delete the items from the Python OrderedDict.

Python find largest N (top N) or smallest N items

Python examples to find the largest (or the smallest) N elements from a collection of elements using nlargest() and nsmallest() functions from heapq library. 1. Using heapq module’s nlargest() and nsmallest() Python heapq module can be used to find N largest or smallest items from collections. It has two functions …

Python Unpack Tuple with Variable Length

Python example to unpack tuple or sequence or iterable such that the tuple may be longer than N elements, causing a “too many values to unpack” exception.

Configuring HttpClient with Spring RestTemplate

We have already gone through the RestTemplate examples for accessing REST APIs inside spring application. In this example, we are extending the configuration to use Apache HttpClient 4. The purpose of this tutorial is to give you pre-cooked recipe for little head-start, and save you from writing all bits and pieces.

Sort a Map by Values in Java

Simple and easy-to-understand examples of sorting a HashMap by values, using Java 8 Stream, in ascending and descending (reverse) orders.

Sort a Map by Keys in Java

Simple and easy-to-understand examples to sort a Map by key, using TreeMap and Java 8 Stream, in ascending and descending (reverse) orders.

JavaScript Logs – Mask Sensitive Information in JSON

Masking sensitive information is very practical need of applications which deal with sensitive customer data. For example, banking applications. When these applications run inside organization intra-net, many times UI logs are generated and stored on user’s machine for debugging purpose. In above scenario, it is regulatory requirement to mask all …

Java Garbage Collection Algorithms [till Java 9]

In java garbage collection tutorial, we will learn about object life cycle, difference between mark-sweep, mark-sweep-compact and mark-copy mechanisms, different single threaded and concurrent GC algorithms (e.g. G1), and various flags to control the gc algorithm’s behavior and log useful information for applications.

Java 9 – Compact Strings Improvement [JEP 254]

Till Java 8, String in java were internally represented by char[]. Each char is stored in 2 bytes in memory. JDK developers at oracle analyzed lots of client’s application help dumps and they noticed that most of the strings can be represented only using Latin-1 characters set. A latin-1 char can be stored in one byte, which is 50% (1 byte) less than char data type storage.

Spring Boot Dev Tools Tutorial

The Spring boot dev tools module provides a lot of useful developer features for improving the development experience such as caching static resources, automatic restarts, live reload, global settings and running the remote applications. 1. Enabling Dev Tools Module Enabling dev tools in the spring boot application is very easy. …

Spring Boot war Packaging Example

In Spring boot applications, the default packaging is jar which is deployed in embedded servers. Learn to generate a war file for deployment.

Spring Boot2 @SpringBootApplication Auto Configuration

String boot is very easy to use and it does a lot of things under the hood, you might not be aware of. In future, a good developer will be who will know exactly what is going on behind spring boot auto configuration, how to use it in your favor and how to disable certain sections which you do not want into your project.

Spring Boot HATEOAS Links Example

In this Spring Boot HATEOAS example, we will learn to add HATEOAS (Hypertext as the Engine of Application State) links to resource representations returned from REST APIs in a Spring boot application. 1. What is HATEOAS? HATEOAS is one of the constraints of the REST architectural style first presented by …

Generate REST Client with Swagger Codegen

Swagger can be integrated with REST APIs in below ways – A top-down approach – First API specification and then code generation. A botton-up approach – First API code and then Swagger integration. In this tutorial, we will learn the top down approach.

Spring @Lazy Loaded Beans

Spring @Lazy allows lazy bean creation either to specific beans or we can configure the lazy loading globally at the application level.

Amazon Alexa Custom Skill Tutorial

Alexa is Amazon’s cloud-based voice service. In this tutorial, learn to add custom skills to amazon Alexa and to use those skills in Amazon Eco device.

Spring Boot Actuator Example

Spring Boot 3 Actuator example to discuss default auto-configuration and monitor and manage our applications in a production-ready manner.

Spring boot RSS feed with rome

In this tutorial, learn to create and consume RSS and Atom feed from spring boot application. You must have seen this in form of text or image buttons on various websites (like our RSS feed) inviting you to “Subscribe via RSS.” RSS is simple syndication API – often referred as …

Spring Boot CORS Configuration Examples

Spring CORS helps in serving web content from multiple domains into browsers who usually have the same-origin security policy. In this example, we will learn to enable CORS support in Spring MVC application at method and global level.

Spring Boot SOAP Webservice Example

In this spring boot soap tutorial, we will focus only in the Spring boot related configurations to see how easily we can create our contract first SOAP webservice.

Tomcat Maven Plugin Example

In this maven tutorial, learn to add and configure tomcat plugin to pom.xml and use it deploy the web application without any tomcat installation in machine.

Spring @GetMapping and @PostMapping

Learn to create Spring MVC controllers and map requests with request mapping annotations e.g. @RequestMapping, @GetMapping, @PostMapping, @PutMapping, @DeleteMapping and @PatchMapping.

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.