Programming Articles - Page 2040 of 3363

What are the different status states of REPL in Java 9?

raja
Updated on 02-Apr-2020 12:50:55

343 Views

REPL stands for Read-Evaluate-Print-Loop. It holds some states, and each statement in JShell has a state. This state denies the execution status of snippets and variables. It can be determined by the results of the eval() method of JShell instance, which evaluates the code.There are seven different status states listed below.DROPPED: The snippet is inactive.NONEXISTENT: The snippet is inactive because it does not yet exist.OVERWRITTEN: The snippet is inactive because it has been replaced by a new snippet.RECOVERABLE_DEFINED: The snippet is a declaration snippet with potentially recoverable unresolved references or other issues in its body.RECOVERABLE_NOT_DEFINED: The snippet is a declaration snippet with ... Read More

How to implement the encapsulation concept in JShell in Java 9?

raja
Updated on 02-Apr-2020 09:44:51

165 Views

Java Shell (simply JShell) is a REPL interactive tool for learning the Java and prototyping Java code. It evaluates declarations, statements, and expressions as entered and immediately prints out the result and runs from the command-line.Encapsulation is an important concept in Java to make sure that "sensitive" data has been hidden from users. To achieve this, we must declare a class variable as private and provides public access to get and set methods and update the value of a private variable.In the below code snippet, we have implemented the Encapsulation concept for Employee class.jshell> class Employee { ...>       private String firstName; ...>     ... Read More

How can we create a multi-release jar(mrjar) using jar tool in Java 9?

raja
Updated on 01-Apr-2020 16:29:09

283 Views

In Java 9, a new feature "multi-release jar format" has been introduced where jar format enhanced with different versions of Java class or resources that can be maintained and used as per the platform. A jar command can be used to create a multi-release jar that contains two versions of the same class compiled for both Java 8 and Java 9 versions with a warning message, telling that both classes are identical.C:\Users\User\tutorialspoint>jar --create --file MR.jar -C sampleproject-base demo --release 9 -C sampleproject-9 demo Warning: entry META-INF/versions/9/demo/SampleClass.class contains a class thatis identical to an entry already in the jarThe " --release 9" option can tell jar ... Read More

How to check a string is palindrome or not in Jshell in Java 9?

raja
Updated on 01-Apr-2020 15:47:43

173 Views

JShell is the first REPL(Read-Evaluate-Print-Loop) interactive tool that has been introduced as a part of Java 9. It evaluates declarations, statements, and expressions as entered and immediately shows the results, and it runs from the command-line prompt.Palindrome string is a string where it remains the same when reversed or word spelled the same way in both forward and backward directions.In the below example, we can able to check whether the given string is palindrome or not in the JShell tool.C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> String str="LEVEL"; str ==> "LEVEL" jshell> ... Read More

What are the core library changes in Process API in Java 9?

raja
Updated on 01-Apr-2020 10:01:49

167 Views

In Java 9, one can retrieve the PID of the process through a native call and can be achievable through the ProcessHandle. We can also retrieve information about the currently running Java Process (JVM) and Info (inner class of ProcessHandle) class that contains details about the process. We can also return a snapshot of all currently running processes in the system.Exampleimport java.lang.ProcessHandle.Info; public class ProcessAPIChanges {    public void detailedAPIInfo(ProcessHandle processHandle) {       Info processInfo = processHandle.info();       System.out.println("Detailed Process Info is Provided Below: ");       System.out.println("[Executable Name] " + processInfo.command().get());       System.out.println("[User Name] " + ... Read More

Which modifiers can't allow in the top-level declaration in JShell in Java 9?

raja
Updated on 01-Apr-2020 07:52:42

225 Views

JShell is an interactive tool for learning the Java language and prototyping Java code. It is a REPL (Read-Evaluate-Print-Loop) that evaluates declarations, statements, and expressions once entered and immediately prints the results in JShell. This tool runs from the command-line prompt.The modifiers like public, protected, private, static, and final have not allowed on top-level declarations and can be ignored with a warning. The keywords like synchronized, native, abstract, and default top-level methods have not allowed and can be errors.In the below code snippets, we have created both final and static variables. It prints out a warning message to the user that "Modifier 'final' or 'static' not permitted ... Read More

MakeFile in C++ and its applications

Ayush Gupta
Updated on 01-Apr-2020 06:46:17

290 Views

In this tutorial, we will be discussing a program to understand MakeFile in C++ and its applications.The task is to break the entire program with MakeFile. It is usually done by making .cpp files and .h files with all the classes/functionalities and link them together.Examplemain.cpp#include #include "function.h" using namespace std; //main execution program int main(){    int num1 = 1;    int num2 = 2;    cout

Kruskal’s Minimum Spanning Tree using STL in C++

Ayush Gupta
Updated on 01-Apr-2020 06:43:15

541 Views

In this tutorial, we will be discussing a program to understand Kruskal’s minimum spanning tree using STL in C++.For this, we will be provided with a connected, undirected and weighted graph. Our task is to calculate the Minimum spanning tree for the given graph.Example Live Demo#include using namespace std; typedef pair iPair; //structure for graph struct Graph{    int V, E;    vector< pair > edges;    Graph(int V, int E){       this->V = V;       this->E = E;    }    void addEdge(int u, int v, int w){       edges.push_back({w, {u, v}});    } ... Read More

Lower bound in C++

Ayush Gupta
Updated on 01-Apr-2020 06:41:03

348 Views

In this tutorial, we will be discussing a program to understand the lower bound in C++.lower_bound() method in C++ is used to return the very first number in the container object which is not less than the given value.Example Live Demo#include int main(){    std::vector v{ 10, 20, 30, 40, 50 };    std::cout

Iseek() in C/C++ to read the alternate nth byte and write it in another file

Ayush Gupta
Updated on 01-Apr-2020 06:38:41

771 Views

In this tutorial, we will be discussing a program to understand how to read the alternate nth byte and write it in another file.For this, we will be provided with two .txt files. Our task is to write the contents from one file to another file using Iseek() which is used to change the pointer of the file descriptor.Example#include #include #include #include void func(char arr[], int n){    int f_write = open("start.txt", O_RDONLY);    int f_read = open("end.txt", O_WRONLY);    int count = 0;    while (read(f_write, arr, 1)){       if (count < n) ... Read More

Advertisements