I taught you how to operate the new version Java8

Java language since its inception, has been loved by many students, even if the moment is true, according to incomplete statistics, most of it 2019 in-service industry, java is still the most-job language. Let us together look!
Preface
got it in Java

In 1995 Sun introduced the Java language, from the birth of the first version to now has twenty years of. If the time fleeting, fleeting. Twenty years IT technology upgrading, programming language after another. Just follow the law of nature, survival of the fittest, the programming language is the same, a lot of old programming language programming language is emerging alternatives, and even decline gradually withdraw from the stage of history, but with Java as a programming language 20 years of history has become increasingly life exuberant! Got it! The reason, which is very important point is that the Java language version iterative ongoing series of new characteristics in line with the development trend of technology!

"From the point of view Java's evolution path, it has been working to make concurrent programming easier, less error .Java 1.0, there are threads and locks, and even a memory model - this was the best practice is .Java 5 added industrial building blocks, such as thread pools concurrently set .Java 7 and add branch / (fork / join) frame, so that the parallel becomes more practical, while the parallel Java 8 have a simpler new ideas ! "

- Excerpt from "Java 8 In Action"

Java8 ** core new features Brief Introduction **

Java 8 can be described as the most revolutionary since Java 5 version, she in languages, compilers, libraries, development tools and Java virtual machines have brought a lot of new features, the most central of Lambda expression type and Stream API (other new features see the end the appendix)

★ Lambda Expressions

Lambda expressions can be said that Java 8 biggest selling point, she will be the introduction of functional programming Java. Lambda allowed to function as an argument of a method, or as the code data.

★Stream API

Stream API is the introduction of a real functional programming style to Java. In fact, it simply Stream can be understood as MapReduce. Syntactically, much like the linux pipe, chain or programming code to write concise, very cool handsome!

Why learn ** Java8 functional programmed ** Cheng

By Java8 document we can see a lot of Java8 added API support for functional programming, you can see the degree of attention to the functional programming Java8. Documents Address:https://docs.oracle.com/javase/8/docs/api/

Java8 reason why so much trouble in the effort to introduce functional programming, for two reasons:

1. The code is simple and functional programming code to write simple and clear intent, such as the use of stream interfaces let you say goodbye to the for loop.

2. multicore-friendly, Java functional programming makes writing parallel programs so simple, just call it parallel () method can be.

"For developers accustomed to object-oriented programming, the abstract concept is not new. Object-oriented programming is a data abstraction, and functional programming is abstract behavior. The real world, data and behavior co-exist, the program also so, so these two programming the way we had to learn.

This new functional programming in an abstract way has other benefits, such as:

Not everyone in the priority code writing performance, and for these people, to bring the benefits of functional programming is particularly evident. Programmers can write the code easier to read - this code is more expressed the intention of the business logic, rather than its implementation mechanism. Readable code is also easier to maintain, more reliable and less prone to error. For example, when writing callback functions and event handlers, programmers do not have to dwell on the tedious and readability anonymous inner classes, so that functional programming event processing system easier. Can easily transfer function also allows the code easier to write inert, inactive when the value of the code required to initialize variables real.

All in all, Java is not the year of their forefathers used Java, and ah, this is not a bad thing. "

- Excerpt from "Java8 Lambdas Exercises"

Annex ** record : Java8 ** Other new features

● The default interface method, and static methods

We can define the default interface method, use the default keyword and provides default implementations. All classes implement this interface will accept the default method of realization, unless the child class provides its own implementation.

● reference method

Usually used in conjunction with Lambda expressions, you can directly reference existing Java classes or objects.

● Repeat comment

Java 8 introduced repeated notes, the same notes in the same place can be declared multiple times.

● Extended annotation support

Java 8 extends the context of the annotation, the annotation can be added to almost anything, including local variables, a generic class of the parent class implements the interface, anomalies can even annotate method.

●Optional

Java 8 Optional classes to prevent the introduction of null pointer exceptions, we do not like to use Optional explicit conduct null pointer checked.

● Date / Time API (JSR 310)

Java 8 new Date-Time API (JSR 310) affected Joda-Time is provided a new java.time packet may be used instead java.util.Date and java.util.Calendar.

● JavaScript engine Nashorn

Nashorn JavaScript allows developers to run applications on the JVM, Java and JavaScript allow call each other.

●Base64

In Java 8, Base64 encoded into a standard Java class libraries. Base64 class also provides a URL, MIME friendly encoder and decoder.

● Better type inference mechanism

With Java 8 in terms of greatly improved type inference, which makes the code more clean, it does not require much of the cast.

● compiler optimization

The Java 8 Parameter names added to the bytecode, so that at run-time can be obtained by reflecting the parameter name, parameter -parameters only need to use at compile time.

● Parallel (Parallel) array

Array support parallel processing, mainly parallelSort () method, which can greatly increase the speed of the array is sorted on a multi-core machine.

● concurrent (Concurrency)

On the basis of the new mechanism and Lambda Stream on top, adding a number of new ways to gather support operations.

● Nashorn engine jjs

Nashorn command-line tool based engine. It accepts some JavaScript source code as a parameter, and execute the source code.

● class dependent parser jdeps

Java class package level may be displayed or class level dependent.

● JVM's PermGen space is removed

It is substituted Metaspace (JEP 122).

Java 8 update is a huge change, drawing a lot of good at other languages ​​and libraries, to make Java easier, more efficient, more powerful!

Guess you like

Origin blog.51cto.com/13007966/2467543