Useful Commands in JShell for Java 9

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

549 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 of the important commands in JShell: /open /var /types /methods /list /help /open To execute a script after JShell has started, we will use ... Read More

Define Expressions, Variables and Methods in JShell in Java 9

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 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

Use of the Cleaner Class in Java 9

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 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

Initialize Immutable Collections in Java 9

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. What does Immutable mean? An object is considered immutable if its state cannot change after it is constructed. Any modification creates a new object instead. String name = "TutorialsPoint"; name = name + "10"; Here, "TutorialsPoint" is an immutable string, and we cannot modify it directly. Instead, we use the ... Read More

Save, Edit, and Drop a Snippet in JShell in Java 9

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

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

Create an Unmodifiable Set in Java 9

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

252 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 and contains no duplicate elements. A Set interface has methods to add, delete, and check the existence of an element. Some of the implementations of the Set interface are: HashSet TreeSet LinkedHashSet What is an ... Read More

When to Use the ofNullable Method of Stream in Java 9

Alshifa Hasnain
Updated on 10-Jun-2025 18:39:17

2K+ Views

In this article, we will learn to use the ofNullable() method of Stream in Java 9. We will first go through the Stream class, after that we will learn about the ofNullable() method along with its syntax and real-world use cases. Stream Class Stream was introduced in Java 8, the Stream API is used to process collections of objects. It represents a sequence of elements that support various operations to perform computations in parallel. Creating an instance of a stream: Stream stream; A stream is not a type of data structure, it takes input from Collections, Arrays, etc. The ofNullable() ... Read More

Extract TXT Files from ZIP File Using Python

Niharikaa Aitam
Updated on 10-Jun-2025 18:29:03

2K+ Views

Python provides a built-in module called zipfile that allows us to create, read, write, and extract ZIP archives. When we want to extract only specific files, such as all .txt files, then we can perform filtering of the file names using string methods such as endswith(). A ZIP file is one of the archive formats which is used to compress one or more files into a single file to easily store and transfer data. It reduces the file size and keeps all related files compressed together for sharing over the internet and for saving disk space. Steps involved in ... Read More

Get Arc Length from Given Angle in Java

Vivek Verma
Updated on 10-Jun-2025 18:22:52

554 Views

An arc of a circle is a segment or portion of the circumference of a circle. In other words, a curve between a pair of distinct points. The length of the arc refers to the length between two points along the arc (two points along a section of a circle or curve). It is a percentage of the circumference of the circle. When two lines intersect each other, the common meeting point is called a vertex and the geometrical figure between the two arms/lines is called an angle. Following diagram will help you to understand the arc and its length: ... Read More

Solve the Dominating Set Problem in C++

Farhan Muhamed
Updated on 10-Jun-2025 17:59:20

453 Views

In this article, we will explain the dominating set problem and implement it's solution in C++. First of all, let's understand what a dominating set is. Dominating Set of a Graph A dominating set for a graph is a subset of the set of all the vertices. Every vertex that is not in the dominating set should be adjacent of at least one vertex in the dominating set. To understand this clearly, consider the following graph: In the above graph, the set of vertices {B, D} is one of the dominating sets, because: ... Read More

Advertisements