Topic: General Level: All
Welcome to the world of cutting-edge technology! Every bi-week, we bring you the latest and most incredible advancements in the tech industry that are sure to leave you feeling inspired and empowered.
Stay ahead of the game and be the first to know about the newest innovations shaping our world. Discover new ways to improve your daily life, become more efficient, and enjoy new experiences.
This time, we've got some exciting news to share with you!
A simple Java program to print "Hello, World" is verbose and lot of constructs to be aware of,
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
How about,
Anonymous main class with main declaration,
class HelloWorld {
void main() {
System.out.println("Hello, World!");
}
}
If there are competing main methods of the class, then the preferential precedence is,
1. public static void main(String[] args)
2. static void main(String[] args)
3. static void main()
4. void main(String[] args)
5. void main()
An anonymous main class is always a member of the unnamed package. It is also final and cannot implement any interface nor extend any class other than Object. An anonymous main class cannot be referenced by name, so there can be no method references to its static methods; the this keyword can still be used, however, and so can method references to instance methods.
No code can refer to an anonymous class by name, so instances of an anonymous main class cannot be constructed directly. Such a class is useful only as a standalone program or as an entry point to a program. Therefore, an anonymous main class must have a main method that can be launched as described above. This requirement is enforced by the Java compiler.
Top-level members are interpreted as members of the anonymous class, so we can also write the program as:
String greeting() { return "Hello, World!"; }
void main() {
System.out.println(greeting());
}
or, using a field, as:
String greeting = "Hello, World!";
void main() {
System.out.println(greeting);
}
JDK 9 has introduced two intermediate operations on the Stream API processing namely,
1. dropWhile - drops the element of the stream as long the predicate holds, else the elements are passed through
2. takeWhile - passes the elements downstream as long as the predicate holds, and drops unless otherwise
Both these intermediate operations produce deterministic results when applied to an ordered collection. If the elements of the stream are unordered then the output is nondeterministic.
The rationale for this deviation in processing ordered and unordered collection stems from the design of dropWhile and takeWhile, the predicates defined act as a barrier point after which the stream is not deemed for processing once the predicate is violated on the very first instance.
The Dispatcher servlet in mapping the URLs to the respective controller has become stringent, which means
GET /some/greeting” and “GET /some/greeting/are not identical as earlier.
Handling trailing slashes has changed in Spring Boot 3, however, there are ways to make it interoperable as this tutorial states,
1. By adding a mapping URL
2. Override the default WebMvcConfigurer/WebFluxConfigurer
3. Redirect via a Custom filter/WebFilter
With the introduction of deconstruction patterns on records and pattern-matching variables, there is often the case that we have unused variables in the code, enter Unnamed Patterns and Variables.
Using _ (underscore) representation, to assign the variable and referencing it would cause compile time error.
Unnamed variables can be used in,
1. Local variable declaration
2. Try with resources
3. Catch exception parameter
4. Lambda parameter
5. For loop variable
Unnamed pattern variables can be used in,
1. Pattern variables with explicit types
Unnamed pattern,
1. Just replace it with _ which binds nothing and matches everything (doesn't matter because we can not reference the variable)
JEP 443 - https://openjdk.org/jeps/443
The Jakarta EE Platform is organized into a collection of APIs, or technically, specifications. These are documents that explain what each specification does and how to use it. Think of specification documents as the manual for each API. Becoming proficient entails being able to take advantage of the specification docs.
For working with dates at the persistence layer we can utilize the Hibernate annotations
1. CreationTimestamp - Creates a new entry of the defined type when persisting the entity object
2. UpdateTimestamp - Updates the column field entry with the current date type defined when the underlying entity is updated
These annotations can be applied at the FIELD level with types belonging to Timestamp, DateTime, and Instant types.
These annotations are programmatically bound within the transaction context, meaning external SQL DML won't have any effect. And by default tied to the JVM date specification, which can be altered using the meta parameter below
CreationTimestamp(source = SourceType.DB)
UpdateTimestamp(source = SourceType.DB)
Multiple FIELDS with the timestamp annotation might have varying dates when persisting the underlying entity as Instant calculates the date respective to each field on persistence however to have a unified date JPA @PrePersist and @PreUpdate callbacks can be used
JUnit5's Timeout annotation can be applied at the method level and class level subjected to the test.
The variants of this annotation declaration are,
1. Timeout(1) - taking in the value
2. Timeout(value = 2, unit = TimeUnit.MINUTES) - value with units
3. Timeout(value = 5, unit = TimeUnit.MINUTES, threadMode = Timeout.ThreadMode.SEPARATE_THREAD) - execute the test in a separate thread without blocking
4. Declaration at the class level and method level, with precedence at the method-specific level
5. Combined with Nested annotation for inner test class declaration
6. Combined with ParameterizedTest annotation supplying arguments to the underlying test
Externalizing application properties offers benefits like modularization, internationalization, non-agnostic application behaviour, isolated application compilation/deployment, and centralized property management.
The default standard for defining application properties is to categorize based on the deployment environment, however, to provide a further gradual definition we can have multiple properties files and programmatically load them on the start-up via,
1. setAdditionalProfiles to SpringApplication on the ConfigurationProperties annotated class
2. PropertySources with ConfigurationProperties annotations taking in a factory of PropertySourceFactory implementation
A brief explanation of the JEPs relieved as part of JDK20 on various projects ie., Loom, Amber and Panama and other minor good-to-know improvements
Demo on features of Project Panama interconnecting the JVM and non-Java APIs
Disclaimer:
This is a personal blog. Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in a professional or personal capacity, unless explicitly stated. Any views or opinions are not intended to malign any religion, ethnic group, club, organization, company, or individual. All content provided on this blog is for informational purposes only. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.
Downloadable Files and ImagesAny downloadable file, including but not limited to pdfs, docs, jpegs, pngs, is provided at the user’s own risk. The owner will not be liable for any losses, injuries, or damages resulting from a corrupted or damaged file.- Comments are welcome. However, the blog owner reserves the right to edit or delete any comments submitted to this blog without notice due to :
- Comments deemed to be spam or questionable spam.
- Comments including profanity.
- Comments containing language or concepts that could be deemed offensive.
- Comments containing hate speech, credible threats, or direct attacks on an individual or group.
Comments
Post a Comment