Listing All Files in a Directory in Java
In this example, we will learn to use java 8 APIs along with Files.list() and DirectoryStream to list all files present in that directory.
In this example, we will learn to use java 8 APIs along with Files.list() and DirectoryStream to list all files present in that directory.
Learn to register for changes in a directory, sub-directories and files using the Java WatchService API, handle the changes and cancel it.
Learn to convert a string to date in Java 8 using the new date time API classes such as LocalDate, LocalDateTime, ZonedDateTime and DateTimeFormatter. 1. Convert string to date in ISO8601 format By default, java dates are in ISO8601 format, so if you have any string which represents a date …
All of us must have encountered NullPointerException in our applications. It happens when you try to use an object that has not been initialized, initialized with null or does not point to any instance. In simple words, NULL simply means ‘absence of a value’. In this Java tutorial, we will …
Java 8 introduced ‘java.util.Base64‘ utility class that provides built-in support for performing base64 encoding and decoding operations as specified in RFC 4648 and RFC 2045. Let us explore Base64 encode and decode processes with various usecases with examples. 1. What is Base64? Base64 is a binary-to-text encoding scheme that converts …
In this Java tutorial, we will learn to read a text file line-by-line methods such as Streams or FileReader. We will also learn to iterate through lines and filter the file content based on some conditions. 1. Files.lines() – Stream through Lines of a File in Java 8 The Files.lines() …
Java 8 has brought many awesome features for java developers. Some of them I have already described in Comparator changes, Streams examples, Internal vs. external iterations, predicates, functional interfaces, default methods, lambda expressions and date and time API changes. All above changes were related to lambda expressions, which is the …
Since Java 8, we can use String.join() method to concatenate strings with a specified delimiter. For advanced usages, use StringJoiner class.
Learn to create a Comparator instance with lambda expressions, method references and chaining multiple comparators for complex comparisons.
Learn the difference between internal iteration and external iteration in Java with examples. 1. External Iteration Till Java 7, the collections framework relied on the concept of external iteration where the Collection provides a means to enumerate its elements by implementing the Iterator interface. The clients use the iterator to …
Java Predicates are boolean-valued statements that may be true or false depending on the test argument. Predicates are used to filter Streams.
In previous post, we learned about Lambda expressions and functional interfaces. Now, let’s move on the discussion and talk about another related feature i.e. default methods. Well, this is truly revolutionary for java developers. Till java 7, we have learned a lot of things about interfaces and all those things …
Lambda expressions are known to many of us who have worked on advanced languages like Scala. The term “lambda” has its origin in Lambda calculus that uses the Greek letter lambda (λ) to denote a function abstraction. Lambda expressions were introduced to Java as part of Java 8 release. 1. What are …
Java 8 contains the new Date and Time APIs/classes (JSR-310), called ThreeTen, which will change how you have been handling dates in Java.
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.