Raja has Published 469 Articles

StackWalker API in Java 9?

raja

raja

Updated on 24-Feb-2020 06:05:26

754 Views

StackWalker API allows easy filtering and lazy access to execute tasks within any method. It is an efficient API for obtaining stack trace information in Java 9.There are three new important classes in StackWalker API: StackWalker,  StackWalker.StackFrame and StackWalker.Option.StackWalker − It is the main class in StackWalker API. We traverse stack frames by using ... Read More

What are the rules for private methods in an interface in Java 9?

raja

raja

Updated on 21-Feb-2020 12:43:46

1K+ Views

Java 9 added a new feature of private methods to an interface. The private methods can be defined using a private modifier. We can add both private and private static methods in an interface from Java 9 onwards.Rules for private methods in an interface:A private method has a body in an interface means that we can’t be declared ... Read More

What are the new methods added to an Optional class in Java 9?

raja

raja

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

261 Views

An Optional class provides a container that may or may not contain a non-null value. This Optional class introduced in Java 8 to reduce the number of places in the code where a NullPointerException can be generated. Java 9 added three new methods to Optional class: or(), ifPresentOrElse() and stream() that help ... Read More

What are the new features added to Stream API in Java 9?

raja

raja

Updated on 21-Feb-2020 12:20:30

184 Views

In Java 9, Oracle Corporation has added four useful new methods to Stream API. Those methods are iterate(), ofNullable(), takeWhile() and dropWhile().iterate()The iterate() can be used as stream version replacement of traditional for-loops. This method has improved by adding another parameter, the Predicate interface that allows us to stop these endless numbers ... Read More

Can a diamond operator be used with an anonymous inner class in Java 9?

raja

raja

Updated on 21-Feb-2020 12:18:26

171 Views

Yes, we can use the diamond operator with an anonymous inner class since Java 9.The purpose of using a diamond operator is to avoid redundant code and make it more readable by no longer using a generic type on the right side of an expression. The diamond operator used only for normal classes but not for ... Read More

@SafeVarargs annotation for private methods in Java 9?

raja

raja

Updated on 21-Feb-2020 12:16:34

364 Views

The @SafeVarargs annotation was introduced in Java 7. This annotation applies to both final and static methods or constructors that take varargs parameters. This annotation used to make sure that a method does not perform unsafe operations on its varargs parameters. Since Java 9, @SafeVarargs annotation also applies to private instance methods.Syntax@SafeVarargs private void methodName(...) {   ... Read More

What are the CompletableFuture API improvements in Java 9?

raja

raja

Updated on 21-Feb-2020 12:15:49

301 Views

CompletableFuture API is used for asynchronous programming in Java. It means that we can write non-blocking code by running a task on a separate thread than the main() thread and notify the main() thread about its progress, completion or failure. Java 9 introduces a few improvements in CompletableFuture API,  they are: "Support for timeouts and delays", ... Read More

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

raja

raja

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

650 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 are the benefits of immutable collections in Java 9?

raja

raja

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

434 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

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

raja

raja

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

429 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