Java 16 Tutorial
Java Other Versions Tutorials
Java 16 Useful Resources
Selected Reading
- Java 16 - Deprecation & Removals
- Java 16 - Other Changes
- Java 16 - Garbage Collectors
- Java 16 - Packaging Tools
- Java 16 - Record
- Java 16 - Warnings for Value-Based Classes
- Java 16 - Pattern Matching for instanceof
- Java 16 - Sealed Classes
- Java 16 - Environment Setup
- Java 16 - Overview
- Java 16 - Home
Java Other Versions Tutorials
- Java 15 Tutorial
- Java 14 Tutorial
- Java 13 Tutorial
- Java 12 Tutorial
- Java 11 Tutorial
- Java 10 Tutorial
- Java 9 Tutorial
- Java 8 Tutorial
- Java Tutorial
Java 16 Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java 16 - Record
Java 16 - Record
Java 14 introduces a new class type record as preview feature to faciptate creation of immutable data objects. Java 15 enhances record type further. With Java 16, record is now a standard feature of JDK.
Consider the following example −
ApiTester.java
Example
pubpc class APITester { pubpc static void main(String[] args) { StudentRecord student = new StudentRecord (1, "Jupe", "Red", "VI", 12); System.out.println(student.id()); System.out.println(student.name()); System.out.println(student); } } record StudentRecord(int id, String name, String section, String className, int age){}
Compile and Run the program
$javac APITester.java $java APITester
Output
1 Jupe StudentRecord[id=1, name=Jupe, section=Red, className=VI, age=12]Advertisements