• Complain

Mala Gupta [Mala Gupta] - Java 11 Quick Start

Here you can read online Mala Gupta [Mala Gupta] - Java 11 Quick Start full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2018, publisher: Packt Publishing, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Mala Gupta [Mala Gupta] Java 11 Quick Start

Java 11 Quick Start: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Java 11 Quick Start" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Discover how Java is bringing the latest developments and projects which will help you advance your development with with the language and make your applications leaner and faster.

About This Book

  • Resolve dilemma of investing into migration to newer Java version aligning to 6 months release cadence
  • Discover how Oracle is planning to introduce lighter threads and bridging the gap between the Java and native code
  • Unlock the relevance and applicability of new features of Java language like type inference with var, data classes, pattern matching, switch expression, enhanced enums; and platform features

Who This Book Is For

Executives and Solutions Architects responsible for technology selection or Java migration decisions. Computer science grads curious to learn about the latest and upcoming Java features. Java developers who are using Java 8 or older and now migrating their solutions to the new Java release.

What You Will Learn

  • Learn about features in recently released and upcoming Java releases
  • Deep dive on using new and improved language features.
  • Discover platform options to reduce launch time for your application.
  • Knowing about ways to compare your application for better performance, throughput or reduced latency by switching garbage collectors.
  • Build awareness about the new Java release cadence
  • Able to define and assess decision criteria for selecting Java or migrating to a newer version

In Detail

With its new six monthly release cadence, Java is moving forward, faster. Apart from the planned version releases, a lot of work is in progress under various Java projects at Oracle.. Programmers must be aware of the latest developments to make the best use of the newer features in their applications and libraries.

This book will take you through the developments in Java language, right from Java 10, from Project Jigsaw, variable type inference, simplified multi-threading to performance improvements, etc, which are all part of project Valhalla, Panama, Amber, and Loom. The book deep dives into the latest developments in the language. Youll know how best these features will help you advance your development with the language and make your applications leaner and faster.

It will uncover the relevance and applicability of newer language features, answer your questions on whether to invest into migrating to newer Java versions aligning to 6 month release cadence, including when to migrate.

You will later explore the platform features like AppCDS and new garbage collectors, to tune and optimize your application - from reduced launch time, to improved performance and throughput and reduced latency.

Style and approach

You will be taken through the new language and platform features in Java version 10, 11 and various umbrella projects, in detail. youll learn how to use these features in their existing or future projects. Along the way, you will explore how to make their code less verbose, leaner and faster. Youll also discover features to configure their virtual machine to reduce start up time and compare their applications to solve throughput and latency challenges in future.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Mala Gupta [Mala Gupta]: author's other books


Who wrote Java 11 Quick Start? Find out the surname, the name of the author of the book and a list of all author's works by series.

Java 11 Quick Start — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Java 11 Quick Start" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Limiting the scope of failed assumptions

As you know, the usage of var types is limited to the local variables in Java. They are not allowed in public API, as method parameters or as return type of methods. Some languages support type inference for all types of variables. Java may allow you to do so in future (who knows? Will it happen? If yes, when?).

However, there are strong reasons for limiting the scope of the inferred variables, to spot the errors due to mismatch of assumptions and the actual, early on. The contracts of the public API's should be explicit. Type inference with public API would allow for these errors to be caught and corrected much later.

The contract of the public API should be explicit, they shouldn't depend on type inference.

Here's a practical example of how mismatch in the assumptions and actual can lead to errors.

Recently my child was travelling overseas with her school for a student exchange program. The school asked me to send back a set of photographs for her visa application. I called up my photographer, requesting him to print photos for visa (specifying the country). Two days later, the school asked me to resubmit the photos because the earlier photos didn't match the rules.

What went wrong? Neither the school nor I were explicit with the specifications of the photograph. The school assumed that I would know the specifications; I assumed that the photographer would know the specifications (because he was doing it for years). In this case, at least one person assumed the result to conform to a specific output, without explicitly specifying the output. Without an explicit contract, there is always a scope of mismatch of expectation and actual.

Despite the confusion, the mistake was spotted and corrected before the applications were submitted to the embassy.

Here's a fun image to reason why the usage of type inference is limited to local variables, when the local instance and static variables were competing in a race, only the local variables could make it to the finish line:

Challenges Usage of var isnt without its share of challenges both for the - photo 1
Challenges

Usage of var isn't without its share of challenges, both for the developers of the Java language and for its users. Let's start with the reason why var has limited usage.

Overriding implicit behaviour

Imagine you want to limit the values that can be passed to a field in your data class during its instantiation. This is feasible, just override the default constructor. Here's an example:

record Emp(String name, int age) { // override default constructor @Override public Emp(String name, int age) { // validate age if (age > 70) throw new IllegalArgumentException("Not employable above 70 years"); else { // call default constructor default.this(name, age); } } }

Similarly, you can also override the default implementation of object methods such as equals(), hashCode() and toString() and others methods such as the accessor methods.

Overriding the default behavior of the methods of your data class, doesn't defeat the purpose of their creation. They are still working as data classes, with finer control on their working. Let's compare it with the POJOs, which were earlier used to model data classes. The compiler doesn't auto-generate any methods for a POJO. So, a user still needs to read all the code, looking for code that isn't the default implementation of its methods. In case of the data classes, this overridden behavior is very explicit. So, a user doesn't have to worry about reading all the code, he/she can assume default implementation of the behavior, which hasn't been overridden by the developer.

Overriding behavior explicitly states the places where a data class diverts from its default behavior, reducing the amount of code that must be read by a user to understand its behavior.
Type inference with var

The following lines of code show how you have been defining your local variable (and all other variables), prior to Java 10:

String name = "Java11"; LocalDateTime dateTime = new LocalDateTime.now();

Starting with Java 10, using var, you can drop the mandatory explicit type in the declaration of local variables, as follows:

var name = "Java11"; // variable 'name' inferred as String var dateTime = new LocalDateTime.now(); // var 'dateTime' inferred as LocalDateTime

Do you think that the preceding code doesn't seem to offer a lot of benefits? What if, instead of the following?

HashMap map = new HashMap();

You could use the following:

var map = new HashMap();

The preceding example drops quite a lot of letters on the left-hand side, making it leaner.

When you move away from stating the data type of the variables explicitly, the compiler takes over to determine or infer the variable type. Type inference is compiler's ability to evaluate the information already present in the code, like, the literal values, operations, method invocation or their declaration to determine the variable type. It follows a set of rules to infer the variable type. As a developer, when you choose type inference with var, you should be aware of compiler's inference algorithm and other rules, so that you don't get unexpected results.

With every new feature, you should adhere to a few rules, restrictions and try to follow best practices to benefit from it. Let's start with the compulsory initialization of the variables that are defined using var.

Type inference with var is not dynamic typing; Java is still a strong static typed language. Usage of var makes your code leaner; you can drop the type of the local variable from its definition.
JVM and native code
Coming soon...!
An example

Let's get started by re-defining the Emp class, which we used in the beginning of the chapter, as a data class:

record Emp(String name, int age) { } // data class - one liner code

The preceding code uses the keyword record to define a data class, accepting comma separated variable name and type, required to store the state. The compiler automatically generates default implements for the Object methods (equals(), hashCode(), toString()) for data classes.

The code looks clear and compact. A reader would immediately know the intent of this single line of code, a carrier of data name (type String) and age (type int). Another advantage for a reader is that she wouldn't need to read through constructors, accessors, mutators, or methods of the object class, just to ascertain that they are doing what they are supposed to, not more, which they should be aware of.

Behind the scenes, the record class Emp is converted to the following by the Java compiler:

final class Emp extends java.lang.DataClass { final String name; final int age; public Emp(String name, int age) { this.name = name; this.age = age; } // deconstructor // public accessor methods // default implementation of equals, hashCode, and toString }

The preceding data class is an example of a non-abstract data class. A data class can also be defined as an abstract data class. A non-abstract data class is implicitly final. In both cases, a data class would get default implementations of hashCode(), equals() and toString(), and accessor methods. For an abstract data class, the constructors would be protected.

In the following image, the compiler looks happy to convert one liner code for the data class, to a full-fledged class:

A data class is implicitly final What is type inference Imagine solving a - photo 2
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Java 11 Quick Start»

Look at similar books to Java 11 Quick Start. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Java 11 Quick Start»

Discussion, reviews of the book Java 11 Quick Start and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.