JAVA10 New Characteristics __java

Source: Internet
Author: User
Tags garbage collection instance method locale repetition stack trace string format

JAVA10 released also for some time, this time is just free, from the official website updated JDK play. While in use I found that previous versions of Eclipse and idea did not support JAVA10, I think it might be because of the introduction of the Var type, the IDE needs to be fit. Fortunately, eclipse4.7.3 is released very quickly and can be a perfect supporter of JAVA10.

The following updates are translated in full and are helpful for learning, reproduced in:

Https://www.oschina.net/translate/109-new-features-in-jdk-10?p=2#comments

JDK10 contains 12 Jep (improvement offers):

"286" local variable type inference: For developers, this is the only true feature of JDK10. It introduces Var, such as JavaScript, that is common in other languages to Java. As long as the compiler can infer this type, you no longer need to specifically declare the type of a local variable. A simple example is:

var x = new arraylist<string> ();

This eliminates the repetition of the arraylist<string> type definition that we must perform before. I encourage you to read Jep, because there are some rules about whether this syntax can be used.

Interestingly, it is important to note that Var cannot be a keyword, but rather a reserved word. This means you can still use Var as a variable, method or package name, but now (although I'm sure you'll never) you can't have another class being invoked.

[310] Application class data sharing (CDS): CDs are introduced in JDK5 to improve the performance of JVM startup while reducing the resource footprint of multiple virtual machines running on the same physical or virtual machine.

JDK10 extends the CDS to the class loader that allows the internal system, the class loader for the internal platform, and the custom class loader to load the acquired classes. Previously, the use of CDS was limited to the bootstrap ClassLoader.

[314] Additional Unicode Language tab extensions: This will improve the Java.util.Locale class and the associated APIs to implement the Unicode extension of the additional BCP 47 language tags. In particular, the currency type, the first day of the week, area coverage and time zone tags will now be supported.

[322] Time-based versioning: As I discussed in my previous blog, our JDK version string format is almost as much as the JDK version. Fortunately, this is the last need to use, we can stick with it. This format is used much like the one presented in JDK9 to provide a more semantic form. One thing that bothers me is the inclusion of a interim element, as the JEP proposal says, "always be 0". Well, if it's always 0, then what's the point? They say it's a reservation for future use, but I still don't agree. I think this is a bit redundant.

This also eliminates the rather bizarre situation in JDK9. The first update is JDK 9.0.1, very logical. The second update is JDK 9.0.4, illogical. The reason is that, in the JDK9 version count mode, there is a need to leave blank for emergency or not scheduled updates to use. But since no updates are necessary, why not simply call it JDK 9.0.2.

[319] Root certificate: A set of default CA root certificates will be provided in the JDK. Key security components, such as TLS, are available by default in OpenJDK builds. This is a useful addition to Oracle's efforts to ensure that OpenJDK binaries and Oracle JDK binaries function as part of their work.

[307] The parallel garbage collector G1:G1 is designed to be a low latency garbage collector (but it will still use a full compression set if it cannot keep up with the rate of ascension generated by the old heap fragments). Before JDK9, the default collector is parallelism, throughput, and collector. To reduce the difference in the application performance profile using the default collector, G1 now has a parallel complete collection mechanism.

[313] Remove the Native-header automatic generation tool: Java9 started some housekeeping for JDK, which is a continuation of this feature. When you compile JNI code, you no longer need a separate tool to generate the header file, as this can be done through Javac. At some point in the future, JNI will be replaced by the results of the Panama project, but it's not clear when that happens.

[304] Garbage collector interface: This is not an interface for developers to control garbage collection; it is an interface that allows the other garbage collector to integrate quickly and easily in the source code of the JVM.

[312] Thread-local variable control: This is a fairly low-level change within the JVM and will now allow thread callbacks to be implemented without running the global virtual machine security point. This makes it possible and inexpensive to stop a single thread, rather than just enabling or stopping all threads.

[316] Heap allocation on standby storage: Hardware technology continues to evolve, and it is now possible to use Non-volatile RAM with the same interface and similar performance characteristics as traditional DRAM. This Jep will enable the JVM to use heaps that apply to different types of storage mechanisms.

[317] Experimental java-based JIT compilers: The recently announced Metropolis project, which proposes to rewrite most JVMs in Java. At first thought, it was strange. If the JVM is written in Java, do you need a JVM to run the JVM. Correspondingly, this leads to a good mirror analogy. The reality is that writing a JVM using Java does not mean that it must be compiled into bytecode, you can use AOT compilation, and then compile code at run time to improve performance.

This Jep introduces the Graal compiler research project into the JDK. And to make the Metropolis project a reality, so that JVM performance and current C + + written version of the match (or lucky to go beyond) to provide the basis.

[296]: Merge JDK Multiple code warehouses into a separate repository: in JDK9, there are 8 warehouses: root, CORBA, hotspot, Jaxp, Jaxws, JDK, Langtools, and Nashorn. These will be merged into one in JDK10, making it possible to run atomic commit (atomic commit) across the repository of interdependent changesets.

New API

73 new additions are added to the standard class library.

Java.awt.Toolkit
int Getmenushortcutkeymaskex (): determines which extension modifier keys is the appropriate accelerator key for menu shortcuts.

Java.awt.geom.Path2D:
void TrimToSize (): Calculates the capacity of this path2d instance to its current size. The application can use this action to minimize the storage space of the path. This method is also added to the path2d.double and Path2d.float classes.

Java.io.ByteArrayOutputStream:
String ToString (Charset): Overload toString () to convert the contents of the buffer to a string by decoding the bytes with the specified character set.

Java.io.PrintStream:
Lang.io.PrintWriter:
These two classes have three new constructors that require additional Charset parameters.

Java.io.Reader:
Long TransferTo (Writer): reads all characters from this reader and writes the characters to the given Writer in the order in which they are read.

Java.lang.Runtime.Version:
There are four new methods that return the integer value of the new (Jep 322) Version string field: Feature (), Interim (), Patch (), and update ().

Java.lang.StackWalker.StackFrame:
String getdescriptor (): Returns a descriptor for the method represented by this stack frame, according to the JVM standard.
String Getmethodtype (): Returns the type of method represented by this stack frame, describing the parameter type and the return value type.

Java.lang.invoke.MethodType:
Class<?> Lastparametertype (): Returns the last parameter type of this method type. If this method type has no arguments, the null type is returned as the Sentry value (Sentinel value).

Java.lang.management.RuntimeMXBean:
Long Getpid (): R Returns the process ID of the running JVM.

Java.lang.management.ThreadMXBean:
Threadinfo[] Dumpallthreads (Boolean, Boolean, int): Returns the thread information for all active threads, with the specified maximum number of elements and the stack trace of the synchronization information.
Threadinfo[] GetThreadInfo (long[], Boolean, Boolean, int): Returns the thread information for each thread, whose identity is in the input array, with the specified maximum number of elements and a stack trace of the synchronization information.

Java.lang.reflect.MalformedParameterizedTypeException: Added a new constructor, which takes the form of a string as a parameter to get details.

Java.net.URLDecoder:
Java.net.URLEncoder:

Each of these two classes has a new overloaded decoding and encoding method that takes charset as an additional parameter.

Java.nio.channels.Channels:
Two new static overloaded methods that allow the use of Charset Newreader (Readbytechannel,charset) and Newwriter (Writebytechannel,charset).

Java.nio.file.FileStore:
Long Getblocksize (): Returns the number of bytes per block in this file store.

Java.time.chrono: There are three classes in this bag, Hijrahera, Miinguoera and Thaibuddhistera, all of which have the same method.
String GetDisplayName (TextStyle, Locale): This returns the text name used to identify the era, which is suitable for presentation to the user.

Java.time.format.DateTimeFormatter:
Localizedby (Locale): Returns a copy of the specified formatter that contains localized values for the region, calendar, area, decimal, and/or time zone, which replaces the value in the formatter.

Java.util:DoubleSummaryStatistics, Intsummarystatistics, and longsummarystatistics all have a new constructor that contains 4 numeric values. It constructs a Non-null instance using the specified count, minimum, maximum, and sum.

Java.util.List:
JAVA.UTIL.MAP:
Java.util.Set: Each of these interfaces adds a new static method, Copyof (Collection). These functions return an immutable list, map, or collection of elements that contain a given collection, in the order in which they are iterated.

Java.util.Optional:
Java.util.OptionalDouble:
Java.util.OptionalInt:
Java.util.OptionalLong: Each class has a new method, Orelsethrow (), which is essentially the same as get (), which is to say, if Optional has a value, it returns. Otherwise, the nosuchelementexception will be thrown.

Java.util.Formatter:
Java.util.Scanner:

These two classes have three new constructors, all with a charset parameter, except for the other parameters.

Java.util.Properties: This has a new constructor that accepts an int parameter. This creates a list of empty attributes with no default values, and specifies the initial size to accommodate the specified number of elements without dynamic resizing. There is also a new overloaded replace method that accepts three Object parameters and returns a Boolean value. The entry for the specified key is replaced only if the specified value is currently mapped.

Java. Splittablerandom:
void Nextbytes (byte[]): Fills a user-supplied byte array with the generated pseudo-random bytes.

Java.util.concurrent.FutureTask: Added the ToString () method, which returns a string identifying the futuretask and its completion state. In parentheses, the state contains one of the following strings, "Completed normally", "Completed exceptionally", "cancelled", or "not Completed".

Java.util.concurrent.locks.StampedLock:
Boolean Islockstamp (Long): Returns a tag stamp indicating whether a lock is held.
Boolean Isoptimisticreadstamp (Long): Returns whether a markup stamp represents the success of an optimistic read (optimistic read).
Boolean Isreadlockstamp (Long): Returns a tag stamp that indicates whether to hold a non-exclusive lock (that is, read lock).
Boolean Iswritelockstamp (Long): Returns a tag stamp indicating whether to hold an exclusive lock (that is, write lock).

Java.jar.JarEntry:
String getrealname (): Returns the real name of this jarentry. If this jarentry is a portal to a multiple-version jar file, it is configured to do so, and this method returns the name of the version entry that Jarentry represents, not the path name of the base entry that Zipentry.getname () returns. If Jarentry does not represent a versioned entry for a multiple-version jar file or the jar file is not configured to process as a multiple-version jar file, this method returns the same name as the Zipentry.getname () return.

Java.util.jar.JarFile:
Stream<jarentry> Versionedstream (): Returns the corresponding Stream for the specified version of the jar file. Similar to the Jarentry Getrealname method, this is related to the multiple version jar file.

Java.util.spi.LocaleNameProvider:
Getdisplayunicodeextensionkey (String, Locale): Returns a localized name for the given Unicode extension key.
Getdisplayunicodeextensiontype (String, String, Locale): Returns a localized name for the given Unicode extension key.

Java.util.stream.Collectors:
Tounmodifiablelist ():
Tounmodifiableset ():
Tounmodifiablemap (function, function):

Tounmodifiablemap (function, function, Binaryoperator): All four new methods return collectors, aggregating the input elements into the appropriate, unmodified collection.

Java.lang.model.SourceVersion: Now you have a field that represents the version of JDK 10.

JAVA.LANG.MODEL.UTIL.TYPEKINDVISITOR6:
JAVAX.LANG.MODEL.UTIL.TYPEKINDVISITOR9:
(I must confess that I have never heard of these classes)
R Visitnotypeasmodule (Notype, P): Accessing the Pseudo-type of a MODULE. I'm not sure why only these two classes get this method, because there are Visitor7 and VISITOR8 variables.

Javax.remote.management.rmi.RMIConnectorServer:
This class has added two fields: Credentials_filter_pattern and Serial_filter_pattern.

Javax. Buttonmodel: Look, Swing is still being updated.
Buttongroup Getgroup (): Returns the group to which the button belongs. are commonly used for radio buttons, which are mutually exclusive in groups.

Javax.plaf.basic.BasicMenuUI:

Dimension getminimumsize (jcomponent): Returns the minimum size that the specified component is suitable for perception.

JVM Specification Changes

These changes are quite small:

Section 4.6: Class file Format (page 99th). There are minor changes to the method access flags.

Section 4.7: Module Properties (Page 169th). If the module is not java.base, JDK 10 is no longer allowed to set acc_transitive or Acc_static_phase.

Section 4.10: Validation of class files (page No. 252). The DUP2 directive has changed the definition of typesafe form 1, reversing the order of the types in the Cansafleypushlist section (you need to look carefully to find it).

Section 5.2: Java Virtual Machine Startup (page No. 350). This description adds the user-defined class loader (except the Bootstrap class loader) that can be used when creating an initial class or interface.

changes to the Java language specification

There are also some changes, but mainly to support local variable type inference.

Sect. 3.8: Identifiers (page 23rd). After ignoring the negligible characters, the equivalence of identifiers is now considered. This seems to be logical.
(page 24th) A new token,typeidentifier that supports new usages of local variable types, while Var is used not as a keyword, but as an identifier with a special meaning as the type of a local variable declaration.

4th. 10.5: Type Prediction (page 76th). This is a fairly complex part that involves capturing variables, nested classes, and using local variable type inference. I suggest you read this part of the specification and not try to explain it.

Section 6.1: Declaration (page 134th). A small change that reflects the inference of using Typeidentifier to support local variable types.

Section 6.5: Determine the meaning of the name (page 153th, page 158th and 159th). Change the class type based on the use of the type identifier.

Part 6.5.4.1: Simple packageortypenames (160th page)

Section 6.5.4.2: Packageortypenames of Compliance (page 160th). Both of these methods have subtle changes with the use of typeidentifier.

7th 5.3: Single Static import Declaration (page 191th). This changes the rules for importing static types with the same name. This will be an error unless the type is the same, in which case the repetition is ignored.

7th 7.1: Reliance (page 198th). If you explicitly declare that a module needs to be java.base, then you can no longer use modifiers (such as static) after the necessary keywords.

Part 8th: Formal parameters (page No. 244). The recipient parameter may appear only in the Formalparameters list of one instance method, or in the constructor of an inner class, where the inner class is not declared in a static context.

9th. 7.4: Where the Notes may appear (page No. 335). There is a change associated with a local variable type inference.

Part 14.4: Local Variable Declaration statements (page No. 433). A large number of changes required to implement the local variable type inference.

Section 14th: Enhanced for Statement (page No. 455). This structure has been updated, including support for inference of local variable types.

14th. 20.3: try-with-resources (474 pages). This structure has been updated, including support for inference of local variable types.

Finally, the 19th chapter has several syntax updates that reflect the need for more use of the Typeidentifier type identifier, not just the Identifier identifier, to support local variable type inference.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.