Learn to use core Java and external libraries to search for files in a directory (including sub-directories) that match a specific extension.
Also find me here:
Baeldung Editor
Luis Javier Peris
Javier is a computer science engineer with more than 12 years of experience. Passionate about product development under agile and devops principles, having exercised the role of Scrum Master and Agile Coach for more than 10 years. His other great passion is software craftsmanship with a focus on clean code, DDD, hexagonal architecture and great testing practices.
Here's what I've reviewed (so far):
Baeldung on Java
- All
- Core Java (11)
- Java IO (9)
- Persistence (8)
- Spring Data (7)
- Java (7)
- Spring (6)
- Java String (6)
- Spring Boot (4)
- Java Dates (4)
- Spring Persistence (3)
- REST (3)
- NoSQL (3)
- Gradle (3)
- Spring Security (2)
- Spring Cloud (2)
- Java Streams (2)
- Java Numbers (2)
- Java Concurrency (2)
- Jackson (2)
- HTTP Client-Side (2)
- Data (2)
- Testing (1)
- Spring Web (1)
- Security (1)
- Reactive (1)
- Networking (1)
- Maven (1)
- Logging (1)
- Java Web (1)
- Java Map (1)
- Java Array (1)
- JSON (1)
- Docker (1)
Handling NullPointerException in findFirst() When the First Element Is Null
Filed under Java Streams
To avoid NullPointerException when using findFirst() in Java, filter the stream before calling findFirst() or use Optional#ofNullable() to wrap values in an Optional object.
Difference Between String isEmpty() and isBlank()
Filed under Java String
Delve into the distinctions between isEmpty() and isBlank() when working with Java Strings.
Manage Kafka Consumer Groups
Filed under Data
Learn about Kafka consumer groups and their role in enhancing scalability by enabling multiple consumers to read from the same topic in parallel.
How to Avoid NoSuchElementException in Stream API
Filed under Java Streams
The NoSuchElementException exception occurs when accessing an element that doesn’t exist. Find out the best practices of avoiding it and writing robust code.
Convert File to Byte Array in Java
Filed under Java IO
Learn how to convert a file into a byte array in Java.
Get First Date of Current Month in Java
Filed under Java Dates
Learn how to obtain the first date of the current month in Java using JDK classes and third-party libraries like Joda Time.
Check if a String Contains a Number Value in Java
Filed under Java String
Learn how to check if a string contains a number in Java.
Capitalize the First Letter of Each Word in a String
Filed under Java String
Learn how to capitalize the initial character of each word in a Java string.
Convert Char Array to Int Array in Java
Filed under Java Array
Explore how to convert a char array to an int array in Java.
Java Double vs. BigDecimal
Filed under Java Numbers
Compare Java’s Double to BigDecimal and learn about their differences.
Java Interface Naming Conventions
Filed under Java
This article summarizes naming conventions for Java interfaces, emphasizing the use of adjectives for capability interfaces and nouns for polymorphic interfaces. It provides a practical example and warns against patterns like IUser and UserImpl for code clarity. Adhering to these conventions enhances code readability and maintainability.
Custom DLL Load – Fixing the “java.lang.UnsatisfiedLinkError” Error
Filed under Java
Explore common causes like incorrect library names, missing directory specifications, and incompatible architectures. Implement solutions such as setting java.library.path and using proper classloaders to resolve this error effectively.
How to Get Last Day of a Month in Java
Filed under Java Dates
Discover how to find the last day of a month in Java using both core Java methods and popular libraries. This article provides step-by-step explanations for accomplishing the task using Date and Calendar classes, Java 8’s Date Time API, and the Joda Time library with code examples and test cases.
Extracting a Tar File in Java
Filed under Java IO
In this tutorial, we explore Java libraries for extracting tar archives: Apache Commons Compression, Apache Ant, and Apache VFS. The article provides concise code snippets and highlights the key features of each approach. Read on to learn efficient ways of extracting tar archives in Java.
Adding One Month to Current Date in Java
Filed under Java Dates
In this short tutorial, we discuss various methods of adding one month to the current date in Java. We cover using core Java methods as well as popular external libraries such as Joda-Time and Apache Commons Lang3.
Difference Between findBy and findOneBy in Spring Data JPA
Filed under Spring Data
This article delves into the similarities and differences between the findBy and findOneBy prefixes in Spring Data JPA. It explores the concept of derived query methods, provides code examples, and explains the exception thrown by findBy queries when the result size doesn’t match expectations.
Lossy and Lossless Image Compression Using Java
Filed under Java IO
Learn how to compress images in Java using built-in libraries and Apache Commons Imaging. Image compression reduces file size without compromising visual quality. It optimizes image-heavy applications and websites for faster loading and better user experience.
Handle NoSuchElementException When Reading a File Through Scanner
Filed under Java IO
In this tutorial, we’ll explore handling the ‘NoSuchElementException: No line found’ exception when reading a file using the Scanner class in Java. We’ll explain its root cause and present three solutions: defensive programming, exception handling, and checking file emptiness.
What’s the Difference between Scanner next() and nextLine() Methods?
Filed under Java IO
This article delves into the difference between the next() and nextLine() methods of the Scanner class.The article also covers the use of custom delimiters and provides code examples for better understanding. Understanding these distinctions enables developers to parse input effectively using Scanner.
Java PrintStream to String
Filed under Java IO, Java String
This article provides several ways of converting a PrintStream to a String in Java.The approaches include using ByteArrayOutputStream, a custom output stream, and Apache Commons IO.
Spring Boot H2 JdbcSQLSyntaxErrorException expected “identifier”
Filed under Persistence, Spring Boot
This tutorial explains the exception org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement expected “identifier”. It provides a practical example to reproduce the exception and showcases how to fix it by double-quoting the keyword or using a JDBC URL workaround. It also covers how to automatically quote all database identifiers when using Hibernate.
Check if the First Letter of a String Is a Number
Filed under Java String
This tutorial explains different ways to check if the first character of a string is a number in Java. It covers using charAt(), Character.isDigit(), Pattern class, and matches() method. It also demonstrates how to use Guava’s CharMatcher utility class to accomplish the same objective.
Best Practices for Passing Many Arguments to a Method in Java
Filed under Core Java
This article discusses the challenges of passing many arguments to a method in Java. It presents two design patterns to mitigate these issues: the Parameter Object Pattern and the Java Bean Pattern.
@StandardException Annotation in Lombok
Filed under Java
This article introduces the @StandardException annotation in Java’s Lombok library that generates constructors for exception classes, avoiding writing duplicate code.
Fix the JsonMappingException: Can not deserialize instance of java.util.ArrayList from Object value (token `JsonToken.START_OBJECT`)
Filed under Jackson
Learn how to fix a common JsonMappingException when deserializing a JSON string.
Fix Spring Data JPA Exception: No Property Found for Type
Filed under Spring Data
This article explains how to fix the “PropertyReferenceException: No property found for type” in Spring Data JPA. It advises using exact property names when defining query methods to avoid the exception. Practical examples are provided.
Hibernate @CreationTimestamp and @UpdateTimestamp
Filed under Persistence
This article explains how to use Hibernate annotations @CreationTimestamp and @UpdateTimestamp to track the creation and update timestamps of an entity in a Java application using the Hibernate framework.
Introduction to QuestDB
Filed under Persistence
A brief introduction to QuestDB, a column-oriented database designed for time-series and event data, and how to create, query and remove data.
Spring Kafka: Configure Multiple Listeners on Same Topic
Filed under Spring
Learn how to configure multiple listeners for the same Kafka topic using Spring Boot.
Change Swagger-UI URL prefix
Filed under Spring Boot
Learn how to change the Swagger-UI URL prefix when using Springfox and how to set up the REST API documentation using OpenAPI 3.0 with redirections.
Configuring Spring Cloud FeignClient URL
Filed under Spring Cloud
Learn different ways of setting up a URL using Spring Cloud FeignClient.
UUID vs. Sequential ID as Primary Key
Filed under Persistence
A comparison between sequential IDs and UUIDs used as primary keys.
Difference Between Javac and the Eclipse Compiler
Filed under Core Java
A comparison between the Java compiler and the Eclipse compiler.
Implementing toString() on enums in Java
Filed under Core Java
Different ways of implementing toString for enums.
Fix EmptyResultDataAccessException When Using JdbcTemplate
Filed under Spring Persistence
Explanation of the reason behind EmptyResultDataAccessException when jdbcTemplate is used and how to fix it.
Create Dynamic Queues in RabbitMQ
Filed under Data
An explanation of the RabbitMQ messaging model. Learn how to create a queue and make it dynamic.
Ahead of Time Optimizations in Spring 6
Filed under Spring Boot
What’s the concept of AOT and how is applied in Spring 6 looking at pros and cons.
Convert byte[] to MultipartFile in Java
How to convert a byte array into a class which implements the Spring MultiPartFile interface.
Fix the IllegalArgumentException: No enum const class
Filed under Java
Why IllegalArgumentException is thrown and how to fix in it in Java.
Class Methods vs Instance Methods in Java
Filed under Core Java
A brief comparison between class and instance methods in Java.
PrintStream vs PrintWriter in Java
Filed under Java IO
A comparison between two classes to output content: PrintWriter and PrintStream, explaining the similarities and differences between them.
Stream Large Byte[] to File With WebClient
Filed under HTTP Client-Side, Spring
This is a short tutorial about how to stream a large file to a file using a DataBuffer and what’s the role of ExchangeStrategies in WebClient.
Convert Anonymous Class into Lambda in Java
Filed under Core Java
A reminder of what an anonymous class is and how to convert it to a lambda expression.
Type Parameter vs Wildcard in Java Generics
Filed under Core Java
A detailed explanation about generics, how and when to use type parameters, and when wildcards are more appropiate.
Getting Started with Blaze Persistence
Filed under Persistence
A brief introductory guide to the Blaze criteria API reviewing the basic parts of queries and also how to use views.
Enum Mapping in Spring Boot
Filed under Spring
Explore different ways to implement case-insensitive enum mapping in Spring Boot.
Calling JMX MBean Method From a Shell Script
Filed under Core Java
Learn how to access MBeans from a shell script.
How to Insert a HashMap Into MongoDB With Java?
Learn how to insert HashMap into MongoDB.
Limiting the Requests per Second With WebClient
Learn various ways of limiting the request per second of a web client.
Understanding java.lang.Thread.State: WAITING (parking)
Filed under Java Concurrency
Learn what waiting and parking mean for a thread.
Send Array as Part of x-www-form-urlencoded Using Postman
Filed under REST, Spring Web
How to send array data using x-www-form-urlencoded via Postman.
Redis Sentinel vs Clustering
Filed under NoSQL, Persistence
A comparison between Redis Cluster and Redis Sentinel going through some basic concepts.
A Guide to Variables in Postman
Filed under REST
Learn about variables in Postman.
Creating Random Numbers With No Duplicates in Java
Filed under Java Numbers
Learn how to generate unique random numbers efficiently.
Create Date From Unix Timestamp in Java
Filed under Java Dates
Learn how to transform UNIX time to Date depending on the Java version.
Compare Characters in Java
Filed under Core Java
Learn how to compare characters in Java.
What Is “Locked Ownable Synchronizers” in Thread Dump?
Filed under Java Concurrency
What are locked ownable synchronizers and how to read a thread dump using them.
Spring JDBC Batch Inserts
Filed under Spring Persistence
How batch operation can increased insert performance.
Reading JSON From a URL in Java
Filed under JSON
How to read JSON from a URL using core java libraries and third-party libraries.
@Operation vs @ApiResponse in Swagger
Uses and differences between @ApiOperation and @ApiResponse.
Spring Data MongoDB – Configure Connection
Filed under Spring Data
Different ways of setting up a MongoDB connection.
Static vs. Instance Initializer Block in Java
Filed under Core Java
A short article explaining the differences between static and instance instantiation.
Count Documents Using Spring Data MongoDB Repository
Filed under Spring Data
Different ways of counting documents using Spring Data MongoDB.
Spring Data Rest – Serializing the Entity ID
Filed under Spring Data
Different ways of serializing entity ids when using Spring Data Rest.
Spring Boot – Keycloak Integration Testing with Testcontainers
Filed under Spring Security
A step by step guide to test the authentication of a Spring Boot app using Keycloak
Unique Field in MongoDB Document in Spring Data
Filed under NoSQL, Spring Data
Different ways to create unique fields via indexes with Spring Data.
Hibernate’s “Detached Entity Passed to Persist” Error
Filed under Persistence
Explanation about detached entities, why occurs the”Detached Entity Passed to Persist” error occurs and how to prevent it.
Difference Between Flux.create and Flux.generate
Filed under Reactive
Understand the generate() and create() methods of the Flux API.
MongoDB Composite Key With Spring Data
Filed under Spring Data
Simple and compound index, generated and custom ids in MongoDB exemplified by a Spring Data Mongo application.
Unit Test Private Methods in Java
Filed under Testing
Why it’s not a good idea to test a private method and how to do it if it’s extremely necessary.
Using Transactions for Read-Only Operations
Filed under Spring Persistence
An explanation about transactions and a practical example of different approaches to handle read-only transactions.
Starting Spring Boot Application in Docker With Profile
Filed under Docker, Spring Boot
How to start up an application with a specific profile using Docker.
Gradle Build Cache Basics
Filed under Gradle
Local and remote Gradle build cache and how to clear them.
Handle Spring Security Exceptions
Filed under Spring Security
Spring Security handlers for exceptions.
Deduction-Based Polymorphism in Jackson 2.12
Filed under Jackson
How to use Jackson’s type inference.
Convert boolean to int in Java
Filed under Core Java
Different ways to convert a boolean to an integer.
Liquibase vs Flyway
Filed under Persistence
Comparison between Liquibase and Flyway.
Java Error “variable might not have been initialized”
Filed under Core Java
How to solve “variable might not have been initialized” in Java.
Using Nginx as a Forward Proxy
Filed under Networking
Learn how to use Nginx as a forward proxy for any requested location.
Gradle: sourceCompatiblity vs targetCompatibility
Filed under Gradle
Understand the difference between sourceCompatiblity and targetCompatibility Gradle parameters.
Customizing Zuul Exceptions
Filed under Spring Cloud
An example of Zuul filter creation.
Printing Thread Info in Log File Using Log4j2
Filed under Logging
Learn how to print thread info using Log4j2
Javadoc: @see, @link, and @inheritDoc
Filed under Java
A comparison between the @see and @link Javadoc annotations.
Adding EventHandler to JavaFX Button
Filed under Java
Learn how to add a handler event to a button for a JavaFX interface.
Testing LDAP Connections With Java
Filed under Security
Learn how to test an LDAP server using a Java client
Convert a Maven Build to Gradle
Learn how to convert a Maven build to a Gradle build.
A Brief History of the Java Programming Language
Filed under Java
Learn about the history of Java.
Convert String to Float and Back in Java
Filed under Java String
Learn how to convert a String to float and vice versa.
Adding Parameters to Apache HttpClient Requests
Filed under HTTP Client-Side
Learn how to add parameters to HttpClient requests.
Baeldung on Linux
- All
- Administration (6)
- Scripting (3)
- Networking (3)
- Security (2)
- Web (1)
- Search (1)
- Processes (1)
- Installation (1)
- Filesystems (1)
- Files (1)
- File Compression (1)
Locking the Screen on Closing the Laptop Lid in Linux
Filed under Administration
Learn three methods to automatically lock the screen when closing the laptop lid in Linux.
Compression of Multiple Files Individually With gzip
Filed under File Compression
Learn how to use the gzip and gunzip utilities to compress and uncompress files and folders from the command line in Linux. Explore compressing individual files and multiple files in subdirectories using wildcard expansion. Further, discover alternatives to gzip, such as Zip and 7-Zip, and learn about their advantages and differences.
How to Find Filenames That End With a Number in Bash
Filed under Files
This tutorial explores different methods in Bash for finding files with numbered names and processing them efficiently. It covers using wildcards and regular expressions to match numbers at the end of file names, filtering files based on specific criteria, retrieving numbers from file names, and executing commands on the matched files.
How to Automate Mouse Movements Using the Command Line
Filed under Administration
Learn how to use xdotool commands such as mousemove, click, and mousedrag to simulate mouse actions, perform complex operations, and add delays between commands. This tutorial is your go-to resource for efficient mouse automation using xdotool.
Standard Error Codes in Linux
Filed under Processes
This article explores standard error codes in Linux, their significance, and how they aid in troubleshooting since they indicate the cause and type of an error during program or command execution.
How to Set up an SSTP Server on Linux
Filed under Networking
This tutorial is a guide on how to configure a Secure Socket Tunneling Protocol (SSTP) VPN server on Linux using SoftEther VPN Server, an open-source and freeware cross-platform multi-protocol VPN implementation. It covers the installation and configuration of SoftEther VPN on Linux, including software requirements, downloading, compiling the server, and its verification.
Getting Information About Currently Unmounted Drives
Filed under Filesystems
This tutorial explains various Linux commands that provide information about block devices that aren’t mounted, including lsblk, fdisk, and querying the sysfs directory.
Managing Password Complexity in Linux
Filed under Administration, Security
This article provides a tutorial on setting up a firm password policy for Linux systems using Pluggable Authentication Modules (PAM). It covers the configuration files and modules used for password management, as well as password quality, history, aging, and lockout.
Alias a Hostname in Linux
Filed under Administration, Networking
Explore three methods for aliasing hostnames in Linux: using the SSH config file, using environment variables, and editing the /etc/hosts file.
How to Store Standard Error in a Linux Variable
Filed under Scripting
How to redirect standard error output and store it in a variable.
Viewing Apache Enabled Modules in Linux
Filed under Administration, Web
Learn how to view Apache-enabled modules in Linux using the command line.
Set up a Port Forward Using UFW
Filed under Networking, Security
Learn how to use UFW to do port forwarding.
How to Reinstall Apt on Ubuntu/Debian
Filed under Administration, Installation
Learn how to reinstall the apt package on a Ubuntu 20.04 system.
How to Run Multiple Bash Scripts in a Terminal Window
Filed under Scripting
This article explains how to run different scripts sequentially and also how to stop and resume in foreground and background.
List Only Directories in a Linux Path
Filed under Search
Different commands to list only directories on Linux.
Hiding User Input in a Bash Terminal
Filed under Scripting
Different ways to hide user input in Linux scripts.
Baeldung on Scala
- All
- Scala Collections (3)
Merge Two Maps in Scala
Filed under Scala Collections
Learn how to merge two maps in Scala.
Split a Sequence in Scala
Filed under Scala Collections
How to split a sequence using the partition, span, or groupBy functions.
Create an Empty Array in Scala
Filed under Scala Collections
Different ways of creating an empty array in Scala.
Baeldung on Kotlin
- All
- Spring (3)
- Patterns (2)
- Kotlin-Java Interop (1)
- Kotlin Dates (1)
- Kotlin Collections (1)
- Kotlin Classes and Objects (1)
- Kotlin Basics (1)
Converting a Custom Object List to Simple List in Kotlin
Filed under Kotlin Basics, Kotlin Collections
This article demonstrates how to convert a list of objects into a list of strings in Kotlin using various methods, including map(), mapNotNull(), mapTo(), mapIndexed(), for loops, and flatMap().
The Adapter Pattern in Kotlin
Filed under Patterns
The article introduces the Adapter Pattern in Kotlin, a design pattern that enables collaboration between classes with incompatible interfaces. We use an Audio Player example to demonstrate how the pattern works.
Spring Dependency Injection With Kotlin
Filed under Spring
This article discusses Spring dependency injection options available with Kotlin, including Spring’s @Autowired annotation for injecting components. The article provides examples of each option and concludes by emphasizing the importance of proper dependency injection in Kotlin.
Convert Java to Kotlin
Filed under Kotlin-Java Interop
This article explores various ways of converting Java code to Kotlin code, including using IntelliJ IDE or Android Studio, an online tool called JavaInUse, and the advantages of Kotlin over Java. It also discusses the limitations of each method and provides recommendations for when to use them.
Singleton Classes in Kotlin
Filed under Kotlin Classes and Objects, Patterns
What’s a singleton and how to create single instance in Kotlin.
Difference Between Two Dates in Kotlin
Filed under Kotlin Dates
A quick example of how to calculate the difference between two dates using Java 8 built-in classes and Joda time.
Kotlin and Spring Boot @ConfigurationProperties
Filed under Spring
Explore different ways of using Spring @ConfigurationProperties with Kotlin classes.
Spring Boot and Kotlin
Filed under Spring
Learn how to use Kotlin together with Spring Boot 2.x.
Baeldung on Ops
- All
- Docker (3)
- Jenkins (1)
Send Email Notification From Jenkins
Filed under Jenkins
An extensive example about how to configure two different options to send emails using Jenkins.
Configuring a Proxy in Docker
Filed under Docker
Learn how to set up a proxy in Docker.
Pushing a Docker Image to a Private Repository
Filed under Docker
How to push to a private repository creating a new image or tagging an existing repository.
Running Docker Containers Indefinitely
Filed under Docker
A brief explanation about entrypoint and cmd to understand when a container terminates and how we can prevent it.