This webinar by Oleksandr Navka (Lead Software Engineer, Consultant, GlobalLogic) was delivered at Java Community Webinar #1 on August 12, 2020.
Webinar agenda:
- The new structural unit of the program is Java Records
- Updated instanceof statement
- Updated switch operator
More details and presentation: https://www.globallogic.com/ua/about/events/java-community-webinar-1/
JDD 2016 - Sebastian Malaca - You Dont Need Unit TestsPROIDEA
How often did you hear developers who were proving quality of their application’s code by sharing information about really high coverage and a huge number of unit tests? How often did you hear how unit tests can make your life easier. How having unit tests makes it possible to introduce changes and make refactoring safier? Do you believe in it? What’s your experience?
I will show you why all of those “proofs” are invalid and wrong. I will show you the false impression of feeling safe in those dangerous places where your code is covered only with tones of unit tests.
But it won’t be all. I won’t leave you alone in this place. I will tell you what you can do to make things better.
I will show you the difference between coverage and quality. Between unit tests and safety.
This webinar by Oleksandr Navka (Lead Software Engineer, Consultant, GlobalLogic) was delivered at Java Community Webinar #1 on August 12, 2020.
Webinar agenda:
- The new structural unit of the program is Java Records
- Updated instanceof statement
- Updated switch operator
More details and presentation: https://www.globallogic.com/ua/about/events/java-community-webinar-1/
JDD 2016 - Sebastian Malaca - You Dont Need Unit TestsPROIDEA
How often did you hear developers who were proving quality of their application’s code by sharing information about really high coverage and a huge number of unit tests? How often did you hear how unit tests can make your life easier. How having unit tests makes it possible to introduce changes and make refactoring safier? Do you believe in it? What’s your experience?
I will show you why all of those “proofs” are invalid and wrong. I will show you the false impression of feeling safe in those dangerous places where your code is covered only with tones of unit tests.
But it won’t be all. I won’t leave you alone in this place. I will tell you what you can do to make things better.
I will show you the difference between coverage and quality. Between unit tests and safety.
Java is moving faster and faster. A lot of features are not as known as they should be.
Let’s review together the old ones you missed.
Then show you the ones you never had time to look at in 9, 10, 11, 12 and 13.
And go crazy to check how it’s implemented under the hood (yes, there will be bytecode).
Appium TestNG Framework and Multi-Device Automation ExecutionpCloudy
TestNG with Appium is one of the most popular choices among Automation engineers when it comes to Mobile App Automation. TestNG eliminates most of the limitations of the older framework and gives the developer the ability to write more flexible and powerful tests with help of easy annotations, grouping, sequencing & parameterizing.
https://www.pcloudy.com
While most bugs reveal their cause within their stack trace, Java’s OutOfMemoryError is less talkative and therefore regarded as being difficult to debug by a majority of developers. With the right techniques and tools, memory leaks in Java programs can however be tackled like any other programming error. This talks discusses how a JVM stores data, categorizes different types of memory leaks that can occur in a Java program and presents techniques for fixing such errors. Furthermore, we will have a closer look at lambda expressions and their considerable potential of introducing memory leaks when they are used incautiously.
Workshop slides from the Alt.Net Seattle 2011 workshop. Presented by Wes Dyer and Ryan Riley. Get the slides and the workshop code at http://rxworkshop.codeplex.com/
Finally Java SE 7 is GA and you can start using it. This talk will cover the most important new features of the language and the virtual machine. It will also cover some features that did not make it in to the SE 7 release. Finally we will discuss current state of Java as an ecosystem and my analysis and hopes for the future.
Some Pitfalls with Python and Their Possible Solutions v1.0Yann-Gaël Guéhéneuc
Python is a very popular programming language that comes with many pitfalls. This presentation describes some of these pitfalls, especially when they could trick unsuspecting object-oriented developers. It proposes solutions to these pitfalls, in particular regarding inheritance, which is easily broken because of the implementation choice of Python for explicit delegation, its method resolution order, and its use of the C3 algorithm. It discusses some advantages of using Python, especially regarding meta-classes.
Advice for writing a NSERC Discovery grant application v0.5Yann-Gaël Guéhéneuc
NSERC Discovery grant applications are judged according to four criteria: (1) Excellence of the researcher, (2) Merit of the proposal, (3) Contribution to the training of HQP, and (4) Cost of research. Each criterion has six possible merit indicators: Exceptional, Outstanding, Very strong, Strong, Moderate, and Insufficient. This presentation describes the process from a candidate's point of view and a reviewer's point of view. It discusses funding decisions, including bins and ER vs. ECR. It gives some advice, including graduating PhD students, having a story, and limiting the number of main objectives.
Más contenido relacionado
Similar a Evolution and Examples of Java Features, from Java 1.7 to Java 22
Java is moving faster and faster. A lot of features are not as known as they should be.
Let’s review together the old ones you missed.
Then show you the ones you never had time to look at in 9, 10, 11, 12 and 13.
And go crazy to check how it’s implemented under the hood (yes, there will be bytecode).
Appium TestNG Framework and Multi-Device Automation ExecutionpCloudy
TestNG with Appium is one of the most popular choices among Automation engineers when it comes to Mobile App Automation. TestNG eliminates most of the limitations of the older framework and gives the developer the ability to write more flexible and powerful tests with help of easy annotations, grouping, sequencing & parameterizing.
https://www.pcloudy.com
While most bugs reveal their cause within their stack trace, Java’s OutOfMemoryError is less talkative and therefore regarded as being difficult to debug by a majority of developers. With the right techniques and tools, memory leaks in Java programs can however be tackled like any other programming error. This talks discusses how a JVM stores data, categorizes different types of memory leaks that can occur in a Java program and presents techniques for fixing such errors. Furthermore, we will have a closer look at lambda expressions and their considerable potential of introducing memory leaks when they are used incautiously.
Workshop slides from the Alt.Net Seattle 2011 workshop. Presented by Wes Dyer and Ryan Riley. Get the slides and the workshop code at http://rxworkshop.codeplex.com/
Finally Java SE 7 is GA and you can start using it. This talk will cover the most important new features of the language and the virtual machine. It will also cover some features that did not make it in to the SE 7 release. Finally we will discuss current state of Java as an ecosystem and my analysis and hopes for the future.
Some Pitfalls with Python and Their Possible Solutions v1.0Yann-Gaël Guéhéneuc
Python is a very popular programming language that comes with many pitfalls. This presentation describes some of these pitfalls, especially when they could trick unsuspecting object-oriented developers. It proposes solutions to these pitfalls, in particular regarding inheritance, which is easily broken because of the implementation choice of Python for explicit delegation, its method resolution order, and its use of the C3 algorithm. It discusses some advantages of using Python, especially regarding meta-classes.
Advice for writing a NSERC Discovery grant application v0.5Yann-Gaël Guéhéneuc
NSERC Discovery grant applications are judged according to four criteria: (1) Excellence of the researcher, (2) Merit of the proposal, (3) Contribution to the training of HQP, and (4) Cost of research. Each criterion has six possible merit indicators: Exceptional, Outstanding, Very strong, Strong, Moderate, and Insufficient. This presentation describes the process from a candidate's point of view and a reviewer's point of view. It discusses funding decisions, including bins and ER vs. ECR. It gives some advice, including graduating PhD students, having a story, and limiting the number of main objectives.
Ptidej Architecture, Design, and Implementation in Action v2.1Yann-Gaël Guéhéneuc
A set of process, architecture, design, and implementation patterns from a real, large program, the Ptidej Tool Suite. This set shows concrete problems and their solutions in Java. It includes: Be A Profiler, Tests as Documentation, Multi-layered Architecture, Proxy Console, Proxy Disk, Hidden Language, Internal Observer, Run-time Deprecation, String Parsimony, Object Identity, Object Address, Final Construction, StringBuffer as Positioning Element.
Examples of (bad) consequences of a lack of software quality and some solutions. This presentation presents some examples of (bad) consequences of a lack of software quality, in particular how poor software quality led to the direct deaths of 89 people. It then provides some background on software quality, especially the concept of Quality Without a Name. It then discusses many principles, their usefulness, and their positive consequences on software quality. Some of these principles are well-known in object-oriented programming while many others are taken from the book 97 Programmers. They include: abstraction, encapsulation, inheritance, types, polymorphism, SOLID, GRASP, YAGNI, KISS, DRY, Do Not Reinvent the Wheel, Law of Demeter, Beware of Assumptions, Deletable Code, coding with reason, and functional programming. They pertain to dependencies, domains, and tools.
(In details: Beautify is Simplicity, The Boy Scout Rule, You Gotta Care About the Code, The Longevity of Interim Solutions, Beware the Share, Encapsulate Behaviour not Just State, Single Responsibility Principle, WET Dilutes Performance Bottlenecks, Convenience Is Not an -ility, Code in the Language of the Domain, Comment Only What the Code Cannot Say, Distinguish Business Exception from Technical, Prefer Domain-specific Types to Primitive Types, Automate Your Coding Standards, Code Layout Matters, Before You Refactor, Improve Code by Removing It, Put the Mouse Down and Step Away from the Keyboard)
Some Pitfalls with Python and Their Possible Solutions v0.9Yann-Gaël Guéhéneuc
Python is a very popular programming language that comes with many pitfalls. This presentation describes some of these pitfalls, especially when they could trick unsuspecting object-oriented developers. It proposes solutions to these pitfalls, in particular regarding inheritance, which is easily broken because of the implementation choice of Python for explicit delegation, its method resolution order, and its use of the C3 algorithm. It discusses some advantages of using Python, especially regarding meta-classes.
An Explanation of the Unicode, the Text Encoding Standard, Its Usages and Imp...Yann-Gaël Guéhéneuc
Unicode is currently the world standard for encoding text. It supports all of the world's major writing systems. With its version 15.1 of 2023/09/12, it defines 149,813 characters and 161 scripts. This presentation starts with the, seemingly, simple example of the polar bear emoji. It then defines the key terms of any such standard. It then asks how a software system can render orthographic characters into glyphs, i.e., to render characters into (combined) glyphs. It introduces the concept of abstract characters and describes a brief history of encoding standards, from ASCII to Unicode. It shows how, by adding one level of indirection, the Unicode standard answers this question. It then presents code examples to display text written in Unicode: HarfBuzz (for shaping) and FreeType (for rendering).
An Explanation of the Halting Problem and Its ConsequencesYann-Gaël Guéhéneuc
The halting problem is an important, famous, and consequential problem in computer science. It is about writing a program that decides if another problem will stop. There is no general solution to this problem, which shows that such a problem is undecidable, with important consequences: for example, it is not possible to write tests that would exhaustively test entirely an arbitrary program. This presentation was written in collaboration with <a href="https://www.iro.umontreal.ca/~hahn/">Gena Hahn</a>.
A presentation summarising FPGAs, their history, their benefits, and showing how to program them. It provides some historical background on the development of computers, from the Difference Engine to the Intel 4004 to the AMD Ryzen Threadripper PRO 3995WX. It shows how the number of transistors increased dramatically but also how this increase led to more complexity and more bugs. It then introduces Field-programmable gate arrays (FPGA) as an alternative. It then presents how to program such FPGA using data-flow graphs. It discusses some tools (Yosys, NextPnR, and IceStorm) and illustrates them with a typical "Hello World" (i.e., blinking an LED) using Cygwin on Windows 10.
A set of brief presentations of some of the women and men who made the history of computer science and software engineering.
- 1936: Alan Turing
- 1948: Claude Elwood Shannon
- 1950: Grace Murray Hopper
- 1960: John McCarthy
- 1966: Frances E. Allen
- 1967: Ole-Johan Dahl
- 1967: Kristen Nygaard
- 1969: Charles A. R. Hoare
- 1970: Edgar F. Codd
- 1972: Dave Parnas
- 1974: Manny Lehman
- 1975: Frederick Brooks
- 1986: Edward Yourdon
- 1987: Barbara Liskov
- 1994: Erich Gamma
- 1997: Grady Booch
- 2001: Butler Lampson
A tutorial on the history, use, and caveats of Java generics. Using the simple example of an interface for sort algorithms, the tutorial presents the history of generics and describes the problems being solved by generics. It also provides definitions, and examples in Java and C++, and discusses Duck Typing. It then describes two scenarios: (1) Scenario 1: you want to enforce type safety for containers and remove the need for typecasts when using these containers and (2) Scenario 2: you want to build generic algorithms that work on several types of (possibly unrelated) things. It also summarises caveats with generics, in particular type erasure.
A tutorial on reflection, with a particular emphasis on Java, with a comparison with C++, Python, and Smalltalk. It describes different scenarios in which reflection is useful, a brief history of reflection and MOPs, a comparison with C++, Python, and Smalltalk, and some particulars about Java. The source code of the examples in Java (Eclipse project), Smalltalk (Squeak image v3.10.6), Python (Eclipse project), and C++ (Eclipse projects and Visual Studio solution) are available. (C++ Eclipse projects require Mirror.) Big thanks to Matúš Chochlík and Marcus Denker for their kind and precious help with C++ and Smalltalk.
The tutorial focuses on four common problems:
- Avoid using instanceof when code must bypass the compiler and virtual machine’s choice of the method to call.
- Create external, user-defined pieces of code loaded, used, and unloaded at run-time.
- Translate data structures or object states into a format that can be stored (file, network...).
- Monitor the execution of a program to understand its behaviour, and measure its space and time complexity.
It shows working examples of Java, Smalltalk, Python, and C++ code solving the four common problems through four scenarios:
- Scenario 1: invoke an arbitrary method on an object (see the problems with instanceof and plugins).
- Scenario 2: access the complete (including private) state of an object (see the problem with serialisation).
- Scenario 3: count the number of instances of a class created at runtime (see the problem with debugging/profiling).
- Scenario 4: patch the method of a class to change its behaviour (see the problem with patching).
It also discusses the different kinds of interconnections among objects that are available in common programming languages (linking, forking, subclassing, inter-process communication, and dynamic loading/invoking), a bit of theory about reflection, and specifically the class-loading mechanism of Java.
REST APIs are nowadays the de-facto standard for Web applications. However, as more systems and services adopt the REST architectural style, many problems arise regularly. To avoid these repetitive problems, developers should follow good practices and avoid bad practices. Thus, research on good and bad practices and how to design a simple but effective REST API are essential. Yet, to the best of our knowledge, there are only a few concrete solutions to recurring REST API practices, like “API Versioning”. There are works on defining or detecting some practices, but not on solutions to the practices. We present the most up-to-date list of REST API practices and formalize them in the form of REST API (anti)patterns. We validate our design (anti)patterns with a survey and interviews of 55 developers.
Utilocate offers a comprehensive solution for locate ticket management by automating and streamlining the entire process. By integrating with Geospatial Information Systems (GIS), it provides accurate mapping and visualization of utility locations, enhancing decision-making and reducing the risk of errors. The system's advanced data analytics tools help identify trends, predict potential issues, and optimize resource allocation, making the locate ticket management process smarter and more efficient. Additionally, automated ticket management ensures consistency and reduces human error, while real-time notifications keep all relevant personnel informed and ready to respond promptly.
The system's ability to streamline workflows and automate ticket routing significantly reduces the time taken to process each ticket, making the process faster and more efficient. Mobile access allows field technicians to update ticket information on the go, ensuring that the latest information is always available and accelerating the locate process. Overall, Utilocate not only enhances the efficiency and accuracy of locate ticket management but also improves safety by minimizing the risk of utility damage through precise and timely locates.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
In software engineering, the right architecture is essential for robust, scalable platforms. Wix has undergone a pivotal shift from event sourcing to a CRUD-based model for its microservices. This talk will chart the course of this pivotal journey.
Event sourcing, which records state changes as immutable events, provided robust auditing and "time travel" debugging for Wix Stores' microservices. Despite its benefits, the complexity it introduced in state management slowed development. Wix responded by adopting a simpler, unified CRUD model. This talk will explore the challenges of event sourcing and the advantages of Wix's new "CRUD on steroids" approach, which streamlines API integration and domain event management while preserving data integrity and system resilience.
Participants will gain valuable insights into Wix's strategies for ensuring atomicity in database updates and event production, as well as caching, materialization, and performance optimization techniques within a distributed system.
Join us to discover how Wix has mastered the art of balancing simplicity and extensibility, and learn how the re-adoption of the modest CRUD has turbocharged their development velocity, resilience, and scalability in a high-growth environment.
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
In this slide, we show the simulation example and the way to compile this solver.
In this solver, the Helmholtz equation can be solved by helmholtzFoam. Also, the Helmholtz equation with uniformly dispersed bubbles can be simulated by helmholtzBubbleFoam.
Enhancing Research Orchestration Capabilities at ORNL.pdfGlobus
Cross-facility research orchestration comes with ever-changing constraints regarding the availability and suitability of various compute and data resources. In short, a flexible data and processing fabric is needed to enable the dynamic redirection of data and compute tasks throughout the lifecycle of an experiment. In this talk, we illustrate how we easily leveraged Globus services to instrument the ACE research testbed at the Oak Ridge Leadership Computing Facility with flexible data and task orchestration capabilities.
Listen to the keynote address and hear about the latest developments from Rachana Ananthakrishnan and Ian Foster who review the updates to the Globus Platform and Service, and the relevance of Globus to the scientific community as an automation platform to accelerate scientific discovery.
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Globus
The U.S. Geological Survey (USGS) has made substantial investments in meeting evolving scientific, technical, and policy driven demands on storing, managing, and delivering data. As these demands continue to grow in complexity and scale, the USGS must continue to explore innovative solutions to improve its management, curation, sharing, delivering, and preservation approaches for large-scale research data. Supporting these needs, the USGS has partnered with the University of Chicago-Globus to research and develop advanced repository components and workflows leveraging its current investment in Globus. The primary outcome of this partnership includes the development of a prototype enterprise repository, driven by USGS Data Release requirements, through exploration and implementation of the entire suite of the Globus platform offerings, including Globus Flow, Globus Auth, Globus Transfer, and Globus Search. This presentation will provide insights into this research partnership, introduce the unique requirements and challenges being addressed and provide relevant project progress.
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
Quarkus Hidden and Forbidden ExtensionsMax Andersen
Quarkus has a vast extension ecosystem and is known for its subsonic and subatomic feature set. Some of these features are not as well known, and some extensions are less talked about, but that does not make them less interesting - quite the opposite.
Come join this talk to see some tips and tricks for using Quarkus and some of the lesser known features, extensions and development techniques.
GraphSummit Paris - The art of the possible with Graph TechnologyNeo4j
Sudhir Hasbe, Chief Product Officer, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
Understanding Globus Data Transfers with NetSageGlobus
NetSage is an open privacy-aware network measurement, analysis, and visualization service designed to help end-users visualize and reason about large data transfers. NetSage traditionally has used a combination of passive measurements, including SNMP and flow data, as well as active measurements, mainly perfSONAR, to provide longitudinal network performance data visualization. It has been deployed by dozens of networks world wide, and is supported domestically by the Engagement and Performance Operations Center (EPOC), NSF #2328479. We have recently expanded the NetSage data sources to include logs for Globus data transfers, following the same privacy-preserving approach as for Flow data. Using the logs for the Texas Advanced Computing Center (TACC) as an example, this talk will walk through several different example use cases that NetSage can answer, including: Who is using Globus to share data with my institution, and what kind of performance are they able to achieve? How many transfers has Globus supported for us? Which sites are we sharing the most data with, and how is that changing over time? How is my site using Globus to move data internally, and what kind of performance do we see for those transfers? What percentage of data transfers at my institution used Globus, and how did the overall data transfer performance compare to the Globus users?
Code reviews are vital for ensuring good code quality. They serve as one of our last lines of defense against bugs and subpar code reaching production.
Yet, they often turn into annoying tasks riddled with frustration, hostility, unclear feedback and lack of standards. How can we improve this crucial process?
In this session we will cover:
- The Art of Effective Code Reviews
- Streamlining the Review Process
- Elevating Reviews with Automated Tools
By the end of this presentation, you'll have the knowledge on how to organize and improve your code review proces
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our team’s work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaYara Milbes
Discover the transformative power of the WhatsApp API in our latest SlideShare presentation, "Top 7 Unique WhatsApp API Benefits." In today's fast-paced digital era, effective communication is crucial for both personal and professional success. Whether you're a small business looking to enhance customer interactions or an individual seeking seamless communication with loved ones, the WhatsApp API offers robust capabilities that can significantly elevate your experience.
In this presentation, we delve into the top 7 distinctive benefits of the WhatsApp API, provided by the leading WhatsApp API service provider in Saudi Arabia. Learn how to streamline customer support, automate notifications, leverage rich media messaging, run scalable marketing campaigns, integrate secure payments, synchronize with CRM systems, and ensure enhanced security and privacy.
We describe the deployment and use of Globus Compute for remote computation. This content is aimed at researchers who wish to compute on remote resources using a unified programming interface, as well as system administrators who will deploy and operate Globus Compute services on their research computing infrastructure.
May Marketo Masterclass, London MUG May 22 2024.pdfAdele Miller
Can't make Adobe Summit in Vegas? No sweat because the EMEA Marketo Engage Champions are coming to London to share their Summit sessions, insights and more!
This is a MUG with a twist you don't want to miss.
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
How Recreation Management Software Can Streamline Your Operations.pptxwottaspaceseo
Recreation management software streamlines operations by automating key tasks such as scheduling, registration, and payment processing, reducing manual workload and errors. It provides centralized management of facilities, classes, and events, ensuring efficient resource allocation and facility usage. The software offers user-friendly online portals for easy access to bookings and program information, enhancing customer experience. Real-time reporting and data analytics deliver insights into attendance and preferences, aiding in strategic decision-making. Additionally, effective communication tools keep participants and staff informed with timely updates. Overall, recreation management software enhances efficiency, improves service delivery, and boosts customer satisfaction.
How Recreation Management Software Can Streamline Your Operations.pptx
Evolution and Examples of Java Features, from Java 1.7 to Java 22
1. Yann-Gaël Guéhéneuc
(/jan/, he/il)
Work licensed under Creative Commons
BY-NC-SA 4.0 International
New Java
yann-gael.gueheneuc@concordia.ca
Version 0.22.1
2024/03/28
6. 6/360
Documents
JLSs: Java Language Specifications
– What is Java
JSRs: Java Specification Requests
– Parts of the JCP
– New specifications and technologies
– JDK/OpenJDK
JEPs: Java Enhancement Proposals
– Experimental ideas
– Could become JSRs
https://stackoverflow.com/questions/51282326/what-is-the-difference-or-relation-between-jls-jsr-and-jep
12. 12/360
Enums
Special data type
– Declares/defines
variables set to
constants
interface PseudoEnum0 {
int YES = 0;
int NO = 1;
}
interface Interface1 {
public boolean foo();
}
enum RealEnum1 implements Interface1 {
YES {
public boolean foo() {
return true;
}
},
NO {
public boolean foo() {
return false;
}
};
public boolean bar() {
return this.foo();
}
}
13. 13/360
Enums
Based on anonymous classes
System.out.println(RealEnum1.YES.bar());
System.out.println(RealEnum1.NO.bar());
System.out.print("Superclass: ");
System.out.println(RealEnum1.NO.getClass().getSuperclass());
System.out.print("Class: ");
System.out.println(RealEnum1.NO.getClass());
for (final Method method : RealEnum1.NO.getClass().getDeclaredMethods()) {
System.out.print("tMethods: ");
System.out.println(method);
}
14. 14/360
Enums
Based on anonymous classes
System.out.println(RealEnum1.YES.bar());
System.out.println(RealEnum1.NO.bar());
System.out.print("Superclass: ");
System.out.println(RealEnum1.NO.getClass().getSuperclass());
System.out.print("Class: ");
System.out.println(RealEnum1.NO.getClass());
for (final Method method : RealEnum1.NO.getClass().getDeclaredMethods()) {
System.out.print("tMethods: ");
System.out.println(method);
}
true
false
Superclass: class net.ptidej.newjava.enums.RealEnum1
Class: class net.ptidej.newjava.enums.RealEnum1$2
Methods: public boolean net.ptidej.newjava.enums.RealEnum1$2.foo()
15. 15/360
Enums
Enum Simulated Enum
interface Interface1 {
public boolean foo();
}
enum RealEnum1 implements Interface1 {
YES {
public boolean foo() {
return true;
}
},
NO {
public boolean foo() {
return false;
}
};
public boolean bar() {
return this.foo();
}
}
interface Interface1 {
public boolean foo();
}
abstract class SimulatedEnum1 implements Interface1 {
public static final SimulatedEnum1 YES =
new SimulatedEnum1() {
@Override
public boolean foo() {
return true;
}
};
public static final SimulatedEnum1 NO =
new SimulatedEnum1() {
@Override
public boolean foo() {
return false;
}
};
private SimulatedEnum1() {
}
public boolean bar() {
return this.foo();
}
}
16. 16/360
Enums
Enum Simulated Enum
interface Interface1 {
public boolean foo();
}
enum RealEnum1 implements Interface1 {
YES {
public boolean foo() {
return true;
}
},
NO {
public boolean foo() {
return false;
}
};
public boolean bar() {
return this.foo();
}
}
interface Interface1 {
public boolean foo();
}
abstract class SimulatedEnum1 implements Interface1 {
public static final SimulatedEnum1 YES =
new SimulatedEnum1() {
@Override
public boolean foo() {
return true;
}
};
public static final SimulatedEnum1 NO =
new SimulatedEnum1() {
@Override
public boolean foo() {
return false;
}
};
private SimulatedEnum1() {
}
public boolean bar() {
return this.foo();
}
}
Instances of two
anonymous classes
17. 17/360
Enums
Enum Simulated Enum
interface Interface1 {
public boolean foo();
}
enum RealEnum1 implements Interface1 {
YES {
public boolean foo() {
return true;
}
},
NO {
public boolean foo() {
return false;
}
};
public boolean bar() {
return this.foo();
}
}
Why private?
interface Interface1 {
public boolean foo();
}
abstract class SimulatedEnum1 implements Interface1 {
public static final SimulatedEnum1 YES =
new SimulatedEnum1() {
@Override
public boolean foo() {
return true;
}
};
public static final SimulatedEnum1 NO =
new SimulatedEnum1() {
@Override
public boolean foo() {
return false;
}
};
private SimulatedEnum1() {
}
public boolean bar() {
return this.foo();
}
}
Instances of two
anonymous classes
18. 18/360
Enums
More than just syntactic sugar
– Constants are constant expressions
final RealEnum3 v = // ...
switch (v) {
case YES:
System.out.println("YES");
break;
case NO:
System.out.println("NO");
break;
default:
throw // ...
}
final SimulatedEnum3 v1 = // ...
switch (v1) {
case SimulatedEnum3.YES:
System.out.println("YES");
break;
case SimulatedEnum3.NO:
System.out.println("NO");
break;
default:
throw // ...
}
19. 19/360
Enums
More than just syntactic sugar
– Constants are constant expressions
final RealEnum3 v = // ...
switch (v) {
case YES:
System.out.println("YES");
break;
case NO:
System.out.println("NO");
break;
default:
throw // ...
}
final SimulatedEnum3 v1 = // ...
switch (v1) {
case SimulatedEnum3.YES:
System.out.println("YES");
break;
case SimulatedEnum3.NO:
System.out.println("NO");
break;
default:
throw // ...
}
case expressions must be constant expressions
20. 20/360
Enums
No work around the compilation error
– Some constants are not constant expressions
final SimulatedEnum3 v1 = // ...
switch (v1) {
case SimulatedEnum3.YES:
System.out.println("YES");
break;
case SimulatedEnum3.NO:
System.out.println("NO");
break;
default:
throw // ...
}
final int v2 = // ...
switch (v2) {
case SimulatedEnum3.YES.constantID:
System.out.println("YES");
break;
case SimulatedEnum3.NO.constantID:
System.out.println("NO");
break;
default:
throw // ...
}
public final int constantID;
28. 28/360
Underscores in Numeric Literals
int i = 12_34_56;
System.out.println(i);
https://www.geeksforgeeks.org/using-underscore-numeric-literals-java/
32. 32/360
JSR-292: invokedynamic
invokestatic, for class methods
invokevirtual, for instance methods
invokeinterface, for interface methods
invokespecial, for instance initialisation,
superclass, and private methods
36. 36/360
JSR-166: Concurrency Utilities
Concurrency utilities under JSR 166
java.util.concurrent wants to be for
concurrency what java.util.Collections
is for collections
With some JVM support
– Timing
– Atomics
– …
https://gee.cs.oswego.edu/dl/concurrency-interest/jsr166-slides.pdf
45. 45/360
JSR-203: New File I/O Library
Extensive File I/O API
Socket channel API
Asynchronous I/O API
46. 46/360
JSR-203: New File I/O Library
Extensive File I/O API
https://www.baeldung.com/java-nio2-file-visitor
https://www.baeldung.com/java-nio2-file-visitor
public class Example1FileVisitor {
public static void main(final String[] args) throws IOException {
final Path startPath = Paths.get("D:DocumentsTutorials220926 - New Java");
final String fileName = "Example1FileVisitor.java";
final FileVisitorImpl visitor = new FileVisitorImpl(fileName, startPath);
Files.walkFileTree(startPath, visitor);
}
}
47. 47/360
JSR-203: New File I/O Library
https://www.baeldung.com/java-nio2-file-visitor
class FileVisitorImpl implements FileVisitor<Path> {
private final String fileName;
private final Path startPath;
public FileVisitorImpl(final String aFileName, final Path aStartPath) {
this.fileName = aFileName;
this.startPath = aStartPath;
}
@Override
public FileVisitResult preVisitDirectory(final Path aPath, final BasicFileAttributes someAttributes) {
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(final Path aPath, final BasicFileAttributes someAttributes) {
final String fileName = aPath.getFileName().toString();
if (fileName.equals(this.fileName)) {
return FileVisitResult.TERMINATE;
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(final Path aPath, final IOException anIOException) {
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(final Path aPath, final IOException anIOException) {
try {
if (Files.isSameFile(aPath, this.startPath)) {
return FileVisitResult.TERMINATE;
}
} catch (final IOException e) {
e.printStackTrace();
}
return FileVisitResult.CONTINUE;
}
}
48. 48/360
JSR-203: New File I/O Library
Socket channel API – Client
public static void client() throws IOException {
final ServerSocketChannel serverSocket = ServerSocketChannel.open();
serverSocket.socket().bind(new InetSocketAddress(9000));
final SocketChannel client = serverSocket.accept();
System.out.println("Connection set: " + client.getRemoteAddress());
final Path path = Paths.get("D:DocumentsTutorials220926 - New JavaReceivedFile.txt");
final FileChannel fileChannel = FileChannel.open(
path,
EnumSet.of(StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.WRITE));
final ByteBuffer buffer = ByteBuffer.allocate(1024);
while (client.read(buffer) > 0) {
buffer.flip();
fileChannel.write(buffer);
buffer.clear();
}
fileChannel.close();
System.out.println("File received");
client.close();
}
https://www.tutorialspoint.com/java_nio/java_nio_socket_channel.htm
49. 49/360
JSR-203: New File I/O Library
Socket channel API – Server
https://www.tutorialspoint.com/java_nio/java_nio_socket_channel.htm
public static void server() throws IOException {
final SocketChannel server = SocketChannel.open();
final SocketAddress socketAddr = new InetSocketAddress("localhost", 9000);
server.connect(socketAddr);
final Path path = Paths.get("D:DocumentsTutorials220926 - New JavaPatterns.txt");
final FileChannel fileChannel = FileChannel.open(path);
final ByteBuffer buffer = ByteBuffer.allocate(1024);
while (fileChannel.read(buffer) > 0) {
buffer.flip();
server.write(buffer);
buffer.clear();
}
fileChannel.close();
System.out.println("File sent");
server.close();
}
50. 50/360
JSR-203: New File I/O Library
Socket channel API – Main
public static void main(final String[] args) {
final Runnable runnableClient = new Runnable() {
public void run() {
try {
Example2SocketChannel.client();
} catch (final IOException e) {
}
}
};
final Runnable runnableServer = new Runnable() {
public void run() {
try {
Example2SocketChannel.server();
} catch (final IOException e) {
}
}
};
final ExecutorService executor = Executors.newFixedThreadPool(2);
executor.execute(runnableClient);
executor.execute(runnableServer);
}
https://www.tutorialspoint.com/java_nio/java_nio_socket_channel.htm
51. 51/360
JSR-203: New File I/O Library
Asynchronous I/O API
“The asynchronous channel APIs were
introduced into the existing
java.nio.channels package […] by
prefixing […] with Asynchronous”
52. 52/360
Translucent and Shaped Windows
Improves Java Swing
Allow new, nicer themes
https://ateraimemo.com/Swing/TranslucentFrame.html
Window.setShape(Shape s)
Window.setOpacity(float f)
53. 53/360
Network Protocols
Network protocols
– Stream Control
Transport Protocol
(SCTP)
– Sockets Direct
Protocol (SDP)
In packages
– com.sun.nio.sctp
– com.sun.sdp
https://www.oracle.com/technical-resources/articles/javase/sctp.html
final SctpServerChannel ssc =
SctpServerChannel.open();
final InetSocketAddress serverAddr = // ...
ssc.bind(serverAddr);
while (true) {
final SctpChannel sc = ssc.accept();
final Date today = new Date();
cbuf.put(USformatter.format(today)).flip();
encoder.encode(cbuf, buf, true);
buf.flip();
messageInfo.streamNumber(FUS_STREAM);
sc.send(buf, messageInfo);
buf.clear();
cbuf.clear();
cbuf.put(FRformatter.format(today)).flip();
encoder.encode(cbuf, buf, true);
buf.flip();
messageInfo.streamNumber(FR_STREAM);
sc.send(buf, messageInfo);
buf.clear();
cbuf.clear();
// ...
54. 54/360
Updates to XML and Unicode
New system property named
org.jcp.xml.dsig.secureValidation
New XML Processing Limits
Regular Expression pattern matching
supports Unicode 6.0.0
– Major version of the Unicode Standard
57. 57/360
default, static Interface Methods
public interface IA {
int foo();
default int bar() {
return 42;
}
}
public static void main(final String[] args) {
final IA anIA = new IA() {
public int foo() {
return 0;
}
};
System.out.println(anIA.foo());
System.out.println(anIA.bar());
final IA anotherIA = new IA() {
public int foo() {
return IA.super.bar();
}
public int bar() {
return 0;
}
};
System.out.println(anotherIA.foo());
System.out.println(anotherIA.bar());
}
58. 58/360
default, static Interface Methods
public interface IA {
int foo();
default int bar() {
return 42;
}
}
public static void main(final String[] args) {
final IA anIA = new IA() {
public int foo() {
return 0;
}
};
System.out.println(anIA.foo());
System.out.println(anIA.bar());
final IA anotherIA = new IA() {
public int foo() {
return IA.super.bar();
}
public int bar() {
return 0;
}
};
System.out.println(anotherIA.foo());
System.out.println(anotherIA.bar());
}
0
42
42
0
59. 59/360
default, static Interface Methods
https://stackoverflow.c
om/questions/512877/
why-cant-i-define-a-
static-method-in-a-
java-interface
public interface IA {
int foo();
static int bar() {
return 42;
}
}
public class A {
int foo() {
return 0;
}
static int bar() {
return 42;
}
}
public static void main(final String[] args) {
final IA anIA = new IA() {
public int foo() {
return 0;
}
};
System.out.println(anIA.foo());
System.out.println(anIA.bar());
final A anA = new A();
System.out.println(anA.foo());
System.out.println(anA.bar());
}
60. 60/360
default, static Interface Methods
https://stackoverflow.c
om/questions/512877/
why-cant-i-define-a-
static-method-in-a-
java-interface
public interface IA {
int foo();
static int bar() {
return 42;
}
}
public class A {
int foo() {
return 0;
}
static int bar() {
return 42;
}
}
public static void main(final String[] args) {
final IA anIA = new IA() {
public int foo() {
return 0;
}
};
System.out.println(anIA.foo());
System.out.println(anIA.bar());
final A anA = new A();
System.out.println(anA.foo());
System.out.println(anA.bar());
}
61. 61/360
default, static Interface Methods
https://stackoverflow.c
om/questions/512877/
why-cant-i-define-a-
static-method-in-a-
java-interface
public interface IA {
int foo();
static int bar() {
return 42;
}
}
public class A {
int foo() {
return 0;
}
static int bar() {
return 42;
}
}
public static void main(final String[] args) {
final IA anIA = new IA() {
public int foo() {
return 0;
}
};
System.out.println(anIA.foo());
System.out.println(anIA.bar());
final A anA = new A();
System.out.println(anA.foo());
System.out.println(anA.bar());
}
System.out.println(IA.bar());
62. 62/360
JSR-335, JEP-126: λ Expressions
λ Expressions
interface Applicable<T, R> {
public R apply(final T aParameter);
}
public static void main(final String[] args) {
final Applicable<String, Integer> strlen = new Applicable<>() {
@Override
public Integer apply(final String aParameter) {
return aParameter.length();
}
};
System.out.println(strlen.apply("Hello, World!"));
}
https://jenkov.com/tutorials/java-functional-programming/functional-interfaces.html
63. 63/360
JSR-335, JEP-126: λ Expressions
interface Applicable<T, R> {
public R apply(final T aParameter);
}
public static void main(final String[] args) {
final Applicable<String, Integer> strlen = new Applicable<>() {
@Override
public Integer apply(final String aParameter) {
return aParameter.length();
}
};
System.out.println(strlen.apply("Hello, World!"));
}
64. 64/360
JSR-335, JEP-126: λ Expressions
Lots of boilerplate code
Difficult to understand
Not common in the libraries
interface Applicable<T, R> {
public R apply(final T aParameter);
}
public static void main(final String[] args) {
final Applicable<String, Integer> strlen = new Applicable<>() {
@Override
public Integer apply(final String aParameter) {
return aParameter.length();
}
};
System.out.println(strlen.apply("Hello, World!"));
}
65. 65/360
JSR-335, JEP-126: λ Expressions
Solution
– Simple syntactic sugar
– Set of functional interfaces
– Libraries using these interfaces
66. 66/360
JSR-335, JEP-126: λ Expressions
Solution
– Simple syntactic sugar
– Set of functional interfaces
– Libraries using these interfaces
67. 67/360
JSR-335, JEP-126: λ Expressions
Solution
– Simple syntactic sugar
– Set of functional interfaces
– Libraries using these interfaces
interface Applicable<T, R> {
public R apply(final T aParameter);
}
public static void main(final String[] args) {
final Applicable<String, Integer> strlen = (paramter) -> paramter.length();
System.out.println(strlen.apply("Hello, World!"));
}
68. 68/360
JSR-335, JEP-126: λ Expressions
Solution
– Simple syntactic sugar
– Set of functional interfaces
– Libraries using these interfaces
interface Applicable<T, R> {
public R apply(final T aParameter);
}
public static void main(final String[] args) {
final Applicable<String, Integer> strlen = (paramter) -> paramter.length();
System.out.println(strlen.apply("Hello, World!"));
}
public static void main(final String[] args) {
final Applicable<String, Integer> strlen = String::length;
System.out.println(strlen.apply("Hello, World!"));
}
69. 69/360
JSR-335, JEP-126: λ Expressions
Solution
– Simple syntactic sugar
– Set of functional interfaces
– Libraries using these interfaces
http://blog.orfjackal.net/2014/07/java-8-functional-interface-naming-guide.html
70. 70/360
JSR-335, JEP-126: λ Expressions
Solution
– Simple syntactic sugar
– Set of functional interfaces
– Libraries using these interfaces
http://blog.orfjackal.net/2014/07/java-8-functional-interface-naming-guide.html
71. 71/360
JSR-335, JEP-126: λ Expressions
Solution
– Simple syntactic sugar
– Set of functional interfaces
– Libraries using these interfaces
https://blogs.oracle.com/javamagazine/post/functional-programming-in-java-part-1-lists-lambdas-and-method-references
72. 72/360
JSR-335, JEP-126: λ Expressions
Solution
– Simple syntactic sugar
– Set of functional interfaces
– Libraries using these interfaces
https://blogs.oracle.com/javamagazine/post/functional-programming-in-java-part-1-lists-lambdas-and-method-references
final List<String> friends = Arrays.asList("Rick Deckard", "Roy Batty", "Harry
Bryant", "Hannibal Chew", "Gaff", "Holden", "Leon Kowalski", "Taffey Lewis",
"Pris", "Rachael", "J.F. Sebastian", "Dr. Eldon Tyrell", "Zhora", "Hodge",
"Mary");
for (int i = 0; i < friends.size(); i++) {
System.out.println(friends.get(i));
}
for (String name : friends) {
System.out.println(name);
}
friends.forEach(new Consumer<String>() {
public void accept(final String aName) { System.out.println(aName); }});
friends.forEach((final String name) -> System.out.println(name));
friends.forEach((name) -> System.out.println(name));
friends.forEach(name -> System.out.println(name));
friends.forEach(System.out::println);
friends.stream().map(String::toUpperCase).forEach(
name -> System.out.print(name + " "));
System.out.println();
final List<String> namesStartingWithN = friends.stream().
filter(name -> name.startsWith("R")).collect(Collectors.toList());
System.out.println(namesStartingWithN);
73. 73/360
JSR-335, JEP-126: λ Expressions
But code duplication!
https://blogs.oracle.com/javamagazine/post/functional-programming-
in-java-part-2-lambda-reuse-lexical-scoping-and-closures-and-reduce
output = friends1.stream().filter(name -> name.startsWith("R")).collect(Collectors.toList());
System.out.println(output);
output = friends2.stream().filter(name -> name.startsWith("R")).collect(Collectors.toList());
System.out.println(output);
final Predicate<String> predicate = name -> name.startsWith("R");
output = friends1.stream().filter(predicate).collect(Collectors.toList());
System.out.println(output);
output = friends2.stream().filter(predicate).collect(Collectors.toList());
System.out.println(output);
vs.
74. 74/360
JSR-335, JEP-126: λ Expressions
But code duplication!
https://blogs.oracle.com/javamagazine/post/functional-programming-
in-java-part-2-lambda-reuse-lexical-scoping-and-closures-and-reduce
// Lexical scoping and closure
output = friends1.stream().filter(checkIfStartsWith("R")).collect(Collectors.toList());
System.out.println(output);
output = friends2.stream().filter(checkIfStartsWith("P")).collect(Collectors.toList());
System.out.println(output);
// Narrower lexical scoping
final Function<String, Predicate<String>> startsWithLetter = letter -> (name ->
name.startsWith(letter));
output = friends1.stream().filter(startsWithLetter.apply("R")).collect(Collectors.toList());
System.out.println(output);
output = friends2.stream().filter(startsWithLetter.apply("P")).collect(Collectors.toList());
System.out.println(output);
vs.
75. 75/360
JSR-335, JEP-126: λ Expressions
But code duplication!
https://blogs.oracle.com/javamagazine/post/functional-programming-
in-java-part-2-lambda-reuse-lexical-scoping-and-closures-and-reduce
// Lexical scoping and closure
output = friends1.stream().filter(checkIfStartsWith("R")).collect(Collectors.toList());
System.out.println(output);
output = friends2.stream().filter(checkIfStartsWith("P")).collect(Collectors.toList());
System.out.println(output);
// Narrower lexical scoping
final Function<String, Predicate<String>> startsWithLetter = letter -> (name ->
name.startsWith(letter));
output = friends1.stream().filter(startsWithLetter("R")).collect(Collectors.toList());
System.out.println(output);
output = friends2.stream().filter(startsWithLetter("P")).collect(Collectors.toList());
System.out.println(output);
vs.
76. 76/360
JSR-335, JEP-126: λ Expressions
But code duplication!
https://forum.devtalk.com/t/functional-programming-in-java-second-
edition-p-35-refactoring-to-narrow-the-scope-code/105447
// Lexical scoping and closure
output = friends1.stream().filter(checkIfStartsWith("R")).collect(Collectors.toList());
System.out.println(output);
output = friends2.stream().filter(checkIfStartsWith("P")).collect(Collectors.toList());
System.out.println(output);
// Narrower lexical scoping
final Function<String, Predicate<String>> startsWithLetter = letter -> (name ->
name.startsWith(letter));
output = friends1.stream().filter(startsWithLetter("R")).collect(Collectors.toList());
System.out.println(output);
output = friends2.stream().filter(startsWithLetter("P")).collect(Collectors.toList());
System.out.println(output);
vs.
77. 77/360
JSR-308, JEP-104: Type Annotations
Allow pluggable type systems
Help enforce stronger typing
public class Example1 {
public static void main(final String[] args) {
final String aString = null;
final String anotherString = aString;
System.out.println(anotherString);
}
}
78. 78/360
JSR-308, JEP-104: Type Annotations
Allow pluggable type systems
Help enforce stronger typing
public class Example1 {
public static void main(final String[] args) {
final String aString = null;
final String anotherString = aString;
System.out.println(anotherString);
}
}
public class Example1 {
public static void main(final String[] args) {
final String aString = null;
final @NonNull String anotherString = aString;
System.out.println(anotherString);
}
}
79. 79/360
JSR-308, JEP-104: Type Annotations
Allow pluggable type systems
Help enforce stronger typing
public class Example1 {
public static void main(final String[] args) {
final String aString = null;
final String anotherString = aString;
System.out.println(anotherString);
}
}
public class Example1 {
public static void main(final String[] args) {
final String aString = null;
final @NonNull String anotherString = aString;
System.out.println(anotherString);
}
}
Null type mismatch: required
'@NonNull String' but the
provided value is null
80. 80/360
JSR-308, JEP-104: Type Annotations
Allow pluggable type systems
Help enforce stronger typing
public class Example1 {
public static void main(final String[] args) {
final String aString = null;
final String anotherString = aString;
System.out.println(anotherString);
}
}
public class Example1 {
public static void main(final String[] args) {
final String aString = null;
final @NonNull String anotherString = aString;
System.out.println(anotherString);
}
}
public class Example1 {
public static void main(final String[] args) {
final String aString = "";
final @NonNull String anotherString = aString;
System.out.println(anotherString);
}
}
Null type mismatch: required
'@NonNull String' but the
provided value is null
81. 81/360
JSR-308, JEP-104: Type Annotations
class A {
String getString() {
return null;
}
}
public class Example2 {
public static void foo1() {
final A a = new A();
final String aString = a.getString();
final @NonNull String anotherString = aString;
System.out.println(anotherString);
}
public static void foo2() {
final A a = new A();
final String aString = a.getString();
if (aString != null) {
final @NonNull String anotherString = aString;
System.out.println(anotherString);
}
}
}
82. 82/360
JSR-308, JEP-104: Type Annotations
class A {
String getString() {
return null;
}
}
public class Example2 {
public static void foo1() {
final A a = new A();
final String aString = a.getString();
final @NonNull String anotherString = aString;
System.out.println(anotherString);
}
public static void foo2() {
final A a = new A();
final String aString = a.getString();
if (aString != null) {
final @NonNull String anotherString = aString;
System.out.println(anotherString);
}
}
}
Null type safety […] needs
unchecked conversion to
conform to '@NonNull String'
83. 83/360
JSR-308, JEP-104: Type Annotations
“The Checker Framework includes compiler
plug-ins ("checkers") that find bugs or verify
their absence. It also permits you to write
your own compiler plug-ins.”
– https://checkerframework.org/tutorial/
84. 84/360
Unsigned Integer Arithmetic
Comparison
Division/Modulo
Parsing
Formatting
https://www.baeldung.com/java-unsigned-arithmetic
public class Example1 {
public static void main(String[] args) {
final int positive = Integer.MAX_VALUE;
final int negative = Integer.MIN_VALUE;
final int signedComparison = Integer.compare(positive, negative);
if (signedComparison > 0) {
System.out.println("Positive > negative (signed comparison)");
}
final int unsignedComparison = Integer.compareUnsigned(positive, negative);
if (unsignedComparison < 0) {
System.out.println("Positive NOT > negative (unsigned comparison)");
}
}
}
85. 85/360
JEP-120: Repeating Annotations
“Annotations, a form of metadata, provide
data about a program that is not part of the
program [and] have no direct effect on the
operation of the code they annotate.”
https://docs.oracle.com/javase/tutorial/java/annotations/
86. 86/360
JEP-120: Repeating Annotations
“Annotations, a form of metadata, provide
data about a program that is not part of the
program [and] have no direct effect on the
operation of the code they annotate.”
https://docs.oracle.com/javase/tutorial/java/annotations/
94. 94/360
JEP-178: Statically-linked JNI
Libraries
Native programs that embed the JRE
Java programs running in environments
without shared libraries
Enable developers to package a Java run-
time, native code, and Java code together
into a single binary
95. 95/360
JEP-122: Permanent Generation
Removal
“Automatic garbage
collection is [..]
identifying which
objects are in use and
[…] deleting the
unused objects.”
Remove Permanent
Generation
– No more size tuning
https://openjdk.org/jeps/122
97. 97/360
JEP-174: Nashorn JS Engine
Successor of Mozilla’s Rhino
100% in ECMAScript v5.1 test suite
Java 8: Introduced
Java 11: Deprecated
Java 15: Removed
98. 98/360
JEP-174: Nashorn JS Engine
https://github.com/openjdk/nashorn
https://www.baeldung.com/java-nashorn
final ScriptEngine engine = new ScriptEngineManager().getEngineByName("Nashorn");
final Bindings bindings = engine.createBindings();
bindings.put("name", "Nashorn");
result = engine.eval("var greeting = 'hello world' + name;" + "print(greeting);" + "greeting");
System.out.println(result);
final Invocable invocable = (Invocable) engine;
engine.eval("function composeGreeting(name) {" + "return 'Hello ' + name" + "}");
result = invocable.invokeFunction("composeGreeting", "Nashorn");
System.out.println(result);
result = engine.eval("var HashMap = Java.type('java.util.HashMap’);"
+ "var map = new HashMap();"
+ "map.put('hello', 'world');" + "map");
System.out.println(result);
99. 99/360
JSR-310, JEP-150: Date, Time API
Need to manipulate dates and times
Disparate APIs, missing features
– Set time to midnight for a date without a time
Complete terminology
Complete, cohesive implementation
– java.time.*
101. 101/360
JEP-153: JavaFX Applications
Three “types” of programs
– Class files
– JAR files
– JavaFX
Enhance the java command-line to launch
JavaFX programs
104. 104/360
Private Interface Methods
public interface IA {
int foo();
default int bar() {
return this.bar1();
}
private int bar1() {
return 42;
}
}
public static void main(final String[] args) {
final IA anIA = new IA() {
public int foo() {
return 0;
}
};
System.out.println(anIA.foo());
System.out.println(anIA.bar());
final IA anotherIA = new IA() {
public int foo() {
return IA.super.bar1();
}
public int bar() {
return 0;
}
};
System.out.println(anotherIA.foo());
System.out.println(anotherIA.bar());
}
105. 105/360
Private Interface Methods
public interface IA {
int foo();
default int bar() {
return this.bar1();
}
private int bar1() {
return 42;
}
}
public static void main(final String[] args) {
final IA anIA = new IA() {
public int foo() {
return 0;
}
};
System.out.println(anIA.foo());
System.out.println(anIA.bar());
final IA anotherIA = new IA() {
public int foo() {
return IA.super.bar1();
}
public int bar() {
return 0;
}
};
System.out.println(anotherIA.foo());
System.out.println(anotherIA.bar());
}
0
42
42
0
106. 106/360
JSR-376: Modularization
JSR-376: Java Platform Module System,
part of Project Jigsaw
– Ease library construction, maintenance
– Security, maintainability of Java (and JDK)
– Allow scaling down programs for small devices
– Improve program compilation and loading times
https://openjdk.org/projects/jigsaw/
107. 107/360
JSR-376: Modularization
JEP-200: The Modular JDK
JEP-201: Modular Source Code
JEP-220: Modular Run-time Images
JEP-260: Encapsulate Most Internal APIs
JEP-261: Module System
JEP-282: jlink: The Java Linker
JSR 376: Java Platform Module System
108. 108/360
JSR-376: Modularization
Classpath / JARs Hell
Version conflicts
Large Monolithic JDK
Security Problems
https://www.geeksforgeeks.org/jpms-java-platform-module-system/
109. 109/360
JSR-376: Modularization
Classpath / JARs Hell
Version conflicts
– Cf. DLL Hell, no versions, one directory
– One, long list of JAR files
• Run-time missing dependencies
• Order of declaration (shadowing)
Large Monolithic JDK
Security Problems
https://www.geeksforgeeks.org/jpms-java-platform-module-system/
110. 110/360
JSR-376: Modularization
Classpath / JARs Hell
Version conflicts
Large Monolithic JDK
– E.g., in Java v1.4.2, RT.jar is 21.8 MB (!)
Security Problems
https://www.geeksforgeeks.org/jpms-java-platform-module-system/
111. 111/360
JSR-376: Modularization
Classpath / JARs Hell
Version conflicts
Large Monolithic JDK
Security Problems
– Implementation classes must be public
– Cannot control access to these classes
– padl.kernel vs. padl.kernel.impl
https://www.geeksforgeeks.org/jpms-java-platform-module-system/
112. 112/360
JSR-376: Modularization
A module is a “package of packages”
– With one module descriptor
– With own resources (data)
A module descriptor
– Domain Specific Language
– exports, module, open, opens, provides,
requires, to, transitive, uses, and with
113. 113/360
JSR-376: Modularization
Raoul-Gabriel Urma, Mario Fusco, Alan Mycroft ; Modern Java in Action ; Manning, 2018 (Chapter 14)
module com.example.foo {
requires transitive com.example.foo.network;
requires static com.example.foo.http;
requires java.logging;
exports com.example.foo.bar;
exports com.example.foo.internal to
com.example.foo.probe;
opens com.example.foo.quux;
opens com.example.foo.internal to
com.example.foo.network,
com.example.foo.probe;
uses com.example.foo.spi.Intf;
provides com.example.foo.spi.Data with
com.example.foo.Impl;
}
114. 114/360
JSR-376: Modularization
Raoul-Gabriel Urma, Mario Fusco, Alan Mycroft ; Modern Java in Action ; Manning, 2018 (Chapter 14)
module com.example.foo {
requires transitive com.example.foo.network;
requires static com.example.foo.http;
requires java.logging;
exports com.example.foo.bar;
exports com.example.foo.internal to
com.example.foo.probe;
opens com.example.foo.quux;
opens com.example.foo.internal to
com.example.foo.network,
com.example.foo.probe;
uses com.example.foo.spi.Intf;
provides com.example.foo.spi.Data with
com.example.foo.Impl;
}
115. 115/360
JSR-376: Modularization
Declaration of module
com.example.foo
Dependencies on
three other modules
– transitive: client
modules also can
access that module
– static: at compile-time,
option at run-time
module com.example.foo {
requires transitive com.example.foo.network;
requires static com.example.foo.http;
requires java.logging;
exports com.example.foo.bar;
exports com.example.foo.internal to
com.example.foo.probe;
opens com.example.foo.quux;
opens com.example.foo.internal to
com.example.foo.network,
com.example.foo.probe;
uses com.example.foo.spi.Intf;
provides com.example.foo.spi.Data with
com.example.foo.Impl;
}
116. 116/360
JSR-376: Modularization
(Qualified) exports to
other, client modules
– Public types accessible
to all client modules
– Or only to types in
com.example.foo.probe
module com.example.foo {
requires transitive com.example.foo.network;
requires static com.example.foo.http;
requires java.logging;
exports com.example.foo.bar;
exports com.example.foo.internal to
com.example.foo.probe;
opens com.example.foo.quux;
opens com.example.foo.internal to
com.example.foo.network,
com.example.foo.probe;
uses com.example.foo.spi.Intf;
provides com.example.foo.spi.Data with
com.example.foo.Impl;
}
117. 117/360
JSR-376: Modularization
(Qualified) opening to
other, client modules
at run-time only
– Public types accessible
to all client modules
– Or only to types in com.
example.foo.network or
com.example.foo.probe
– Allows introspection
module com.example.foo {
requires transitive com.example.foo.network;
requires static com.example.foo.http;
requires java.logging;
exports com.example.foo.bar;
exports com.example.foo.internal to
com.example.foo.probe;
opens com.example.foo.quux;
opens com.example.foo.internal to
com.example.foo.network,
com.example.foo.probe;
uses com.example.foo.spi.Intf;
provides com.example.foo.spi.Data with
com.example.foo.Impl;
}
118. 118/360
module com.example.foo {
requires transitive com.example.foo.network;
requires static com.example.foo.http;
requires java.logging;
exports com.example.foo.bar;
exports com.example.foo.internal to
com.example.foo.probe;
opens com.example.foo.quux;
opens com.example.foo.internal to
com.example.foo.network,
com.example.foo.probe;
uses com.example.foo.spi.Intf;
provides com.example.foo.spi.Data with
com.example.foo.Impl;
}
JSR-376: Modularization
Service consumer
– Interface/abstract class
com.example.foo.spi.Intf
Service provider
– Interface/abstract class
com.example.foo.spi.Data
– With concrete class
com.example.foo.Impl
119. 119/360
JSR-376: Modularization
modularisation.Client
– Can access any public
type at compile-time
and at run-time
– Can access some
protected/private
data with introspection
internal.Client
– Cannot access
HiddenImplementation
120. 120/360
JSR-376: Modularization
modularisation.Client
– Can access any public
type at compile-time
and at run-time
– Can access some
protected/private
data with introspection
internal.Client
– Cannot access
HiddenImplementation
Package-protected
Class (not public!)
121. 121/360
JSR-376: Modularization
final Interface aki = new Implementation();
aki.foo();
System.out.println("Call on public implementation: ");
final Class<? extends Interface> implementation1 = Class
.forName(“....impl.Implementation").asSubclass(Interface.class);
final Interface aki1 = implementation1.getDeclaredConstructor().newInstance();
final Method[] methods1 = implementation1.getDeclaredMethods();
for (final Method method : methods1) {
try {
method.setAccessible(true);
method.invoke(aki1, new Object[0]);
} catch (final RuntimeException e) {
System.out.println(e.getMessage());
}
}
final Class<? extends Interface> implementation2 = Class
.forName(“....impl.HiddenImplementation").asSubclass(Interface.class);
final Interface aki2 = implementation2.getDeclaredConstructor().newInstance();
final Method[] methods2 = implementation2.getDeclaredMethods();
for (final Method method : methods2) {
// Same code
122. 122/360
JSR-376: Modularization
The client code has access to the fields and
methods in all public types, even if private
Direct call: Implementation.bar()
Call on public implementation:
bar: Implementation.bar()
foo: Implementation.bar()
Call on hidden implementation:
Exception in thread "main" java.lang.IllegalAccessException: class
net.ptidej.modularisation.Client cannot access a member of class
net.ptidej.modularisation.kernel.impl.HiddenImplementation with package
access
...
123. 123/360
JSR-376: Modularization
The client code has access to the fields and
methods in all public types, even if private
Direct call: Implementation.bar()
Call on public implementation:
bar: Implementation.bar()
foo: Implementation.bar()
Call on hidden implementation:
Exception in thread "main" java.lang.IllegalAccessException: class
net.ptidej.modularisation.Client cannot access a member of class
net.ptidej.modularisation.kernel.impl.HiddenImplementation with package
access
...
Including the
private method
125. 125/360
JSR-376: Modularization
Client (not a module)
Client (module)
Direct call: Implementation.bar()
Call on public implementation:
bar: Implementation.bar()
foo: Implementation.bar()
Call on hidden implementation:
Exception in thread "main" java.lang.IllegalAccessException: class net.ptidej.modularisation.Client
cannot access a member of class net.ptidej.modularisation.kernel.impl.HiddenImplementation with
package access
Direct call: Implementation.bar()
Call on public implementation:
foo: Implementation.bar()
bar: Unable to make private void net.ptidej.modularisation.kernel.impl.Implementation.bar()
accessible: module ModularizationWithModulesLibrary1 does not "opens
net.ptidej.modularisation.kernel.impl" to module ModularizationWithModulesClient1
Call on hidden implementation:
Exception in thread "main" java.lang.IllegalAccessException: class net.ptidej.modularisation.Client
(in module ModularizationWithModulesClient1) cannot access a member of class
net.ptidej.modularisation.kernel.impl.HiddenImplementation (in module
ModularizationWithModulesLibrary1) with package access
126. 126/360
JSR-376: Modularization
Client (not a module)
Client (module)
Direct call: Implementation.bar()
Call on public implementation:
bar: Implementation.bar()
foo: Implementation.bar()
Call on hidden implementation:
Exception in thread "main" java.lang.IllegalAccessException: class net.ptidej.modularisation.Client
cannot access a member of class net.ptidej.modularisation.kernel.impl.HiddenImplementation with
package access
Direct call: Implementation.bar()
Call on public implementation:
foo: Implementation.bar()
bar: Unable to make private void net.ptidej.modularisation.kernel.impl.Implementation.bar()
accessible: module ModularizationWithModulesLibrary1 does not "opens
net.ptidej.modularisation.kernel.impl" to module ModularizationWithModulesClient1
Call on hidden implementation:
Exception in thread "main" java.lang.IllegalAccessException: class net.ptidej.modularisation.Client
(in module ModularizationWithModulesClient1) cannot access a member of class
net.ptidej.modularisation.kernel.impl.HiddenImplementation (in module
ModularizationWithModulesLibrary1) with package access
Non-module can still
access private methods
127. 127/360
JSR-376: Modularization
Client (not a module)
Client (module)
Direct call: Implementation.bar()
Call on public implementation:
bar: Implementation.bar()
foo: Implementation.bar()
Call on hidden implementation:
Exception in thread "main" java.lang.IllegalAccessException: class net.ptidej.modularisation.Client
cannot access a member of class net.ptidej.modularisation.kernel.impl.HiddenImplementation with
package access
Direct call: Implementation.bar()
Call on public implementation:
foo: Implementation.bar()
bar: Unable to make private void net.ptidej.modularisation.kernel.impl.Implementation.bar()
accessible: module ModularizationWithModulesLibrary1 does not "opens
net.ptidej.modularisation.kernel.impl" to module ModularizationWithModulesClient1
Call on hidden implementation:
Exception in thread "main" java.lang.IllegalAccessException: class net.ptidej.modularisation.Client
(in module ModularizationWithModulesClient1) cannot access a member of class
net.ptidej.modularisation.kernel.impl.HiddenImplementation (in module
ModularizationWithModulesLibrary1) with package access
Non-module can still
access private methods
Modules cannot access
private/package data
129. 129/360
JSR-376: Modularization
Client implementation
Client output
Implementation.bar()
Call on public implementation:
Exception in thread "main" java.lang.IllegalAccessException: class net.ptidej.modularisation.Client
(in module ModularizationWithModulesClient2) cannot access class
net.ptidej.modularisation.kernel.impl.Implementation (in module ModularizationWithModulesLibrary2)
because module ModularizationWithModulesLibrary2 does not export
net.ptidej.modularisation.kernel.impl to module ModularizationWithModulesClient2
final ServiceLoader<Interface> providers = ServiceLoader.load(Interface.class);
final Interface aki = providers.findFirst().orElse(null);
aki.foo();
130. 130/360
JSR-376: Modularization
Client implementation
Client output
Implementation.bar()
Call on public implementation:
Exception in thread "main" java.lang.IllegalAccessException: class net.ptidej.modularisation.Client
(in module ModularizationWithModulesClient2) cannot access class
net.ptidej.modularisation.kernel.impl.Implementation (in module ModularizationWithModulesLibrary2)
because module ModularizationWithModulesLibrary2 does not export
net.ptidej.modularisation.kernel.impl to module ModularizationWithModulesClient2
No access to data not
exported/provided,
even if public!
final ServiceLoader<Interface> providers = ServiceLoader.load(Interface.class);
final Interface aki = providers.findFirst().orElse(null);
aki.foo();
134. 134/360
JSR-376: Modularization
Relation to OSGi
– Open Service Gateway Initiative
• From 05/2000, latest 12/2020
– Eclipse Foundation open-source project
– Framework for developing and deploying
• Modular programs and libraries
• IoT and other constrained devices
https://www.techtarget.com/searchnetworking/definition/OSGi
135. 135/360
JSR-376: Modularization
OSGi (Bundles)
Several class loaders
– Cannot be used for the JDK
– Allow “duplicate” packages
– Allow multiple versions
Visibility
JPMS (Modules)
One class loader
– Can be used in the JDK
– Disallow same packages
– No versioning
Accessibility
https://www.infoq.com/articles/java9-osgi-future-modularity/, https://www.infoq.com/articles/java9-osgi-future-modularity-
part-2/, https://www.baeldung.com/java-illegal-reflective-access, https://en.wikipedia.org/wiki/OSGi
136. 136/360
JSR-376: Modularization
OSGi (Bundles)
“[B]uild dependencies and
runtime dependencies can
and often do differ”
JPMS (Modules)
“[T]he module system
should […] work [same] at
compile time, run time…”
Export-Package: org.example.foo;
version=1.0.1, org.example.bar;
version=2.1.0
Import-Package: org.example.foo;
version='[1,2)', org.example.bar;
version='[2.0,2.1)'
module A {
exports org.example.foo;
exports org.example.bar;
}
module B {
require A;
}
https://www.infoq.com/articles/java9-osgi-future-modularity/, https://www.infoq.com/articles/java9-osgi-future-modularity-
part-2/, https://www.baeldung.com/java-illegal-reflective-access, https://en.wikipedia.org/wiki/OSGi
137. 137/360
JEP-213: Milling Project Coin
From Java 7
– Allow @SafeVargs on private instance methods
– Allow effectively-final variables as resources in the try-
with-resources statement
– Allow diamond with anonymous classes in some cases
From Java 8
– Remove underscore as legal identifier names
In Java 9
– Support for private methods in interfaces
141. 141/360
Collection Factory Methods
No null values
No modification
– Run-time exception
public class Example1 {
public static void main(final String[] args) {
final List<String> list = List.of("Rick Deckard", "Roy Batty", "Harry Bryant", "Hannibal
Chew", "Gaff", "Holden", "Leon Kowalski", "Taffey Lewis", "Pris", "Rachael", "J.F.
Sebastian", "Dr. Eldon Tyrell", "Zhora", "Hodge", "Mary");
System.out.println(list);
list.add("Paul Atreides");
}
}
142. 142/360
Collection Factory Methods
No null values
No modification
– Run-time exception
public class Example1 {
public static void main(final String[] args) {
final List<String> list = List.of("Rick Deckard", "Roy Batty", "Harry Bryant", "Hannibal
Chew", "Gaff", "Holden", "Leon Kowalski", "Taffey Lewis", "Pris", "Rachael", "J.F.
Sebastian", "Dr. Eldon Tyrell", "Zhora", "Hodge", "Mary");
System.out.println(list);
list.add("Paul Atreides");
}
}
[Rick Deckard, Roy Batty, Harry Bryant, [...] Tyrell, Zhora, Hodge, Mary]
Exception in thread "main" java.lang.UnsupportedOperationException
at java.base/java.util.ImmutableCollections.uoe(ImmutableCollections.java:142)
at [...]
at net.ptidej.newjava.collectionfactories.Example1.main(Example1.java:11)
143. 143/360
JavaDB Removal
JavaDB was a repackaging of Apache Derby
– Relational database
– Open-source
– Entirely in Java
– Embedded JDBC driver
144. 144/360
JEP-254: Compact Strings
Problem and Solution
More space-efficient
internal representation
– Not about using UTF-8
From a UTF-16 char
array to a byte array
with an encoding flag
– ISO-8859-1/Latin-1 (1 byte
per char) or UTF-16 (2 bytes)
– String-related classes and
HotSpot intrinsic operations
Consequences
Reduction in memory
footprint
Substantial reductions of
GC activity
Minor performance
regressions in some
corner cases
145. 145/360
JEP-263: HiDPI Graphics
Java programs sized and
rendered based on pixels
HiDPI displays can have 2
to 3 times higher pixel
densities
Windows Direct2D APIs
Linux GTK+ 3 libraries
https://stackoverflow.com/questions/52519777/java-swing-app-looks-tiny-on-high-dpi-screen-when-it-should-be-scaled-to-normal
146. 146/360
JEP-266: More on Concurrency
“[A]synchronous stream processing with
non-blocking back pressure”
– https://www.reactive-streams.org/
https://www.baeldung.com/java-9-reactive-streams
// Given
final SubmissionPublisher<String> publisher = new SubmissionPublisher<>();
final EndSubscriber<String> subscriber = new EndSubscriber<>();
final List<String> items = List.of("1", "x", "2", "x", "3", "x");
// When
publisher.subscribe(subscriber);
items.forEach(publisher::submit);
publisher.close();
// Then
Awaitility.await().atMost(1000, TimeUnit.MILLISECONDS)
.until(() -> subscriber.consumedElements.containsAll(items));
147. 147/360
JEP-268: XML Catalogs
OASIS XML Catalogs standard, v1.1
– Map XML external identifiers into (local) URIs
Java API
– javax.xml.catalog.*
<?xml version="1.0"?>
<!DOCTYPE catalog
PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
"http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="public">
<public publicId="-//W3C//DTD XHTML 1.0 Strict//EN"
uri="dtd/xhtml1/xhtml1-strict.dtd"/>
<public publicId="-//W3C//DTD XHTML 1.0 Transitional//EN"
uri="dtd/xhtml1/xhtml1-transitional.dtd"/>
<public publicId="-//W3C//DTD XHTML 1.1//EN"
uri="dtd/xhtml11/xhtml11-flat.dtd"/>
</catalog>
150. 150/360
JEP-282: jlink
Assemble, optimize some modules and their
dependencies into a custom run-time image
– JEP-220: Modular run-time images
javac -d out module-info.java
javac -d out --module-path out
netptidejnewjavajlinkHelloWorld.java
jlink --module-path "%JAVA_HOME%jmods";out
--add-modules testJLinkModule
--output CustomJRE
cd CustomJRE/bib/
java --module testJLinkModule/net.ptidej.newjava.jlink.HelloWorld
https://www.baeldung.com/jlink
151. 151/360
JEP-295: jaotc
Ahead-of-time compilation
– Compile Java classes to native code
before launching the virtual machine
https://stackoverflow.com/questions/45298045/how-do-i-run-a-class-compiled-with-jaotc
javac Test.java
jaotc Test.class
jaotc --output libjava.base.so --module java.base
java -XX:AOTLibrary=./Test.so Test
159. 159/360
JEP-312: Thread-local Handshakes
Callback on threads without performing a
global VM safepoint
Possible and cheap to stop individual
threads and not just all threads
-XX:ThreadLocalHandshakes=<true|false>
160. 160/360
JEP-316: Heap Allocation on
Alternative Memory Devices
Availability of cheap NVDIMM memory
– Non Volatile Dual In-line Memory Module
https://blog.workinghardinit.work/2019/07/18/a-quick-intro-to-nvdimm-n/
-XX:AllocateHeapAt=<path>
161. 161/360
JEP-317: Experimental Java-based
JIT Compiler
Efficient JIT compiler
for Java in Java
As of 18/09/30
https://www.graalvm.org/
https://www.javacodegeeks.com/2018/10/java-graalvm-database-stream-performance.html
-XX:+UnlockExperimentalVMOptions
-XX:+UseJVMCICompiler
163. 163/360
JEP-314: Additional Unicode
Language-Tag Extensions
BCP 47 language tags
– Codes to identify languages
• en: English
• en-US: English, in United States
• km-Khmr-KH: Khmer, in Khmer script, in Cambodia
• km-fonipa: Khmer, transcribed in IPA
Changes to many APIs
– java.text.DateFormat, java.util.Currency,
java.time.format.DateTimeFormatter, …
https://help.keyman.com/developer/current-version/reference/bcp-47
168. 168/360
JEP-319: Root Certificates
Default set of root Certification Authority
(CA) certificates
– Oracle Java SE Root CA becomes open source
– OpenJDK can use the same certificates
169. 169/360
JEP-322: Time-based Release
Versioning
New version scheme
final Version version = Runtime.version();
System.out.println(version);
System.out.print("Feature: ");
System.out.println(version.feature());
System.out.print("Interim: ");
System.out.println(version.interim());
System.out.print("Update: ");
System.out.println(version.update());
System.out.print("Patch: ");
System.out.println(version.patch());
System.out.print("Build: ");
System.out.println(version.build());
System.out.print("Optional: ");
System.out.println(version.optional());
System.out.print("Pre: ");
System.out.println(version.pre());
173. 173/360
JEP-181: Nest-based Access Control
Before Java 11
– Bridge method, e.g.,
access$000(Example1)
Since Java 11
– Direct access
– Access to nest mates’
private members
https://mkyong.com/java/java-11-nest-based-access-control/
public class Example1 {
private String name = "I'm Example1!";
public class A {
public void printName() {
System.out.println(name);
}
}
public class B {
public void printName() {
System.out.println(Example1.this.name);
}
public class B1 {
public void printName() {
System.out.println(Example1.this.name);
}
}
}
public static void main(final String[] args) {
final Example1 e1 = new Example1();
final Example1.B b = e1.new B();
final Example1.B.B1 b1 = b.new B1();
b1.printName();
}
}
174. 174/360
JEP-181: Nest-based Access Control
https://mkyong.com/java/java-11-nest-based-access-control/
public class Example2 {
private String name = "I'm Example2!";
public class A {
public void printName() {
System.out.println(name);
}
}
public class B {
public void printName() {
System.out.println(Example2.this.name);
}
public class B1 {
public void printName() {
System.out.println(Example2.this.name);
}
}
}
public static void main(final String[] args) {
System.out.println(A.class.getNestHost());
System.out.println(A.class.isNestmateOf(B.class));
for (final Class<?> clazz : Example2.B.class.getNestMembers()) {
System.out.println(clazz);
}
}
}
175. 175/360
JEP-181: Nest-based Access Control
https://mkyong.com/java/java-11-nest-based-access-control/
public class Example2 {
private String name = "I'm Example2!";
public class A {
public void printName() {
System.out.println(name);
}
}
public class B {
public void printName() {
System.out.println(Example2.this.name);
}
public class B1 {
public void printName() {
System.out.println(Example2.this.name);
}
}
}
public static void main(final String[] args) {
System.out.println(A.class.getNestHost());
System.out.println(A.class.isNestmateOf(B.class));
for (final Class<?> clazz : Example2.B.class.getNestMembers()) {
System.out.println(clazz);
}
}
}
class net.ptidej.newjava.nest.Example2
true
class net.ptidej.newjava.nest.Example2
class net.ptidej.newjava.nest.Example2$A
class net.ptidej.newjava.nest.Example2$B
class net.ptidej.newjava.nest.Example2$B$B1
176. 176/360
JEP-323: Local-variable Syntax for
Lambda Parameters
interface Comparator<T> {
int compare(final T a, final T b);
}
public class Example1 {
public static void main(final String[] args) {
final Comparator<String> comparator1 = new Comparator<>() {
@Override
public int compare(final String a, final String b) {
return a.compareTo(b);
}
};
System.out.println(comparator1.compare("Hello", "World"));
final Comparator<String> comparator2 = (a, b) -> a.compareTo(b);
System.out.println(comparator2.compare("Hello", "World"));
final Comparator<String> comparator3 = (String a, String b) -> a.compareTo(b);
System.out.println(comparator3.compare("Hello", "World"));
final Comparator<String> comparator4 = (final var a, final var b) -> a.compareTo(b);
System.out.println(comparator4.compare("Hello", "World"));
final Comparator<String> comparator5 = (@NonNull var a, @NonNull var b) -> a.compareTo(b);
System.out.println(comparator5.compare("Hello", "World"));
}
}
177. 177/360
JEP-323: Local-variable Syntax for
Lambda Parameters
interface Comparator<T> {
int compare(final T a, final T b);
}
public class Example1 {
public static void main(final String[] args) {
final Comparator<String> comparator1 = new Comparator<>() {
@Override
public int compare(final String a, final String b) {
return a.compareTo(b);
}
};
System.out.println(comparator1.compare("Hello", "World"));
final Comparator<String> comparator2 = (a, b) -> a.compareTo(b);
System.out.println(comparator2.compare("Hello", "World"));
final Comparator<String> comparator3 = (String a, String b) -> a.compareTo(b);
System.out.println(comparator3.compare("Hello", "World"));
final Comparator<String> comparator4 = (final var a, final var b) -> a.compareTo(b);
System.out.println(comparator4.compare("Hello", "World"));
final Comparator<String> comparator5 = (@NonNull var a, @NonNull var b) -> a.compareTo(b);
System.out.println(comparator5.compare("Hello", "World"));
}
}
Now posssible
179. 179/360
JEP-309: Dynamic .class Constants
Extend the class-file format with a new
constant-pool form
– CONSTANT_Dynamic
Avoid initialising “expansive” values
– Also, no need to use volatile
https://www.javacodegeeks.com/2018/08/hands-on-java-constantdynamic.html
180. 180/360
JEP-309: Dynamic .class Constants
Problem: How to share some “expensive” data
among different threads?
Solution: Singleton design pattern
public class SomeExpensiveData {
public SomeExpensiveData() {
// Some very expensive (time, space) data to create
System.out.println("tSomeExpensiveData instance created");
}
}
181. 181/360
JEP-309: Dynamic .class Constants
public class MyCallable implements Callable<SomeExpensiveData> {
private static MyCallable UniqueInstance;
public static MyCallable getInstance() {
if (MyCallable.UniqueInstance == null) {
synchronized (MyCallable.class) {
if (MyCallable.UniqueInstance == null) {
MyCallable.UniqueInstance = new MyCallable();
}
}
}
return MyCallable.UniqueInstance;
}
private volatile SomeExpensiveData someExpensiveData;
private MyCallable() {
this.someExpensiveData = new SomeExpensiveData();
}
@Override
public SomeExpensiveData call() throws Exception {
return this.someExpensiveData;
}
}
182. 182/360
JEP-309: Dynamic .class Constants
public class MyCallable implements Callable<SomeExpensiveData> {
private static MyCallable UniqueInstance;
public static MyCallable getInstance() {
if (MyCallable.UniqueInstance == null) {
synchronized (MyCallable.class) {
if (MyCallable.UniqueInstance == null) {
MyCallable.UniqueInstance = new MyCallable();
}
}
}
return MyCallable.UniqueInstance;
}
private volatile SomeExpensiveData someExpensiveData;
private MyCallable() {
this.someExpensiveData = new SomeExpensiveData();
}
@Override
public SomeExpensiveData call() throws Exception {
return this.someExpensiveData;
}
}
Not a true constant
No caching, etc.
183. 183/360
JEP-309: Dynamic .class Constants
public class MyCallable implements Callable<SomeExpensiveData> {
private static MyCallable UniqueInstance;
public static MyCallable getInstance() {
if (MyCallable.UniqueInstance == null) {
synchronized (MyCallable.class) {
if (MyCallable.UniqueInstance == null) {
MyCallable.UniqueInstance = new MyCallable();
}
}
}
return MyCallable.UniqueInstance;
}
private volatile SomeExpensiveData someExpensiveData;
private MyCallable() {
this.someExpensiveData = new SomeExpensiveData();
}
@Override
public SomeExpensiveData call() throws Exception {
return this.someExpensiveData;
}
}
Not a true constant
No caching, etc.
Eager initialisation
184. 184/360
JEP-309: Dynamic .class Constants
Dynamic constants
– Created once at run-time
– Can be shared among threads
– Can be cached, optimised, etc.
Problem: How to create dynamically a constant
Solution: CONSTANT_Dynamic
185. 185/360
JEP-309: Dynamic .class Constants
Dynamic constants, javac vs. java
– Cannot be created from source code
• As of 24/03/24
– Can be created in the byte code
Byte code generation, manipulation library
– Create, modify Java classes at run-time
186. 186/360
JEP-309: Dynamic .class Constants
final Unloaded<Callable> unloaded = new ByteBuddy().subclass(Callable.class)
.method(ElementMatchers.named("call")).intercept(FixedValue.value(
JavaConstant.Dynamic.ofInvocation(SomeExpensiveData.class.getConstructor()))).make();
final Constructor<? extends Callable> loaded =
unloaded.load(Example2.class.getClassLoader()).getLoaded().getConstructor();
final Callable<SomeExpensiveData> first = loaded.newInstance();
final Callable<SomeExpensiveData> second = loaded.newInstance();
System.out.println("tCallable instances created");
assertThat(first.call()).isEqualTo(second.call());
187. 187/360
JEP-309: Dynamic .class Constants
final Unloaded<Callable> unloaded = new ByteBuddy().subclass(Callable.class)
.method(ElementMatchers.named("call")).intercept(FixedValue.value(
JavaConstant.Dynamic.ofInvocation(SomeExpensiveData.class.getConstructor()))).make();
final Constructor<? extends Callable> loaded =
unloaded.load(Example2.class.getClassLoader()).getLoaded().getConstructor();
final Callable<SomeExpensiveData> first = loaded.newInstance();
final Callable<SomeExpensiveData> second = loaded.newInstance();
System.out.println("tCallable instances created");
assertThat(first.call()).isEqualTo(second.call());
test_CONSTANT_Dynamic()
Callable instances created
SomeExpensiveData instance created
188. 188/360
JEP-309: Dynamic .class Constants
final Unloaded<Callable> unloaded = new ByteBuddy().subclass(Callable.class)
.method(ElementMatchers.named("call")).intercept(FixedValue.value(
JavaConstant.Dynamic.ofInvocation(SomeExpensiveData.class.getConstructor()))).make();
final Constructor<? extends Callable> loaded =
unloaded.load(Example2.class.getClassLoader()).getLoaded().getConstructor();
final Callable<SomeExpensiveData> first = loaded.newInstance();
final Callable<SomeExpensiveData> second = loaded.newInstance();
System.out.println("tCallable instances created");
assertThat(first.call()).isEqualTo(second.call());
test_CONSTANT_Dynamic()
Callable instances created
SomeExpensiveData instance created
Lazy initialisation: two
instances created, but not
SomExpensiveData
189. 189/360
JEP-309: Dynamic .class Constants
final Unloaded<Callable> unloaded = new ByteBuddy().subclass(Callable.class)
.method(ElementMatchers.named("call")).intercept(FixedValue.value(
JavaConstant.Dynamic.ofInvocation(SomeExpensiveData.class.getConstructor()))).make();
final Constructor<? extends Callable> loaded =
unloaded.load(Example2.class.getClassLoader()).getLoaded().getConstructor();
final Callable<SomeExpensiveData> first = loaded.newInstance();
final Callable<SomeExpensiveData> second = loaded.newInstance();
System.out.println("tCallable instances created");
assertThat(first.call()).isEqualTo(second.call());
test_CONSTANT_Dynamic()
Callable instances created
SomeExpensiveData instance created
Lazy initialisation: two
instances created, but not
SomExpensiveData
SomExpensiveData created
only once, with first call()
190. 190/360
JEP-309: Dynamic .class Constants
final Unloaded<Callable> unloaded = new ByteBuddy().subclass(Callable.class)
.method(ElementMatchers.named("call")).intercept(FixedValue.value(
JavaConstant.Dynamic.ofInvocation(SomeExpensiveData.class.getConstructor()))).make();
final Constructor<? extends Callable> loaded =
unloaded.load(Example2.class.getClassLoader()).getLoaded().getConstructor();
final Callable<SomeExpensiveData> first = loaded.newInstance();
final Callable<SomeExpensiveData> second = loaded.newInstance();
System.out.println("tCallable instances created");
assertThat(first.call()).isEqualTo(second.call());
// (version 17 : 61.0, super bit)
public class net.bytebuddy.[...].Callable$ByteBuddy$7xbn1EIQ implements java.util.concurrent.Callable
public java.lang.Object call() throws java.lang.Exception;
0 ldc <Dynamic> 0 _ net.ptidej.newjava.constantdynamic.SomeExpensiveData [28]
2 areturn
public Callable$ByteBuddy$7xbn1EIQ();
0 aload_0 [this]
1 invokespecial java.lang.Object() [29]
4 return
Bootstrap methods:
0 : # 24 invokestatic java/lang/invoke/ConstantBootstraps.invoke:([...])Ljava/lang/Object;
Method arguments:
#17 net/ptidej/newjava/constantdynamic/SomeExpensiveData.<init>:()V
191. 191/360
JEP-309: Dynamic .class Constants
final Unloaded<Callable> unloaded = new ByteBuddy().subclass(Callable.class)
.method(ElementMatchers.named("call")).intercept(FixedValue.value(
JavaConstant.Dynamic.ofInvocation(SomeExpensiveData.class.getConstructor()))).make();
final Constructor<? extends Callable> loaded =
unloaded.load(Example2.class.getClassLoader()).getLoaded().getConstructor();
final Callable<SomeExpensiveData> first = loaded.newInstance();
final Callable<SomeExpensiveData> second = loaded.newInstance();
System.out.println("tCallable instances created");
assertThat(first.call()).isEqualTo(second.call());
// (version 17 : 61.0, super bit)
public class net.bytebuddy.[...].Callable$ByteBuddy$7xbn1EIQ implements java.util.concurrent.Callable
public java.lang.Object call() throws java.lang.Exception;
0 ldc <Dynamic> 0 _ net.ptidej.newjava.constantdynamic.SomeExpensiveData [28]
2 areturn
public Callable$ByteBuddy$7xbn1EIQ();
0 aload_0 [this]
1 invokespecial java.lang.Object() [29]
4 return
Bootstrap methods:
0 : # 24 invokestatic java/lang/invoke/ConstantBootstraps.invoke:([...])Ljava/lang/Object;
Method arguments:
#17 net/ptidej/newjava/constantdynamic/SomeExpensiveData.<init>:()V
CONSTANT_Dynamic
with bootstrap method
192. 192/360
JEP-331: Low-overhead Heap
Profiling
Since Java 6
– No more JVM Profiler
Interface (JVMPI)
– No more JVM Debug
Interface (JVMDI)
– Replaced by JVM Tool
Interface (JVMTI)
Sampling of Java heap
allocations
– All allocations
– Low-overhead
– Well-defined API
– Live, dead objects
https://docs.oracle.com/en/java/javase/11/docs/specs/jvmti.html
194. 194/360
JEP-333: Scalable Low-latency GC
Z Garbage Collector
– GC pause no more than 10ms
– Handle megabyte to terabyte heaps
– No more than 15% throughput reduction wrt. G1
– Foundation for future features and optimisations
– (Only on 64bit operating systems)
-XX:+UnlockExperimentalVMOptions -XX:+UseZGC
196. 196/360
JEP-320: Java EE and CORBA
Modules Removal
Since Java 1.2
– OMG CORBA API
– ORB implementation
– CosNaming implementation
– idlj compiler
– Support for IDL and IIOP in rmic compiler
– No significant interest in CORBA anymore
Since Java 6
– Full Web Services stack
– Now available from third parties
Deprecated in Java 9
197. 197/360
JEP-321: HTTP Client
Problems with HttpURLConnection API
– Designed for (now dead) protocols (gopher…)
– Designed before HTTP/1.1
– Too abstract
– Hard to use
– Badly documented
– Blocking mode only
– Very hard maintenance
198. 198/360
JEP-321: HTTP Client
Three core classes
– HttpClient as a container for configuration
information common to multiple requests
– HttpRequest for requests sent by HttpClient
– HttpResponse for the result of an HttpRequest
https://www.baeldung.com/java-9-http-client
201. 201/360
JEP-327: Unicode 10
Major version of the Unicode Standard
Support
– Character and String in java.lang
– NumericShaper in java.awt.font
– Bidi, BreakIterator, Normalizer in java.text
202. 202/360
JEP-335: Nashorn Deprecation
Since Java 8
– JEP-174
ECMAScript changes rapidly
– Language
– APIs
Maintenance challenges
– Deprecate Nashorn, its APIs, and jjs
204. 204/360
JEP-328: Flight Recorder
Monitoring tool
– Collects information about the events in a JVM
– An event
• Name
• Timestamp
• Other data
– Thread data, state of the heap, etc.
https://www.baeldung.com/java-flight-recorder-monitoring
-XX:+UnlockCommercialFeatures
-XX:+FlightRecorder
-XX:StartFlightRecording=duration=200s,filename=flight.jfr
207. 207/360
JEP-336: Pack200 Tools and API
Deprecation
Since Java 5
– Compression scheme for JAR files
– To accommodate 56k modems
Since Java 9 (and JEP-220)
– Modules
– Compression
– No more applets
– Maintenance challenges
– Modularisation challenges
212. 212/360
JEP-344: Abortable Mixed
Collections
Ability for G1 to abort its collection pauses
G1 predicts the number of regions to collect
and proceeds only with abortable ones
Lower pause latency and higher probability
to achieve pause-time target
https://blogs.oracle.com/javamagazine/post/understanding-the-jdks-new-superfast-garbage-collectors
-XX:G1MixedGCCountTarget=<number of mixed garbage collections>
213. 213/360
JEP-346: Unused Committed
Memory Prompt Return
G1 automatically returns heap memory to
the operating system when idle
-XX:G1PeriodicGCInterval=<true|false>
-XX:G1PeriodicGCInvokesConcurrent=<true|false>
-XX:G1PeriodicGCSystemLoadThreshold=<average 1-minute system load>
215. 215/360
JEP-334: JVM Constants API
API to describes some class-file and run-
time elements (e.g., constants)
https://iampravo.medium.com/java-12-features-and-highlights-81938474cd31
public class Example1 {
public static void main(final String[] args) {
final ClassDesc example1ClassDesc = ClassDesc.of("[...].constantsapi", "Example1");
final MethodTypeDesc mainMethodTypeDesc = MethodTypeDesc.of(example1ClassDesc);
final MethodHandleDesc mainMethodHandleDesc = MethodHandleDesc.ofMethod(
DirectMethodHandleDesc.Kind.STATIC, example1ClassDesc, "main", mainMethodTypeDesc);
System.out.println("Class descriptor: " + example1ClassDesc);
System.out.println("Method type descriptor: " + mainMethodTypeDesc);
System.out.println("Method handle descriptor: " + mainMethodHandleDesc);
}
}
216. 216/360
JEP-334: JVM Constants API
API to describes some class-file and run-
time elements (e.g., constants)
https://iampravo.medium.com/java-12-features-and-highlights-81938474cd31
public class Example1 {
public static void main(final String[] args) {
final ClassDesc example1ClassDesc = ClassDesc.of("[...].constantsapi", "Example1");
final MethodTypeDesc mainMethodTypeDesc = MethodTypeDesc.of(example1ClassDesc);
final MethodHandleDesc mainMethodHandleDesc = MethodHandleDesc.ofMethod(
DirectMethodHandleDesc.Kind.STATIC, example1ClassDesc, "main", mainMethodTypeDesc);
System.out.println("Class descriptor: " + example1ClassDesc);
System.out.println("Method type descriptor: " + mainMethodTypeDesc);
System.out.println("Method handle descriptor: " + mainMethodHandleDesc);
}
}
Class descriptor: ClassDesc[Example1]
Method type descriptor: MethodTypeDesc[()Example1]
Method handle descriptor: MethodHandleDesc[STATIC/Example1::main()Example1]
218. 218/360
JEP-230: Microbenchmark Suite
Java Microbenchmark Harness (JMH)
– An annotation-based DSL
• @State, @Fork, @Warmup, @Measurement, @Benchmark…
Microbenchmarks suite integrated into
OpenJDK source code
https://cl4es.github.io/2018/11/16/JEP-230-Microbenchmarks-Suite.html
make build-microbenchmark
219. 219/360
JEP-230: Microbenchmark Suite
Java Microbenchmark Harness (JMH)
– An annotation-based DSL
• @State, @Fork, @Warmup, @Measurement, @Benchmark…
Microbenchmarks suite integrated into
OpenJDK source code
https://cl4es.github.io/2018/11/16/JEP-230-Microbenchmarks-Suite.html
make build-microbenchmark
build/$PROFILE/images/test/micro/benchmarks.jar
220. 220/360
JEP-230: Microbenchmark Suite
Run one java.util.UUIDBench benchmark
– https://github.com/openjdk/jdk/blob/master/test/mi
cro/org/openjdk/bench/java/util/UUIDBench.java
https://cl4es.github.io/2021/01/04/Investigating-MD5-Overheads.html
make test TEST=micro:UUIDBench.fromType3Bytes
221. 221/360
JEP-230: Microbenchmark Suite
Run one java.util.UUIDBench benchmark
– https://github.com/openjdk/jdk/blob/master/test/mi
cro/org/openjdk/bench/java/util/UUIDBench.java
https://cl4es.github.io/2021/01/04/Investigating-MD5-Overheads.html
make test TEST=micro:UUIDBench.fromType3Bytes
Benchmark Score Error Units
fromType3Bytes 1.460 ± 0.089 ops/us
222. 222/360
JEP-230: Microbenchmark Suite
Benchmarking the
JVM is difficult
– Just-in-time compiler
– Dead code elimination
– Loop unrolling
– Method inlining
– …
– Warmup iterations
– Iteration durations
– …
https://www.oracle.com/technical-resources/articles/java/architect-benchmarking.html
235. 235/360
-XX:+ShowCodeDetailsInExceptionMessages
JEP-358: Helpful
NullPointerExceptions
Describe precisely which variable was null
class Employee {
String getName() {
// return "Bob";
return null;
}
}
public class Example1 {
public static void main(final String[] args) {
final Employee e = new Employee();
e.getName().toString();
}
}
Exception in thread "main" java.lang.NullPointerException
at net.ptidej.newjava.helpfulnullpointerexceptions.Example1.main(Example1.java:13)
236. 236/360
-XX:+ShowCodeDetailsInExceptionMessages
JEP-358: Helpful
NullPointerExceptions
Describe precisely which variable was null
class Employee {
String getName() {
// return "Bob";
return null;
}
}
public class Example1 {
public static void main(final String[] args) {
final Employee e = new Employee();
e.getName().toString();
}
}
Exception in thread "main" java.lang.NullPointerException
at net.ptidej.newjava.helpfulnullpointerexceptions.Example1.main(Example1.java:13)
Exception in thread "main" java.lang.NullPointerException: Cannot invoke
"String.toString()" because the return value of "[...].Employee.getName()" is null
at net.ptidej.newjava.helpfulnullpointerexceptions.Example1.main(Example1.java:13)
237. 237/360
JEP-361: switch Expressions
https://medium.com/@imagarg/switch-expression-jep-361-3b5649ec36c9
private static int getDayLength(final Day day) {
int numberOfCharacters = 0;
switch (day) {
case MONDAY:
case FRIDAY:
case SUNDAY:
numberOfCharacters = 6;
break;
case TUESDAY:
numberOfCharacters = 7;
break;
case THURSDAY:
case SATURDAY:
numberOfCharacters = 8;
break;
case WEDNESDAY:
numberOfCharacters = 9;
break;
default:
throw new IllegalArgumentException();
}
return numberOfCharacters;
}
private static int getDayLength(final Day day) {
int result = switch (day) {
case MONDAY, FRIDAY, SUNDAY -> 6;
case TUESDAY -> 7;
case THURSDAY, SATURDAY -> 8;
case WEDNESDAY -> 9;
default ->
throw new IllegalArgumentException();
};
return result;
}
enum Day {
MONDAY, TUESDAY,
WEDNESDAY,
THURSDAY, FRIDAY,
SATURDAY, SUNDAY;
}