Java SE 8 new features Tour: Big changes in the world of Java development

Source: Internet
Author: User
Tags time zones new set stream api netbeans java se

I am proud to be a member of ADOPT-OPENJDK, like other professional team members, but I just joined for 8 months, we went through the Java SE 8 development, compilation, coding, discussion ... Wait until the JDK is online. Java SE 8 was released on March 18, 2014 and is now available for download.
I'm happy to release this series of "new features for Java SE 8", and I'll write some examples to simplify the acquisition of Java SE 8 knowledge, development experience, new features, and APIs, and then
Use your knowledge to improve your coding skills while improving your productivity. I hope you can enjoy it as much as I write an article.
We'll explore the key features of Java SE 8 (projects and APIs), which support faster, simpler Java development. We'll learn about the Lambda project, a Java
The code supports the new syntax for lambda expressions. Learn about the new stream API for working with collections and managing parallel processing. The time interval is calculated using the DateTime API that represents, manages, and calculates date and time values.
And Nashorn, a new engine, with it, Java virtual machines can better support the use of JavaScript code.
Finally, I'll cover features that few people know about, such as new ways to add strings to lists and other features that can help you with your daily tasks.
For more Java SE 8 features and guidelines, I recommend you refer to the Http://docs.oracle.com/javase/tutorial/official website and the Java SE 8 java API documentation.

The topics we cover in this series include:
1. Install Java SE 8, considerations and recommendations.
2. Introduce the main features of Java SE 8, big changes.
3. Use lambda expressions and method references.
4. Iterate through the collection with streams.
5. Calculate the time interval with the new DateTime API.
6. Run JavaScript in Java with Nashorn.
7. Other new features and API changes.

1. Installing Java SE 8, considerations and recommendations

1) Install Java SE 8 on Windows
To run Java SE 8 on a Microsoft Windows system, first check your Windows system version. Java SE 8 supports Windows8,7,vista and XP.

If you want to run Java Applets, you need a 64-bit browser that includes IE 7 and above, Firefox3.6 and Windows-enabled Google Chrome instead
On the Mac. You can download the Java SE 8 jdk from:
1. Address java.oracle.com, display the Java home page.
2. Click Java SE.
3. Under Top Downloads, click the download link for Java 8.

2) Install Java SE 8 on Mac

In order to run Java SE 8 on Mac OS X, you must have an Intel-based Mac and run Mac OS X 10.7.3, version lion or higher. If you're an older version of Mac, you can't program it to run Java 8 applications. In order to install Java SE 8 You need Administrator privileges on Mac computer. And to run Java Applets on your browsing, you need a 64-bit browser, such as Safari or Firefox. Google Chrome is 32-bit and cannot run Java Applets. As with the previous description of installing Java SE on Windows, the same Web site downloads the Mac OS version of the. dmg file to install. In fact, this page contains all of the supported operating system versions. However
Our focus is on Widnows and Mac.

Now on Windows and Mac OS x platforms, you're ready to start programming with Java SE 8.
After we've installed Java SE 8, let's put in the 1th, simply take a look at the main features of Java SE 8 and start the programming journey on our favorite IDE.

2. Introduction to Java SE 8 key features, big changes

JSR 337 Overview: Java SE 8 Publishing content

Java SE 8 is an important release of the Java programming language and Java virtual machines. Involves a lot of changes. Some of them are more comprehensive than others, such as lambda expressions, but I'm going to talk about big changes and some small changes.

JSR 335:lambda Expressions

Perhaps the most noticeable is the Lambda project, a new set of syntax that allows Java developers to work like functional programmers. This project includes lambda expressions, method references, and some other capabilities.

JSR 310:date and Time API
New API for managing dates and times. Replaces the old version of the class. Older versions of the classes are still in Java runtime, but when you create new applications, you may migrate to this new set of APIs, which will simplify your code and make your programming more intuitive. There are new classes that manage local dates, times, and time zones, and calculate differences in time.

Stream API

Added new tools for managing collections, including Lists,maps,sets, and more. Stream allows you to work with each item in the collection without having to write the loop code. It also allows you to decompose your processing to multiple CPUs. All, you can see significant performance improvements for complex big data sets.

Nashorn Project

The Nashorn JavaScript engine is also a new addition to Java SE 8. This is a new JavaScript engine that allows you to encode with JavaScript and integrate with Java classes. The goal of Nashorn is to implement a lightweight, high-performance JavaScript runtime in Java, the native JVM. This project is designed to enable Java developers through JSR-223

Embed JavaScript in a Java application and develop a standalone JavaScript application with the Jrunscript command-line tool. In Nashorn's article,
I'll describe how to run the Nashorn code on the command line. But how do you write JavaScript in different files, and then execute them in your Java code.

Parallel API Enhancement
The parallel framework has also been enhanced to allow you to manage and accumulate values in multiple threads.

String,numbers has a new tool.
Create new tools and other new classes that store the string restriction lists. There are tools for calculating numbers, including Intergers,longs,doubles and so on.

Other new features
There are also new tools to better detect null cases, and I'll describe all of them in this series. I'll also describe how to work with files in new and convenient ways.

So, when does Java SE 8 work?

The answer is, now. Java SE 8 was officially released on March 18, 2014. Java developers can build their website applications, and the JavaFX Rich Network application framework now supports Java 8. And the majority of Java Enterprise Edition vendors also support Java 8. Whether you immediately migrate to Java 8 depends on the project you are currently working on.
For many services and customer Web applications, Java SE 8 is now valid.

Not Android yet.

Android Developer Note: The Java SE 8 syntax and APIs are now not supported on Android.
Recently Android has just supported Java 7 syntax. So it may take some time for Android to support the latest syntax or APIs. But for all Java developers, it's worth knowing about these features.

What about development tools?

Java 8 has been supported in the main Java development environment, including Oracle's Netbeans,intellij idea and Eclipse. All of the examples I've written in the article series are done under NetBeans. With the NetBeans V8, https://netbeans.org/downloads/.

Anyway, before we get into this series, let's first check if we've installed Java SE 8, start a new project with NetBeans, and include what we'll write

To all of the code. Then develop a lambda code to test whether our project is working properly in Java SE 8.

You can choose to download all the code in this series on my Githut, https://github.com/mohamed-taman/JavaSE8-Features.

Hello World application written with lambda expression based on Java SE 8

Steps

1. Open NetBeans 8–> from file–> New project–> Select maven–> from the left and select Java application–> from the right click Next.

2. Fill in the contents as shown, or change to your preferred name and value, click the Finish button.

3. If things go well you should be able to see the structure below, with Project Navigator view.

4. Click the Project "Java8features", click File, from the parent menu, and then, "Project Properties".

5. Under category, select Source from the left, and then check "scource/binary format" is 1.8. , open build from the left, then select Complier, then check "Java Platform" pointing to JDK 8 you have installed, click OK.

6. If JDK 8 does not appear, locate the tools-> option, Java platforms->add platform-> and then select Java Standard Edition-> and point to the JDK 8 that you have installed.

7. Now that our project is configured with JDK 8, let's add some lambda code.

8. In the package "Eg.com.tm.java8.features", right-click, select New->java interface-> from the menu named Printable, click the Finish button.

9. Implement the printable interface as follows

package eg.com.tm.java8.features.overview;@FunctionalInterfacepublicinterface Printable {    publicvoidprint();}

10. Under the same package, add the following class, named "Print", the Main method is as follows:

static java.lang.System.out;publicclass Print {    publicstaticvoidmain(String[] args) {        out.println("Java SE 8 is working "                                        "and Lambda Expression too.");        job.print();    }}

11. Right-click the Print class and select Run. If everything works, you will see the following output.

Building Java8Features 1.0-SNAPSHOT--------------------------------------------------------------------------- exec-maven-plugin:1.2.1:exec (default-cli) @ Java8Features ---Java SE 8 is working and Lambda Expression too.------------------------------------------------------------------------BUILD SUCCESS

12. Congratulations on your Java SE 8 Project working Well, let's explain the code we just wrote.
Most of this code can run on Java 7, but one annotation is newly added in Java SE 8, Functionalinterface. If you have

The NetBeans working environment is not configured with Java 8, and this comment will be error-free because it will be treated as invalid code. I didn't see the mistake, so it was a good sign.

Below we open the definition of Print.java. This class has a main method, so I can run it with a console program with a single line of key code that is Java 8 syntax. It lambda expression creates an instance of the functional interface I just showed you, a syntax that didn't exist before Java 8. I will explain the role of this grammar in the next article. But what you need to know now is that if this code doesn't get an error, then again, NetBeans thinks it's a valid code. I created an instance of that interface and called the Print method of the interface. So, I ran this code.
I clicked the Run button on the toolbar and I saw a successful result on the console. I have created an object that is an instance of the interface created with lambda expression.

I also called its method, which outputs a string on the console. So, if all works fine, you're in good shape. You've started programming in NetBeans with Java SE 8. If you have any problems with this process, go back to the previous step and check your steps. One step at a time.

Java SE 8 new features Tour: Big changes in the world of Java development

Related Article

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.