Java 9 - 21 Flashcards

(72 cards)

1
Q

[JAVA 9] What are the main features released in Java 9?

A

Module System (Project Jigsaw) - JShell REPL - Private methods in Interfaces - Stream API enhancements (takeWhile - dropWhile - iterate) - Optional enhancements - Collection factory methods (List.of - Set.of - Map.of) - Reactive Streams (Flow API) - HTTP/2 Client - Process API updates - Stack-Walking API

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

[JAVA 9] What is the Java 9 Module System (Project Jigsaw)?

A

The Module System allows the JDK and applications to be divided into named modules. Each module declares what it exports and what it requires. This improves encapsulation - reduces the classpath and makes large applications easier to maintain

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

[JAVA 9] What is JShell in Java 9?

A

JShell is a Read-Eval-Print-Loop (REPL) tool that allows developers to execute Java statements interactively without creating a class or main() method. Useful for quick testing and experimentation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

[JAVA 9] What are the new Collection factory methods in Java 9?

A

List.of() - Set.of() and Map.of() create immutable collections in one line. Adding or removing elements throws UnsupportedOperationException. Much cleaner than Arrays.asList() for immutable collections

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

[JAVA 9] What are the new Stream methods added in Java 9?

A

takeWhile(predicate) returns elements while predicate is true then stops. dropWhile(predicate) skips elements while predicate is true then returns the rest. iterate(seed - predicate - function) adds predicate-based termination

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

[JAVA 9] Can interfaces have private methods in Java 9?

A

Yes - Java 9 allows private methods in interfaces to share common code between default methods within the same interface without exposing that code to implementing classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

[JAVA 9] What is the Flow API in Java 9?

A

The Flow API introduces Reactive Streams support with Publisher - Subscriber - Subscription and Processor interfaces for building asynchronous and backpressure-aware data pipelines

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

[JAVA 9] What enhancements were made to Optional in Java 9?

A

Java 9 added ifPresentOrElse() - stream() to convert Optional to Stream - and or() to provide an alternative Optional when the original is empty

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

[JAVA 9] MEMORY BOOSTER: Java 9 key features

A

Java 9 = Modules + JShell + private interface methods + List/Set/Map.of(). Module System is the biggest change since Java 1. JShell = interactive Java playground. List.of() = immutable one-liner. takeWhile/dropWhile = smarter stream processing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

[JAVA 10] What are the main features released in Java 10?

A

Local Variable Type Inference (var keyword) - Application Class-Data Sharing - Parallel Full GC for G1 - Garbage Collector Interface - Thread-Local Handshakes - Root Certificates - Time-Based Release Versioning

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

[JAVA 10] What is the var keyword in Java 10?

A

var enables Local Variable Type Inference. The compiler infers the type of a local variable from the right-hand side of the assignment. Example: var list = new ArrayList<String>() - compiler infers ArrayList<String>. Only works for local variables not fields or method parameters</String></String>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

[JAVA 10] What are the limitations of the var keyword in Java 10?

A

var can only be used for local variables with an initializer. It cannot be used for method parameters - return types - fields or variables without initialization. The type is fixed at compile time - it is NOT dynamic typing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

[JAVA 10] What is Application Class-Data Sharing in Java 10?

A

Class-Data Sharing allows application classes to be placed in a shared archive to reduce startup time and memory footprint when multiple JVM instances run the same application

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

[JAVA 10] MEMORY BOOSTER: Java 10 key features

A

Java 10 = var keyword. var = local variable type inference = compiler figures out the type. var is NOT dynamic typing. Type is fixed at compile time. Cannot use var for fields - method params or return types. Only local variables with initializer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

[JAVA 11] What are the main features released in Java 11 (LTS)?

A

New String methods (isBlank - strip - lines - repeat) - New File methods (readString - writeString) - HTTP Client API (standard) - Local Variable Syntax for Lambda (var in lambdas) - Nest-Based Access Control - Flight Recorder open sourced - Launch Single-File Source Programs - Epsilon GC - ZGC (experimental)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

[JAVA 11] What are the new String methods introduced in Java 11?

A

isBlank() checks if string is empty or whitespace. strip() removes leading and trailing whitespace (Unicode-aware). lines() returns a Stream of lines. repeat(n) returns the string repeated n times. stripLeading() and stripTrailing() for one-sided removal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

[JAVA 11] What is the difference between strip() and trim() in Java 11?

A

trim() removes only ASCII whitespace (below Unicode 32). strip() is Unicode-aware and removes all types of whitespace including Unicode whitespace characters. strip() is the modern preferred method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

[JAVA 11] What is the HTTP Client API in Java 11?

A

The HTTP Client API became standard in Java 11. It supports HTTP/1.1 and HTTP/2 - synchronous and asynchronous requests - and WebSocket. It is a clean modern alternative to the old HttpURLConnection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

[JAVA 11] What does the new File API in Java 11 provide?

A

Files.readString(path) reads a file into a String in one line. Files.writeString(path - string) writes a String to a file in one line. These replace multi-line boilerplate for simple file operations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

[JAVA 11] Can we use var in Lambda parameters in Java 11?

A

Yes - Java 11 allows var in lambda parameter declarations: (var x - var y) -> x + y. This enables adding annotations to lambda parameters which was not possible with plain lambda syntax

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

[JAVA 11] What is the Epsilon Garbage Collector in Java 11?

A

Epsilon GC is a no-op garbage collector that allocates memory but never reclaims it. Useful for performance testing - memory pressure analysis and short-lived jobs where GC overhead should be eliminated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

[JAVA 11] MEMORY BOOSTER: Java 11 key features

A

Java 11 = LTS. Key: String.isBlank/strip/lines/repeat + Files.readString/writeString + HTTP Client standard + var in lambdas. strip() beats trim() for Unicode. Java 11 is Long-Term Support - commonly used as a production baseline

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

[JAVA 12] What are the main features released in Java 12?

A

Switch Expressions (preview) - Shenandoah GC (experimental) - Microbenchmark Suite - JVM Constants API - Default CDS Archives - G1 GC improvements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

[JAVA 12] What is the Switch Expression introduced in Java 12?

A

Java 12 introduced Switch Expressions as a preview feature. Unlike the traditional switch statement the new switch expression can return a value - uses arrow syntax (case X -> result) and does not fall through between cases

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
[JAVA 12] What is the Shenandoah GC in Java 12?
Shenandoah is a low-pause garbage collector that performs GC work concurrently with running Java threads. It reduces GC pause times regardless of heap size making it suitable for latency-sensitive applications
26
[JAVA 12] MEMORY BOOSTER: Java 12 key features
Java 12 = Switch Expressions preview. New switch: case X -> value (no fall-through + can return value). Old switch: case X: ... break (falls through). Shenandoah GC for low-latency. Preview features require --enable-preview flag to compile and run
27
[JAVA 13] What are the main features released in Java 13?
Text Blocks (preview) - Switch Expressions (second preview) - Reimplement Legacy Socket API - Dynamic CDS Archives - ZGC: Uncommit Unused Memory
28
[JAVA 13] What are Text Blocks in Java 13?
Text Blocks are multi-line string literals using triple quotes. They preserve formatting without escape characters for newlines and quotes. They improve readability of HTML - JSON and SQL strings in Java code
29
[JAVA 13] What is the difference between a regular String literal and a Text Block?
Regular String requires escape sequences like \n and \". Text Block uses triple quotes and preserves literal formatting making multi-line strings much more readable and maintainable
30
[JAVA 13] MEMORY BOOSTER: Java 13 key features
Java 13 = Text Blocks preview (triple-quote strings). Perfect for SQL - HTML - JSON embedded in Java. No more \n concatenation for multi-line strings. Switch Expressions second preview getting closer to standard
31
[JAVA 14] What are the main features released in Java 14?
Records (preview) - Pattern Matching for instanceof (preview) - Switch Expressions (standard) - Text Blocks (second preview) - Helpful NullPointerExceptions - ZGC on macOS and Windows - Remove CMS GC
32
[JAVA 14] What are Records in Java 14?
Records are a preview feature providing a concise way to declare immutable data classes. A record automatically generates constructor - getters - equals() - hashCode() and toString(). Example: record Point(int x - int y) {}
33
[JAVA 14] What is Pattern Matching for instanceof in Java 14?
Pattern Matching for instanceof eliminates explicit casting after an instanceof check. Instead of checking instanceof then casting - you write if(obj instanceof String s) and use s directly in the block
34
[JAVA 14] What are Helpful NullPointerExceptions in Java 14?
Java 14 improved NullPointerException messages to say exactly which variable was null. Instead of just NullPointerException the message now says something like Cannot invoke method because X is null - making debugging much faster
35
[JAVA 14] When did Switch Expressions become standard in Java?
Switch Expressions became a standard (non-preview) feature in Java 14 after being a preview in Java 12 and Java 13
36
[JAVA 14] MEMORY BOOSTER: Java 14 key features
Java 14 = Records + Pattern Matching instanceof + Switch standard. Records = compact immutable data class (auto-generates all boilerplate). instanceof Pattern = no explicit cast needed. NullPointerException messages now tell you exactly WHAT was null
37
[JAVA 15] What are the main features released in Java 15?
Sealed Classes (preview) - Text Blocks (standard) - Records (second preview) - Pattern Matching for instanceof (second preview) - ZGC (production ready) - Shenandoah GC (production ready) - Hidden Classes - Remove Nashorn JavaScript Engine
38
[JAVA 15] What are Sealed Classes in Java 15?
Sealed Classes restrict which classes or interfaces can extend or implement them. The sealed class declares its permitted subclasses using the permits keyword. This gives more control over class hierarchies and enables exhaustive pattern matching
39
[JAVA 15] When did Text Blocks become standard in Java?
Text Blocks became a standard feature in Java 15 after being previewed in Java 13 and Java 14
40
[JAVA 15] What happened to the Nashorn JavaScript Engine in Java 15?
Nashorn JavaScript Engine introduced in Java 8 was removed in Java 15 after being deprecated in Java 11. GraalVM is the recommended alternative for running JavaScript in Java applications
41
[JAVA 15] MEMORY BOOSTER: Java 15 key features
Java 15 = Sealed Classes preview + Text Blocks standard. Sealed class = permits keyword = controls who can extend. Text Blocks = standard (triple quotes). ZGC and Shenandoah both production ready. Nashorn removed - use GraalVM instead
42
[JAVA 16] What are the main features released in Java 16?
Records (standard) - Pattern Matching for instanceof (standard) - Sealed Classes (second preview) - Unix-Domain Socket Channels - Vector API (incubator) - Foreign Linker API (incubator) - Strongly Encapsulate JDK Internals
43
[JAVA 16] When did Records become standard in Java?
Records became a standard feature in Java 16 after being previewed in Java 14 and Java 15
44
[JAVA 16] When did Pattern Matching for instanceof become standard?
Pattern Matching for instanceof became a standard feature in Java 16 after being previewed in Java 14 and Java 15
45
[JAVA 16] What is the Vector API introduced in Java 16?
The Vector API (incubator) provides a way to express vector computations that reliably compile to optimal SIMD hardware instructions on supported CPUs enabling significant performance improvements for numerical processing
46
[JAVA 16] MEMORY BOOSTER: Java 16 key features
Java 16 = Records standard + instanceof Pattern Matching standard. Both graduated from preview to standard. Preview journey: Records 14>15>16 standard. instanceof Pattern 14>15>16 standard. Sealed Classes still in preview heading to 17
47
[JAVA 17] What are the main features released in Java 17 (LTS)?
Sealed Classes (standard) - Pattern Matching for switch (preview) - Restore Always-Strict Floating-Point Semantics - New macOS Rendering Pipeline - Foreign Function and Memory API (incubator) - Deprecate Applet API - Strongly Encapsulate JDK Internals
48
[JAVA 17] When did Sealed Classes become standard in Java?
Sealed Classes became a standard feature in Java 17 after being previewed in Java 15 and Java 16
49
[JAVA 17] What is Pattern Matching for switch in Java 17?
Pattern Matching for switch (preview) allows switch expressions and statements to test a variable against multiple type patterns - handle null and use guarded patterns making complex type-checking logic much more concise
50
[JAVA 17] Why is Java 17 significant?
Java 17 is a Long-Term Support (LTS) release. It consolidates Records - Text Blocks - Sealed Classes and instanceof Pattern Matching all as standard features. It is widely adopted as the modern production baseline replacing Java 11 LTS
51
[JAVA 17] MEMORY BOOSTER: Java 17 key features
Java 17 = LTS + Sealed Classes standard + Switch Pattern Matching preview. The big trio: Records (16 standard) + instanceof Pattern Matching (16 standard) + Sealed Classes (17 standard). Java 17 is the modern production baseline after Java 11 LTS
52
[JAVA 18] What are the main features released in Java 18?
UTF-8 as default Charset - Simple Web Server - Code Snippets in Java API Documentation - Vector API (third incubator) - Internet-Address Resolution SPI - Foreign Function and Memory API (second incubator) - Pattern Matching for switch (second preview) - Deprecate Finalization
53
[JAVA 18] What is the Simple Web Server in Java 18?
Java 18 includes a minimal HTTP file server that can be launched from the command line in one command. It serves static files and is intended for testing - prototyping and educational use only - not for production
54
[JAVA 18] What changed about the default Charset in Java 18?
UTF-8 became the default Charset for the Java standard library in Java 18. Previously the default was platform-dependent causing inconsistent behavior across operating systems. Now UTF-8 is always the default
55
[JAVA 18] MEMORY BOOSTER: Java 18 key features
Java 18 = UTF-8 default (finally consistent across platforms) + Simple Web Server (one-line static file server for testing). Finalization deprecated - use try-with-resources or Cleaner API instead. Small quality-of-life release between LTS versions
56
[JAVA 19] What are the main features released in Java 19?
Virtual Threads (preview - Project Loom) - Structured Concurrency (incubator) - Record Patterns (preview) - Pattern Matching for switch (third preview) - Foreign Function and Memory API (preview) - Vector API (fourth incubator)
57
[JAVA 19] What are Virtual Threads in Java 19?
Virtual Threads (Project Loom) are lightweight threads managed by the JVM rather than the OS. They allow writing simple synchronous-looking code that scales like asynchronous code. Millions of virtual threads can run concurrently with very low memory overhead
58
[JAVA 19] What is the difference between Virtual Threads and Platform Threads?
Platform threads are OS threads - expensive to create and limited in number (typically thousands). Virtual threads are JVM-managed - very cheap to create and can number in the millions. Virtual thread blocking is cheap while platform thread blocking ties up an OS thread
59
[JAVA 19] What is Structured Concurrency in Java 19?
Structured Concurrency treats groups of related tasks running in different threads as a single unit of work. It simplifies error handling and cancellation ensuring that when a parent task ends all its child tasks are also completed or cancelled
60
[JAVA 19] What are Record Patterns in Java 19?
Record Patterns extend pattern matching to allow destructuring of Record values in instanceof checks and switch expressions. Example: if(obj instanceof Point(int x - int y)) extracts x and y directly without calling accessor methods
61
[JAVA 19] MEMORY BOOSTER: Java 19 key features
Java 19 = Virtual Threads preview (Project Loom). Virtual Thread = lightweight JVM thread + millions possible + cheap blocking. Game changer for high-concurrency servers. Structured Concurrency = manage task groups as one unit. Record Patterns = destructure records in instanceof/switch
62
[JAVA 20] What are the main features released in Java 20?
Virtual Threads (second preview) - Structured Concurrency (second incubator) - Record Patterns (second preview) - Pattern Matching for switch (fourth preview) - Scoped Values (incubator) - Foreign Function and Memory API (second preview) - Vector API (fifth incubator)
63
[JAVA 20] What are Scoped Values in Java 20?
Scoped Values provide a way to share immutable data within and across threads in a bounded scope. They are a safer and more efficient alternative to ThreadLocal especially for virtual threads where ThreadLocal can be expensive due to per-thread storage
64
[JAVA 20] What is the difference between Scoped Values and ThreadLocal?
ThreadLocal is mutable and each thread gets its own copy that lives as long as the thread. Scoped Values are immutable and have a defined scope - automatically cleaned up when the scope ends. Scoped Values are more memory-efficient with virtual threads
65
[JAVA 20] MEMORY BOOSTER: Java 20 key features
Java 20 = refinement release - most features are 2nd or 3rd previews heading to Java 21 LTS. Key new concept: Scoped Values as a better ThreadLocal for virtual threads. Java 20 = final polish before Java 21 LTS milestone
66
[JAVA 21] What are the main features released in Java 21 (LTS)?
Virtual Threads (standard) - Record Patterns (standard) - Pattern Matching for switch (standard) - Sequenced Collections - String Templates (preview) - Unnamed Classes and Instance Main Methods (preview) - Structured Concurrency (preview) - Scoped Values (preview)
67
[JAVA 21] When did Virtual Threads become standard in Java?
Virtual Threads became a standard feature in Java 21 after being previewed in Java 19 and Java 20. This is one of the most significant concurrency improvements in Java history
68
[JAVA 21] What are Sequenced Collections in Java 21?
Sequenced Collections introduce three new interfaces: SequencedCollection - SequencedSet and SequencedMap. They provide uniform methods to access the first and last elements using getFirst() - getLast() - addFirst() - addLast() and reversed()
69
[JAVA 21] What are String Templates in Java 21?
String Templates (preview) provide a safe and expressive way to embed expressions inside string literals using template processors. Safer than String.format() and more readable than concatenation. Example: STR."Hello \{name}"
70
[JAVA 21] When did Pattern Matching for switch become standard in Java?
Pattern Matching for switch became a standard feature in Java 21 after being previewed across Java 17 through Java 20
71
[JAVA 21] What is the significance of Java 21 as an LTS release?
Java 21 is a Long-Term Support release and the current modern LTS. It consolidates Virtual Threads - Record Patterns - Switch Pattern Matching and Sequenced Collections as standard features. It is the recommended upgrade target from Java 17 LTS
72
[JAVA 21] MEMORY BOOSTER: Java 21 key features
Java 21 = LTS + Virtual Threads standard + Sequenced Collections + Switch Pattern Matching standard. Landmark feature: Virtual Threads finally standard. Sequenced Collections = getFirst/getLast on any ordered collection. Current recommended LTS alongside Java 17