Java Basics ( Java-25 )
Click ★ if you like the project. Your contributions are heartily ♡ welcome.
Calendarand Locale;java.lang.String(byte[], *) and method performance java.lang.String.getBytes();AccessController.doPrivileged that allows you to set a subset of privileges without having to check all * other access levels;jjs for using JavaScript Nashorn;java can run JavaFX applications;jdeps for analyzing .class files.Nashorn is a JavaScript engine developed in Java by Oracle. Designed to provide the ability to embed JavaScript code in Java applications. Compared to Rhino , which is supported by the Mozilla Foundation, Nashorn provides 2 to 10 times better performance, as it compiles code and transfers bytecode to the Java virtual machine directly in memory. Nashorn can compile JavaScript code and generate Java classes that are loaded with a special loader. It is also possible to call Java code directly from JavaScript.
jjs - This is a command line utility that allows you to execute JavaScript programs directly in the console.
In Java, there are three different ways for reading input from the user in the command line environment ( console ).
1. Using Buffered Reader Class:
This method is used by wrapping the System.in ( standard input stream ) in an InputStreamReader which is wrapped in a BufferedReader, we can read input from the user in the command line.
/**
* Buffered Reader Class
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) throws IOException {
// Enter data using BufferReader
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// Reading data using readLine
String name = reader.readLine();
// Printing the read line
System.out.println(name);
}
}2. Using Scanner Class:
The main purpose of the Scanner class is to parse primitive types and strings using regular expressions, however it is also can be used to read input from the user in the command line.
/**
* Scanner Class
*/
import java.util.Scanner;
class GetInputFromUser {
public static void main(String args[]) {
// Using Scanner for Getting Input from User
Scanner in = new Scanner(System.in);
String s = in.nextLine();
System.out.println("You entered string " + s);
int a = in.nextInt();
System.out.println("You entered integer " + a);
float b = in.nextFloat();
System.out.println("You entered float " + b);
}
}3. Using Console Class:
It has been becoming a preferred way for reading user's input from the command line. In addition, it can be used for reading password-like input without echoing the characters entered by the user; the format string syntax can also be used ( like System.out.printf() ).
/**
* Console Class
*/
public class Sample {
public static void main(String[] args) {
// Using Console to input data from user
String name = System.console().readLine();
System.out.println(name);
}
}The javap command displays information about the fields, constructors and methods present in a class file. The javap command ( also known as the Java Disassembler ) disassembles one or more class files.
/**
* Java Disassembler
*/
class Simple {
public static void main(String args[]) {
System.out.println("Hello World");
}
}cmd> javap Simple.class Output
Compiled from ".java"
class Simple {
Simple();
public static void main(java.lang.String[]);
} System.out::println?The specified expression illustrates passing a reference to a static method of a println()class System.out.
Streams can be sequential and parallel. Operations on sequential streams are performed in one processor thread, on parallel streams - using several processor threads. Parallel streams use the shared stream ForkJoinPoolthrough the static ForkJoinPool.commonPool()method. In this case, if the environment is not multi-core, then the stream will be executed as sequential. In fact, the use of parallel streams is reduced to the fact that the data in the streams will be divided into parts, each part is processed on a separate processor core, and in the end these parts are connected, and final operations are performed on them.
You can also use the parallelStream()interface method to create a parallel stream from the collection Collection.
To make a regular sequential stream parallel, you must call the Streammethod on the object parallel(). The method isParallel()allows you to find out if the stream is parallel.
Using, methods parallel()and sequential()it is possible to determine which operations can be parallel, and which only sequential. You can also make a parallel stream from any sequential stream and vice versa:
collection
.stream ()
.peek ( ... ) // operation is sequential
.parallel ()
.map ( ... ) // the operation can be performed in parallel,
.sequential ()
.reduce ( ... ) // operation is sequential againAs a rule, elements are transferred to the stream in the same order in which they are defined in the data source. When working with parallel streams, the system preserves the sequence of elements. An exception is a method forEach()that can output elements in random order. And in order to maintain the order, it is necessary to apply the method forEachOrdered().
ArrayListeasy to use, since the structure of this collection assumes a sequence of unrelated data. But a type collection LinkedListis not the best option, since in a sequential list all the elements are connected with previous / next. And such data is difficult to parallelize.ForkJoinPool, such long operations can stop all parallel streams in the JVM due to the lack of available threads in the pool, etc. e. parallel streams should be used only for short operations where the count goes for milliseconds, but not for those where the count can go for seconds and minutes;unordered():collection.parallelStream ()
.sorted ()
.unordered ()
.collect ( Collectors . toList ());Java Virtual Machine (JVM) is a specification that provides runtime environment in which java bytecode(.class files) can be executed. The JVM is the platform. The JVM acts as a "virtual" machine or processor. Java's platform independence consists mostly of its Java Virtual Machine (JVM). JVM makes this possible because it is aware of the specific instruction lengths and other particularities of the platform (Operating System).
The JVM is not platform independent. Java Virtual Machine (JVM) provides the environment to execute the java file(. Class file). So at the end it's depends on kernel and kernel is differ from OS (Operating System) to OS. The JVM is used to both translate the bytecode into the machine language for a particular computer and actually execute the corresponding machine-language instructions as well.
The Just-In-Time (JIT) compiler is a component of the runtime environment that improves the performance of Java applications by compiling bytecodes to native machine code at run time.
Java programs consists of classes, which contain platform-neutral bytecodes that can be interpreted by a JVM on many different computer architectures. At run time, the JVM loads the class files, determines the semantics of each individual bytecode, and performs the appropriate computation. The additional processor and memory usage during interpretation means that a Java application performs more slowly than a native application. The JIT compiler helps improve the performance of Java programs by compiling
No open issues yet, or sync has not completed.