NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Java is not a pure object oriented language because: it has primitive datatype and primitive data type is not an object.
Collections use objects.
Generic classes use objects.
Wrapper class converts primitive datatype to object.

Java features:
-> Funtional Interface
-> Lambda expressions
-> Default and static methods in Interface
-> Stream API
-> Type Inference
-> Methods and Constructor Reference e.g. System.out::println
-> Optional Class
-> Base encode/decode.

What advantages of Java?
Code is more concise and readable
Code is more reusable
Code is more testable and maintainable
Users can write parallel code.
Code is simplified and concise as usage of stream skips implementation class.


Microservice: An architecture wherein an application is divided into smaller modules
that are deployed separately and,
communicate with each other using api,
The services can use different tech.
Scaling the app is easier.
Could be rolled back faster as services are diff.
For large teams.
Fault tolerance.

Monolithic: An architecture wherein an application is a single module that is deployed as a single unit.





What is a functional interface?
A functional interface in Java is an interface that has exactly one abstract method. Since functional interfaces have only one abstract method, they can represent a single functionality that can be implemented by a lambda expression.
Key points about functional interfaces:
-> Single Abstract Method (SAM): A functional interface must contain exactly one abstract method. It can have more than one non-abstract method (default or static methods), but only one abstract method is allowed.

-> @FunctionalInterface Annotation: While it’s not required, it’s good practice to annotate a functional interface with @FunctionalInterface. This annotation ensures that the interface meets the requirements of a functional interface for compiler, If you try to add a second abstract method, the compiler will raise an error.

-> Built-in Functional Interfaces: Java 8 introduced several built-in functional interfaces within the java.util.function package. Some common ones include Predicate<T>, Function<T, R>, Supplier<T>, Consumer<T>, and others.

-> Lambda Expressions: Since functional interfaces have only one abstract method, you can use lambda expressions to provide the implementation of that method directly within the code where it’s needed. For example:
Java.



Name some of the functional interfaces in the standard library.
Some common built-in functional interfaces in Java’s standard library include:
Predicate<T>: Represents a boolean-valued function of one argument.
Function<T, R>: Represents a function that accepts one argument and produces a result.
Supplier<T>: Represents a supplier of results.
Consumer<T>: Represents an operation that accepts a single input argument and returns no result.




What Is the Difference Between a Normal and Functional Interface in Java?
A normal interface can have multiple abstract methods, whereas a functional interface must have exactly one abstract method.
Functional interfaces enable the use of lambda expressions and method references for concise code.



What is a Function interface?
The Function<T, R> interface represents a function that takes an argument of type T and produces a result of type R.

What is a Predicate interface?
The Predicate<T> interface represents a boolean-valued function that takes an argument of type T and returns a boolean result.
Example: filetr();

What is the Consumer interface?
The Consumer<T> interface represents an operation that accepts a single input argument of type T and performs some action without returning a result.

What is the Supplier interface?
The Supplier<T> interface represents a supplier of results (i.e., it produces a value of type T).


test() -> abstract
and(), or(), negate() -> default
isEqual() ` -> static

Abstract: test()

Static Methods:
isEqual(Object targetRef): Returns a predicate that tests if two arguments are equal according to Objects.equals(Object, Object).
Example: Predicate<Integer> isEqualToTen = Predicate.isEqual(10);

Default Methods:
and(Predicate other): Returns a composed predicate that represents a short-circuiting logical AND of this predicate and another.
or(Predicate other): Returns a composed predicate that represents a short-circuiting logical OR of this predicate and another.
negate(): Returns a predicate that represents the logical negation of this predicate.
Example:
Predicate<Integer> greaterThanTen = i -> i > 10;
Predicate<Integer> greaterThanTenAndEven = greaterThanTen.and(i -> i % 2 == 0);
Predicate<Integer> lessThanTwentyOrOdd = greaterThanTen.or(i -> i % 2 != 0);
lessThanTwentyOrOdd.test(number);



Function:
The Function interface represents a transformation from one type to another.
It accepts an argument and produces a result.

apply() -> abstract
andThen() -> default
compose() -> default
identity() -> static


Method 1: apply()
Syntax: apply(T t)
Parameters: This method takes in only one parameter t which is the function argument
Return Type: This method returns the function result.

Example
Function<Integer, Double> half = a -> a / 2.0;
System.out.println(half.apply(10));


Method 2: andThen()
It returns a composed function wherein the function will be executed after the first one.

Example
Function<Integer, Double> half = a -> a / 2.0;
half = half.andThen(a -> 3 * a);
System.out.println(half.apply(10));
//Output 15.0


Method 3: compose()
It returns a composed function wherein the function will be executed first and then the first one.

Example
Function<Integer, Double> half = a -> a / 2.0;
half = half.compose(a -> 2 * a);
System.out.println(half.apply(20));
// Output 20.0


Method 4: identity()
This method returns a function that returns its only argument.

Example
Function<Integer, Integer> i = Function.identity();
System.out.println(i.apply(10));
// Output 10


List<Integer> list=Arrays.asList();
.mapToInt(Integer::intValue).sum();


.
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.