-
What is the new
varkeyword introduced in Java 11?- The
varkeyword allows local variable type inference. It lets the compiler infer the type of the variable based on the value assigned to it.
- The
-
How can you run a single Java source file directly from the command line in Java 11?
- You can use the
javacommand to run a single source file directly. For example:java HelloWorld.java.
- You can use the
-
What is the difference between
String::linesandBufferedReader::linesin Java 11?String::linesreturns a stream of lines extracted from the string, whereasBufferedReader::linesreturns a stream of lines read from aBufferedReader.
-
What is the purpose of the
isBlankmethod in theStringclass?- The
isBlankmethod returnstrueif the string is empty or contains only white space codepoints.
- The
-
Explain the
stripmethod in theStringclass.- The
stripmethod removes leading and trailing white spaces from the string, including Unicode white spaces.
- The
-
What is the difference between
stripandtrimmethods in theStringclass?striphandles Unicode white spaces, whiletrimonly handles ASCII white spaces.
-
How do you create an immutable collection in Java 11?
- You can use the
List.of,Set.of, orMap.ofmethods to create immutable collections.
- You can use the
-
What is the
repeatmethod in theStringclass used for?- The
repeatmethod returns a new string whose value is the concatenation of the original string repeated a specified number of times.
- The
-
Describe the
LocalVariable.getmethod introduced in Java 11.LocalVariable.getis a method in theLocalVariableclass that retrieves the value of the variable.
-
What enhancements have been made to the
Optionalclass in Java 11?- Java 11 introduces the
isEmptymethod to check if anOptionalis empty, andOptional::streamto convert anOptionalto a stream.
- Java 11 introduces the
-
Explain the new
HttpClientAPI introduced in Java 11.- The new
HttpClientAPI provides a modern and flexible way to perform HTTP requests. It supports synchronous and asynchronous requests, HTTP/2, and WebSocket.
- The new
-
How can you read a file as a string in Java 11?
- You can use
Files.readString(Path path)to read the contents of a file as a string.
- You can use
-
What is the purpose of the
Predicate.notmethod?- The
Predicate.notmethod is a static method that returns a predicate representing the negation of the specified predicate.
- The
-
Explain the
Collectors::toUnmodifiableListmethod.Collectors.toUnmodifiableListreturns aCollectorthat accumulates the input elements into an unmodifiable list.
-
How has the
ZGCgarbage collector been enhanced in Java 11?- ZGC in Java 11 is designed to handle very large heaps (multi-terabyte heaps) with low latency.
-
What improvements have been made to the
Nest-Based Access Controlin Java 11?- Nest-Based Access Control allows classes that are logically grouped together (nested types) to access each other's private members.
-
How do you create a new
Stringfrom bytes using the new methods in Java 11?- You can use
String(byte[] bytes, int offset, int length)to create a newStringfrom a byte array.
- You can use
-
Explain the
Files.writeStringmethod introduced in Java 11.Files.writeString(Path path, CharSequence csq)writes the specified string to a file.
-
What is the purpose of the
Key AgreementAPI introduced in Java 11?- The
Key AgreementAPI allows two parties to securely agree on a shared secret key over an insecure channel.
- The
-
How has the
JEP 330: Launch Single-File Source-Code Programsimproved Java development?- JEP 330 allows developers to run a single Java source file directly without needing to compile it first, simplifying quick prototyping and scripting.
- JDK Enhancement Proposals
-
Describe the
toArray(IntFunction)method added to theCollectioninterface.- The
toArray(IntFunction)method allows the creation of an array of the collection's elements using the provided array generator function.
- The
-
How does the
HttpClient::sendAsyncmethod work?HttpClient::sendAsyncsends an HTTP request asynchronously and returns aCompletableFuturethat completes with theHttpResponse.
-
Explain the enhancements in
Flight Recorderin Java 11.- Flight Recorder in Java 11 is now open-sourced and provides detailed profiling and diagnostic data for Java applications.
-
What is the
Epsilongarbage collector in Java 11?- Epsilon is a no-op garbage collector that handles memory allocation without reclamation, intended for performance testing and special use cases where GC overhead is unnecessary.
-
How do you create an unmodifiable copy of a
Mapin Java 11?- You can use
Map.copyOfto create an unmodifiable copy of the given map.
- You can use
-
Explain how the
varkeyword improves type inference in lambda expressions.- The
varkeyword can be used in lambda parameters to enable type annotations, which can improve readability and allow for annotations.
- The
-
How does the
ZGCgarbage collector achieve low-latency performance?- ZGC achieves low latency by using a coloring mechanism for pointers and concurrent phases that allow most operations to be non-blocking.
-
What are the security enhancements in the TLS 1.3 implementation in Java 11?
- TLS 1.3 improves security with features like zero round-trip time (0-RTT), simplified handshake, and removal of weaker algorithms.
-
How can the
HttpClientAPI be used to handle WebSocket communication in Java 11?- The
HttpClientAPI provides aWebSocket.Builderto create WebSocket clients, allowing for asynchronous communication with WebSocket servers.
- The
-
Describe the improvements to the
Lambda Metafactoryin Java 11.- The
Lambda Metafactoryhas been optimized for better performance, reducing the overhead of lambda expression creation and execution.
- The
-
Explain the significance of the
dynamic class-file constants(JEP 309) in Java 11.- Dynamic class-file constants allow for more flexible and efficient handling of constants in the JVM, improving performance and enabling new features.
- Dynamic class-file constants is a feature in Java 11 that allows you to define constants in the class file that are determined at runtime. This is in contrast to traditional constants, which are defined at compile time and cannot be changed.
-
How does the
Nest-Based Access Control (JEP 181)enhance encapsulation in Java 11?- Nest-Based Access Control allows nested classes to access each other's private members, improving encapsulation and reducing boilerplate code.
-
What are the advantages of the new
compact number formattingin Java 11?- Compact number formatting provides a way to format numbers in a more readable, locale-sensitive manner, such as "1K" for 1,000.
-
How does the
HttpClientAPI handle HTTP/2 features in Java 11?- The
HttpClientAPI supports multiplexing, header compression, and server push, all features of HTTP/2, improving performance and efficiency.
- The
-
What changes have been made to the
AArch64port in Java 11?- The
AArch64port has been stabilized and improved for better performance and compatibility on ARM architectures.
- The
-
Describe how the
Switch Expressions(preview feature) can simplify code in Java 11.- Switch expressions allow switch statements to return values and be used as expressions, reducing boilerplate and increasing readability.
-
How do you handle raw string literals in Java 11?
- Although raw string literals were proposed, they were not included in Java 11. Instead, text blocks were introduced in later versions for multiline strings.
-
Explain the purpose and usage of the
Pattern.compilemethod with flags in Java 11.Pattern.compilecompiles a regular expression with optional flags for case insensitivity, multiline mode, etc., for more flexible pattern matching.
-
How does the
Flight RecorderAPI help in performance monitoring?- Flight Recorder records events and metrics from the JVM and application, providing insights for performance tuning and troubleshooting.
-
Describe the impact of
JEP 321: HTTP Clienton legacyHttpURLConnectioncode.- The new
HttpClientAPI replaces the legacyHttpURLConnection, offering a more modern, flexible, and performant way to handle HTTP requests.
- The new
-
What are the key benefits of the
String::stripfamily of methods?strip,stripLeading, andstripTrailingprovide efficient and Unicode-aware trimming of whitespace characters.
-
How can
Stack-Walking APIin Java 11 be used for better performance in stack trace analysis?- The
Stack-Walking APIprovides a flexible and efficient way to traverse and analyze stack frames, improving performance and capabilities for diagnostics.
- The
-
What improvements have been made to the
G1 Garbage Collectorin Java 11?- Enhancements to the G1 garbage collector include better performance, lower pause times, and improvements to heap region size selection.
-
Explain how
JEP 318: Epsilonis beneficial for certain Java applications.- Epsilon is beneficial for performance testing, short-lived jobs, and other scenarios where GC overhead is unnecessary, providing predictable performance.
-
How does
JEP 328: Flight Recorderenhance JVM monitoring?- Flight Recorder provides a detailed and low-overhead event-based profiling and diagnostics framework, aiding in performance tuning and troubleshooting.
-
Describe the concept of
Key Agreementand its implementation in Java 11.- Key Agreement allows two parties to securely agree on a shared secret key using algorithms like Diffie-Hellman, providing secure communication channels.
-
What are the improvements in
Nashornin Java 11?- Although Nashorn was deprecated for removal, improvements included better ES6 support and performance optimizations.
-
Explain the role of
java.lang.invokein supporting dynamic languages on the JVM.java.lang.invokeprovides low-level primitives for efficient method handle-based invocation, supporting dynamic language features on the JVM.
-
How does the
ConstantDynamicfeature (JEP 309) enhance JVM capabilities?ConstantDynamicallows constants to be computed at runtime, providing more flexibility and efficiency in class file constant handling.
-
What are the benefits of the
GC Interfaceintroduced in Java 11?- The GC Interface allows for better isolation and modularization of garbage collectors, enabling easier experimentation and development of new GCs.
-
Explain the improvements made to
JEP 329: ChaCha20 and Poly1305 Cryptographic Algorithms.- These algorithms provide high-performance, secure encryption and authentication, enhancing Java's cryptographic capabilities.
-
How does the
java.util.concurrentpackage in Java 11 improve concurrency handling?- Improvements include better performance, additional utility methods, and enhancements to existing concurrency constructs for better scalability.
-
Describe the enhancements in
Dynamic Class-File Constants(JEP 309).- These enhancements improve performance and flexibility in constant pool handling, allowing for more dynamic and efficient constant resolution.
-
How has the
Class-Data Sharingfeature been improved in Java 11?- Class-Data Sharing now supports application classes, reducing startup time and memory footprint by sharing common class metadata across JVM instances.
-
What are the key security updates in Java 11?
- Security updates include TLS 1.3 support, improvements to the default cryptographic algorithms, and enhancements to the Java security manager.