[VV91] Java22 for dev, Java Between, TextBlock delimiters, Kubernetes, memento pattern, Kafka Avro compatibility modes
?????Java 22 features for developers
Java 22, released on March 19, 2024, introduced several exciting features and enhancements. Here are some of the key highlights:
??? ?????????????? ?????????????????? & ???????????????? (?????? ??????):
This feature allows for more concise code by using an underscore (_) for variables that are not used, such as in lambda parameters or catch blocks.
???? ???????????? ??????????-???????? ????????????-???????? ???????????????? (?????? ??????):
With this feature, you can run programs consisting of multiple .java files without compiling them in advance.
?? ???????????????????? ???????????? ?????????? (??????????????, ?????? ??????):
This allows code to be executed in constructors before calling super(...) or this(...), with some restrictions.
?? ???????????? ?????????????????? (??????????????, ?????? ??????):
This addition provides a new way to write intermediate stream operations.
?? ?????????????? ???????????????? & ???????????? ?????? (?????? ??????):
After several rounds of incubation and preview, this API has been finalized, offering a standardized way to interact with native code and memory.
?? ???????????????????? ?????????????????????? (???????????? ??????????????, ?????? ??????):
This feature simplifies concurrent programming by treating multiple tasks running in different threads as a single unit of work.
?? ???????????? ???????????? (???????????? ??????????????, ?????? ??????):
Scoped values introduce a new way to manage shared data within a thread or across child threads.
?? ???????????? ?????????????????? (???????????? ??????????????, ?????? ??????):
This feature enhances string manipulation and formatting capabilities.
???? ???????????????????? ???????????????? ?????????????? ?????? ???????????????? ???????? ?????????????? (???????????? ??????????????, ?????? ??????):
Renamed from "Unnamed Classes and Instance Main Methods," this feature has been revised and provides a way to declare classes and main methods implicitly.
These features aim to improve developer productivity, code readability, and application performance.
#java #java22 #features
???JAVA CERTIFICATION QUESTION: Between
Given:
Period p = Period.between(
LocalDate.of( 2023, Month.MAY, 4 ),
LocalDate.of( 2024, Month.MAY, 4 ) );
System.out.println( p );
Duration d = Duration.between(
LocalDate.of( 2023, Month.MAY, 4 ),
LocalDate.of( 2024, Month.MAY, 4 ) );
System.out.println( d );
What is the output?
A)
P1Y
PT8784H
B)
PT8784H
P1Y
C)
UnsupportedTemporalTypeException
D)
P1Y
UnsupportedTemporalTypeException
E)
PT8784H
UnsupportedTemporalTypeException
#java #certificationquestion #ocp
The output is:
P1Y
java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Seconds
at java.base/java.time.LocalDate.until(LocalDate.java:1636)
at java.base/java.time.Duration.between(Duration.java:489)
Period works well with LocalDate, while Duration no.
Because duration works with Time and according to JavaDoc:
"The specified temporal objects must support the SECONDS unit. For full accuracy, either the NANOS unit or the NANO_OF_SECOND field should be supported."
Duration javadoc: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/Duration.html#between(java.time.temporal.Temporal,java.time.temporal.Temporal)
Period javadoc: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/Period.html#between(java.time.LocalDate,java.time.LocalDate)
???JAVA CERTIFICATION QUESTION: TextBlock delimiters
Given:
String textBlock = """
j \
a \t
v \s
a \
""";
System.out.println(textBlock.length()+" "+textBlock.split("\\n").length);
System.out.println(textBlock.length());
What is the output?
10
11
12
14
#java #certificationquestion #ocp
Let's decompose this text block.
The first line is 'j \': a letter 'j', a space ' ', and an escaping end line '\' (so no break line).
So this first line has a length of 2.
The second line is 'a \t': a letter 'a', a space ' ', a tab '\t', and a break line '\n' (implicit).
So this second line has a length of 4.
The third line is 'v \s': a letter 'v', a space ' ', a space '\s', and a break line '\n' (implicit).
So this second line has a length of 4.
The fourth line is 'a \': a letter 'a', a space ' ', and an escaping end line '\' (so no break line).
So this second line has a length of 2.
Oracle Java text block documentation: https://docs.oracle.com/en/java/javase/15/text-blocks/index.html#that-final-new-line
??? QUOTE
?? What is Kubernetes? An Unorthodox Guide for Developers
????????????????????????
????????????, ???????????? ?????????????? & ??????????: ?? ??????????
???????????????????? ??????: ???????????? & ????????????????
????????????????????: ???????????????????? ????????????
?? DESIGN PATTERN: The quiz!
The _____ Pattern is a design pattern that captures and externalizes an object's internal state,
allowing it to be saved and restored later.
It's often used for implementing undo and redo features in applications.
* Pipeline
* Chain of responsibility
* Command
* Memento
#design #pattern #programming #memento #software
The Memento Pattern is a behavioral design pattern in software development that allows you to capture and externalize an object's internal state without exposing its internal structure. This enables you to save and restore the object's state at a later time, providing a way to undo or revert changes.
Key components of the Memento Pattern:
1) Originator: The Originator is the object whose state needs to be saved. It creates a Memento object to represent its state and can restore its state from a Memento.
2) Memento: The Memento is an object that stores the state of the Originator. It has methods to get and set the state but does not reveal the internal details of the Originator.
3) Caretaker: The Caretaker is responsible for keeping track of and managing Memento objects. It can save and retrieve the Originator's state using Mementos.
The Memento Pattern is particularly useful for implementing features like undo and redo functionality in applications, as well as for managing checkpoints and history in various systems. It allows you to capture an object's state at specific points in time and restore it as needed, all while keeping the object's internal details hidden.
??Understanding Kafka Avro Compatibility: FORWARD, BACKWARD, and FULL
When dealing with Kafka and Avro, schema compatibility is crucial.
Compatibility types dictate how schema evolution is handled.
Let’s delve into the three main compatibility kinds: FORWARD, BACKWARD, and FULL.
? FORWARD Compatibility
FORWARD compatibility is ideal when producers need to evolve without waiting for consumers to update.
? BACKWARD Compatibility
BACKWARD compatibility is best when consumers need to evolve without waiting for producers to update.
?? FULL Compatibility
FULL compatibility offers the greatest flexibility but requires careful management to avoid breaking changes.
#kafka #avro #compatibility #forward #backward #full
??chair.exe has stopped working ???
Assistant Project Manager
9 个月Foreign function api. ??