Java 14 Tutorial
Selected Reading
- Java 14 - Discussion
- Java 14 - Useful Resources
- Java 14 - Quick Guide
- Java 14 - Deprecation & Removals
- Java 14 - Others
- Java 14 - NUMA Aware G1
- Java 14 - Packaging Tools
- Java 14 - NullPointerException
- Java 14 - pattern for instanceOf
- Java 14 - Text Blocks
- Java 14 - Switch Expressions
- Java 14 - Environment Setup
- Java 14 - Overview
- Java 14 - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java 14 - NullPointerException
Java 14 - Helpful NullPointerException
Java 14 introduces NullPointerException with helpful information in case -XX:+ShowCodeDetailsInExceptionMessages flag is passed to JVM.
Example
Consider the following example −
ApiTester.java
pubpc class APITester { pubpc static void main(String[] args) { String message = null; System.out.println(message.length()); } }
Old Way: Compile and Run the program
$javac APITester.java $java APITester
Output
Exception in thread "main" java.lang.NullPointerException at APITester.main(APITester.java:6)
New Way: Compile and Run the program with new Flag
$javac APITester.java $java -XX:+ShowCodeDetailsInExceptionMessages APITester
Output
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.length()" because "<local1>" is null at APITester.main(APITester.java:6)Advertisements