Java Articles

Page 339 of 450

Importance of the Collectors.filtering() method in Java 9?

raja
raja
Updated on 05-Mar-2020 436 Views

Collectors class is an essential part of the Stream API. In Java 9, a new method: filtering() added to the Collectors class. The Collectors.filtering() method can be used for filtering elements in a stream. It is similar to the filter() method on streams. The filter() method processes the values before they have grouped whereas the filtering() method can be used nicely with the Collectors.groupingBy() method to group the values before the filtering step takes place.Syntaxpublic static Collector filtering(Predicate

Read More

What is a forward reference in JShell in Java 9?

raja
raja
Updated on 05-Mar-2020 370 Views

JShell is a command-line tool that allows us to enter Java statements (simple statements, compound statements, or even full methods and classes), evaluates it and prints the result.Forward references are commands that refer to methods, variables, or classes that don't exist in any code we have typed in JShell. As code entered and evaluated sequentially in JShell, these forward references have temporarily unresolved. JShell supports forward references in method bodies, return types, parameter types, variable types, and within a class.In the below code snippet, created a method forwardReference() in Jshell. This method can't be invoked until the variable is declared. ...

Read More

How to create JShell instance programmatically in Java 9?

raja
raja
Updated on 04-Mar-2020 594 Views

JShell is an interactive tool introduced since Java 9. It is Java's first official REPL tool to create a simple programming environment in the command-line that reads the user's inputs, evaluates it, and prints the result.We can able to create a new JShell instance programmatically in Java language. JShell and its associated APIs can be found under jdk.jshell package. we can get a new instance for JShell by using the static method: create() of JShell class. The eval() method of JShell class used to add an expression to JShell instance. It returns a list of events triggered by the evaluation. ...

Read More

What are the different shortcut keys in JShell in Java 9?

raja
raja
Updated on 04-Mar-2020 485 Views

JShell is an interactive tool that allows us to execute the java code and getting immediate results. We quickly evaluate expressions or short algorithms without compiling or build it. We can execute expressions, classes, methods, variables, and etc with the help of the JShell tool.Below are some of the keyboard shortcut keys:Entrance - Validate the lineLeft arrow - Move left in the lineRight arrow - Move right in the lineCtrl-A - Move to the start of the lineCtrl-E- Move to the end of the lineAlt-B - Move left, word by wordAlt-F - Move right, word by wordDelete - Delete characters ...

Read More

What is Project Jigsaw in Java 9?

raja
raja
Updated on 04-Mar-2020 1K+ Views

The primary objective of the Jigsaw project is to introduce the modularity concept to create a module in Java 9 and then applying the same to JDK.Below are some of the benefits of Modularity(Jigsaw)Strong Encapsulation: The modules can access only those parts that can be available for use. Unless the package is explicitly exported into the module-info.java file, public classes in a package can't be public.Clear Dependencies: A module must declare about other modules that they are used through the required clause. The modules are combined in order to create a shorter runtime that can be scaled to comparatively smaller ...

Read More

What are the different compilation modes of a module in Java 9?

raja
raja
Updated on 03-Mar-2020 350 Views

A module is a container of packages and each module contains a module descriptor that includes module name, module dependencies,  it means that the name of other modules depends on and name of the packages it exports that can be used only by modules that depend on it.module com.tutorialspoint.app {    /** Modules upon which the module com.tutorialspoint.app depends on */    requires com.tutorialspoint.services;    /** Packages exposed by this module which can be used by other modules */    exports com.tutorialspoint.app.util; }There are three different compilation modes provided by Java 9 Module: Legacy mode, single module mode, and multi-module mode.Compilation modes of ...

Read More

How to declare a class and an interface in JShell in Java 9?

raja
raja
Updated on 03-Mar-2020 425 Views

JShell can provide an interactive shell for quickly prototyping, debugging, and learning Java and Java API without the need for the main() method or need to compile our code before executing it.Declaration of Class:We can declare a class just like we have written a code in Java Language. The JShell can detect when the class completes it.In the below code snippet, we can declare a class Employee with two parameters and one method.C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> class Employee { ...> String ...

Read More

Importance of transferTo() method of InputStream in Java 9?

raja
raja
Updated on 26-Feb-2020 2K+ Views

The transferTo() method has been added to the InputStream class in Java 9. This method has been used to copy data from input streams to output streams in Java. It means it reads all bytes from an input stream and writes the bytes to an output stream in the order in which they are reading.Syntaxpublic long transferTo(OutputStream out) throws IOExceptionExampleimport java.util.Arrays; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; public class TransferToMethodTest { public void testTransferTo() throws IOException { byte[] inBytes = "tutorialspoint".getBytes(); ByteArrayInputStream bis = ...

Read More

What is the difference between transient and volatile in Java?

Rishi Raj
Rishi Raj
Updated on 26-Feb-2020 829 Views

transient: An instance variable is marked transient to indicate the JVM to skip the particular variable when serializing the object containing it.  This modifier is included in the statement that creates the variable, preceding the class or data type of the variable.Examplepublic transient int limit = 55;   // will not persist public int b;   // will persistvolatile: The volatile modifier is used to let the JVM know that a thread accessing the variable must always merge its own private copy of the variable with the master copy in the memory.Accessing a volatile variable synchronizes all the cached copied ...

Read More

What are the benefits of a module in Java 9?

raja
raja
Updated on 26-Feb-2020 759 Views

An important feature introduced in Java 9 is Module. By using a module, we can divide the code into smaller components called modules. It means each module has its own responsibility and declare its dependency on other modules to work correctly.Below are the steps to create a modular project in Java 9:Initially, we can create a file named "module-info.java" and add to a package(module) for which it is created. For instance, if our package name is com.mycompany.mypackage then the file goes to the same package (src/com.mycompany.mypackage/module-info.java). We can create a module by declaring "exports" and "requires" expressions.If our modules require another module ...

Read More
Showing 3381–3390 of 4,498 articles
« Prev 1 337 338 339 340 341 450 Next »
Advertisements