Java 11 Interview Questions and Answers
Experienced / Expert level questions & answers
Ques 1. What is Java Mission Control in Java 11?
Java Mission Control is an application that can analyze the dumps that come from Java Flight Recorder, and give you a graphical overview of what's happening inside of a JVM.
Ques 2. What is Nest-Based Access Control in Java 11?
Java allows classes and interfaces to be nested within each other. These nested forms have unlimited access to each other, including private fields, methods, and constructors.
Nests allow nested classes, which are part of the same enclosing class but are compiled into different class files, to access each other\'s private members without the need for compilers to insert synthetic accessibility-broadening bridge methods. This is a Java class bytecode level change.
public class TestOuter {
public void testingOuterPublic() {
}
private void testingOuterPrivate() {
}
class TestInner {
public void testingInner() {
testingOuterPrivate();
}
}
}
TestOuter and TestInner form a nest together, they are each other\'s nestmates.
The method testingOuterPrivate() can be accessed inside inner class, even tough testingOuterPrivate() method is private.
If we compile above class, will get compilation error. This is because of the reason that the outer and nested classes are compiled to different files and they need package-private visibility to access each other\'s private members. JVM access rules do not permit private access between nestmates.
Java 11 provides JVM level support for private access through the \"NestMembers\" and \"NestHost\" attributes within outer / nested classes.
NestMembers
corresponds to nested classes.NestHost
corresponds to the enclosing outer class. Now these attributes connect outer and nested classes, rather than package-private bridge methods created synthetically.
Using Reflection:
package com.withoutbook;
import java.lang.reflect.Field;
public class TestOuter {
private static int testingNumber = 17;
public static class NestedInnerTest {
public static void test() throws Exception {
Field value = TestOuter.class.getDeclaredField(\"testingNumber\");
value.setInt(null, 12);
}
}
public static void main(String[] args) throws Exception {
NestedInnerTest.test();
System.out.println(TestOuter.testingNumber);
}
}
If we run above code in Java 10, will get below exception:
Exception in thread \"main\" java.lang.IllegalAccessException:
class com.techgeeknext.TestOuter$NestedInnerTest cannot access a member of class com.techgeeknext.controller.TestOuter with modifiers \"private static\"
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:376)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:639) at java.base/java.lang.reflect.Field.checkAccess(Field.java:1075)
at java.base/java.lang.reflect.Field.setInt(Field.java:958) at com.techgeeknext.controller.TestOuter$NestedInnerTest.test(TestOuter.java:12)
at com.techgeeknext.controller.TestOuter.main(TestOuter.java:18)
Whereas in Java 11, it will run successfully without exception with below output:
12
Ques 3. What is Epsilon: A No-Op Garbage Collector in Java 11?
Epsilon is the "No Op" garbage collector. It allocates new memory but never recycles it. Once the application exhausts the available Java heap, the JVM shuts down. It means, Epsilon will allow your application to run out of memory and crash. Elipson is good only for test environments and no-op garbage collector is useful for measuring and managing application performance.
Java 11 also added Z Garbage Collector(ZGC), which promises to manage large heaps with high throughput and short pause times. You need to specify below two runtime switches on the command line, to tell the JVM to use the Epsilon GC
XX:+UnlockExperimentalVMOptions
-XX:+UseEpsilonGC
Below command generate heap dump if JVM runs out of memory.
-XX:HeapDumpOnOutOfMemoryError
Run specified command when an out-of-memory error occurs.
-XX:OnOutOfMemoryError=
Ques 4. What is Remove the Java EE and CORBA Modules in Java 11?
Java 11 removed the Java EE and CORBA modules from the Java SE Platform and the JDK, these modules were already deprecated in Java 9 with the declared intent to remove them in a future release.
- java.xml.ws (JAX-WS, plus the related technologies SAAJ and Web Services Metadata)
- java.xml.bind (JAXB)
- java.activation (JAF)
- java.xml.ws.annotation (Common Annotations)
- java.corba (CORBA)
- java.transaction (JTA)
- java.se.ee
- jdk.xml.ws (Tools for JAX-WS)
- jdk.xml.bind (Tools for JAXB)
Ques 5. What is HTTP Client (Standard) in Java 11?
It standardizes Http Client API, in the java.net.http package, based upon the incubated API, and removed the incubated API. The new API supports both HTTP/1.1 and HTTP/2. It is designed to enhance the overall performance of sending requests by a client and receiving responses from the server. It also natively supports WebSockets.
Ques 6. What is Key Agreement with Curve25519 and Curve448 in Java 11?
Java makes further improvements in cryptography which provides security and performance. This feature implements a key agreement using Curve25519 and Curve448. Other cryptography libraries, such as OpenSSL and BoringSSL, already support key exchanges using Curve25519 and Curve448.
Ques 7. What is Flight Recorder in Java 11?
Java Flight Recorder (JFR) is a profiling tool that collects data about events during the execution of a Java application in Java Virtual Machine (JVM). JFR is integrated into the JVM and part of the JDK distribution.
- Using Command Line: Compile FlightRecTest Java program by executing the below command, which will generate FlightRecTest.class file at src/com/withoutbook/flightrecorder location.
Once compilation is successful, the following options can be taken to start the program:javac -d out -sourcepath src/com/withoutbook/flightrecorder/FlightRecTest.java
java -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=duration=200s,filename=recording.jfr -cp ./out/ com.withoutbook.flightrecorder.FlightRecTest
- Using Diagnostic Command: The jcmd tool also allows registration of events to start. To start a 70-second recording on the running Java process with the identifier 4532 and save it to recording.jfr in the current directory, use the following:
Below commands relevant to Java Flight Recorder are:jcmd 4532 JFR.start duration=70s filename=recording.jfr
//Start a recording.JFR.start//It check the status of all recordings running for the specified process, including the recording file name, identification number, duration.JFR.check//It stop recording with a specific identification number, by default, recording 1 is stopped.JFR.stop//It dump the data collected by the recording with a specific identification number, by default, data from recording 1 is dumped.JFR.dump
Ques 8. What are ChaCha20 and Poly1305 Cryptographic Algorithms in Java 11?
Java 11 has Implement the ChaCha20 and ChaCha20-Poly1305 ciphers.
ChaCha20 is a new stream cipher which replaces the older, insecure RC4 stream cipher.
Poly1305 is a cryptographic Message Authentication Code (MAC), used on both Encrypted and Decrypted messages, it creates the authentication token and guarantees the integrity of the message.
In ChaCha20-Poly1305 algorithm, ChaCha20 Stream cipher performs the Encryption and Poly1305 performs the Authentication. The ChaCha20 and ChaCha20-Poly1305 algorithms will implement the javax.crypto.CipherSpi API within the SunJCE provider.
Ques 9. What is Low-Overhead Heap Profiling in Java 11?
It provides a way to get information from the JVM about Java object heap allocations that:
- Is low-overhead enough to be enabled by default continuously
- Is accessible via a well-defined, programmatic interface
- Sample all allocations (which is not limited to allocations that are in one particular heap region or that were allocated in one particular way)
- It can be defined in an implementation-independent way (i.e., without relying on any particular GC algorithm or VM implementation)
- It provide information about both live and dead Java objects.
Ques 10. What is Transport Layer Security (TLS) 1.3 in Java 11?
Transport Layer Security, or TLS, is a cryptographic protocol that protects data exchanged over a computer network. TLS (Transport Layer Security) and is the successor to SSL (Secure Sockets Layer). TLS provides secure communication between web browsers and servers.
TLS 1.3 is a major revision of the TLS protocol and provides significant security and performance improvements over previous versions.
Ques 11. Write about Deprecate the Nashorn JavaScript Engine in Java 11?
Below two JDK modules will be terminally deprecated, by using annotation @Deprecated(forRemoval=true):
- jdk.scripting.nashorn -- contains the jdk.nashorn.api.scripting and jdk.nashorn.api.tree packages.
- jdk.scripting.nashorn.shell -- contains the jjs tool. Running jjs will display a warning:
Most helpful rated by users:
- What is Java 11?
- What is Local-Variable Syntax for Lambda Parameters in Java 11?
- What is the difference between Oracle JDK and OpenJDK?
- What is Java Mission Control in Java 11?
- Which commercial features are available as open source in Java 11?