Java Articles

Page 337 of 450

What does the method toString(int[] a) do?

karthikeya Boyini
karthikeya Boyini
Updated on 13-Mar-2020 133 Views

The toString(int[]) method of the class java.util.Arrays return a string representation of the contents of the specified int array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space).Exampleimport java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { int[] i1 = new int[] { 33, 12, 98 }; System.out.println("The array is:"); for (int number : i1) ...

Read More

What does the method fill(obj[], object val) do?

Sharon Christine
Sharon Christine
Updated on 13-Mar-2020 256 Views

The fill(Object[] a, Object val) method of the java.util.Arrays class assigns the specified Object reference to each element of the specified array of Objects.Exampleimport java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { Object arr[] = new Object[] {10.5, 5.6, 4.7, 2.9, 9.7}; System.out.println("Actual values: "); for (Object value : arr) { System.out.println("Value = " + value); } Arrays.fill(arr, 12.2); System.out.println("New values after using fill() method: "); for (Object value : arr) { System.out.println("Value = " + value); } } }OutputActual values: Value = 10.5 Value = 5.6 Value = 4.7 Value = 2.9 Value = 9.7 New values after using fill() method: Value = 12.2 Value = 12.2 Value = 12.2 Value = 12.2 Value = 12.2

Read More

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

raja
raja
Updated on 12-Mar-2020 595 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 ...

Read More

How to implement an ArrayList using JShell in Java 9?

raja
raja
Updated on 11-Mar-2020 477 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
raja
Updated on 11-Mar-2020 351 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 ...

Read More

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

raja
raja
Updated on 11-Mar-2020 408 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
raja
Updated on 11-Mar-2020 370 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[]) { ...

Read More

How can we implement the SubmissionPublisher class in Java 9?

raja
raja
Updated on 09-Mar-2020 1K+ 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 ...

Read More

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

raja
raja
Updated on 09-Mar-2020 834 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

Read More

How to terminate/destroy a process using Process API in Java 9?

raja
raja
Updated on 06-Mar-2020 2K+ Views

In Java 9, Process API supports an easy way to get much information about a process. ProcessHandle interface can identify and provide the control of native processes and method to check processes liveness and destroy the processes whereas ProcessHandle.Info interface can give an Information snapshot of a process. We need to destroy a process by using the destroy() method of the ProcessHandle interface.In the below example, we need to terminate a process by using the ProcessHandle interface.Exampleimport java.io.File; import java.io.IOException; import java.util.Objects; public class DestroyProcessTest { public static void main(String[] args) throws InterruptedException { ...

Read More
Showing 3361–3370 of 4,498 articles
« Prev 1 335 336 337 338 339 450 Next »
Advertisements