Enhance the Java programming language with unnamed variables and unnamed patterns, which can be used when variable declarations or nested patterns are required but never used. Both are denoted by the underscore character, _.
이름 없는 변수와 이름 없는 패턴으로 자바 프로그래밍 언어를 강화한다. 이것들은 변수 선언이나 중첩 패턴이 필요하지만 실제로는 전혀 사용되지 않을 때 쓸 수 있다. 둘 다 밑줄 문자 _로 표시된다. Java 21에선 Preview였는데 JDK 22에서 정식 기능이 됨. 안 쓰는 값을 _ 로 표시.
// 안 쓰는 값인데도 이름을 붙여야 함
try {
int n = Integer.parseInt(s);
} catch (NumberFormatException e) { // e 안 쓰는데 이름 필요
System.out.println("숫자 아님");
}
// 안 쓰는 값은 _ 로
try {
int n = Integer.parseInt(s);
} catch (NumberFormatException _) {
System.out.println("숫자 아님");
}
In constructors in the Java programming language, allow statements that do not reference the instance being created to appear before an explicit constructor invocation. This is a preview language feature.
자바 프로그래밍 언어의 생성자에서, 생성 중인 인스턴스를 참조하지 않는 문(statement)들이 명시적인 생성자 호출 앞에 나타나는 것을 허용한다. 이것은 미리보기 언어 기능이다. 원래 super()/this()는 생성자 맨 첫 줄이어야 했는데, 그 앞에 (인스턴스를 안 건드리는) 검증 코드 등을 넣을 수 있게 됨.
class Sub extends Sup {
Sub(int x) {
super(x); // 무조건 첫 줄이어야 함
// 검증을 super 뒤에서 → 잘못된 값도 일단 부모에 전달됨
if (x < 0) throw new IllegalArgumentException();
}
}
class Sub extends Sup {
Sub(int x) {
if (x < 0) throw new IllegalArgumentException(); // super 앞에서 검증
super(x); // 검증 통과 후 호출
}
}
Enhance the Stream API to support custom intermediate operations. This will allow stream pipelines to transform data in ways that are not easily achievable with the existing built-in intermediate operations. This is a preview API.
사용자 정의 중간 연산을 지원하도록 Stream API를 강화한다. 이로써 스트림 파이프라인이, 기존의 내장된 중간 연산으로는 쉽게 달성할 수 없는 방식으로 데이터를 변환할 수 있게 된다. 이것은 미리보기 API다. map, filter 같은 정해진 중간 연산 외에, 내가 직접 만든 중간 연산(gather)을 스트림에 끼워넣을 수 있게 됨.
// map, filter 등 정해진 것만. "3개씩 묶기" 같은 건 직접 못 함
List result = stream
.map(x -> x * 2)
.filter(x -> x > 0)
.toList();
// gather로 커스텀 중간 연산 (예: 3개씩 묶는 windowing)
List<List> windows = stream
.gather(Gatherers.windowFixed(3)) // 사용자 정의 연산
.toList();
Enhance the Java programming language with string templates. String templates complement Java's existing string literals and text blocks by coupling literal text with embedded expressions and template processors to produce specialized results. This is a preview language feature and API.
string templates로 자바 프로그래밍 언어를 강화한다. string templates는 리터럴 텍스트를 내장된 표현식 및 템플릿 프로세서와 결합함으로써, 자바의 기존 string literal과 text block을 보완하여 특화된 결과를 만들어낸다. 이것은 미리보기 언어 기능이자 API다. Java 21의 첫 미리보기에 이어 두 번째 미리보기. 단, 이 기능은 이후 Java 23에서 설계 문제로 제거됨.
String name = "홍길동";
String msg = name + "님 환영합니다"; // + 로 연결
String name = "홍길동";
String msg = STR."\{name}님 환영합니다"; // 값을 직접 삽입
Evolve the Java programming language so that students can write their first programs without needing to understand language features designed for large programs. Far from using a separate dialect of the language, students can write streamlined declarations for single-class programs and then seamlessly expand their programs to use more advanced features as their skills grow. This is a preview language feature.
학생들이 큰 프로그램을 위해 설계된 언어 기능을 이해할 필요 없이 첫 프로그램을 작성할 수 있도록 자바 프로그래밍 언어를 발전시킨다. 언어의 별개 방언을 쓰는 것과는 거리가 멀게(결코 방언이 아니라), 학생들은 단일 클래스 프로그램을 위한 간결한 선언을 작성하고, 이후 실력이 자람에 따라 매끄럽게 더 고급 기능을 쓰도록 프로그램을 확장할 수 있다. 이것은 미리보기 언어 기능이다. Java 21의 "Unnamed Classes..."가 이름을 바꿔 두 번째 미리보기로. Hello World를 클래스/public static 없이 쓰게 해줌.
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
void main() {
System.out.println("Hello World");
}
Introduce an API by which Java programs can interoperate with code and data outside of the Java runtime. By efficiently invoking foreign functions (i.e., code outside the JVM), and by safely accessing foreign memory (i.e., memory not managed by the JVM), the API enables Java programs to call native libraries and process native data without the brittleness and danger of JNI.
자바 프로그램이 자바 런타임 바깥의 코드 및 데이터와 상호작용할 수 있게 해주는 API를 도입한다. 외부 함수(즉, JVM 밖의 코드)를 효율적으로 호출하고, 외부 메모리(즉, JVM이 관리하지 않는 메모리)에 안전하게 접근함으로써, 이 API는 자바 프로그램이 JNI의 취약함과 위험 없이 네이티브 라이브러리를 호출하고 네이티브 데이터를 처리할 수 있게 한다. Java 21까지 Preview였다가 JDK 22에서 정식 기능이 됨. 낡고 위험하던 JNI를 대체.
public native long strlen(String s); // 자바: 선언만
// + C 코드를 JNI 규칙대로 작성 + OS별 컴파일 필요
// 메모리 수동 관리, 실수 시 JVM 크래시
// 순수 자바만으로 C 함수 호출
Linker linker = Linker.nativeLinker();
MethodHandle strlen = linker.downcallHandle(
linker.defaultLookup().find("strlen").orElseThrow(),
FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.ADDRESS));
try (Arena arena = Arena.ofConfined()) {
MemorySegment s = arena.allocateUtf8String("Hello");
long len = (long) strlen.invoke(s);
} // 메모리 자동 해제
Provide a standard API for parsing, generating, and transforming Java class files. This is a preview API.
자바 클래스 파일을 파싱하고, 생성하고, 변환하기 위한 표준 API를 제공한다. 이것은 미리보기 API다. 기존엔 ASM 같은 외부 라이브러리로 하던 바이트코드 조작을, 자바 표준 API로 할 수 있게 함. 프레임워크 개발자용.
// 클래스 파일 조작을 위해 ASM 같은 서드파티 라이브러리 필요
ClassReader reader = new ClassReader(bytes);
ClassWriter writer = new ClassWriter(0);
// ... ASM 고유 API 사용
// 자바 표준 API로 클래스 파일 파싱
ClassFile cf = ClassFile.of();
ClassModel model = cf.parse(bytes);
model.methods().forEach(m ->
System.out.println(m.methodName()));
Simplify concurrent programming by introducing an API for structured concurrency. Structured concurrency treats groups of related tasks running in different threads as a single unit of work, thereby streamlining error handling and cancellation, improving reliability, and enhancing observability. This is a preview API.
구조화된 동시성을 위한 API를 도입함으로써 동시성 프로그래밍을 단순화한다. 구조화된 동시성은 서로 다른 스레드에서 실행되는 관련 작업들의 그룹을 하나의 작업 단위로 취급하며, 그럼으로써 오류 처리와 취소를 간소화하고, 신뢰성을 향상시키고, 관측성을 높인다. 이것은 미리보기 API다. Java 21에 이어 두 번째 미리보기. 동시 작업들을 try-with-resources처럼 하나의 블록으로 묶음.
ExecutorService executor = Executors.newFixedThreadPool(2);
try {
Future a = executor.submit(() -> fetchA());
Future b = executor.submit(() -> fetchB());
return a.get() + b.get(); // 하나 실패해도 다른 건 계속 돎
} finally {
executor.shutdown();
}
try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
var a = scope.fork(() -> fetchA());
var b = scope.fork(() -> fetchB());
scope.join();
scope.throwIfFailed(); // 하나 실패하면 나머지 자동 취소
return a.get() + b.get();
}
Introduce scoped values, which enable managed sharing of immutable data both with child frames in the same thread, and with child threads. Scoped values are easier to reason about than thread-local variables and have lower space and time costs, especially when used in combination with Virtual Threads and Structured Concurrency. This is a preview API.
scoped values를 도입한다. 이것은 같은 스레드 내의 자식 프레임과, 자식 스레드 양쪽 모두와 불변 데이터를 관리된 방식으로 공유할 수 있게 해준다. scoped values는 thread-local 변수보다 이해하기 쉽고, 특히 가상 스레드 및 구조화된 동시성과 함께 사용할 때 공간·시간 비용이 더 낮다. 이것은 미리보기 API다. Java 21의 첫 미리보기에 이어 두 번째. 가상 스레드 환경에서 ThreadLocal을 대체. 정해진 범위에서만 살아있는 불변 값.
static final ThreadLocal USER = new ThreadLocal<>();
USER.set(user);
try { process(); }
finally { USER.remove(); } // 수동 제거 필수, 가변, 가상 스레드에 무거움
static final ScopedValue USER = ScopedValue.newInstance();
ScopedValue.where(USER, user).run(() -> {
process(); // USER.get() 으로 접근
}); // 블록 끝나면 자동 소멸, 불변, 가상 스레드에 가벼움
Introduce an API to express vector computations that reliably compile at runtime to optimal vector instructions on supported CPU architectures, thus achieving performance superior to equivalent scalar computations.
벡터 연산을 표현하는 API를 도입한다. 이 연산은 지원되는 CPU 아키텍처에서 런타임에 최적의 벡터 명령어로 안정적으로 컴파일되며, 따라서 동등한 스칼라 연산보다 우수한 성능을 달성한다. 한 번에 여러 데이터를 병렬 처리하는 CPU의 벡터(SIMD) 명령어를 자바에서 쓸 수 있게 함. JDK 22에서 일곱 번째 인큐베이터.
// 배열 요소를 하나씩 순차 처리
for (int i = 0; i < a.length; i++) {
c[i] = a[i] + b[i];
}
// 한 번에 여러 요소를 병렬 연산 (SIMD)
var species = FloatVector.SPECIES_PREFERRED;
var va = FloatVector.fromArray(species, a, i);
var vb = FloatVector.fromArray(species, b, i);
va.add(vb).intoArray(c, i); // 여러 요소 동시 덧셈
Reduce latency by implementing region pinning in G1, so that garbage collection need not be disabled during Java Native Interface (JNI) critical regions.
G1에 region pinning을 구현함으로써 지연 시간을 줄인다. 그리하여 JNI(자바 네이티브 인터페이스) 임계 영역 동안 가비지 컬렉션을 비활성화할 필요가 없어진다. 기존엔 JNI 임계 영역에서 GC를 통째로 멈춰야 해서 지연이 생겼는데, 이제 해당 영역만 "고정(pin)"해서 GC를 계속 돌릴 수 있음.
// GetPrimitiveArrayCritical 사용 중에는
// G1 GC 전체가 멈춤 → 지연(latency) 발생
// 사용 중인 메모리 region만 pin(고정)
// → 나머지는 GC 계속 진행 → 지연 감소
// (코드 변경 없이 JVM 내부 동작이 개선됨)
Enhance the java application launcher to be able to run a program supplied as multiple files of Java source code. This will make the transition from small programs to larger ones more gradual, enabling developers to choose whether and when to go to the trouble of configuring a build tool.
여러 개의 자바 소스 코드 파일로 제공된 프로그램을 실행할 수 있도록 java 런처를 강화한다. 이로써 작은 프로그램에서 큰 프로그램으로의 전환이 더 점진적으로 이루어질 것이며, 개발자가 빌드 도구를 구성하는 수고를 들일지 여부와 그 시점을 선택할 수 있게 된다. 기존엔 여러 파일 프로그램을 그냥 실행하려면 컴파일·빌드 설정이 필요했는데, 이제 java 명령 하나로 여러 소스 파일을 바로 실행 가능.
# 여러 .java 파일이면 먼저 컴파일해야 실행 가능
javac Main.java Helper.java Util.java
java Main
# 여러 소스 파일도 java 명령 하나로 바로 실행
java Main.java
# (Main.java가 참조하는 Helper.java 등을 자동으로 찾아 컴파일)
JDK 22 — openjdk.org/projects/jdk/22
'릴리스노트' 카테고리의 다른 글
| Java 21 릴리스 노트 독해 겸 정리 - Major New Functionality(핵심 기능만) (1) | 2026.07.15 |
|---|---|
| Spring Boot 4.0 릴리스 노트 독해 겸 정리 (0) | 2026.07.10 |