From Idea to IDE

How Java Features Are Considered, Designed, And Shipped

Developer Advocate

Java Team at Oracle

Accento 2023

  • Karlsruhe

  • October 24th, 25th

  • 50% discount: AccJUGCH23

I have two free tickets!

Text Blocks

A text block is a multi-line string literal that avoids the need for most escape sequences, automatically formats the string in a predictable way, and gives the developer control over the format when desired.

  • language feature added in Java 15

  • triggered additions to String:
    formatted, indent, stripIndent, translateEscapes

Hallmarks

Java features:

  • come as syntax, VM capabilities, APIs
    (or any combination)

  • specified in JLS, JVMS, Javadoc, etc. &
    implemented in openjdk/jdk

  • fulfill clearly defined requirements

  • fit in seamlessly & have good tool support

Why did this take so long?

Evolution

But where does a feature come from?

Long story:

  • starts with an idea

  • refinement in explorations

  • prototype and proposal

  • preview feature

  • finalized feature

From Idea to IDE

Features
Previews
Proposals
Explorations
Ideas

Previews in Java 21

  • foreign function & memory API (3rd)

  • string templates (1st)

  • simplified main (1st)

  • unnamed patterns & variables (1st)

  • scoped values (1st)

  • structured concurrency (1st)

Specification

The concept of preview features was:

Artifacts

Required artifacts for preview features:

  • specified in JLS:

    • all preview features are mentioned

    • JLS changes/diffs are linked

  • implemented in openjdk/jdk, but:

    • disabled by default

    • by compiler and runtime

Enabling

Enabling:

  • for compiler and runtime
    with --enable-preview

  • generates compiler warnings

  • pins Java version

Example

public class TextBlocks {

	public static void main(String[] args) {
		System.out.println("""
				Hello,
				text blocks!""");
	}

}

Enabling For Compilation

Compiling with Java 14:

$ javac TextBlocks.java
> TextBlocks.java:4: error: text blocks are a preview
> feature and are disabled by default.
>                 System.out.println("""
>                                    ^
>   (use --enable-preview to enable text blocks)
> 1 error

$ javac --enable-preview --release 14 TextBlocks.java
> Note: TextBlocks.java uses preview language features.
> Note: Recompile with -Xlint:preview for details.

Enabling For Execution

Running with Java 14:

$ java TextBlocks
> Error: LinkageError occurred while loading main class
> TextBlocks
>        java.lang.UnsupportedClassVersionError:
>        Preview features are not enabled for
>        TextBlocks (class file version 58.65535).
>        Try running with '--enable-preview'

$ java --enable-preview TextBlocks
> Hello,
> text blocks!

Version Pinning

Compiled with Java 14, launched with 15:

$ java --enable-preview TextBlocks
> Error: LinkageError occurred while loading main class
> TextBlocks
>        java.lang.UnsupportedClassVersionError:
>        TextBlocks (class file version 58.65535)
>        was compiled with preview features that are
>        unsupported. This version of the Java Runtime
>        only recognizes preview features for class
>        file version 59.65535

Goals & Considerations

Goals of preview features:

  • prevent (accidental) use in production

  • foster early IDE support

  • user experimentation and reports

  • review and refinement

Considerations:

  • "Is it surfaced correctly?"

  • "Are there unforeseen edge cases?"

Evolution

Preview features evolve a bit
(particularly on the surface)
and usually finalize.

My guesstimates:

  • duration: 12-24 months

  • rate of change: 5%

  • rate of progression: 95%

From Idea to IDE

Features
Previews
Proposals
Explorations
Ideas

Some Current Proposals

Defined in JDK Enhancement Proposals (JEPs)
(essentally decision records):

  • asynchronous stack trace VM API (JEP 435)

  • statements before super() (JEP 447)

  • compact object headers (JEP 450)

Specification

JEPs were introduced by JEP 1 (in 2011).

It was superseded by JEP 2.0 draft (in 2014).

JEP Filters

JEP Progression (All)

  • drafted: 437

  • open:

    • draft: 51

    • candidate & active: 33

    • candidate & dormant: 13

  • closed:

    • withdrawn: 18

    • rejected: 31

    • delivered: 291

JEP Progression (Closed)

  • drafted: 340

  • withdrawn: 18

  • rejected: 31

  • delivered: 291 (85%)

Artifacts

Proposals are defined by JEPs.

Often also come with implementations in
project forks or feature branches of openjdk/jdk, e.g.:

Goals & Considerations

Goals of JEPs:

  • expose proposal to wider audience

  • seek feedback on the proposed solution

  • motivate, describe, archive proposals
    with their contexts and consequences

Proposal considerations:

  • "Is this the right way to do it?"

Evolution

Proposals evolve noticeably
(particularly until Candidate)
and most are delivered.

My guesstimates:

  • duration: 6-36 months

  • rate of change: 40%

  • rate of progression: 85%

From Idea to IDE

Features
Previews
Proposals
Explorations
Ideas

Some Ongoing Explorations

Artifacts

(Roughly in order.)

Unspecified

Unlike the steps so far, this one is:

  • mostly unspecified

  • mostly unstructured

  • without barrier for contribution

Goals

  • assess feasibility

  • shape a general idea
    to a specific proposal

  • estimate complexity and effort

Considerations

  • "Does it fit into Java / the ecosystem?"

  • "Can it be implemented?"

  • "Can it be introduced?"

  • "What priority does it have?"

Evolution

During exploration, features evolve
fundamentally and many are dropped.

My guesstimates:

  • duration: 6-60 months

  • rate of change: 50-500%

  • rate of progression: 25-75%

From Idea to IDE

Features
Previews
Proposals
Explorations
Ideas

Existing Ideas

If only Java had $FEATURE, this would be so much more elegant.
(Stares procrastinatingly into distance…​)

— Every Java Programmer

Existing Ideas

$FEATURE works great in $LANG.
Java needs $FEATURE!

— Every Java/$LANG Programmer

Existing Ideas

Even Brian Goetz has so many,
he needs a bunch of notebooks
to keep track of them.

Free For All

Ideas are cheap…​

  • no specifications

  • no process

  • no barriers

  • no attention

…​execution is everything.

Goals & Considerations

Goal is to make Java / the JVM better.

Considerations:

  • "Is this a good idea?"

  • "…​ for Java?"

  • "…​ now and/or in the future?"

Evolution

My guesstimates:

  • duration: 🤷🏾‍♂️

  • rate of change: 🤷🏾‍♂️

  • rate of progression: 🤷🏾‍♂️

From Idea to IDE

Features
Previews
Proposals
Explorations
Ideas
Feature Evolution

Feature_final2.docx

Even final features aren’t final!

Evolution

Considerations for feature evolution/removal:

  • Does it hurt?

  • Is it used?

  • Can it be extended/improved?

  • Would a change/removal hurt?

Some Removals

Single underscore as variable name ⛔⑨:
  • rarely used

  • prevents very useful language feature

  • easy to fix

Concurrent mark sweep GC ⛔⑭:
  • maintenance cost

  • lots of alternative GCs

  • easy to fix

RMI Activation ⛔⑰:
  • obsolete and disused

Some Terminal Deprecations

Primitive wrapper constructors ⚠️⑯:
  • prevent primitive types

  • easy to fix

Applet API ⚠️⑰:
  • unused and unusable

Finalization ⚠️⑱:
  • easy to get wrong

  • peformance & maintenance cost

  • better mechanisms exist

inside java newscast 41

Prepare Your Code Bases For Future Java
Inside Java Newscast #41

Evolution

Features are extremely stable
but not immutable.

My guesstimates:

  • rate of change: 0.5%

  • survival rate: 99.95%

The Full Journey

Got everything?

Let’s rewind.

The Full Journey

Considerations

Idea

"Can it be good for Java?"

Exploration

"How can it be implemented/introduced?"

Proposal

"Is this the best way to implement it?"

Preview

"Is it surfaced correctly?"

Feature

"Does it hurt? Can it be changed/removed?"

The Full Journey

SpecArtifacts📆🧬🚀

Idea

 — 

🌬, 📔

🤷🏾‍♂️

🤷🏾‍♂️

🤷🏾‍♂️

Explorat.

 — 

🎟, 📬, …

6-60

50-500%

25-75%

Proposal

JEP 1

JEP / jdk 🌳

6-36

40%

85%

Preview

JLS

JLS diff / jdk

12-24

5%

95%

Feature

JLS

JLS / jdk

0.5%

Nota Bene

Incubating APIs:

  • belong into Proposal (not Preview)

  • come with alpha implementations

JEPs:

  • not all proposals need one

  • smaller changes rely on JBS issues

Why So Serious?

Every change impacts:

  • millions of developers

  • billions of lines of code

  • industry, research, games, hobbies

  • billions of Euros of annual revenue

Better safe than sorry.

So long…​

37% off with
code fccparlog

bit.ly/the-jms

More

Slides at slides.nipafx.dev
⇜ Get my book!

Follow Nicolai

nipafx.dev
/nipafx

Follow Java

inside.java // dev.java
/java    //    /openjdk

Image Credits