Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Articles - Page 179 of 745
4K+ Views
In this article, we will learn about the differences between Optional.ifPresentOrElse() and Optional.or() methods in Java 9. Both Optional.ifPresentOrElse() and Optional.or() methods were introduced in Java 9 to improve its functionality. Optional Class Optional Class is a part of java.util package, and it was introduced in Java 8. It is a container object that may or may not contain a non-null value. It helps in writing code without using too many null checks. The following are some of the common methods of the Optional Class: empty(): This method returns an empty Optional instance. ... Read More
452 Views
In this article, we will learn to handle an exception in JShell in Java 9. We will learn about the JShell, exceptions in Java, JShell exceptions, their handling, and Types of exceptions in JShell with examples. What is JShell? JShell is a new command-line interactive REPL (Read-Evaluate-Print-Loop) tool introduced in Java 9 to evaluate declarations, statements, and expressions written in Java. This tool also allows us to execute Java code snippets and get immediate results. C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> JShell provides a fast and friendly environment that ... Read More
3K+ Views
In this article, we will learn about the purpose of using the Optional.ifPresentOrElse() method in Java 9. The Optional Class The Optional class was introduced in Java 8. Many Java developers face null pointer exceptions to avoid this, we need to put null checks we need to put if, to check if a method is null we can put it in the if statement; otherwise, we have to put it in the else statement. And to check this, we need to put this at multiple points to avoid this situation, We use the Optional class. It avoids the null pointer ... Read More
2K+ Views
In this article, we will learn to import external libraries in JShell in Java 9. JShell is an interactive tool to learn the Java language and prototype Java code. This tool works on the principle of REPL (Read-Evaluate-Print-Loop). Default Imports in JShell By default, JShell automatically imports a few useful Java packages when the JShell session is started. We can type the command /imports to get a list of all these imports. jshell> /imports | import java.io.* | import java.math.* | import java.net.* | import java.nio.file.* | import java.util.* | import java.util.concurrent.* | import java.util.function.* | import java.util.prefs.* | import ... Read More
368 Views
Since Java 9, we are able to add private methods and private static methods in an interface. The advantage of using private methods in an interface is to reduce code duplication among default and static methods. For instance, if two or more default methods need to share some code, a private method can be created for the same and called from each of the default methods. Different Types of Variables and Methods in an Interface In Java 9, the following variables/methods have been defined in an interface. Constant Variables Abstract Method ... Read More
2K+ Views
In this article, we will learn about the use of the Optional.stream() method in Java 9. First, we will learn about the optional class and its method. Then we will see the use cases along with an example.Optional class The Optional class was introduced in Java 8 to reduce the null pointer exception that occurs in Java. It is basically a container for the actual object that needs to be returned by a method. The point here is that if a method returns a null value, which can be null, then that method could return a value instead contained inside ... Read More
1K+ Views
In this article, we will learn about the use of the Cleaner class in Java 9. Below, we will first tell the basic usage and then we will know how we can use the Cleaner method practically. Garbage Collector An Object that has been created during the program execution is automatically removed by the Garbage Collector (GC). When an object not referenced by any thread and when JVM determines that this object can't be accessed, then it can be eligible for garbage collection. The finalize() method The Object class has a finalize() method, which is automatically called by GC before it attempts to remove the ... Read More
1K+ Views
JShell is a Read-Evaluate-Print Loop (REPL) that evaluates declarations, statements, and expressions as we have entered and immediately shows the results. This tool is run from the command prompt. Below, we can define expressions, variables, and methods in JShell. Expression The combination of variables, operators, and methods is known as an Expression in Java. They perform some logic that evaluates to a single value. int a=5, b=10, c=0; c=a+b; Here, "a+b" is an expression that evaluates the value of c as 15. Expression in JShell We can type any valid Java expression in JShell. The expression ... Read More
525 Views
Java Shell or JShell is an official REPL(Read-Evaluate-Print-Loop) introduced with Java 9. It provides an interactive shell for quickly prototyping, debugging and without the need for the main() method or the need to compile the code before executing it. JShell is easily started by typing "jshell" in the command prompt. What are Snippets? JShell allows the execution of Java statements, variables, methods, class definitions, imports, and expressions. These pieces of Java code are referred to as snippets. Every snippet is assigned an ID(unique) that we can use later to reference it. Example Below is an example to represent a snippet ... Read More
216 Views
In this article, we will learn about the new methods added to the Process API in Java 9. First, we will know about what is process API, and the methods in Process API in detail. What is Process API? In Java, the Process API, we can perform any operation regarding a process. If one must get the process ID of currently running process, or to create a new process, or destroy an already running one, or find child and parent processes of currently running process, or just get any information about a process, then the Process API is used to perform ... Read More