Optional.ofNullable()
Optional.ofNullable()
in code. With Optional, you can write cleaner and more concise code that is easier
to maintain.
Optional.ofNullable()
The Optional.ofNullable() method returns a Non-empty Optional if a value present in
the given object. Otherwise returns empty Optional. Optional.empty() method is
useful to create an empty Optional object.
Optional<String> opt = Optional.ofNullable("Ramesh");
if (opt.isPresent()) { System.out.println(opt.get().getName());}
orElse
It is used to return the value wrapped in the Optional, if it is present. if the
Optional is empty, It takes a default value from an argument.
String name = Optional.ofNullable(nullName).orElse(new Student("no one", 0,
"Unknown"));
String name = Optional.ofNullable(nullName).orElseGet(() -> "Ramesh");
System.out.println(name);
orElseGet
String name = Optional.ofNullable(nullName).orElseGet(() -> "Ramesh");
System.out.println(name);
orElseThrow
This will throw exception
String name =
Optional.ofNullable(nullName).orElseThrow(IllegalArgumentException::new);
System.out.println(name);
Optional.of()
The Optional.ofNullable() method returns a Non-empty Optional if a value present in
the given object. Otherwise returns java.lang.NullPointerException
Optional<String> opt = Optional.of("Ramesh");
empty()
this method will simply generate an empty Optional (no value ).
Optional<T> empty = Optional.empty();
orElse() vs orElseGet()
orElse() will always call the given function whether you want it or not, regardless
of Optional.isPresent() value
orElseGet() will only call the given function when the Optional.isPresent() ==
false
In real code, you might want to consider the second approach when the required
resource is expensive to get.
-----------------------------------------------------------------------------------
--
JAVA 11 features :
Among other changes, JDK 11 introduces 6 new methods for java.lang.String class:
repeat(int) - Repeats the String as many times as provided by the int parameter
lines() - Uses a Spliterator to lazily provide lines from the source string
isBlank() - Indicates if the String is empty or contains only white space
characters
stripLeading() - Removes the white space from the beginning
stripTrailing() - Removes the white space from the end
strip() - Removes the white space from both, beginning and the end of string
-----------------------------------------------------------------------------------
---
Static---
Memory efficiency: It is allocated memory only once during the execution of the
program, which can resuse.
A Static block code is executed only once when the class is loaded into memory.
Mostly it’s used to create static resources when the class is loaded. We can’t
access non-static variables in the static block.
A static method and attributes, we can access without creating an object of a class
A static method can access only static variables of class and invoke only static
methods of the class.
The static keyword means the value is the same for every instance of the class.
Final---
A final class cannot be subclassed.
A final method can't be overridden by subclasses
A final keyword once the variable is assigned a value it can never be changed.
-----------------------------------------------------------------------------------
------------
Hi, I’m Karthik and I have tatally 8.5 years experience in softwre development. I
specialize in Java, Spring boot, microservices and extensive experience in
Healthcare, Insurance, Automobile and Banking domains. I am passionate about
staying up-to-date with the latest technologies and trends in the industry. My
goal is to continue to develop my skills and work on projects that make a positive
impact on society.
101262492346
About my project,
Currently working on CitiKYC application for last three years and it is used to
validate the customer details before account opening in citi bank.
CitiKYC application is used to validate the customer details before account opening
in citi bank.
This application has different login users and each user has different roles like
KYC Maker, KYC Checker, KYC Owner, Management.
Once login, In the application inbox we can find customer kyc records. Each kyc
record contains different sections like client profile Identification and
verification, Screening Additional and Beneficial members. Once all sections
verified, user able to submit the kyc record to next level user queue. Once passes
all queue's, customer can open the account in citi bank.
we have developed the microservices for each section crud operations by using
springboot, microservices.
code repository maintained by bitbucket. tasks managed by JIRA.
Using jenkins to Build and deployment by tectia, openshift.