JavaNewFeaturesGroup3
JavaNewFeaturesGroup3
JAVA NEW
FEATURES
Made by: GROUP 3
Akshat Pandey(2300430100006) Rishabh Pandey(2300430100052)
Prasoon Tiwari(2300430100045) Sarthak Kesarwani(2300430100058)
Pushpendra(2300430100049)
TOPICS DISCUSSED:
01 02 03
Try-with-resources Type Annotations and Java Module System
Repeating Annotations
page: 3 page: 4-5 page: 6-7
04 05 06
Diamond Syntax, Local Switch Expressions Text Blocks, Records,
Variable Type and Yield Keyword Sealed Classes
Inference
page: 8-9 page: 10 page: 11-12
TRY-WITH-RESOURCES
Try-with-resources is a feature Example:
introduced in Java 7 that allows try (ResourceType resource
you to automatically close = new ResourceType()) {
resources (like files, sockets, or // Use the resource
database connections) after } catch (Exception e) {
e.printStackTrace();
usage. It works with any class
}
that implements the // The resource is
AutoCloseable or Closeable automatically closed after
interface. It explicits the need try-block execution
for finally blocks to close
resources.
TYPE ANNOTATIONS
Type Annotations allow annotations to be used anywhere a type is used. They
provide better code analysis, error detection, and runtime checks.
You can use these in the following ways:
Person p = new
Key Features:
Person("Alice", 25);
Less boilerplate for data classes
System.out.println(p.name()
Immutable fields (final) ); // Alice
Useful for Data Transfer Objects System.out.println(p);
// Person[name=Alice,
age=25]