Found 7442 Articles for Java

What are the components in a module-info file in Java 9?

raja
Updated on 20-Mar-2020 07:07:25

1K+ Views

A module is an independent unit of application that represents a single functionality. A module contains three important componentsName: To uniquely identify itDependencies: Other modules in which it depends onExported packages: Packages which are open for external applicationIn order to declare a module, we need to add the "module-info.java" file to the root source code. The components of the "module-info.java" file includes "name", "requires", "exports", and "exports to".Below is the template of "module-info.java" filemodule {    requires ;    requires ;    ...    exports ;    exports ;    ...    exports to ; }Name: It is ... Read More

How can we display all module names in Java 9?

raja
Updated on 19-Mar-2020 14:02:31

338 Views

In Java 9, the module concept has introduced. It is a named, self-describing collection of code and data. The code can be organized as a set of packages containing types like java classes and interfaces, and data includes resources and other kinds of static information. A module contains a name, dependencies, and exported packages.Syntaxmodule com.tutorialspoint.mymodule {    // some statements }In the below example, we can able to display all module names by using the ModuleLayer class.Examplepublic class AllModulesNamesTest {    public static void main(String args[]) {       ModuleLayer.boot().modules().forEach((module) -> {          System.out.println(module.getName());       ... Read More

How to print the pattern of stars in JShell in Java 9?

raja
Updated on 19-Mar-2020 12:10:10

282 Views

JShell is a REPL tool introduced in Java 9 that allows us to execute Java code and getting results immediately. We can evaluate expressions or simple algorithms without creating a new project, compile or build it by using JShell. We can also execute expressions, use imports, define classes, methods, and variables. It is a part of Java 9 JDK but not JRE.We can start JShell session in command-prompt by simply typing jshell. We can use different commands: /exit to quit the JShell session, reset/reload JShell anytime by typing /reset, and /reload,  /import to list the imports, etc.In the below example, we can print ... Read More

Executing C# code in Linux

Ajay yadav
Updated on 05-Jan-2021 06:38:26

5K+ Views

The .NET centric applications are meant to windows operating system up till now, but now Microsoft has introduced a new cross-platform application called Mono which enables the execution of the application developed under the .NET platform in Linux environment by giving an impression in such a way that as if we are running Linux package rather than executing .exe file.MonoMono is an open-source utility that allows the developer to execute .NET centric applications on other platforms such as Mac or Linux as it provides an installation package for Windows platform to compile and execute .NET assemblies on Windows OS without ever ... Read More

How to implement the Fibonacci series in JShell in Java 9?

Alshifa Hasnain
Updated on 06-Jun-2025 14:44:13

191 Views

In this article, we will learn to implement the Fibonacci series in JShell in Java 9. First, we will learn how the Fibonacci series works, then learn two approaches(iterative and recursive) to implement this sequence in the JShell environment. JShell JShell is a Java shell tool introduced in Java 9 that allows us to execute Java code and print the result immediately. It is a REPL (Read-Evaluate-Print-Loop) tool that runs from the command-line prompt. What is a Fibonacci Series? A number is said to be in the Fibonacci series if each subsequent number is the sum of the previous two ... Read More

What are new methods added to the String class in Java 9?

Alshifa Hasnain
Updated on 09-Jun-2025 19:29:15

266 Views

In this article, we will learn about the new methods added to the String class in Java 9. We will learn about Strings and the new methods in the String class, along with examples. Strings A String is the type of object that contains a collection of characters enclosed by double quotes (" "). The Java platform provides the String class to create and manipulate strings in Java. The String class is immutable, so that once it is created, a String object cannot be changed. String is the only class where operator overloading is supported in Java, we can concatenate ... Read More

How to get the parent process of the Process API in Java 9?

Alshifa Hasnain
Updated on 12-Jun-2025 17:32:47

852 Views

In this article, we will learn to get the parent process of the Process API in Java 9. First, we will know about Process API and its methods, after that we will learn about 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, finding child and parent processes of the currently running process, and destroying the process. The following are some of the common methods of the Process API: destroy(): ... Read More

How to implement a lambda expression in JShell in Java 9?

Alshifa Hasnain
Updated on 09-Jun-2025 19:29:50

366 Views

In this article, we will learn to implement a lambda expression in JShell in Java 9. We will learn the syntax, explain the working of lambda expressions, and how they work with functional interfaces, and give examples with the JShell environment. JShell JShell is Java's first REPL and command-line tool that provides interactive use of Java programming language elements. We can test the functionality in isolation of a class by using this tool. JShell creates a simple and easy programming environment in the command-line that takes input from the user, reads it, and prints the result. What is a ... Read More

What is Variable Handle in Java 9?

raja
Updated on 13-Mar-2020 13:47:12

606 Views

Variable Handle is a variable or reference to a set of variables, including other components of a static field, non-static fields, and outer array elements in the heap data structure. It means that Variable Handle is similar to the existing Method Handle. It can be represented by using java.lang.invoke.VarHandle class. We can use java.lang.invoke.MethodHandles.Lookup static factory method to create Variable Handle objects. It can also be used to access a single element in the array, and byte[] array.Syntaxpublic abstract class VarHandle extends ObjectExampleimport java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.Arrays; public class VarHandleTest {    public static void main(String args[]) {       VarHandle varHandle = MethodHandles.arrayElementVarHandle(int[].class); ... Read More

What is the importance of the ProcessHandle interface in Java 9?

raja
Updated on 13-Mar-2020 11:27:01

592 Views

ProcessHandle interface introduced in Java 9. It allows us to perform actions and check the state of a process that relates. This interface provides the process’s native process ID (pid), start time, accumulated CPU time, arguments, command, user, parent process, and descendants.ProcessHandle interface allows us to perform the following actions.It returns a ProcessHandle.Info containing further information about a processThe Pid of a processIf it is aliveRetrieve a snapshot of the direct children of a processRetrieve a snapshot of all descents of a processRetrieve a snapshot of all currently running processesAllow the process to be destroyedIt returns a CompletableFuture with a ProcessHandle for when the ... Read More

Advertisements