Learnitweb

Category: Java tutorial

  • 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.…

  • Parallel streams in Java

    1. Introduction Parallel computing entails fragmenting a task into smaller segments, tackling these segments concurrently (in parallel, with each one operating within its own thread), and subsequently combining the outcomes of the individual segment solutions. There is problem in implementing parallelism in Java applications that use collections as collections are not thread-safe. This means that…

  • Epsilon: A No-Op Garbage Collector

    1. Introduction In Java 11, a No-Op Garbage Collector called Epsilon was introduced which handles memory allocation but does not implement any actual memory reclamation mechanism. When the Java heap limit is exhausted, the JVM terminates. Epsilon garbage collector promises lowest possible GC overhead. 2. Enabling Epsilon GC Epsilon GC can be enabled using -XX:+UnlockExperimentalVMOptions…

  • String lines() method in Java

    1. Introduction The signature of the lines() method introduced in Java 11 is: This method returns a stream of lines extracted from the string, separated by line terminators. This method returns a stream which contains the lines from this string in the same order in which they occur in the string. A line terminator is…

  • String strip() method in Java

    1. Introduction The syntax of this method is: This method returns the string after removing returning all its leading and trailing white spaces. This method was added in Java 11. A character is a Java whitespace character if and only if it satisfies one of the following criteria: If the String object represents an empty…