Java 11 Interview Questions and Answers
Freshers / Beginner level questions & answers
Ques 1. What is Java 11?
Java 11 is the second release of the long-term support (LTS) after Java 8. Since Java 11, Oracle JDK is no longer free for commercial use. You can use it in the development stages, but you need to buy a license to use it commercially. After Java 11, Oracle will not provide free long-term (LTS) support for any single Java version.
Ques 2. What is the difference between Oracle JDK and OpenJDK?
To check the detail difference, please check here: OracleJDK vs OpenJDK 💯💯
- Ever since Java 7, Java has been developed out in the open in the OpenJDK project. It's open source, but it's mainly driven by committers from Oracle, the owners of Java. But there are also many outside contributions from the likes of Red Hat, Twitter, and IBM. When you want to run Java, you have a choice to either use the OpenJDK releases or to use the Oracle JDK release. The Oracle JDK release used to be a slightly extended and amended version of OpenJDK. The ultimate goal here is to have no differences between the Oracle JDK builds and the OpenJDK builds.
- The main difference between Oracle JDK and OpenJDK is that Oracle JDK incorporates some commercial features. Rather than stripping these features to get conversions between Oracle JDK and OpenJDK, Oracle has committed to open source these commercial features into OpenJDK. This process already started with Java 9 and 10 and is continued with Java 11.
- With Java 11, the goal of a convergence between the Oracle JDK and OpenJDK code bases have been achieved. there's some pretty big differences in licensing. OpenJDK is GPL 2 licensed, so it has a true open source license. Oracle JDK, on the other hand, has a proprietary license called the Oracle Binary Code License Agreement. Up until Java 10, you could use both OpenJDK and Oracle JDK in production free of charge. For Oracle JDK, you could buy optional support from Oracle. That's changing with Java 11. For OpenJDK there are no changes, you can still use the GPL 2 license builds. However, you can no longer use Oracle JDK free of charge in production.
Ques 3. Which commercial features are available as open source in Java 11?
One of the Oracle JDK commercial features that have been open-sourced is Java Flight Recorder. In addition to Java Flight Recorder, Java Mission Control has also been open sourced.
Ques 4. How can I download the free version of Java 11?
You can download from Java 11. Download tar/zip, unzip them, install and set the environment variables to use java 11.
Ques 5. What are Java 11 Features?
Below is a list of the main features included in Java 11 :
- Nest-Based Access Control
- Dynamic Class-File Constants
- Improve Aarch64 Intrinsics
- Epsilon: A No-Op Garbage Collector
- Remove the Java EE and CORBA Modules
- HTTP Client (Standard)
- Local-Variable Syntax for Lambda Parameters
- Key Agreement with Curve25519 and Curve448
- Unicode 10
- Flight Recorder
- ChaCha20 and Poly1305 Cryptographic Algorithms
- Launch Single-File Source-Code Programs
- Low-Overhead Heap Profiling
- Transport Layer Security (TLS) 1.3
- ZGC: A Scalable Low-Latency Garbage Collector(Experimental)
- Deprecate the Nashorn JavaScript Engine
- Deprecate the Pack200 Tools and API
Intermediate / 1 to 5 years experienced level questions & answers
Ques 6. What is Flight Recorder in Java 11?
Java Flight Recorder is an always-on, low-overhead, data collection framework that you can use to get metrics on your JVMs. It's implemented as a bounded circular buffer, which buffers internal JVM metrics for a configurable amount of minutes. The great thing about this feature is that you can leave it enabled on your prediction systems because it's so low overhead.
Ques 7. What is Dynamic Class-File Constants in Java 11?
The Java class-file format is now expanding support for a new kind of constant pool, called CONSTANT_Dynamic. The loading of CONSTANT_Dynamic delegates the creation of a bootstrap method. Same as linking an invokedynamic call site delegates linkage to a bootstrap method. Same as, Java 7 which introduces MethodHandle and MethodType entry in constant pool.
Ques 8. What is Improve Aarch64 Intrinsics in Java 11?
Improve the current string and array intrinsic, and added new intrinsics on AArch64 processors for the java.lang.Math sin, cos and log functions. Intrinsics are used to optimize CPU architecture-specific assembly code that is executed for a given method to boost performance, instead of generic Java code. Although most of the intrinsics are already implemented in port AArch64, optimized intrinsics are still lacking for the following java.lang.Math methods:
- sin (sine trigonometric function)
- cos (cosine trigonometric function)
- log (logarithm of a number) This JEP is intended to cover this gap by implementing optimized intrinsics for these methods.
Ques 9. What is Local-Variable Syntax for Lambda Parameters in Java 11?
It allows var to be used when declaring the formal parameters of implicitly typed lambda expressions.
In Java 10, Local Variable Type Inference was introduced.
var str = "Java 10"; // infers Stringvar list = new ArrayList<String>(); // infers ArrayList<String>var stream = list.stream(); // infers Stream<String>svar bos = new ByteArrayOutputStream();
Java 11, allows var to be used to declare the formal parameters of an implicitly typed lambda expression.
(var a, var b) -> a + b
The examples below are illegal:
// Not allowed to mix 'var' and 'no var' in implicitly typed lambda expression(var a, b) -> a+b// Not allowed to mix 'var' and manifest types in explicitly typed lambda expression(var a, int b) -> a+b
Ques 10. What is Unicode 10 in Java 11?
It supports the latest Unicode version, particularly in the classes below:
- Character and String in the java.lang package
- NumericShaper in the java.awt.font package
- Bidi, BreakIterator, and Normalizer in the java.text package
Ques 11. What is Launch Single-File Source-Code Programs in Java 11?
It enhances the Java launcher to run the program provided as a single Java source code file, including the use of "shebang" files and related techniques from within the script.
Ques 12. What is ZGC: A Scalable Low-Latency Garbage Collector(Experimental) in Java 11?
The Z Garbage Collector, also known as ZGC, is a low latency scalable garbage collector designed to meet the following objectives.
- Pause times shall not exceed 10 ms
- Handle heaps ranging from a few hundred megabytes to multi terabytes in size
- Pause times do not increase with the size of the heap or live-set.
Ques 13. Tell me about Deprecate the Pack200 Tools and API in Java 11.
Below three types will be deprecated from java.base module, i.e. with annotation @Deprecated(forRemoval = true):
- java.util.jar.Pack200
- java.util.jar.Pack200.Packer
- java.util.jar.Pack200.Unpacker
Experienced / Expert level questions & answers
Ques 14. 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 15. 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 16. 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 17. 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 18. 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 19. 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 20. 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 21. 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 22. 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 23. 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 24. 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?