Hello - new features in Java 10, please take a look

On March 20, 2018, Java 10 was officially released!

Related address:

Official address: http://www.oracle.com/technetwork/java/javase/downloads/index.html

Jdk download address: http://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html

Installation Guide: https://docs.oracle.com/javase/10/install/overview-jdk-10-and-jre-10-installation.htm

 

Current status of Java:

1) According to statistics, 90% of users are currently using Java8 and below (fortunately, Java8 has become the main force).

2) Under the constant stimulation of the community, for a faster iterative version. The official version will be upgraded in March and September every year (the version update cycle will be stable at 6 months).

3) In the latest development language rankings, Java still dominates the pack and ranks first!

 

1. 12 key new features in Java 10

✔  Type inference for local variables

   Java started referencing types like var in the scripting language JavaScript (weak typing), allowing you to define variables of any type via var.

   As a developer, this is the only feature that is closely related to you. It can help you greatly simplify your code.

   Some students will ask, what is the difference between var and Object?

   Let's take a chestnut:

Object objList = new ArrayList<String>();
objList.add("hello, world!");//This code will compile exception

var varList = new ArrayList<String>();
varList.add("hello, world!");//And this code will compile and pass

  When the above code is compiled with Java10, an exception will occur on line 2 (error: symbol not found), of course, the version below Java10 will also compile exceptions.

  But variables defined by var can be compiled and passed, why? Because var is a type reference object, it has the same properties as the type on the right side of the expression.

  That is, the following two lines of code are equivalent:

var varList = new ArrayList<String>();

ArrayList<String> varList = new ArrayList<String>();

 

✔  Application class data sharing (CDS) 

  CDS was introduced in JDK5 to improve JVM startup performance and reduce resource usage when multiple virtual machines are running on the same physical or virtual machine.
  JDK10 will extend CDS to allow internal system classloaders, internal platform classloaders and custom classloaders to load obtained classes. Previously, the use of CDS was limited to bootstrap's classloader.

 

✔Extra  Unicode language tag extension

  This will improve the java.util.Locale class and related APIs to implement Unicode extensions for additional BCP47 language tags. In particular, tags such as currency type, first day of the week, regional overlay and time zone will now be supported.

 

Time-based version control

  We have almost as many JDK version string formats as there are JDK versions. Fortunately, this is the last thing we need to use, and we can stick with it. This format is used much like the one introduced in JDK9 to provide a more semantic form. One thing that bothers me is the inclusion of an INTERIM element, which, as the JEP proposal says, is "always 0". Well, if it's always 0, what's the point of it? They say it's reserved for future use, but I still don't quite agree. I think it's a bit redundant and cumbersome.
  This also eliminates the rather odd situation that was present in JDK9. The first update was JDK 9.0.1 , very logically. The second update is JDK 9.0.4, illogical. The reason is that in JDK9's version counting mode, it needs to be left blank for emergency or unexpectedly scheduled updates. But since no update is necessary, why not simply call it JDK 9.0.2?

 

✔Root  certificate

  A default set of CA root certificates will be provided in the JDK. Critical security components, such as TLS, will be enabled by default in OpenJDK builds. This is part of Oracle's ongoing efforts to ensure that OpenJDK binaries are functionally identical to Oracle JDK binaries, and is a useful addition.

 

✔  Parallel full garbage collector G1

  G1 is designed to be a low-latency garbage collector (but will still use the full compaction set if it can't keep up with the rate of improvement from old heap fragmentation). Before JDK9, the default collector was parallel, throughput, collector. To reduce differences in application performance profiles using the default collector, G1 now has a parallel full collection mechanism.

 

✔Remove  Native-Header auto-generating tool

  Java9 started some housekeeping for the JDK, and this feature is a continuation of it. When compiling JNI code, there is no longer a need for a separate tool to generate header files, as this can be done with javac. At some point in the future, JNI will be replaced by the results of the Panama project, but when that happens is unclear.

 

✔  Garbage collector interface

  This is not an interface for developers to control garbage collection; it is an interface in the JVM source code that allows quick and easy integration of other garbage collectors.

 

✔Thread  -local variable management

  This is a fairly low-level change inside the JVM and will now allow thread callbacks to be implemented without running a global virtual machine safepoint. This would make it possible and cheaper to stop a single thread, rather than just enabling or stopping all threads.

 

✔  Heap allocation on alternate 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 conventional DRAM. This JEP will enable the JVM to use heaps for different types of storage mechanisms.

 

Experimental Java-based JIT compiler

  The recently announced Metropolis project proposes to rewrite most of the JVM in Java. At first thought, it felt strange. If the JVM is written in Java, do I need a JVM to run the JVM? Correspondingly, this leads to a nice mirroring analogy. The reality is that writing a JVM in Java doesn't mean it has to be compiled to bytecode, you can use AOT compilation and then compile the code at runtime to improve performance.

  This JEP brings the Graal compiler research project into the JDK. And provide the basis for making the Metropolis project a reality, with JVM performance matching (or fortunately exceeding) versions written in current C++.

 

✔  Merge multiple JDK repositories into a single repository

   In JDK9, there are 8 repositories: root, corba, hotspot, jaxp, jaxws, jdk, langtools and nashorn. In JDK10 these will be merged into one, making it possible to run atomic commits across repositories of interdependent changesets.

 

 

2. New API or function

There are 73 new additions to the standard class library.

▪ java.awt.Toolkit:
  int getMenuShortcutKeyMaskEx(): Determines which extended modifier key is the appropriate accelerator key for the menu shortcut key.

 

▪ java.awt.geom.Path2D:
  void trimToSize(): Calculates the capacity of this Path2D instance to its current size. Applications can use this action to minimize storage space for paths. This method has also been added to the Path2D.Double and Path2D.Float classes.

 

▪ java.io.ByteArrayOutputStream:
  String toString(Charset): Overrides toString() to convert the contents of the buffer to a string by decoding bytes using the specified character set.

 

▪ java.io.PrintStream:
 lang.io.PrintWriter:
  Both classes have three new constructors that require an additional Charset parameter.

 

▪ java.io.Reader:
  long transferTo(Writer): Reads all characters from this Reader and writes them to the given Writer in the order they were 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 the descriptor of the method represented by this stack frame according to JVM standards.
  String getMethodType():  Returns the method type represented by this stack frame, describing the parameter type and return value type.

 

▪ java.lang.invoke.MethodType:
  Class<?> lastParameterType():  Returns the last parameter type of this method type. If this method type has no parameters, the empty type is returned as the Sentinel Value.

 

▪ java.lang.management.RuntimeMXBean:
  long getPid():   Returns the process ID of the running JVM.

 

▪ java.lang.management.ThreadMXBean:
  ThreadInfo[] dumpAllThreads(boolean, boolean, int): Returns thread information for all active threads, including stack traces with the specified maximum number of elements and synchronization information.
  ThreadInfo[] getThreadInfo(long[], boolean, boolean, int): Returns thread information for each thread whose identities are in the input array with the specified maximum number of elements and stack traces for synchronization information.

 

▪ java.lang.reflect.MalformedParameterizedTypeException:

  Added a new constructor that takes a string as an argument to get details.

 

▪ java.net.URLDecoder:
  java.net.URLEncoder:
  Both classes have new overloaded decoding and encoding methods that take a charset as an additional parameter.

 

▪ java.nio.channels.Channels:
  Two new static overloaded methods that allow using Charset's 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.HijrahEra:

  java.time.chrono.MiinguoEra:

  java.time.chrono.ThaiBuddhistEra:
  String getDisplayName(TextStyle, Locale): This returns the textual name used to identify the era, suitable for display to the user.

 

▪ java.time.format.DateTimeFormatter:
  localizedBy(Locale): Returns a copy of the specified formatter with localized values ​​for the locale, calendar, region, decimal and/or time zone, which supersedes the values ​​in that formatter.

 

▪ java.util.DoubleSummaryStatistics:

  java.util.IntSummaryStatistics:

  java.util.LongSummaryStatistics:

  A new constructor has been added to these 3 classes, which contains 4 values. It constructs a non-null instance with the specified count, minimum, maximum and sum.

 

▪ java.util.List:
  java.util.Map:
  java.util.Set:

  All three interfaces have added a new static method, copyOf(Collection). These functions return an unmodifiable list, map, or collection containing the elements of the given collection in the order in which it is iterated.

 

▪ java.util.Optional:
  java.util.OptionalDouble:
  java.util.OptionalInt:
  java.util.OptionalLong: These classes have added a new method orElseThrow(). It is essentially the same as get(), that is, returns if Optional has a value. Otherwise, a NoSuchElementException will be thrown.

 

▪ java.util.Formatter:
  java.util.Scanner:
  Both classes have three new constructors that take a charset parameter in addition to other parameters.

 

▪ java.util.Properties:

  Added a new constructor that accepts an int parameter. This creates an empty property list with no default values, and an initial size specified to accommodate the specified number of elements without dynamic resizing. There is also a new overloaded replace method that takes three Object parameters and returns a boolean value. The entry for the specified key will only be replaced if it is currently mapped to the specified value.

 

▪ java.SplittableRandom:
  void nextBytes(byte[]): Fills a user-supplied byte array with generated pseudo-random bytes.

 

▪ java.util.concurrent.FutureTask:

  Added the toString() method, which returns a string identifying the FutureTask, and its completion status. 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 stamp indicating whether a lock is held.
  boolean isOptimisticReadStamp(long): Returns a stamp indicating whether an optimistic read was successful or not.
  boolean isReadLockStamp(long): Returns a stamp indicating whether an inclusive lock (ie read lock) is held.
  boolean isWriteLockStamp(long): Returns a stamp indicating whether an exclusive lock (ie, write lock) is held.

 

▪ java.jar.JarEntry:
  String getRealName(): Returns the real name of this JarEntry. If this JarEntry is the entry for a multiversioned jar file, and it is configured to handle this, the name returned by this method is the entry of the version entry represented by the JarEntry, not the pathname of the base entry returned by ZipEntry.getName(). If JarEntry does not represent a versioned entry for a multi-version jar file or the jar file is not configured to be handled as a multi-version jar file, this method will return the same name as returned by ZipEntry.getName().

 

▪ java.util.jar.JarFile:
  Stream<JarEntry> versionedStream(): Returns the Stream corresponding to the entry of the specified version in the jar file. Similar to JarEntry's getRealName method, this is related to multi-version jar files.

 

▪ 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, which aggregate input elements into appropriate unmodifiable collections.

 

▪ java.lang.model.SourceVersion:

  There is now a field that represents the JDK 10 version.

 

▪ java.lang.model.util.TypeKindVisitor6: javax.lang.model.util.TypeKindVisitor9
  :
  R visitNoTypeAsModule(NoType, P): Visit the pseudo-type of a module. It's not clear why Visitor7 and Visitor8 don't have this method.

 

▪ javax.remote.management.rmi.RMIConnectorServer:
  This class adds two fields: CREDENTIALS_FILTER_PATTERN and SERIAL_FILTER_PATTERN.

 

▪ javax.ButtonModel:
  ButtonGroup getGroup(): Returns the group to which the button belongs. Typically used for radio buttons, they are mutually exclusive in a group.

 

▪ javax.plaf.basic.BasicMenuUI:
  Dimension getMinimumSize(JComponent): Returns the minimum size suitable for the look and feel of the specified component.

 

 

3. Other

▪If   the Kerberos configuration file krb5.conf contains an INCLUDEDIR option, then all files ending in .conf in the INCLUDEDIR directory will be loaded by default.

▪   The outdated Java startup options -d32 and -d64 in previous versions have been removed in the current version. If you still use these two options in the new version, the JVM will not start properly.

▪   JDK10 supports the new version of Doclet in JDK9, and the Doclet versions in JDK6, JDK7, and JDK8 are no longer supported.

▪   JDK10 re-enables the newFactory() method that was improperly obsolete in JDK9.

▪   JDK10 introduces a new Javadoc tag: {@summary…}, which fixes an issue where previous versions could not generate API summaries.

▪   JDK10 removes the 4 second startup delay of BiasedLockingStartupDelay.

▪   The following obsolete classes in the com.sun.security.auth package have been removed in the new version:

    PolicyFile

    SolarisNumericGroupPrincipal

    SolarisNumericUserPrincipal

    X500Principal

    SolarisLoginModule

    Solaris system

▪The   following properties and methods in the java.lang.SecurityManager class (deprecated since JDK 1.2) have finally been removed:

    inCheck (property)

    getInCheck

    classDepth

    classLoaderDepth

    currentClassLoader

    currentLoadedClass

    inClass

    inClassLoader

▪The   deprecated internationalization methods in the following java.lang.Runtime classes are removed in the new version:

    getLocalizedInputStream

    getLocalizedOutputStream

▪The   following obsolete Hotspot -X options are removed in the new version: -Xoss, -Xsqnopause, -Xoptimize, -Xboundthreads and -Xusealtsigs.

▪   policytool has been removed in the new version.

▪   The javadoc tool now supports multiple stylesheets via the --add-stylesheets command option.

▪The   new version of JVM can configure the thread pool and GC mechanism according to the number of CPUs and memory allocated by the system to the current Docker container, instead of directly using the system's CPU and memory. And three more powerful command options have been added: -XX:InitialRAMPercentage, -XX:MaxRAMPercentage and -XX:MinRAMPercentage.

▪The   new version adds a new system property: jdk.disableLastUsageTracking. This new property, as its name suggests, disables the JRE's last usage tracking.

 

 

To sum up, we can see that each version upgrade of JDK will affect us more or less. We need to constantly learn new technologies and accept new thinking modes.

Of course, some internal optimizations of JDK are transparent to developers. While it continues to become stronger, it is also optimizing and improving performance, security, and stability.

Java 10 is here, so will Java 11 be far behind? See you in September!

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324522799&siteId=291194637