Category Archives: Java 9 Features

Private Methods in Java 9 Interfaces

Java 9 Private Interface Methods: From Java 9 onwards, we can create private non-static/static methods inside an interface. The interface allows us to define private methods that help to share common code between non-abstract/default methods. Prior to Java 9, When you create private methods inside an interface then you will get a compile-time error. Private methods in interfaces have… Read More »

Java 9 SafeVarargs Annotation

@SafeVarargs annotation was introduced in Java7 and can only be applied on: Final methods Static methods Constructors This annotation is used to ensure that the method/Constructors does not perform unsafe operations on its varargs parameters. From Java 9 onwards, it can also be used with private instance methods.

If you run as Java Application… Read More »

Java 9 Try with Resource Enhancement

Java introduced try-with-resources feature in Java 7 that helps to close resources automatically after being used. In other words, we can say that we don’t need to close resources (file, connection etc) explicitly, try-with-resource close that automatically by using the AutoClosable interface. If you look in Java 7 then you will find that try-with-resources has a limitation… Read More »

Java 9 Collection Factory Methods Example

In this post, We will talk and learn about Java 9 Collection Factory Methods Example with a demo project Java 9 has added simple ways to create immutable Collections without null values by providing a set of <Collection>.of methods. The created collection should not have null values and should not be modified later else it… Read More »

Java 9 Stream API improvements

In this post, We will talk and learn about Java 9 Stream API improvements using an example Java 9 added the new APIs for Stream. Java Stream Iterate Method A new overloaded iterate method is added in Java 9 stream interface. This function usually help us to iterate stream elements till the specified condition is true.… Read More »

Java 9 Jshell Tutorial

In this post of Java 9 Jshell Tutorial, we will talk and learn all the concepts related to JSHELL using various examples. What is JShell in Java 9? It is an interactive Java Shell tool that allows us to execute Java code from the shell and shows output immediately.JShell is a REPL (Read Evaluate Print Loop)… Read More »