Learnitweb

Category: Java tutorial

  • The guide to jlink in Java

    1. Introduction The jlink tool is used to link a set of modules, along with their transitive dependencies, to create a custom runtime image. The jlink enables you to generate a custom runtime image that contains only the required platform modules for an application. You can use the jlink tool to assemble and optimize a…

  • Aggregator module in Java

    1. Introduction Sometimes there is requirement to group related modules so that these can be read as a group. Else, each module needs to be read individually. That is why it is better to group related modules. We can group the related common modules in a single module, and we can read this module directly.…

  • Module resolution and module path

    1. Introduction Before Java 9, the scan of the whole classpath was required to search for a type. The classpath is a flat list of types. In Java 9, the modules are resolved from module path which contains only modules. The Java runtime and compiler are able to look for the module in the module…

  • requires static in Java

    1. Introduction The requires static is used to define compile-time dependencies. The compile-time dependencies are required only during the compile time. Sometimes our code may have a dependency on another module, but only at the compile-time. The users of our code may not want to include the unwanted module on which our module depends. In…

  • requires transitive in java

    1. Introduction In this tutorial, we’ll discuss the requires transitive. Before starting the discussion, let us discuss what is transitive dependency. Suppose there are three entities, A, B and C such that the following statements are correct: Then the functional dependency A -> C represents a transitive dependency. By default a transitive accessibility is not…

  • Accessibility of class with Java module

    1. Introduction In this tutorial, we’ll discuss the accessibility of classes within a module. We’ll discuss different cases with the help of public class in a module and accessing this class from another module. For this tutorial, the two modules are moduleA and moduleB. The two packages are pack1 and pack2. pack1 is in moduleA…

  • Java module with example

    1. Introduction In Java, a module is a unit of organization for Java code introduced in Java 9 as part of the Java Platform Module System (JPMS). It encapsulates a set of related packages and resources, providing a way to define dependencies and access controls between different parts of a Java application. Each module should…

  • Stream ofNullable method in Java

    1. Introduction The signature of the method is: This method produces a sequential Stream comprising one element if it’s not null; otherwise, returns an empty Stream. This method is helpful in dealing with null values in the stream. The main advantage of this method is that can avoid NullPointerException and null checks everywhere. 2. Example…

  • Stream iterate method in Java

    1. Introduction There are two overloaded versions of iterate method: 1. static <T> Stream<T> iterate​(T seed, UnaryOperator<T> f) : This was available in Java 8. This method takes an initial value and a function that provides next value. This method returns an infinite sequential ordered Stream produced by iterative application of a function f to…

  • Stream dropWhile method in Java

    1. Introduction The dropWhile method was added in Stream interface in Java 9. It is a default method. Following is the signature of dropWhile method: It is the opposite of takeWhile method. It drops elements instead of taking them as long as predicate returns true. Once predicate returns false then rest of the Stream will…