Found 9150 Articles for Object Oriented Programming

What is New Versioning Scheme in Java 9?

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

631 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 print different stack frames using StackWalker API in Java?

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

305 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?

Alshifa Hasnain
Updated on 16-Jun-2025 16:32:44

4K+ Views

In this article, we will learn to use the delayedExecutor() method of CompletableFuture in Java 9. We're gonna know about the delayedExecutor() method and also the CompletableFuture class, as this method belongs to this class, and we're gonna know the uses of the delayedExecutor() method along with an example. CompletableFuture Class The CompletableFuture Class was introduced in Java 8. CompletableFuture is a class in java.util.concurrent package that implements the Future and CompletionStage Interface. CompletableFuture provides a powerful and flexible way to write asynchronous, non-blocking code. It supports delays and timeouts. The delayedExecutor() Method The delayedExecutor() method has been added ... Read More

How can we implement the SubmissionPublisher class in Java 9?

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

887 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

743 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

811 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

How to get all children of a process using Process API in Java 9?

Alshifa Hasnain
Updated on 12-Jun-2025 15:53:54

1K+ Views

In this article, we will learn to get all children of a process using Process API in Java 9. First, we will learn about Process API and its methods, ProcessHandle interface and after that we will use the children method of the ProcessHandle interface. Process API In Java, the Process API, we can perform any operation regarding a process. The Process class provides methods for performing input on the processes, performing output to the processes, waiting for the process to complete, finding child and parent processes of the currently running process, getting any information about a process, and destroying the process. The ... Read More

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

raja
Updated on 06-Mar-2020 12:28:44

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 {       System.out.println("---------------------------");       ... Read More

Importance of ofInstant() method in Java 9?

raja
Updated on 06-Mar-2020 10:35:54

219 Views

In Java 9, the ofInstant() method has introduced for conversion. It is a static method of LocalDate, LocalTime, and LocalDateTime classes. This method converts java.time.Instant object to LocalDate that requires a time zone in the form of java.time.ZoneId.Syntaxpublic static LocalTime ofInstant(Instant instant, ZoneId zone) public static LocalDate ofInstant(Instant instant, ZoneId zone) public static LocalDateTime ofInstant(Instant instant, ZoneId zone)Exampleimport java.time.LocalDate; import java.time.LocalTime; import java.time.LocalDateTime; import java.time.Instant; import java.time.ZoneId; public class OfInstantMethodTest {    public static void main(String args[]) { Instant instant = Instant.parse("2020-02-05T02:35:15.245Z"); System.out.println("Instant: " + instant); ... Read More

What is the use of the toEpochSecond() method in Java 9?

Alshifa Hasnain
Updated on 16-Jun-2025 16:33:50

859 Views

In this article, we will learn about the use of the toEpochSecond() method in Java 9. First, we will learn about the LocalDate class, its methods, then we will know about the Epoch Time and the toEpochSecond() method with its uses and example in Java. LocalDate Class The LocalDate class is a part of java.time package. LocalDate class represents a date without a time-zone in the ISO-8601 calendar system, such as 2020-10-14. This class represents a date in the format yyyy-MM-dd. The following are some of the common methods of the LocalDate Class getDayOfMonth(): This ... Read More

Advertisements