Articles on Trending Technologies

Technical articles with clear explanations and examples

What is the importance of REPL in Java 9?

raja
raja
Updated on 27-Mar-2020 692 Views

REPL stands for Read-Eval-Print-Loop. It is a shell where the user types an expression, it's evaluated, and the result returned to the user. The main purpose of using REPL is to interact quickly with Java programs without creating a java file, compile it, and run it. JShell is very useful for the developers and allows us to learn the Java language.Below are some of the features of REPLIt’s built-in in Java 9.We can test any Java expression without a class file, compiling and running it.It autocompletes the methods, just typing the TAB key, as in your editor.We can define methods, ...

Read More

How to get a stream from Optional class in Java 9?

raja
raja
Updated on 27-Mar-2020 209 Views

The Optional class provides a container that may or may not contain a non-null value. It has been introduced in Java 8 to reduce the number of places in the code where a NullPointerException has generated. Java 9 added three methods: ifPresentOrElse(), or(), and stream(), which helps us deal with default values.In the below example, we can get a stream from Optional class using Person classExampleimport java.util.Optional; import java.util.stream.Stream; public class OptionalTest { public static void main(String args[]) { getPerson().stream() ...

Read More

How to get Java and OS version, vendor details in JShell in Java 9?

raja
raja
Updated on 27-Mar-2020 633 Views

Java 9 introduces the JShell tool for the Java Programming Language. This tool allows us to evaluate code snippets such as declarations, statements, and expressions. We will get the details about Java Version and Vendor, and also get the details about OS Version and Name by using the static method: getProperty() of System class.In the below code snippet, we can able to get the details of Java version, Java Vendor and OS version and OS name in JShell console.C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> System.out.println(System.getProperty("java.version")); 9.0.4 jshell> System.out.println(System.getProperty("java.vendor")); ...

Read More

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 281 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 267 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 786 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

How to edit the CSV file using PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 26-Mar-2020 7K+ Views

To edit the CSV file using PowerShell, you need to use the below commands.We already have the CSV file output.csv, we will import this file first.$csvfile = Import-csv C:\temp\Outfile.csvOutputBelow is the output of the CSV file.EMP_Name    EMP_ID     CITY --------    ------     ---- Charles     2000       New York James       2500       Scotland Charles     3000       PolandWe need to update the above file. We will change the CITY of the EMP_ID ‘3000’ to MUMBAI. If we update the CITY name by the EMP_Name, it ...

Read More

How to append data into a CSV file using PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 26-Mar-2020 44K+ Views

To append the data into CSV file you need to use –Append parameter while exporting to the CSV file.In the below example, we have created a CSV fileExample$outfile = "C:\temp\Outfile.csv" $newcsv = {} | Select "EMP_Name", "EMP_ID", "CITY" | Export-Csv $outfile $csvfile = Import-Csv $outfile $csvfile.Emp_Name = "Charles" $csvfile.EMP_ID = "2000" $csvfile.CITY = "New York" $csvfile | Export-CSV $outfile Import-Csv $outfileNow we need to append the below data to the existing file. So first we will import the csv file into a variable called $csvfile$csvfile = Import-Csv $outfile $csvfile.Emp_Name = "James" $csvfile.EMP_ID = "2500" $csvfile.CITY = "Scotland"Once data is inserted into ...

Read More

How to Export and import CSV file manually in PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 26-Mar-2020 2K+ Views

When you run a command Export-Csv in PowerShell, it automatically creates a CSV file to the specific location.ExampleGet-Service | Select Name, Starttype, Status | Export-Csv C:\temp\services.csv -NoTypeInformationIn the above example, Services.csv file created in C:\Temp folders with the header Name, Starttype, and Status headers.Similarly, you can use the other commands to get the output into the CSV file format.If you want to check this file from the PowerShell console, you need to use Import-CSV command.Import-Csv C:\temp\Services.csv | ft -AutosizeOutputName                                     StartType     ...

Read More
Showing 54451–54460 of 61,297 articles
Advertisements