Found 2617 Articles for Java

What are the changes of class loaders in Java 9?

raja
Updated on 29-Apr-2020 10:49:22

715 Views

All java programs run on Java Virtual Machine (JVM). After compilation, a java class gets transformed into a platform and machine-independent bytecode, and compiled classes are stored as .class files. Whenever we try to use it, ClassLoader loads that class into memory. The classes get introduced into the Java environment when they are referenced by name. The loading of classes has been done by the class loader, once the class starts running, and the main() method is a way to start that class.There are few minor changes of class loaders in Java 9:The system class loader is no more in Java 9, ... Read More

How can we display all modules with classloaders in Java 9?

raja
Updated on 29-Apr-2020 09:11:04

361 Views

Before Java 9, the extension and the application class loader are an instance of the java.net.URLClassLoader class. In Java 9, the classification of class loaders has changed, instead of an external class loader, we have the Platform class loader. The purpose of using Platform class loader is that classes loaded by the bootstrap class loader have all permissions by default.In the below example, we can display all modules with classloaders.Exampleimport static java.util.Objects.isNull; public class Java9ClassLoaderTest {    public static void main(String args[]) {       ModuleLayer layer = ModuleLayer.boot();       layer.modules().forEach(module -> { ... Read More

What is the use of the "export" clause in a module-info file in Java 9?

raja
Updated on 28-Apr-2020 14:10:29

2K+ Views

A Module is a combination of both code and data that has a name, declares dependencies on other modules, exports packages that contain the public types that can be accessible outside this module and specifies the services it uses or the service implementations it provides. All of these have specified in a module-info.java file, which is included in the root directory of a module.There are two types of "export" clause can be used in "module-info.java" file.1) export : By default, the type public of a module is no longer visible outside the module. To make the public types of a given package visible from ... Read More

What is the importance of jdeps tool in Java 9?

raja
Updated on 28-Apr-2020 11:33:16

365 Views

The jdeps is a Java Class Dependency Analyzer tool, which is a command-line tool to show the package-level or class-level dependencies of given Java class files. The input classes can be given as a path-name to a .class file, a directory, a jar file, or it will be a fully qualified class name to analyze all class files."jdeps" has included in the jdk installation since jdk 8 and, it is represented by the "%java_home%\bin\jdeps.exe" program file. If we have "%java_home%\bin" directory included in the "path" environment variable, we will run "jdeps --help" command to see a complete list of all options. Below, we can ... Read More

How to implement String utility and immutability in JShell in Java 9?

raja
Updated on 27-Apr-2020 18:01:09

53 Views

JShell is an interactive command-line tool used to implement simple statements like expressions, classes, methods, fields, interfaces, and etc. String class is part of the built-in java.lang package and provides several methods for common text processing.1) String Utility: String provides several built-in utility methods. The methods like indexOf(), lastIndexOf(), startsWith(), endsWith(), isEmpty(), equals(), equalsIgnoreCase() are that part of string utility.In the below code snippet, we have implemented the string utility methods in the JShell tool.Snippet-1jshell> String str = "JShell is a new feature in Java9"; str ==> "JShell is a new feature in Java9" jshell> str.indexOf("new") $4 ==> 12 ... Read More

What are the rules we need to follow in JShell in Java 9?

raja
Updated on 27-Apr-2020 12:18:03

130 Views

Java 9 introduced an interactive REPL (Read-Evaluate-Print-Loop) tool: JShell, and it allows us to execute code snippets and get an immediate result. A snippet is an instruction that can use standard Java syntax. It represents a single expression, statement, or declaration.Below are some of the rules we need to follow while using the JShell tool.Rules for JShell tool:A snippet is like import declarations, class declarations, method declarations, interface declarations, field declarations, statements, and primary expressions.The package declarations are not allowed. JShell code is placed under the transient JShell package.The access modifiers: public, protected, and private, and the modifiers: final and static are not allowed in ... Read More

What is the use of the "requires" clause in a module-info file in Java 9?

raja
Updated on 28-Apr-2020 13:21:42

2K+ Views

A module is an important concept introduced in Java 9. By using this concept, we can able to divide code into smaller components called modules. Therefore, each module has its own responsibility and declare its dependency on other modules to work properly. In order to declare a module, we need to include the "module-info.java" file to root source code.There are few types of "requires" clause in "module-info" file1)  requires : By default, a module doesn't know other modules present in a module-path. So, it is necessary to add a line in our module-info.java: "requires" each time when we want to access ... Read More

How to declare reference types in JShell in Java 9?

raja
Updated on 24-Apr-2020 19:46:37

121 Views

JShell is an interactive tool in Java 9 that allows user inputs, evaluates it, and prints output to the user.Unlike a value type, a reference type doesn't store its value directly. Instead, it will store the address where a value is stored. It means that a reference type contains a pointer to another memory location that holds the data. The reference types are String, arrays, class, and delegates.In the below code snippet, when we create a new instance of Animal, it can be created on the heap memory. The new Animal() creates an object on the Heap. Animal@73846619, the object is ... Read More

What is the use of the jdeprscan tool in Java 9?

raja
Updated on 24-Apr-2020 17:33:05

198 Views

The jdeprscan tool can be used for static analysis of classes, archives, and folders for the presence of API elements marked as deprecated. This tool only detects items marked as deprecated in Java SE, and it doesn't detect marked items in other libraries. All classes on which the examined class or set of classes depends must be available when compiling or running a class. In the absence of a dependent class, this tool provides a list of unavailable classes preceded by the error: cannot find a class.Below is the syntax for the jdeprscan tool.Syntaxjdeprscan [options] {dir | jar | class}The "jdeprscan" command can be supported by "jmods\jdk.jdeps.jmod" ... Read More

How to initialize an array in JShell in Java 9?

raja
Updated on 24-Apr-2020 16:43:30

292 Views

JShell is a command-line tool used to evaluate simple statements, expressions, classes, methods, variables, etc.. and prints the output immediately to the user.An array in Java is also an object. We need to declare an array and then created. In order to declare a variable that holds an array of integers, we can mention like int[] array. In an array, the index starts from 0 to (length of array - 1).In the below code snippet, we can use an index to find the specific element from the array. It will be done by using an indexing operator: []. The expression marks[0] maps ... Read More

Advertisements