Raja has Published 760 Articles

How to create scratch variables in JShell in Java 9?

raja

raja

Updated on 27-Feb-2020 12:18:55

256 Views

JShell is a REPL interactive tool introduced in Java 9 to execute and evaluate simple java programs like variable declarations, statements, expressions, and the programs without using the main() method.In JShell, any value returned by a snippet automatically saved into a scratch variable. These scratch variables can be represented by $. When we do ... Read More

What is the JLink tool in Java 9?

raja

raja

Updated on 27-Feb-2020 06:43:08

297 Views

JLink is a new linker tool that has been used to create our own customized JRE. Usually, we can run our program using default JRE provided by Oracle. If we need to create our own JRE then use this tool. JLink tool can help to create its own JRE with only the required ... Read More

Importance of transferTo() method of InputStream in Java 9?

raja

raja

Updated on 26-Feb-2020 13:20:24

1K+ Views

The transferTo() method has been added to the InputStream class in Java 9. This method has been used to copy data from input streams to output streams in Java. It means it reads all bytes from an input stream and writes the bytes to an output stream in the order in ... Read More

How to define control flow statements in JShell in Java 9?

raja

raja

Updated on 26-Feb-2020 11:31:21

242 Views

JShell is a new interactive command-line tool introduced in Java 9. This tool can also be called REPL (Read-Eval-Print-Loop) because it takes input, evaluates it and returns output to the user via command-line.We can execute multiple-line control flow statements using JShell the same as Java. The control flow statements like If-else statement, for-loop and ... Read More

What are the benefits of a module in Java 9?

raja

raja

Updated on 26-Feb-2020 10:04:14

554 Views

An important feature introduced in Java 9 is Module. By using a module, we can divide the code into smaller components called modules. It means each module has its own responsibility and declare its dependency on other modules to work correctly.Below are the steps to create a modular project in ... Read More

What are the characteristics of a module in Java 9?

raja

raja

Updated on 26-Feb-2020 05:01:28

238 Views

The module is a collection of code, data, and resources. It is a set of related packages and types like classes, abstract classes, and interfaces with code, data files, and some static resources.Below are some of the characteristics of a module.Characteristics of a module:A module must define an interface for communication with other modules.A ... Read More

Differences between Optional.ifPresentOrElse() and Optional.or() methods in Java 9?

raja

raja

Updated on 25-Feb-2020 12:42:26

3K+ Views

Both Optional.ifPresentOrElse() and Optional.or() methods have introduced in Java 9 version to improve its functionality. The Optional.ifPresentOrElse() method checks if the value is present, apply action with value, else return empty action whereas Optional.or() method checks if the value is present, return option contains value, else return Optional applies to ... Read More

How to handle an exception in JShell in Java 9?

raja

raja

Updated on 25-Feb-2020 10:13:32

266 Views

In Java 9, JShell provides a fast and friendly environment that enables us to quickly explore, discover, and experiment with Java language features and extensive libraries.In JShell, manually catching the exceptions is not required. JShell automatically catches each exception and displays information about it, then displays the next JShell prompt so we ... Read More

What is the purpose of using Optional.ifPresentOrElse() method in Java 9?

raja

raja

Updated on 25-Feb-2020 07:45:01

2K+ Views

The improvement of ifPresentOrElse() method in Optional class is that accepts two parameters, Consumer and Runnable. The purpose of of using ifPresentOrElse() method is that if an Optional contains a value, the function action is called on the contained value, i.e. action.accept (value), which is consistent with ifPresent() method. The difference from the ifPresent() ... Read More

What kind of variables/methods defined in an interface in Java 9?

raja

raja

Updated on 24-Feb-2020 13:11:34

274 Views

Since Java 9, we able to add private methods and private static methods in an interface. The advantage of using private methods in an interface is to reduce code duplication among default and static methods. For instance, if two or more default methods needed to share some code, a private method can be created for the same and ... Read More

Advertisements