DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 3: Understanding Janus
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • How to Introduce a New API Quickly Using Micronaut
  • Introducing Graph Concepts in Java With Eclipse JNoSQL

Trending

  • Software Delivery at Scale: Centralized Jenkins Pipeline for Optimal Efficiency
  • Understanding the Shift: Why Companies Are Migrating From MongoDB to Aerospike Database?
  • SaaS in an Enterprise - An Implementation Roadmap
  • How to Introduce a New API Quickly Using Micronaut
  1. DZone
  2. Coding
  3. Java
  4. Features in Java 10

Features in Java 10

Let's take a sneak peek int what's coming in Java 10, including local variable type inference and APIs for unmodifiable collections.

By 
Gowtham Girithar Srirangasamy user avatar
Gowtham Girithar Srirangasamy
·
Updated Mar. 13, 18 · Tutorial
Likes (16)
Comment
Save
Tweet
Share
59.6K Views

Join the DZone community and get the full member experience.

Join For Free

Java 9 has changed Java's structure by introducing modular development (Project Jigsaw). Meanwhile, Java 10 will add flavors by introducing new features of its own. A few features are explained below, with snippets.

Local Variable Type Inference

Java 7 introduced the diamond operator:

 List list=new ArrayList<>();  

But even though we have a diamond operator, there is still a lot of boilerplate code. So, Java 10 introduced var as a reserve type name to reduce verbosity. It can be used as a variable, method, and package name, but we cannot use it as a class or interface name.

The advantage is that we no need to explicitly declare the variable type, so it reduces boilerplate code and increases readability.

Image title

In the above example, we have used the var in various examples of local variable type inference.

Image title

The above example describes that we can use the var reserved keyword as a variable name and method names.

Image title

The above example describes that var is a restricted local variable type and cannot be used for class and interface names. That should be very helpful in reducing boilerplate code.

Image title

I personally don't prefer this type inference much due to cases where we are not sure which datatype it is implying.

Image title

The types are inferred at compiletime and not runtime, so it will not affect performance.The resulting bytecode is the same as that with an explicit type declaration.

Restrictions

We cannot use the var on a variable without initializers.

var i; // invalid


Also, var is not allowed in a compound declaration.

var i , j =0; //invalid


And we cannot initialize with a null value for var-type variables:

var i=null; // invalid


Optional.orElseThrow() Method

Java 10 introduced the new method orElseThrow to the Optional class. It is preferred as an alternative to the existing get method. An example below describes the working of the orElseThrow() method.

Image title


Removal of Runtime.getLocalizedInputStream and getLocalizedOutputStream Methods

Java 1o removed the getLocalizedInputStream and getLocalizedOutputStream methods from the Runtime class, as they had no uses with respect to an internalization mechanism.

Image title

APIs for Creating Unmodifiable Collections

List.copyOf, Set.copyOf, and Map.copyOf methods are added to create the instance from an existing instance. 

Example:

Image title

Also, toUnmodifiableList, toUnmodifiableSet, and toUnmodifiableMap have been added to the Collectors class in the Stream package, which will produce unmodifiable collections.

Example:

Image title

Byte Code Generation for Enhanced For Loops

The following example describes the generation of the following lines of code until Java 9.

 List data = new ArrayList<>();for (String b : data);  

Image title

In Java 10, iterator variables are declared outside for loops and initialized to the null value immediately once the operation is over, so GC can get rid of unused memory.

{
    Iterator iterator = data.iterator();
    for (; iterator.hasNext();) 
    {
        String b = (String)iterator.next();
    }
    b = null;
    iterator = null;
} 


Relax the Removal of Finalize Methods in FileInputStreams and FileOutputStreams

The resources used by the stream should be cleaned by calling the close method or using the try with resources feature. In the future, classes that extend the FileInputStream or FileOutputStream should modify the cleanup approach such as Cleaner instead overriding the finalize method.

Removal of Deprecated Methods

The deprecated java.security.{Certificate, Identity, IdentityScope, Signer} classes are marked for removal by setting the value of forRemoval=true in a Deprecated annotation.

The deprecated java.security.acl is also now marked for removal by the setting the value of forRemoval=true in a Deprecated annotation. A few fields and methods in java.lang.SecurityManager are also marked for removal in this version.

javax.security.auth.Policy is also marked for removal and features of the class are now available in java.security.Policy.

com.sun.security.auth.** classes, which were marked for removal in JDK 9 by setting the value of forRemoval =true in a Deprecated annotation, have been removed

Parallel Full GC for G1

Java 9 made G1 as the default, and in Java 10, parallel full Garbage Collection support for G1 will improve the worst-case latencies. It parallelized the mark-sweep-compact algorithm.

The number of threads in parallel can be controlled by the XX:ParallelGCThreads option.

Removal of javah  

The native header tool is now removed and we can generate the native header using the Java compiler with the -h option

All the code is executed using JShell.

Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 3: Understanding Janus
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • How to Introduce a New API Quickly Using Micronaut
  • Introducing Graph Concepts in Java With Eclipse JNoSQL

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!