Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// Is a final top-level class in the unnamed package;
/// Extends java.lang.Object and does not implement any interfaces;
/// Has a default constructor with no parameters, and no other constructors;
/// Has, as its members, the fields and methods in the compact source file; and
/// Must have a launchable main method; if it does not, a compile-time error is reported.
void main() {
IO.println("Compact source file & main method here ...");
}
10 changes: 10 additions & 0 deletions JavaReleases/src/main/java/pl/mperor/lab/java/JavaBaseImport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package pl.mperor.lab.java;

import module java.base;

class JavaBaseImport {

private final List<String> listFromUtilPackage = List.of("a", "b", "c");
private final File fileFromIoPackage = new File("file.txt");

}
2 changes: 1 addition & 1 deletion JavaReleases/src/test/java/pl/mperor/lab/java/Java12.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private String generateFileHashMD5(Path file) throws NoSuchAlgorithmException, I

StringBuilder sb = new StringBuilder();
for (byte b : hashBytes) {
sb.append(String.format("%02x", b));
sb.append(String.format("%02x", b)); // byte to 2‑digit hex
}
return sb.toString();
}
Expand Down
10 changes: 9 additions & 1 deletion JavaReleases/src/test/java/pl/mperor/lab/java/Java15.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ public void testTextBlock() {

@Test
public void testStringFormatted() {
Assertions.assertEquals("Hello World!", "Hello %s".formatted("World!"));
var positionInFormatted = """
user: %1$s
last name: %2$s
name: %1$s""".formatted("John", "Smith");
Assertions.assertEquals("""
user: John
last name: Smith
name: John""", positionInFormatted);

Assertions.assertEquals("Value: 0.00", String.format(Locale.US, "Value: %.2f", 0d));
}

Expand Down
54 changes: 54 additions & 0 deletions JavaReleases/src/test/java/pl/mperor/lab/java/Java24.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package pl.mperor.lab.java;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.stream.Gatherers;
import java.util.stream.IntStream;

/// Java 24 (March 2025)
/// [JDK 24](https://openjdk.org/projects/jdk/24)
///
/// - STANDARD FEATURES:
/// - 472: Prepare to Restrict the Use of JNI
/// - 475: Late Barrier Expansion for G1
/// - 479: Remove the Windows 32-bit x86 Port
/// - 483: Ahead-of-Time Class Loading & Linking
/// - 484: Class-File API
/// - 485: Stream Gatherers
/// - 486: Permanently Disable the Security Manager
/// - 490: ZGC: Remove the Non-Generational Mode
/// - 491: Synchronize Virtual Threads without Pinning
/// - 493: Linking Run-Time Images without JMODs
/// - 496: Quantum-Resistant Module-Lattice-Based Key Encapsulation Mechanism
/// - 497: Quantum-Resistant Module-Lattice-Based Digital Signature Algorithm
/// - 498: Warn upon Use of Memory-Access Methods in sun.misc.Unsafe
/// - 501: Deprecate the 32-bit x86 Port for Removal
///
/// - PREVIEW & INCUBATOR:
/// - 404: Generational Shenandoah (Experimental)
/// - 450: Compact Object Headers (Experimental)
/// - 478: Key Derivation Function API (Preview)
/// - 487: Scoped Values (Fourth Preview)
/// - 488: Primitive Types in Patterns, instanceof, and switch (Second Preview)
/// - 489: Vector API (Ninth Incubator)
/// - 492: Flexible Constructor Bodies (Third Preview)
/// - 494: Module Import Declarations (Second Preview)
/// - 495: Simple Source Files and Instance Main Methods (Fourth Preview)
public class Java24 {

@Test
public void testWindowFixedGatherer() {
var result = IntStream.rangeClosed(1, 3)
.boxed()
.gather(Gatherers.windowFixed(2))
.toList();

Assertions.assertEquals(
List.of(
List.of(1, 2),
List.of(3)
), result);
}
}
41 changes: 41 additions & 0 deletions JavaReleases/src/test/java/pl/mperor/lab/java/Java25.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package pl.mperor.lab.java;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import pl.mperor.lab.common.TestUtils;

/// Java 25 (September 2025)
/// [JDK 25](https://openjdk.org/projects/jdk/25)
///
/// - STANDARD FEATURES:
/// - 503: Remove the 32-bit x86 Port
/// - 506: Scoped Values
/// - 510: Key Derivation Function API
/// - 511: Module Import Declarations
/// - 512: Compact Source Files and Instance Main Methods
/// - 513: Flexible Constructor Bodies
/// - 514: Ahead-of-Time Command-Line Ergonomics
/// - 515: Ahead-of-Time Method Profiling
/// - 518: JFR Cooperative Sampling
/// - 519: Compact Object Headers
/// - 520: JFR Method Timing & Tracing
/// - 521: Generational Shenandoah
///
/// - PREVIEW & INCUBATOR:
/// - 470: PEM Encodings of Cryptographic Objects (Preview)
/// - 502: Stable Values (Preview)
/// - 505: Structured Concurrency (Fifth Preview)
/// - 507: Primitive Types in Patterns, instanceof, and switch (Third Preview)
/// - 508: Vector API (Tenth Incubator)
/// - 509: JFR CPU-Time Profiling (Experimental)
public class Java25 {

@Test
public void testPrintFromIOClass() {
var out = TestUtils.setTempSystemOut();
IO.println("Hello World!"); // ⇒ System.out.println("Hello World!");
Assertions.assertEquals("Hello World!" + System.lineSeparator(), out.all());
TestUtils.resetSystemOut();
}

}
24 changes: 23 additions & 1 deletion JavaReleases/src/test/java/pl/mperor/lab/java/Java4.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import pl.mperor.lab.common.TestUtils;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.beans.EventHandler;
import java.io.*;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.time.Instant;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.logging.Logger;
Expand All @@ -37,8 +42,12 @@ public void testNewInputOutputAkaNIO() throws IOException {
Path path = Path.of("src", "test", "resources", "nio.txt");
byte[] fileBytes = Files.readAllBytes(path);
String content = new String(fileBytes);

Assertions.assertEquals("Hello NIO!", content);

var fileCreationTime = Files.readAttributes(path, BasicFileAttributes.class)
.creationTime();
System.out.printf("📃 File '%s' - last access time: ⌚%s%n: ", path.getFileName(), fileCreationTime);
Assertions.assertTrue(fileCreationTime.compareTo(FileTime.from(Instant.now())) <= 0);
}

@Test
Expand Down Expand Up @@ -125,4 +134,17 @@ private void handleConnectedClient(ServerSocket serverSocket) throws IOException
}
}

@Test
public void testJavaBeansEventHandler() {
var out = TestUtils.setTempSystemOut();
Runnable runnable = EventHandler.create(Runnable.class, this, "run"); // () -> run();
runnable.run();
Assertions.assertEquals("Run was called!", out.all());
TestUtils.resetSystemOut();
}

public void run() {
System.out.print("Run was called!");
}

}
11 changes: 11 additions & 0 deletions JavaReleases/src/test/java/pl/mperor/lab/java/Java5.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.lang.annotation.*;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -146,4 +147,14 @@ public void testStringBuilderInsteadOfStringBuffer() {
Assertions.assertEquals("Hello World", sb.reverse().toString());
}

@Test
public void testCollectionsAPI() {
var collection = List.of(1,2,3,2,2);
Assertions.assertEquals(3, Collections.frequency(collection, 2));

List<String> empty = Collections.emptyList();
Assertions.assertNotNull(empty);
Assertions.assertTrue(empty.isEmpty());
}

}
Loading