Learnitweb

Category: Java tutorial

  • Method references in Java

    Method references are a special type of lambda expressions. This feature was introduced in Java 8. Method references are often used to create simple lambda expressions by referencing existing methods. We use lambda expressions to create anonymous methods. Sometimes, a lambda expression does nothing but calls an existing method. In such cases, method references can…

  • Primitive type functional interfaces

    Before we start, we should spend a minute to see what is autoboxing and unboxing. Autoboxing is the automatic conversion that the Java compiler does between the primitive types and their corresponding object wrapper classes. For example, converting an int to an Integer. Converting an object of a wrapper type to its corresponding primitive value…

  • BiConsumer interface in Java

    BiConsumer interface was introduced in Java 8. This interface is available in java.util.function package. BiConsumer represents an operation that accepts two arguments and return no result. BiConsumer is similar to the Consumer interface with the difference that BiFunction accepts two arguments whereas Consumer accepts only one. BiConsumer is expected to process the data and thus…

  • BiFunction interface in Java

    BiFunction interface was introduced in Java 8 and is available in java.util.function package. BiFunction represents a function that accepts two arguments and produces a result. BiFunction is similar to Function interface with the difference that BiFunction accepts two arguments whereas Function arguments accepts one argument. Methods in BiFunction interface default<V> BiFunction<T,U,V> andThen(Function<? super R,? extends…

  • BiPredicate interface in Java

    BiPredicate is a functional interface introduced in JDK 8. This interface is provided in java.util.function package. BiPredicate operates on two arguments and returns a boolean based on a condition. It is a functional interface and thus can be used in lambda expression also. BiPredicate is same as Predicate with the difference that it takes two…

  • Supplier interface in Java

    Supplier is a functional interface introduced in Java 8 and available in java.util.function package. This interface has functional method get(). Supplier does not take a argument and returns a result every time it is called. Here, T represents the type of the result. The supplier can be used in cases where there is no input…

  • Consumer interface in Java

    Consumer interface is predefined functional interface available in Java 8. This interface is available in java.util.function package. This interface represents an operation which accepts an input argument and does not return a result. Consumer interface has one functional method void accept(T t). There is another default method in Consumer interface: default Consumer andThen(Consumer after) void…

  • Function interface in Java 8

    java.util.function.Function is part of java.util.function package. In Java 8, Function is a functional interface. It accepts one argument(object of type T) and produces a result (object of type R). Here, T is the Type of input to the function. R is the type of result of the function. In addition to abstract method apply(), this…

  • @Override annotation in Java

    @Override annotation was introduced in Java 1.5. @Override annotation indicates that the element is meant to override an element declared in super class. It is not required to use this annotation while overriding a method, but using @Override annotation helps in preventing errors. If you do not override a method marked with @Override correctly, the…

  • @Deprecated annotation in Java

    Over the time libraries, frameworks and APIs change. With every change comes the easy and simpler way of writing code. Whenever there is a change, we might not want people to use our old program elements like methods, constructors, fields and types. Such elements may be annotated as @Deprecated. @Deprecated annotation indicates that the marked…