Alshifa Hasnain has Published 283 Articles

What is the purpose of using Optional.ifPresentOrElse() method in Java 9?

Alshifa Hasnain

Alshifa Hasnain

Updated on 11-Jun-2025 13:41:57

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 ... Read More

What kind of variables/methods defined in an interface in Java 9?

Alshifa Hasnain

Alshifa Hasnain

Updated on 11-Jun-2025 13:40:07

350 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 ... Read More

How to import external libraries in JShell in Java 9?

Alshifa Hasnain

Alshifa Hasnain

Updated on 10-Jun-2025 18:42:54

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 ... Read More

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

Alshifa Hasnain

Alshifa Hasnain

Updated on 10-Jun-2025 18:42:26

252 Views

In this article, we will learn about the new methods that have been added to the Arrays class in Java 9. First, we will learn about arrays, and then the new methods added to the equals(), compare(), and mismatch() methods with examples. Arrays Java provides a data structure called the ... Read More

What are the useful commands in JShell in Java 9?

Alshifa Hasnain

Alshifa Hasnain

Updated on 10-Jun-2025 18:42:06

507 Views

In this article, we will learn about useful commands in JShell. Java 9 has introduced a new interactive tool called JShell. This tool can be used to execute, test user-friendly and easy way of Java classes, interfaces, enums, objects, statements and etc.  Different Useful Commands in JShell Below are some ... Read More

How to define expressions, variables, and methods in JShell in Java 9?

Alshifa Hasnain

Alshifa Hasnain

Updated on 10-Jun-2025 18:41:50

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 ... Read More

What is the use of the Cleaner class in Java 9?

Alshifa Hasnain

Alshifa Hasnain

Updated on 10-Jun-2025 18:41:30

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 ... Read More

How to initialize immutable collections in Java 9?

Alshifa Hasnain

Alshifa Hasnain

Updated on 10-Jun-2025 18:40:27

1K+ Views

Java 9 provides factory methods to create immutable lists, sets, and maps. It can be useful to create empty or non-empty collection objects. In Java 8 and earlier versions, we can use collection class utility methods like unmodifiableXXX to create immutable collection objects. If we need to create an immutable list, then use the Collections.unmodifiableList() method. ... Read More

How to save, edit, and drop a snippet in JShell in Java 9?

Alshifa Hasnain

Alshifa Hasnain

Updated on 10-Jun-2025 18:40:01

497 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. ... Read More

How can we create an unmodifiable Set in Java 9?

Alshifa Hasnain

Alshifa Hasnain

Updated on 10-Jun-2025 18:39:41

232 Views

In this article, we will learn to create an unmodifiable Set in Java 9. We will be learning about Set and unmodifiable Set, and will be learning different ways of creating an unmodifiable Set(Set.of() Method and unmodifiableSet() Method). Set In Java, a Set is an interface that inherits the Collection interface ... Read More

Advertisements