SlideShare a Scribd company logo
JAVA 7.0 NEW FEATURES AN OVERVIEW
New Language features in Java 7.0 Underscores in Numeric Literals Strings in switch Statements Binary Literals Catching Multiple Exception Types Rethrowing Exceptions with Improved Type Checking The try-with-resources Statement Type Inference for Generic Instance Creation
Underscores in Numeric Literals In Java SE 7, Any number of underscore(_) can appear anywhere between digits in numeric literal. The advantage of this feature is to improve the readability of the numeric literals. Compiler ignores these underscores. Few Valid Examples long creditCardNumber = 1234_5678_9012_3456L; float pi = 3.14_15F; long hexBytes = 0xFF_EC_DE_5E; long hexWords = 0xCAFE_BABE; long maxLong = 0x7fff_ffff_ffff_ffffL; byte nybbles = 0b0010_0101; long bytes = 0b11010010_01101001_10010100_10010010;
Underscores in Numeric Literals Underscore can’t be used in following scenarios At the beginning or end of a number Adjacent to a decimal point in a floating point literal Prior to an F or L suffix In positions where a string of digits is expected like 0x
A little Quiz – Valid or Invalid float pi1 = 3_.1415F; float pi2 = 3._1415F; long socialSecurityNumber = 999_99_9999_L; int x1 = _52; int x2 = 5_2; int x3 = 52_; int x4 = 5_______2; int x5 = 0_x52; int x6 = 0x_52; int x7 = 0x5_2; int x8 = 0x52_; int x9 = 0_52; int x10 = 05_2; int x11 = 052_;
Strings in switch Statements In Java SE 7, String object can also be used in the expression of switch statement. Uses String.equals() method to compare String object expression and expression in case labels. Advantages : No need to write too many if-else statements JVM generates efficient bytecode for switch than multiple if-else statements Various different type of objects also could be used depending on their implementation of toString() method.
An Example public String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) { String typeOfDay; switch (dayOfWeekArg) { case "Monday": typeOfDay = "Start of work week"; break; case "Tuesday": case "Wednesday": case "Thursday": typeOfDay = "Midweek"; break; case "Friday": typeOfDay = "End of work week"; break; case "Saturday": case "Sunday": typeOfDay = "Weekend"; break; default: throw new IllegalArgumentException("Invalid day of the week: " + dayOfWeekArg); } return typeOfDay; }
Binary Literals In Java SE 7,  the integral types (byte, short, int, and long) can also be expressed using the binary number system.  To specify a binary literal, add the prefix 0b or 0B to the number. Examples // An 8-bit 'byte' value: byte aByte = (byte)0b00100001; // A 16-bit 'short' value: short aShort = (short)0b1010000101000101; // Some 32-bit 'int' values: int anInt1 = 0b10100001010001011010000101000101; int anInt2 = 0b101; int anInt3 = 0B101; // The B can be upper or lower case. // A 64-bit 'long' value. Note the "L" suffix: long aLong = 0b1010000101000101101000010100010110100001010001011010000101001L;
Binary Literals Advantages (See footnotes for examples): Binary literals can make relationships among data more apparent than they would be in hexadecimal or octal. We can use binary integral constants in code that you can verify against a specifications document, such as a simulator for a hypothetical 8-bit microprocessor. We can use binary literals to make a bitmap more readable.
Catching Multiple Exception Types The catch clause can specify the types of exceptions that the block can handle, and each exception type is separated with a vertical bar (|).  Prior to Java 7.0 catch (IOException ex) { logger.log(ex); throw ex; catch (SQLException ex) { logger.log(ex); throw ex; } In Java 7.0 catch (IOException|SQLException ex) { logger.log(ex); throw ex; }
Catching Multiple Exception Types Contd… Advantages Contains less duplicate code and ultimately reduced amount of bytecode. Bytecode generated by compiling a catch block that handles multiple exception types will be smaller and thus superior. Constraint If a catch block handles more than one exception type, then the catch parameter is implicitly final. In this example, the catch parameter ex is final and therefore you cannot assign any values to it within the catch block.
Rethrowing Exceptions with More Inclusive Type Checking Prior to Java 7.0 if we had to rethrow an exception from a method then we will have to do either of the following ways Putting multiple catch blocks public void rethrowException(String exceptionName) throws FirstException,SecondException { try { if (exceptionName.equals("First")) { throw new FirstException(); } else { throw new SecondException(); } } catch (FirstException e) { throw e; } catch (SecondException e) { throw e; } }
Rethrowing Exceptions with More Inclusive Type Checking Contd… 2. Widening the Exception i.e. catching parent Exception class public void rethrowException(String exceptionName) throws Exception { try { if (exceptionName.equals("First")) { throw new FirstException(); } else { throw new SecondException(); } } catch (Exception e) { throw e; } }
Rethrowing Exceptions with More Inclusive Type Checking Contd… Now Java 7.0 has improved in a way that you can catch wide level of Exception and still keep the narrow exceptions in method defination. Just like below code public void rethrowException(String exceptionName) throws FirstException,SecondException { try { if (exceptionName.equals("First")) { throw new FirstException(); } else { throw new SecondException(); } } catch (Exception e) { throw e; } }
Rethrowing Exceptions with More Inclusive Type Checking Contd… Advantages : Fewer lines of code Calling method of rethrowException(String s) has to only catch narrow and specific exception Compiler can determine that the exception thrown by the statement throw e must have come from the try block, and the only exceptions thrown by the try block can be FirstException and SecondException This analysis is disabled if the catch parameter is assigned to another value in the catch block.
Rethrowing Exceptions with More Inclusive Type Checking Contd… In Java SE 7 and later, when we declare one or more exception types in a catch clause, and rethrow the exception handled by this catch block, the compiler verifies that the type of the rethrown exception meets the following conditions:  The try block is able to throw it. There are no other preceding catch blocks that can handle it.  It is a subtype or supertype of one of the catch clause's exception parameters.
try-with-resources A resource is defined as an object that must be closed after the program is finished with it like streams, connections etc. Any object that implements java.lang.AutoCloseable or java.io.Closeable interface, can be used as a resource The try-with-resources statement is a try statement that declares one or more resources and closes them automatically even if the block completes abruptly. Syntax : try(<resource Declaration A>;<resource Declaration B>;<resource Declaration C>) { … … } catch{} //Use it to catch other exceptions like IllegalArgumentException finally{} //For different business logics
try-with-resources - Example public String readFirstLineFromFile(String path) throws IOException { try (BufferedReader br = new BufferedReader(new FileReader(path))) { return br.readLine(); } } Java 1.6 code public  String readFirstLineFromFileWithFinallyBlock(String path) throws IOException { BufferedReader br = new BufferedReader(new FileReader(path)); try { return br.readLine(); } finally { if (br != null) br.close(); } }
try-with-resources – Contd… Note that the close methods of resources are called in the opposite order of their creation i.e. C , B and then A In a try-with-resources statement, any catch or finally block is run after the resources declared have been closed. Connection, ResultSet and Statement of JDBC 4.1 and higher could be used with try-with-resources statement for automatic closure. Using try-with-resources statement code can be written precisely without writing obvious lines of code like closing a stream.
Type Inference for Generic Instance Creation We can replace the type arguments required to invoke the constructor of a generic class with an empty set of type parameters (<>) as long as the compiler can infer the type arguments from the context. This pair of angle brackets is informally called the diamond. In Java 6.0 Map<String, List<String>> myMap = new HashMap<String, List<String>>();  In Java 7.0 Map<String, List<String>> myMap = new HashMap<>(); Map<String, List<String>> myMap = new HashMap(); // unchecked conversion warning
Type Inference for Generic Instance Creation Contd… But Java SE 7 supports limited type inference for generic instance creation i.e. we can only use type inference if the parameterized type of the constructor is obvious from the context. For example, the following example does not compile:  List<String> list = new ArrayList<>(); list.add(&quot;A&quot;); // The following statement should fail since addAll expects // Collection<? extends String> list.addAll(new ArrayList<>()); In comparison, the following example compiles: List<? extends String> list2 = new ArrayList<>(); list.addAll(list2);
Other Good To know Enhancements Multithreaded class loading modifies the locking mechanism to avoid deadlock. Concurrency The fork/join framework is introduced to efficiently run a large number of tasks using a pool of worker threads  Supports Unicode 6.0 and can accommodate new currencies that are identified by their  ISO 4217  codes Java virtual machine support for non-Java languages Java SE 7 introduces a new JVM instruction that simplifies the implementation of dynamically typed programming languages on the JVM.  Garbage-first collector a server-style garbage collector that replaces the Concurrent Mark-Sweep Collector (CMS).  Java HotSpot virtual machine performance enhancements
Thanks !! Any Queries ?? Write to  [email_address]

More Related Content

PDF
NestJS
PPTX
Threading in C#
PDF
The Art Of Readable Code
PDF
Microservices Design Patterns | Edureka
PPT
JavaScript - An Introduction
PPTX
PDF
Spring Framework - Core
PPSX
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
NestJS
Threading in C#
The Art Of Readable Code
Microservices Design Patterns | Edureka
JavaScript - An Introduction
Spring Framework - Core
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides

What's hot (20)

PDF
Collections Api - Java
PDF
Spring framework core
PPTX
Java DataBase Connectivity API (JDBC API)
PPT
Java Socket Programming
PDF
Introduction to kotlin
PDF
Java Collections API
PPTX
Json Web Token - JWT
PDF
07 java collection
PPTX
Asp.net web api
PPTX
Network programming in java - PPT
PPTX
Php Tutorial
PDF
Spring Security
PDF
Spring Framework
PPT
PPT
Spring ppt
PPS
Jdbc architecture and driver types ppt
PDF
Testing with JUnit 5 and Spring - Spring I/O 2022
PDF
도메인 주도 설계의 본질
PDF
Nest.js Introduction
PDF
ES6 presentation
Collections Api - Java
Spring framework core
Java DataBase Connectivity API (JDBC API)
Java Socket Programming
Introduction to kotlin
Java Collections API
Json Web Token - JWT
07 java collection
Asp.net web api
Network programming in java - PPT
Php Tutorial
Spring Security
Spring Framework
Spring ppt
Jdbc architecture and driver types ppt
Testing with JUnit 5 and Spring - Spring I/O 2022
도메인 주도 설계의 본질
Nest.js Introduction
ES6 presentation
Ad

Similar to Java 7 new features (20)

PDF
Java se 7 new language features
PDF
New Features Of JDK 7
PPT
PPTX
Java 7 & 8 New Features
PPTX
Java 7 - What's New?
PPT
PPT
Java 7
PDF
Java 17
PPT
55 New Features in Java 7
PPT
Java SE 7 New Features and Enhancements
DOCX
Java 7 Dolphin manjula kollipara
PPTX
New features in Java 7
PPTX
Java se7 features
PPT
PPT
New syntax elements of java 7
PPT
Java 7 Language Enhancement
PPT
JDK1.7 features
PPTX
Java7 Features
DOCX
Jist of Java
DOCX
JAVA CONCEPTS AND PRACTICES
Java se 7 new language features
New Features Of JDK 7
Java 7 & 8 New Features
Java 7 - What's New?
Java 7
Java 17
55 New Features in Java 7
Java SE 7 New Features and Enhancements
Java 7 Dolphin manjula kollipara
New features in Java 7
Java se7 features
New syntax elements of java 7
Java 7 Language Enhancement
JDK1.7 features
Java7 Features
Jist of Java
JAVA CONCEPTS AND PRACTICES
Ad

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Spectroscopy.pptx food analysis technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
cuic standard and advanced reporting.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Machine learning based COVID-19 study performance prediction
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
sap open course for s4hana steps from ECC to s4
Spectroscopy.pptx food analysis technology
Spectral efficient network and resource selection model in 5G networks
Building Integrated photovoltaic BIPV_UPV.pdf
MIND Revenue Release Quarter 2 2025 Press Release
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
MYSQL Presentation for SQL database connectivity
Dropbox Q2 2025 Financial Results & Investor Presentation
Advanced methodologies resolving dimensionality complications for autism neur...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Diabetes mellitus diagnosis method based random forest with bat algorithm
cuic standard and advanced reporting.pdf
Understanding_Digital_Forensics_Presentation.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation_ Review paper, used for researhc scholars
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine learning based COVID-19 study performance prediction
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

Java 7 new features

  • 1. JAVA 7.0 NEW FEATURES AN OVERVIEW
  • 2. New Language features in Java 7.0 Underscores in Numeric Literals Strings in switch Statements Binary Literals Catching Multiple Exception Types Rethrowing Exceptions with Improved Type Checking The try-with-resources Statement Type Inference for Generic Instance Creation
  • 3. Underscores in Numeric Literals In Java SE 7, Any number of underscore(_) can appear anywhere between digits in numeric literal. The advantage of this feature is to improve the readability of the numeric literals. Compiler ignores these underscores. Few Valid Examples long creditCardNumber = 1234_5678_9012_3456L; float pi = 3.14_15F; long hexBytes = 0xFF_EC_DE_5E; long hexWords = 0xCAFE_BABE; long maxLong = 0x7fff_ffff_ffff_ffffL; byte nybbles = 0b0010_0101; long bytes = 0b11010010_01101001_10010100_10010010;
  • 4. Underscores in Numeric Literals Underscore can’t be used in following scenarios At the beginning or end of a number Adjacent to a decimal point in a floating point literal Prior to an F or L suffix In positions where a string of digits is expected like 0x
  • 5. A little Quiz – Valid or Invalid float pi1 = 3_.1415F; float pi2 = 3._1415F; long socialSecurityNumber = 999_99_9999_L; int x1 = _52; int x2 = 5_2; int x3 = 52_; int x4 = 5_______2; int x5 = 0_x52; int x6 = 0x_52; int x7 = 0x5_2; int x8 = 0x52_; int x9 = 0_52; int x10 = 05_2; int x11 = 052_;
  • 6. Strings in switch Statements In Java SE 7, String object can also be used in the expression of switch statement. Uses String.equals() method to compare String object expression and expression in case labels. Advantages : No need to write too many if-else statements JVM generates efficient bytecode for switch than multiple if-else statements Various different type of objects also could be used depending on their implementation of toString() method.
  • 7. An Example public String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) { String typeOfDay; switch (dayOfWeekArg) { case &quot;Monday&quot;: typeOfDay = &quot;Start of work week&quot;; break; case &quot;Tuesday&quot;: case &quot;Wednesday&quot;: case &quot;Thursday&quot;: typeOfDay = &quot;Midweek&quot;; break; case &quot;Friday&quot;: typeOfDay = &quot;End of work week&quot;; break; case &quot;Saturday&quot;: case &quot;Sunday&quot;: typeOfDay = &quot;Weekend&quot;; break; default: throw new IllegalArgumentException(&quot;Invalid day of the week: &quot; + dayOfWeekArg); } return typeOfDay; }
  • 8. Binary Literals In Java SE 7,  the integral types (byte, short, int, and long) can also be expressed using the binary number system. To specify a binary literal, add the prefix 0b or 0B to the number. Examples // An 8-bit 'byte' value: byte aByte = (byte)0b00100001; // A 16-bit 'short' value: short aShort = (short)0b1010000101000101; // Some 32-bit 'int' values: int anInt1 = 0b10100001010001011010000101000101; int anInt2 = 0b101; int anInt3 = 0B101; // The B can be upper or lower case. // A 64-bit 'long' value. Note the &quot;L&quot; suffix: long aLong = 0b1010000101000101101000010100010110100001010001011010000101001L;
  • 9. Binary Literals Advantages (See footnotes for examples): Binary literals can make relationships among data more apparent than they would be in hexadecimal or octal. We can use binary integral constants in code that you can verify against a specifications document, such as a simulator for a hypothetical 8-bit microprocessor. We can use binary literals to make a bitmap more readable.
  • 10. Catching Multiple Exception Types The catch clause can specify the types of exceptions that the block can handle, and each exception type is separated with a vertical bar (|). Prior to Java 7.0 catch (IOException ex) { logger.log(ex); throw ex; catch (SQLException ex) { logger.log(ex); throw ex; } In Java 7.0 catch (IOException|SQLException ex) { logger.log(ex); throw ex; }
  • 11. Catching Multiple Exception Types Contd… Advantages Contains less duplicate code and ultimately reduced amount of bytecode. Bytecode generated by compiling a catch block that handles multiple exception types will be smaller and thus superior. Constraint If a catch block handles more than one exception type, then the catch parameter is implicitly final. In this example, the catch parameter ex is final and therefore you cannot assign any values to it within the catch block.
  • 12. Rethrowing Exceptions with More Inclusive Type Checking Prior to Java 7.0 if we had to rethrow an exception from a method then we will have to do either of the following ways Putting multiple catch blocks public void rethrowException(String exceptionName) throws FirstException,SecondException { try { if (exceptionName.equals(&quot;First&quot;)) { throw new FirstException(); } else { throw new SecondException(); } } catch (FirstException e) { throw e; } catch (SecondException e) { throw e; } }
  • 13. Rethrowing Exceptions with More Inclusive Type Checking Contd… 2. Widening the Exception i.e. catching parent Exception class public void rethrowException(String exceptionName) throws Exception { try { if (exceptionName.equals(&quot;First&quot;)) { throw new FirstException(); } else { throw new SecondException(); } } catch (Exception e) { throw e; } }
  • 14. Rethrowing Exceptions with More Inclusive Type Checking Contd… Now Java 7.0 has improved in a way that you can catch wide level of Exception and still keep the narrow exceptions in method defination. Just like below code public void rethrowException(String exceptionName) throws FirstException,SecondException { try { if (exceptionName.equals(&quot;First&quot;)) { throw new FirstException(); } else { throw new SecondException(); } } catch (Exception e) { throw e; } }
  • 15. Rethrowing Exceptions with More Inclusive Type Checking Contd… Advantages : Fewer lines of code Calling method of rethrowException(String s) has to only catch narrow and specific exception Compiler can determine that the exception thrown by the statement throw e must have come from the try block, and the only exceptions thrown by the try block can be FirstException and SecondException This analysis is disabled if the catch parameter is assigned to another value in the catch block.
  • 16. Rethrowing Exceptions with More Inclusive Type Checking Contd… In Java SE 7 and later, when we declare one or more exception types in a catch clause, and rethrow the exception handled by this catch block, the compiler verifies that the type of the rethrown exception meets the following conditions: The try block is able to throw it. There are no other preceding catch blocks that can handle it. It is a subtype or supertype of one of the catch clause's exception parameters.
  • 17. try-with-resources A resource is defined as an object that must be closed after the program is finished with it like streams, connections etc. Any object that implements java.lang.AutoCloseable or java.io.Closeable interface, can be used as a resource The try-with-resources statement is a try statement that declares one or more resources and closes them automatically even if the block completes abruptly. Syntax : try(<resource Declaration A>;<resource Declaration B>;<resource Declaration C>) { … … } catch{} //Use it to catch other exceptions like IllegalArgumentException finally{} //For different business logics
  • 18. try-with-resources - Example public String readFirstLineFromFile(String path) throws IOException { try (BufferedReader br = new BufferedReader(new FileReader(path))) { return br.readLine(); } } Java 1.6 code public String readFirstLineFromFileWithFinallyBlock(String path) throws IOException { BufferedReader br = new BufferedReader(new FileReader(path)); try { return br.readLine(); } finally { if (br != null) br.close(); } }
  • 19. try-with-resources – Contd… Note that the close methods of resources are called in the opposite order of their creation i.e. C , B and then A In a try-with-resources statement, any catch or finally block is run after the resources declared have been closed. Connection, ResultSet and Statement of JDBC 4.1 and higher could be used with try-with-resources statement for automatic closure. Using try-with-resources statement code can be written precisely without writing obvious lines of code like closing a stream.
  • 20. Type Inference for Generic Instance Creation We can replace the type arguments required to invoke the constructor of a generic class with an empty set of type parameters (<>) as long as the compiler can infer the type arguments from the context. This pair of angle brackets is informally called the diamond. In Java 6.0 Map<String, List<String>> myMap = new HashMap<String, List<String>>(); In Java 7.0 Map<String, List<String>> myMap = new HashMap<>(); Map<String, List<String>> myMap = new HashMap(); // unchecked conversion warning
  • 21. Type Inference for Generic Instance Creation Contd… But Java SE 7 supports limited type inference for generic instance creation i.e. we can only use type inference if the parameterized type of the constructor is obvious from the context. For example, the following example does not compile: List<String> list = new ArrayList<>(); list.add(&quot;A&quot;); // The following statement should fail since addAll expects // Collection<? extends String> list.addAll(new ArrayList<>()); In comparison, the following example compiles: List<? extends String> list2 = new ArrayList<>(); list.addAll(list2);
  • 22. Other Good To know Enhancements Multithreaded class loading modifies the locking mechanism to avoid deadlock. Concurrency The fork/join framework is introduced to efficiently run a large number of tasks using a pool of worker threads Supports Unicode 6.0 and can accommodate new currencies that are identified by their  ISO 4217  codes Java virtual machine support for non-Java languages Java SE 7 introduces a new JVM instruction that simplifies the implementation of dynamically typed programming languages on the JVM. Garbage-first collector a server-style garbage collector that replaces the Concurrent Mark-Sweep Collector (CMS). Java HotSpot virtual machine performance enhancements
  • 23. Thanks !! Any Queries ?? Write to [email_address]

Editor's Notes

  • #4: It can be used like a comma generally used for punctuation in numbers or separating a number in groups only for readability purposes 0xCAFEBABE is in the class file format, and 0xCAFEDEAD is in the persistent object format.
  • #5: Underscore can’t be used in following scenarios
  • #6: float pi1 = 3_.1415F; // Invalid; cannot put underscores adjacent to a decimal point float pi2 = 3._1415F; // Invalid; cannot put underscores adjacent to a decimal point long socialSecurityNumber = 999_99_9999_L; // Invalid; cannot put underscores prior to an L suffix int x1 = _52; // This is an identifier, not a numeric literal int x2 = 5_2; // OK (decimal literal) int x3 = 52_; // Invalid; cannot put underscores at the end of a literal int x4 = 5_______2; // OK (decimal literal) int x5 = 0_x52; // Invalid; cannot put underscores in the 0x radix prefix int x6 = 0x_52; // Invalid; cannot put underscores at the beginning of a number int x7 = 0x5_2; // OK (hexadecimal literal) int x8 = 0x52_; // Invalid; cannot put underscores at the end of a number int x9 = 0_52; // OK (octal literal) int x10 = 05_2; // OK (octal literal) int x11 = 052_; // Invalid; cannot put underscores at the end of a number
  • #7: Paste an example for 3 rd advantage as well
  • #10: 1. public static final int[] phases = { 0b00110001, 0b01100010, 0b11000100, 0b10001001, 0b00010011, 0b00100110, 0b01001100, 0b10011000 } In hexadecimal, the relationship among the numbers is not readily apparent: public static final int[] phases = { 0x31, 0x62, 0xC4, 0x89, 0x13, 0x26, 0x4C, 0x98 } 2. public State decodeInstruction(int instruction, State state) { if ((instruction &amp; 0b11100000) == 0b00000000) { final int register = instruction &amp; 0b00001111; switch (instruction &amp; 0b11110000) { case 0b00000000: return state.nop(); case 0b00010000: return state.copyAccumTo(register); case 0b00100000: return state.addToAccum(register); case 0b00110000: return state.subFromAccum(register); case 0b01000000: return state.multiplyAccumBy(register); case 0b01010000: return state.divideAccumBy(register); case 0b01100000: return state.setAccumFrom(register); case 0b01110000: return state.returnFromCall(); default: throw new IllegalArgumentException(); } } else { final int address = instruction &amp; 0b00011111; switch (instruction &amp; 0b11100000) { case 0b00100000: return state.jumpTo(address); case 0b01000000: return state.jumpIfAccumZeroTo(address); case 0b01000000: return state.jumpIfAccumNonzeroTo(address); case 0b01100000: return state.setAccumFromMemory(address); case 0b10100000: return state.writeAccumToMemory(address); case 0b11000000: return state.callTo(address); default: throw new IllegalArgumentException(); } } } 3. public static final short[] HAPPY_FACE = { (short)0b0000011111100000; (short)0b0000100000010000; (short)0b0001000000001000; (short)0b0010000000000100; (short)0b0100000000000010; (short)0b1000011001100001; (short)0b1000011001100001; (short)0b1000000000000001; (short)0b1000000000000001; (short)0b1001000000001001; (short)0b1000100000010001; (short)0b0100011111100010; (short)0b0010000000000100; (short)0b0001000000001000; (short)0b0000100000010000; (short)0b0000011111100000; }
  • #18: The Closeable interface extends theAutoCloseable interface. The close method of the Closeable interface throws exceptions of type IOException while the close method of the AutoCloseable interface throws exceptions of type Exception. Consequently, subclasses of the AutoCloseable interface can override this behavior of the close method to throw specialized exceptions, such as IOException, or no exception at all. Multiple resource declarations are separated by semicolon(;) in try() Normal catch and finally block could be used as well in the same manner as prior to Java 7.0
  • #19: However, in this example, if the methods readLine and close both throw exceptions, then the method readFirstLineFromFileWithFinallyBlock throws the exception thrown from the finally block; the exception thrown from the try block is suppressed. In contrast, in the example readFirstLineFromFile, if exceptions are thrown from both the try block and the try-with-resources statement, then the method readFirstLineFromFile throws the exception thrown from the tryblock; the exception thrown from the try-with-resources block is suppressed. In Java SE 7 and later, we can retrieve suppressed exceptions.