Found 9150 Articles for Object Oriented Programming

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

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

853 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

367 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

608 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

What is Http/2 Client in Java 9?

raja
Updated on 13-Mar-2020 08:52:38

512 Views

Http/2 Client API introduced in Java 9. It has more performance improvements over Http/1.1 and also supports server-side push events. This makes the website efficient and faster to browse. Http/2 Client is an incubator module named jdk.incubator.httpclient, which means that all features are still not finalized, and new changes may come in future versions of java. It exports jdk.incubator.http package that contains all public APIs.To use Http/2 Client, we need to use the incubator module, we simply pass the httpclient module into JShell using the "–add-modules" command as belowC:\>jshell -v --add-modules jdk.incubator.httpclient | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help introExamplejshell> import jdk.incubator.http.*; jshell> HttpClient httpClient ... Read More

How to debug JShell in Java 9?

raja
Updated on 13-Mar-2020 07:05:27

417 Views

JShell is a REPL tool that allows snippets of code to be run without placing them in classes. This tool provides a way to evaluate declarations, statements, and expressions in Java and no need to create the main() method to test some parts of the code.The command "/debug" can be used to display debugging information for the JShell tool implementation. Once we type the "/debug" command, the debugging mode is on. After enabling the debug mode and type something like a simple addition, or a simple string, then it prints as below.Example-1jshell> /debug | Debugging on jshell> 5+3 Compiling: 5+3 Kind: EXPRESSION_STATEMENT ... Read More

What is Unified JVM Logging in Java 9?

Alshifa Hasnain
Updated on 16-Jun-2025 16:36:39

539 Views

In this article, we will learn about the unified JVM logging in Java 9. Logging in the JVM is a great tool for performing root cause analysis, and it is a part of the JDK(Java Development Kit). Starting from JDK 9, the JVM maintainers chose to rebuild the way the JVM logs things. What is Unified JVM Logging? Java 9 can provide a common logging system for JVM components with a detailed level. By using a new command-line option: -Xlog for all logging settings, and unified JVM logging, gives us an easy-to-configure tool to do a root cause analysis (RCA) ... Read More

Advertisements