java 9 - topjavatutorial.com

JShell – Java 9 REPL

JShell JDK 9 is planning to add JShell for REPL(Read-Eval-Print Loop) functionality in Java platform. JShell is a command-line tool for quickly running statements. JShell provides a way to interactively evaluate declarations, statements, and expressions in Java. So, we don’t need to create a class with main method to test some code.   Getting started […]

java 9 - topjavatutorial.com

Java 9 : Try-with-Resources enhancement

try-with-resources Statement Java 7 added a new feature try-with-resources that automates resource management. It looks like this : try (Resource r1 = new Resource("resource1"); Resource r2 = new Resource("resource1")) {   // use the resource } When the try block ends, the resource is automatically released. Example : private void readFile() throws IOException {   int i; […]

java 9 - topjavatutorial.com

Java 9 : Convenience Factory methods List.of(), Set.of() and Map.of() for creating immutable collections

Java 9 added new static factory methods on the List, Set, and Map interfaces make it simpler to create immutable instances of those collections. Set.of() for creating immutable Set Map.of() for creating immutable Map List.of() for creating immutable List   Immutable Set using Set.of() Creating a small immutable Collection in Java using the traditional way […]

java 9 - topjavatutorial.com

Java 9 : Private Interface Methods

What are Private Methods in an Interface ? Java 8 introduced the concept of default methods in Interface. It basically lets us provide a default implementation for a method in an interface. For example : public interface MyInterface {   // default method   default void hello(String name) {     System.out.println("Hello " + name);   } } So, unless […]