Learnitweb

Category: Java tutorial

  • Preview feature in Java

    1. Introduction A preview feature is a new feature whose design, specification, and implementation are complete, but which is not permanent, which means that the feature may not exist in future JDK release but if exists then may exist in a different form. Every preview feature is described by JDK Enhancement Proposal (JEP). For example,…

  • Comparing file with Files.mismatch() method in Java

    1. Introduction In Java 12, mismatch() method was added to compare two files. This method returns the position of the first mismatched byte in the two files. Two files are considered a match if one of the two following conditions are satisfied: If none of the conditions are satisfied then the files are considered a…

  • Java Teeing Collectors

    1. Introduction In Java 12, method teeing() was added in Collectors. This method returns a Collector that is a composite of two downstream collectors. It allows two different collectors on a stream and then merges their results using a specified BiFunction. The Collectors.teeing() method is useful when we want to simultaneously process a stream in…

  • Compact Number Formatting in Java

    1. Introduction In US locale, you may have seen 1000 written as “1k”, 1000000 as “1M”. Here, “1K” and “1M” are shorter or compact forms. A compact number formatting refers to the representation of a number in a shorter form, based on the patterns provided for a given locale. CompactNumberFormat is a concrete subclass of…

  • Java Flight Recorder

    1. Introduction Java Flight Recorder (JFR) is a tool for collecting diagnostic and profiling data about a running Java application. It is embedded within the Java Virtual Machine (JVM) and introduces minimal performance overhead, making it suitable for use in highly demanding production environments. JFR gathers information about both the JVM and the Java application…

  • Java Predicate.not() method

    1. Introduction In this short tutorial, we’ll discuss the not() method of Predicate Interface. This method was added in Java 11. 2. Syntax static<T> Predicate<T> not​(Predicate<? super T> target) : This method returns a predicate that is the negation of the supplied predicate. This is accomplished by returning result of the calling target.negate(). 3. Example…

  • Java 11 Files.readString() and Files.writeString() methods

    1. Introduction In this tutorial, we’ll discuss two methods added in Java 11 in Files class, readString() and writeString(). 2. Syntax static String readString​(Path path) Reads all content from a file into a string, decoding from bytes to characters using the UTF-8 charset. static String readString​(Path path, Charset cs) Reads all characters from a file…

  • Java 11 Single-File Source-Code Programs

    1. Introduction Java 11 introduced a new feature of launching single-file source-code programs. A single-file program is one where the program fits in a single source file. Before Java 11, to run even a single line program we had to first compile the code and then run the program. For example, to run a HelloWorld.java…

  • The Z Garbage Collector

    1. Introduction In this tutorial, we’ll discuss the Z garbage collector(ZGC) in Java. ZGC is a scalable low-latency garbage collector. In Java 11, ZGC was introduced as an experimental feature. In Java 15, this was included as a product feature in Java after receiving positive feedback and fixing of bugs. ZGC was integrated into JDK…

  • Stream.reduce() in Java

    1. Introduction While working with Java streams, there are many terminal operations (such as sum, min, max, count and average) that return one value by combining the contents of a stream. These operations are called reduction operations. Reduction operations are not limited to returning a single value. Reduction operations can return a collection as well.…