Programming Articles

Page 2368 of 2547

How to implement reactive streams using Flow API in Java 9?

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

Flow API is official support for reactive streams specification since Java 9. It is a combination of both Iterator and Observer patterns. The Flow API is an interoperation specification and not an end-user API like RxJava.Flow API consists of four basic interfaces:Subscriber: The Subscriber subscribes to Publisher for callbacks.Publisher: The Publisher publishes the stream of data items to the registered subscribers.Subscription: The link between publisher and subscriber.Processor: The processor sits between Publisher and Subscriber, and transforms one stream to another.In the below example, we have created a basic subscriber that asks for one data object, prints it and asks for one more. ...

Read More

How to create a thread in JShell in Java 9?

raja
raja
Updated on 27-Mar-2020 278 Views

JShell is an interactive java shell tool introduced in Java 9 and allows us to execute code snippets, and shows the result immediately without declaring the main() method like Java. It is a REPL (Read-Evaluate-Print- Loop) tool and runs from the command-line prompt. We can create variables, methods, classes, scratch variables, external libraries, and etc using JShellIn the below code snippet, we can create a thread by extending the Thread class.C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> class ThreadTest extends Thread { ...> public ...

Read More

What is the purpose of using JLink in Java 9?

raja
raja
Updated on 26-Mar-2020 263 Views

The main purpose of the JLink feature is to create our own Customized JRE. Usually, we run a program with the default JRE that has been provided by Oracle Corporation with 214 MB of size.For instance, a user wants to print a simple "Hello World" message as shown belowpublic class HelloWorldModuleTest {    public static void main(String args[[]) {       System.out.println("Hello World!");    } }To run the above program of 1 KB size, we need 4 – 5 classes like String, System, Object, and HelloWorldModuleTest.class files. Then why do we need to load 214 MB of JRE using ...

Read More

Importance of Module Descriptor in a Module in Java 9?

raja
raja
Updated on 26-Mar-2020 785 Views

A module is a collection of code in the form of classes organized in packages and static resources such as property files or others. It provides the outside environment with all the information that can be required to use that module. The module descriptor is a key source of the module system, and it's compiled version of a module declaration specified in a file named "module-info.java" file at the root of the module’s directory hierarchy.The module describes itself by a module declaration as belowmodule com.myproject.module1 {    requires com.myproject.module2;    exports com.myproject.project1;    exports com.myproject.project2; }Below are some of the module descriptors described:module module. name: declares a module ...

Read More

Why @SafeVarargs is required in Java 9?

raja
raja
Updated on 24-Mar-2020 322 Views

The varargs functionality has been introduced in Java to facilitate the creation of methods with a variable number of arguments without resorting to array-type parameters or overloaded versions of the same method.Before Java 9 versions, if vararg methods are used with generics, then there is a warning message. Even though not all methods create heap pollution, compiler shows warning for all vararg methods used with generics. That's the reason @SafeVarargs concept was added to Java 9 version to avoid these warnings. If we added this annotation, then the compiler stops these warnings.We can compile the code by using the below ...

Read More

How to re-execute existing snippets in JShell in Java 9?

raja
raja
Updated on 23-Mar-2020 228 Views

JShell is the first REPL tool introduced in Java 9. We can able to execute simple snippets in a command-line prompt by using JShell tool. We can start a JShell session by typing "jshell" command, stop the session by typing "/exit" command, and search for particular command by using "/help" command.The "/reload" command can be used to re-execute all existing snippets in JShell. We can also remove all prior code from a JShell session by using the "/reset" command.In the below code snippet, we have created a set of snippets.jshell> 2+10 $1 ==> 12 jshell> String s = "Tutorialspoint" ...

Read More

Differences between Java 8 and Java 9?

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

Java 9 version has introduced new enhancements and added new features. It includes JShell, Http2Client, Java Platform Module System (JPMS), Multi-release jar files, Stack Walking API, Private methods in an interface, Process API updates, Collection API updates, Stream API improvements, and etc.Below are the few differences between Java 8 and Java 9In Java 8 and earlier versions, the top-level component is the package. It places a set of related types (classes, interfaces, enums, and etc) into a group, and also contains a set of resources whereas Java 9 introduces a new component: module, which can be used to place a ...

Read More

Draw a line in C++ graphics

Ayush Gupta
Ayush Gupta
Updated on 23-Mar-2020 7K+ Views

In this tutorial, we will be discussing a program to draw a line in C++ graphics.To implement different shapes and sizes, animations, graphics.h library is used in C++.Example#include int main(){    int gd = DETECT, gm;    initgraph(&gd, &gm, "");    line(150, 150, 450, 150);    line(150, 200, 450, 200);    line(150, 250, 450, 250);    getch();    closegraph();    return 0; }Output

Read More

Delete and free() in C++ Program

Ayush Gupta
Ayush Gupta
Updated on 23-Mar-2020 218 Views

In this tutorial, we will be discussing a program to understand delete() and free() functions in C++.Both of these functions are primarily used for the same purpose i.e freeing up unused memory. The delete() operator is for the ones allocated using new() and free() for the ones allocated using malloc().Example#include #include int main(){    int x;    int *ptr1 = &x;    int *ptr2 = (int *)malloc(sizeof(int));    int *ptr3 = new int;    int *ptr4 = NULL;    //incorrect usage of delete    delete ptr1;    delete ptr2;    //correct usage of delete    delete ptr3;    delete ptr4;    getchar();    return 0; }

Read More

How can we execute snippets by ID in JShell in Java 9?

raja
raja
Updated on 23-Mar-2020 246 Views

JShell is an interactive tool (REPL) introduced in Java 9. We can execute snippets like expressions, variables, methods, classes, and etc without a main () method in the JShell tool.We can execute any prior snippet by simply typing /id, which indicates the snippet’s ID. For instance, if we type "/1", then JShell can display the first snippet that we have entered, executes it, and shows the result. We can re-execute the last snippet that we have entered (whether it is valid or invalid) by using "/!".In the below code snippet, we have created a set of snippets, and execute those ...

Read More
Showing 23671–23680 of 25,466 articles
Advertisements