Java 8 features - class 21- UnaryOperator interface and BinaryOperator interface in detail

Published: 18 September 2024
on channel: Learn Java
186
7

You can learn Java with me as the Java Programming language is being made easily. It would take a period of minimum three months and maximum 6 months to master Java. I would recommend you to watch all my videos to crack any software interviews that would require Java Programming language as a primary skill.

UnaryOperators and BinaryOperators:-
==================================
Please be informed that the UnaryOperator T interface is a part of the java.util.function package. It is a functional interface that represents an operation on a single operand that produces a result of the same type. Essentially, it is a specialized version of the Function T, R interface where the input and output types are the same.
Key Points:-
===========
Functional Interface: UnaryOperator can be used as the assignment target for a lambda expression or method reference.
Primitive versions of UnaryOperator:-
===================================
The primitive versions of this interface to improve performance by avoiding the overhead of boxing and unboxing. These primitive versions are:
IntUnaryOperator: For int values.
================================
@FunctionalInterface
public interface IntUnaryOperator {
int applyAsInt(int operand);
}
LongUnaryOperator: For long values.
==================================
@FunctionalInterface
public interface LongUnaryOperator {
long applyAsLong(long operand);
}
DoubleUnaryOperator: For double values.
======================================
@FunctionalInterface
public interface DoubleUnaryOperator {
double applyAsDouble(double operand);
}

BinaryOperator:-
============
Please be informed that the BinaryOperator T interface is part of the java.util.function package. It represents an operation on two operands of the same type that produces a result of the same type. Essentially, it's a specialized version of the BiFunction T, U, R interface where the input types are the same.
Key Points:
=========
Functional Interface: BinaryOperator can be used as the assignment target for a lambda expression or method reference.

Primitive Versions of BinaryOperators:-
================================
There are primitive versions of the BinaryOperator interface designed to improve performance by avoiding the overhead of boxing and unboxing for primitive types. The primitive versions of BinaryOperator are:
IntBinaryOperator: For int values.
===========================
@FunctionalInterface
public interface IntBinaryOperator {
int applyAsInt(int left, int right);
}
LongBinaryOperator: For long values.
===============================
@FunctionalInterface
public interface LongBinaryOperator {
long applyAsLong(long left, long right);
}
DoubleBinaryOperator: For double values.
==================================
@FunctionalInterface
public interface DoubleBinaryOperator {
double applyAsDouble(double left, double right);
}


On this page of the site you can watch the video online Java 8 features - class 21- UnaryOperator interface and BinaryOperator interface in detail with a duration of hours minute second in good quality, which was uploaded by the user Learn Java 18 September 2024, share the link with friends and acquaintances, this video has already been watched 186 times on youtube and it was liked by 7 viewers. Enjoy your viewing!