Raja has Published 760 Articles

Which attributes have added to @Deprecated annotation in Java 9?

raja

raja

Updated on 21-Feb-2020 12:14:47

527 Views

There are two new parameters or attributes added to @Deprecated annotation in Java 9. Those parameters are Since and forRemoval, both of these two parameters are optional with a default value when we can't specify it.SinceThis string parameter specifies the version in which the API became deprecated. The default value of this element is ... Read More

What is the use of the Tab key in JShell in Java 9?

raja

raja

Updated on 21-Feb-2020 10:22:01

202 Views

JShell can also provide an auto-completion feature when we partially type the name of an existing class, variable, or method by pressing the Tab key. If an item can't determine from what we entered, then possible options are provided.Pressing the Tab key in JShell performs one of the following tasks:If no other name matches what ... Read More

What are the benefits of immutable collections in Java 9?

raja

raja

Updated on 21-Feb-2020 10:08:12

341 Views

In Java 9, several factory methods have added to Collections API. By using these factory methods, we can create unmodifiable list, set and map collection objects to reduce the number of lines of code. The List.of(), Set.of(), Map.of() and Map.ofEntries() are the static factory methods that provide convenient way of creating immutable collections in Java 9.Benefits ... Read More

How to save, edit, and drop a snippet in JShell in Java 9?

raja

raja

Updated on 21-Feb-2020 10:06:42

335 Views

Java Shell or JShell is an official REPL(Read-Evaluate-Print-Loop) introduced with Java 9. It provides an interactive shell for quickly prototyping, debugging and without the need for the main() method or without the need to compile the code before executing it. JShell is easily started by typing "jshell" in the command prompt. Save a snippetWe can ... Read More

How can we create an unmodifiable Set in Java 9?

raja

raja

Updated on 21-Feb-2020 06:23:39

143 Views

The immutable static factory method Set.of() can provide a convenient way to create unmodifiable sets in Java 9. An instance of a set created by using the Set.of() method has the following characteristics.The set returned by a factory method is conventionally immutable. It means that elements can't be added, removed, or replaced from a ... Read More

How can we create an unmodifiable List in Java 9?

raja

raja

Updated on 21-Feb-2020 06:02:16

355 Views

A list considered to be unmodifiable if the elements can't be added, removed, or replaced from a list once an unmodifiable instance of a list has created. The static factory method: List.of() provides a convenient way to create unmodifiable lists in Java 9.An instance of a list created by using the List.of() method ... Read More

How can we create an unmodifiable Map in Java 9?

raja

raja

Updated on 21-Feb-2020 05:56:23

263 Views

An unmodifiable Map is one whose keys and values can't be added, removed, or updated once an unmodifiable instance of a map has created. The static factory methods: Map.of() and Map.ofEntries() from Map that provides a convenient way to create unmodifiable maps in Java 9.An instance of a map created by using Map.of() ... Read More

When to use the ofNullable() method of Stream in Java 9?

raja

raja

Updated on 21-Feb-2020 05:31:34

1K+ Views

The ofNullable() method is a static method of Stream class that returns a sequential Stream containing a single element if non-null, otherwise returns an empty. Java 9 has introduced this method to avoid NullPointerExceptions and also avoid null checks of streams. The main objective of using the ofNullable() method is to return an empty ... Read More

Differences between orTimeout() and completeOnTimeOut() methods in Java 9?

raja

raja

Updated on 21-Feb-2020 05:13:46

1K+ Views

Both orTimeout() and completeOnTimeOut() methods are defined in CompletableFuture class and these two methods are introduced in Java 9. The orTimeout() method can be used to specify that if a given task doesn't complete within a certain period of time, the program stops execution and throws TimeoutException whereas completeOnTimeOut() method completes the ... Read More

Importance of iterate() method of Stream API in Java 9?

raja

raja

Updated on 21-Feb-2020 05:11:39

356 Views

In Java 8, the iterate() method of Stream API takes the seed and the unary operator as arguments. As stream becomes infinite, it makes the developer add explicit termination conditions by using limit, findFirst, findAny and etc. In Java 9, the iterate() method of Stream API has added a new argument, a predicate that takes the condition to break ... Read More

Advertisements