Found 2612 Articles for Java

What is Common Locale Data Repository (CLDR) in Java 9?

raja
Updated on 12-Mar-2020 10:15:10

413 Views

Internationalization enhancements for Java 9 include enabling of CLDR Locale Data by Default.There are four distinct sources for locale data identified by using the below keywords:CLDR: The locale data provided by a Unicode Common Locale Data Repository (CLDR) project.HOST: The current user’s customization of an underlying operating system’s settings. Depending on the operating system, formats like date, time, number, and currency can be supported.SPI: The locale-sensitive services implemented in installed SPI providers.COMPAT (JRE): The locale data that is compatible with releases prior to Java 9. The JRE can still be used as a value but deprecated, and removed in the future.In Java ... Read More

What is New Versioning Scheme in Java 9?

raja
Updated on 12-Mar-2020 08:15:26

510 Views

Since Java 9, versioning can be consistent with semantic versioning. The version number can be a non-empty sequence of strings separated by dots. It contains three major parts: major version number, minor version number, and security. The new versioning scheme has documented in Runtime. Version class and version information can be accessed from it.The version numbers have the below format:$MAJOR.$MINOR.$SECURITY(.$otherpart)?$MAJOR is the major version number and incremented when a major version has released that typically changes the platform specification. For JDK 9, this value is 9.$MINOR is the minor version number and incremented for releases that contain bug fixes and enhancements to ... Read More

How to implement an ArrayList using JShell in Java 9?

raja
Updated on 11-Mar-2020 13:52:23

284 Views

JShell is an interactive Java Shell tool that enables us to execute java code from the shell and instantly displays the output. JShell is the REPL(Read Evaluate Print Loop) tool that runs from the command-line. We can start a JShell by simply typing "jshell" in the command prompt, and to exit the jshell by using "/exit" command. For small snippets, we do not need to create a main() method in JShell.We can also implement the major collections like list, map and set by using this tool. In the below program, we can implement an ArrayList with various scenarios.ExampleC:\Users\User\Desktop\Java 9 QNA>jshell | Welcome to JShell ... Read More

What is Platform Logging API in Java 9?

raja
Updated on 11-Mar-2020 12:28:37

216 Views

In Java 9, Platform Logging API can be used to log messages with a service interface for consumers of those messages. An implementation of LoggerFinder has been loaded with the help of java.util.ServiceLoader API by using System ClassLoader. Based on this implementation, an application can plug in its own external logging backend without configuring java.util.logging.We can pass a class name or module to LoggerFinder so that it knows which logger to return.public class MyLoggerFinder extends LoggerFinder {    @Override    public Logger getLogger(String name, Module module) {       // return a logger depends on name/module    } }If no concrete implementation can be found, then ... Read More

How to filter stack frames using StackWalker API in Java 9?

raja
Updated on 11-Mar-2020 10:11:48

241 Views

StackWalker API provides a stream of information in stack traces during the execution of a program. This API requires a virtual machine to capture a snapshot of the entire stack and returns an array of elements for filtering purposes. We need to skip, drop, and limit the stack frames by using the walk() method. We can also filter a stack frame by class for getting the first matching frame, and all matching frames by using the filter() method.In the below example, we can filter a stack frame by using StackWalker API.Exampleimport java.lang.StackWalker.StackFrame; import java.util.*; import java.util.stream.*; public class StackWalkerFilterTest { ... Read More

How to print different stack frames using StackWalker API in Java?

raja
Updated on 11-Mar-2020 07:26:27

187 Views

Java 9 defines a StackWalker API that provides laziness and frame filtering. An object of StackWalker allows us to traverse and access stacks and contains one useful method: walk(). This method opens a StackFrame stream for the current thread, then applies the function with that StackFrame stream. We need to get StackWalker object, then use StackWalker.getInstance() method.In the below example, we can print different stack frames: all stack frames, skip some stack frames and limit stack frames by using StackWalker API.Exampleimport java.lang.StackWalker.StackFrame; import java.util.*; import java.util.stream.*; public class StackWalkerTest {    public static void main(String args[]) {       new StackWalkerTest().walk();    }    private void walk() {     ... Read More

When to use the delayedExecutor() method of CompletableFuture in Java 9?

raja
Updated on 09-Mar-2020 10:59:05

2K+ Views

The delayedExecutor() method has been added to the CompletableFuture class in Java 9. CompletableFuture defines two overloaded methods of delayedExecutor(): first method returns an Executor object from the default Executor object that CompletableFuture object uses to execute the task after the delay and new Executor object can do task execution whereas the second method also returns an Executor object but is an Executor object that we pass into this method after the delay and new Executor object can also do task execution.Syntaxpublic static Executor delayedExecutor(long delay, TimeUnit unit, Executor executor) public static Executor delayedExecutor(long delay, TimeUnit unit)Exampleimport java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; ... Read More

How can we implement the SubmissionPublisher class in Java 9?

raja
Updated on 09-Mar-2020 09:45:11

587 Views

Since Java 9, we can create Reactive Streams by introducing four core interfaces: Publisher, Subscriber, Subscription, Processor, and one concrete class: SubmissionPublisher that implements the Publisher interface. Each interface plays a different role, corresponding to the principles of Reactive Streams. We can use the submit() method of SubmissionPublisher class to publish the provided item to each subscriber.Syntaxpublic class SubmissionPublisher extends Object implements Flow.Publisher, AutoCloseableIn the below example, we can implement the SubmissionPublisher classExampleimport java.util.concurrent.Flow.Subscriber; import java.util.concurrent.Flow.Subscription; import java.util.concurrent.SubmissionPublisher; class MySubscriber implements Subscriber {    private Subscription subscription;    private String name;    public MySubscriber(String name) {       this.name = name;   ... Read More

What are the core interfaces of Reactive Streams in Java 9?

raja
Updated on 09-Mar-2020 06:36:32

501 Views

Java 9 has introduced Reactive Streams under java.util.concurrent.Flow package that supports an interoperable publish-subscribe framework. It processes an asynchronous stream of data across the asynchronous boundary (passing elements into another thread or thread-pool), and the receiving side is not forced to buffer arbitrary amounts of data, then buffer overflow can't occur.Flow API contains four interrelated core interfaces: Publisher, Subscriber, Subscription, and Processor.Syntax@FunctionalInterface public static interface Publisher {    public void subscribe(Subscriber

How to retrieve all processes data of Process API in Java 9?

raja
Updated on 09-Mar-2020 05:36:55

460 Views

In Java 9, Process API has been used to control and manage operating system processes. ProcessHandle class provides the process’s native process ID, start time, accumulated CPU time, arguments, command, user, parent process, and descendants. It also provides a method to check processes liveness and to destroy processes. We retrieve all ProcessHandle data as a stream by using the allProcesses() method.In the below example, we retrieve all the processes information.Exampleimport java.util.stream.Stream; import java.util.Optional; import java.util.stream.Stream; public class AllProcessesTest {    public static void main(String args[]) throws InterruptedException {       System.out.println("---------------------------");       System.out.println("All Processes:");       Stream processStream = ProcessHandle.allProcesses();       processStream.forEach(process -> ... Read More

Advertisements