Posts

Showing posts from September, 2025

Java 8 Specific Best Practices to secure Application

Use of Optional Keyword 5.1 What Optional is? ‘Optional’ is a keyword introduced in Java8 which has the potential of removing the in-famous NullPointerException. Essentially, it is a wrapper class which contains an optional value and hence it can either contain an object or it can be empty. Lets start using a simple use case where in we see that before Java 8, any number of operations involving accessing an object’s methods or properties could lead to a NullPointerException. A classic example of this is –  String ISBNNumber = book.getPublisher().getISBN().toUpperCase(); If we want to ensure that we don’t get the NullPointerException then we need to write our code as under –  if (book != null) { Publisher publisher = book.getPublisher(); If (publisher != null) { String isBNNumber = publisher.getISBN(); If (isBNNumber != null) { String ISBNNumber = isBNNumber.toUpperCase(); } } } As seen above, if we want to ensure that there is no NullPointerException we ne...