Top [1–200] Interview Questions on Java 10 Topics (Part-2) with Examples & Output.
Welcome Readers !!! A Comprehensive guide for Java 10 Topics that covers below topics:
🔥 Top 200 Java 10 Interview Questions (Part 2) — With Hands-On Examples & Output!
Welcome Readers !!!
Supercharge your interview preparation! Dive into the essential Java 10 topics with expertly crafted questions, real code examples, and actual outputs. Master the latest features and impress your interviewers with your in-depth knowledge and practical skills.

Java 10 Topics -Part-2
Info on Java 10 Topics
Java 10 introduced groundbreaking container awareness features, enabling the JVM to automatically detect and respect resource limits set by platforms like Docker and Kubernetes. This means Java applications can now reliably adapt to memory and CPU constraints in cloud and containerized deployments, resulting in safer, more efficient and predictable performance.
In this comprehensive set of 200 interview questions, you’ll find practical examples and outputs covering everything from JVM flags and resource detection to troubleshooting, monitoring, deployment patterns, and hybrid cloud scenarios. These questions will help you understand how Java 10 manages resources in containers, tunes JVM behavior for microservices and cloud-native apps, and tackles edge cases encountered in modern DevOps and cloud environments.
Whether you’re a developer, architect, or DevOps engineer, mastering these container-focused Java 10 features is essential for building scalable, robust, and cloud-ready Java applications.
Root Certificates
Question 1. What are root certificates in Java 10?
// Root certificates are trusted CA certificates included in the Java runtime.
Output: Trusted CA certificates in JRE.
Question 2. How do you list the root certificates in a Java 10 installation?
keytool -list -keystore $JAVA_HOME/lib/security/cacerts -storepass changeit
Output: Lists CA certificates (aliases, issuers).
Question 3. What is the default password for the Java root certificate keystore?
// "changeit"
Output: changeit
Question 4. How can you programmatically access root certificates?
KeyStore ks = KeyStore.getInstance("JKS");
try (FileInputStream fis = new FileInputStream(System.getProperty("java.home") +
"/lib/security/cacerts")) {
ks.load(fis, "changeit".toCharArray());
System.out.println(ks.size());
}
Output: (Number of certificates)
Question 5. Can you add a custom certificate to the Java root CA store?
keytool -import -trustcacerts -file mycert.crt -keystore $JAVA_HOME/lib/security/cacerts -storepass changeit
Output: Certificate added to keystore.
Question 6. How do you verify if a certificate is trusted by Java 10?
// If it chains to a root certificate in $JAVA_HOME/lib/security/cacerts, it's trusted.
Output: Certificate is trusted if chain is valid.
Question 7. How do you remove a certificate from the Java root store?
keytool -delete -alias mycert -keystore $JAVA_HOME/lib/security/cacerts -storepass changeit
Output: Certificate removed.
Question 8. What format are root certificates stored in?
// Java Key Store (JKS).
Output: JKS format.
Question 9. What is the alias for the default root CA in Java 10?
keytool -list -keystore $JAVA_HOME/lib/security/cacerts -storepass changeit
Output: Aliases like “verisignclass1ca”, “digicert”, etc.
Question 10. How do you update root certificates in Java 10?
// Replace $JAVA_HOME/lib/security/cacerts with updated keystore.
Output: Keystore replaced or updated.
Question 11. Can you use root certificates for HTTPS connections in Java 10?
URLConnection conn = new URL("https://example.com").openConnection();
conn.connect(); // Uses JRE root CAs for TLS
Output: HTTPS connection succeeds if CA is trusted.
Question 12. How do you check certificate validity programmatically?
X509Certificate cert = ...;
cert.checkValidity();
Output: Throws exception if expired/not yet valid.
Question 13. What happens if a root certificate expires?
// All certificates chaining to it are no longer trusted.
Output: SSL/TLS connections may fail.
Question 14. How do you list expired certificates in the Java keystore?
Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
Certificate cert = ks.getCertificate(alias);
if (cert instanceof X509Certificate) {
try { ((X509Certificate) cert).checkValidity(); }
catch (Exception e) { System.out.println(alias + " expired"); }
}
}
Output: List of expired certificate aliases.
Question 15. Can you use root certificates for client authentication?
// Only for validating server certificates; client certs must be separately configured.
Output: Root CAs for trust, not identity.
Question 16. How do you get the issuer of a root CA certificate?
X509Certificate cert = ...;
System.out.println(cert.getIssuerDN());
Output: Issuer DN printed.
Question 17. Can you export a root certificate from Java keystore?
keytool -export -alias rootca -file rootca.crt -keystore $JAVA_HOME/lib/security/cacerts -storepass changeit
Output: rootca.crt file created.
Question 18. How does Java 10 ensure the integrity of root certificates?
// JRE ships with signed keystore; updates must be trusted.
Output: Keystore integrity ensured by distribution.
Question 19. How do you programmatically check if a CA is present?
Certificate cert = ks.getCertificate("verisignclass1ca");
System.out.println(cert != null);
Output: true (if present)
Question 20. Can you replace all root certificates in the Java keystore?
// Yes, but not recommended; may break trust for many sites.
Output: All root CAs replaced.
Question 21. How do you handle a certificate validation exception in Java?
try {
X509Certificate cert = ...;
cert.checkValidity();
} catch (CertificateException e) {
System.err.println("Certificate validation failed: " + e.getMessage());
}
Output: Certificate validation failed: [reason]
Question 22. How do you check if a certificate is self-signed?
X509Certificate cert = ...;
boolean isSelfSigned = cert.getIssuerDN().equals(cert.getSubjectDN());
System.out.println(isSelfSigned);
Output: true (if self-signed)
Question 23. How do you programmatically build a certificate chain in Java?
List<X509Certificate> chain = Arrays.asList(cert1, cert2, rootCert);
CertPath cp = CertificateFactory.getInstance("X.509").generateCertPath(chain);
System.out.println(cp.getCertificates().size());
Output: (Number of certificates in chain)
Question 24. How do you validate a certificate chain against the root store?
PKIXParameters params = new PKIXParameters(ks);
params.setRevocationEnabled(false);
CertPathValidator cpv = CertPathValidator.getInstance("PKIX");
CertPath cp = ...; // built as above
cpv.validate(cp, params);
Output: Throws exception if chain is invalid.
Question 25. How do you configure a custom keystore for trust in Java?
System.setProperty("javax.net.ssl.trustStore", "/path/to/keystore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "secret");
Output: JVM uses custom trust store.
Question 26. How do you load a PKCS12 keystore for root certificates?
KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(new FileInputStream("mykeystore.p12"), "password".toCharArray());
System.out.println(ks.size());
Output: Number of certificates in PKCS12 store.
Question 27. How do you handle missing keystore file errors?
try {
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream("missing.jks"), "secret".toCharArray());
} catch (FileNotFoundException e) {
System.err.println("Keystore file not found");
}
Output: Keystore file not found
Question 28. How do you handle incorrect keystore password errors?
try {
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream("keystore.jks"), "wrongpass".toCharArray());
} catch (IOException e) {
System.err.println("Incorrect password or I/O error");
}
Output: Incorrect password or I/O error
Question 29. How do you create a new keystore and add a certificate programmatically?
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(null, null);
ks.setCertificateEntry("mycert", cert);
try (FileOutputStream fos = new FileOutputStream("newkeystore.jks")) {
ks.store(fos, "mypassword".toCharArray());
}
Output: Keystore created with one certificate.
Question 30. How do you list all aliases in a keystore?
Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
System.out.println(aliases.nextElement());
}
Output: List of aliases.
Question 31. How do you validate certificate expiration for all entries in a keystore?
Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
Certificate cert = ks.getCertificate(alias);
if (cert instanceof X509Certificate) {
try { ((X509Certificate) cert).checkValidity(); }
catch (Exception e) { System.out.println(alias + " expired"); }
}
}
Output: Aliases with expired certificates.
Question 32. How do you programmatically remove a certificate from a keystore?
ks.deleteEntry("aliasToRemove");
Output: Certificate removed from keystore.
Question 33. How do you import a certificate into a keystore programmatically?
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate cert = cf.generateCertificate(new FileInputStream("cert.crt"));
ks.setCertificateEntry("newalias", cert);
Output: Certificate imported with alias “newalias”.
Question 34. How do you set a custom trust store for an SSLContext?
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream("keystore.jks"), "password".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ks);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, tmf.getTrustManagers(), null);
SSLContext.setDefault(ctx);
Output: SSLContext uses custom trust store.
Question 35. How do you handle trust store loading errors in SSL connections?
try {
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, tmf.getTrustManagers(), null);
} catch (Exception e) {
System.err.println("SSLContext initialization failed: " + e.getMessage());
}
Output: SSLContext initialization failed: [reason]
Question 36. How do you update the default Java trust store at runtime?
System.setProperty("javax.net.ssl.trustStore", "mytruststore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "secret");
Output: Default trust store changed for JVM.
Question 37. How do you use a PEM file for a trust store in Java?
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate cert = cf.generateCertificate(new FileInputStream("root.pem"));
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(null, null);
ks.setCertificateEntry("pemcert", cert);
Output: PEM certificate added to keystore.
Question 38. How do you check if an alias exists in a keystore?
System.out.println(ks.containsAlias("myalias"));
Output: true or false
Question 39. How do you use multiple trust stores in a single JVM process?
// You must merge them into one, or use custom SSLContext per connection.
Output: Multiple trust stores via custom SSLContext.
Question 40. How do you remove all expired certificates from a keystore?
Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
Certificate cert = ks.getCertificate(alias);
if (cert instanceof X509Certificate) {
try { ((X509Certificate) cert).checkValidity(); }
catch (Exception e) { ks.deleteEntry(alias); }
}
}
Output: Expired certificates deleted.
Garbage Collector Improvements
Question 41. What GC improvements were introduced in Java 10?
// Parallel Full GC for G1, better container awareness, continued improvements in garbage collection.
Output: Faster, more efficient GC.
Question 42. How do you enable G1 GC in Java 10?
java -XX:+UseG1GC -jar app.jar
Output: JVM uses G1 garbage collector.
Question 43. What is Parallel Full GC for G1?
// Full garbage collections in G1 are now multi-threaded.
Output: Reduced pause times during full GC.
Question 44. How do you view GC logs in Java 10?
java -Xlog:gc -jar app.jar
Output: GC log output to console.
Question 45. How do you tune G1 GC parallel threads?
java -XX:ParallelGCThreads=8 -XX:+UseG1GC -jar app.jar
Output: G1 GC uses 8 threads for parallel phases.
Question 46. How do you force a full GC in Java 10?
System.gc();
Output: Full GC triggered (may run in parallel for G1).
Question 47. How does G1 Parallel Full GC improve performance?
// By running full GC phases in parallel, pause times are reduced.
Output: Shorter and more predictable GC pauses.
Question 48. How do you check which GC is being used?
java -XX:+PrintCommandLineFlags -version
Output: Flags list includes active GC.
Question 49. Can you use CMS collector in Java 10?
java -XX:+UseConcMarkSweepGC -jar app.jar
Output: CMS is deprecated, may warn.
Question 50. How do you monitor GC performance?
java -Xlog:gc* -jar app.jar
Output: Detailed GC logs.
Question 51. What happens when heap size exceeds container memory limit?
// JVM in Java 10 recognizes container limits (if running in a container).
Output: Heap constrained to container limit.
Question 52. How do you set max GC pause for G1?
java -XX:MaxGCPauseMillis=200 -XX:+UseG1GC -jar app.jar
Output: G1 GC tries to keep pause below 200ms.
Question 53. How do you get GC stats programmatically?
List<GarbageCollectorMXBean> beans = ManagementFactory.getGarbageCollectorMXBeans();
for (GarbageCollectorMXBean bean : beans) {
System.out.println(bean.getName() + ": " + bean.getCollectionCount());
}
Output: GC name and collection count.
Question 54. How do you disable explicit GC calls?
java -XX:+DisableExplicitGC -jar app.jar
Output: System.gc() calls ignored.
Question 55. Can you use Epsilon GC in Java 10?
java -XX:+UseEpsilonGC -jar app.jar
Output: Not available in Java 10 (added in Java 11).
Question 56. How do you set initial heap size in Java 10?
java -Xms512m -jar app.jar
Output: Initial heap size set to 512MB.
Question 57. How do you set max heap size in Java 10?
java -Xmx1024m -jar app.jar
Output: Max heap set to 1GB.
Question 58. How do you check GC overhead in Java?
java -XX:+PrintGCDetails -jar app.jar
Output: GC details show overhead percent.
Question 59. How do you log GC events to a file?
java -Xlog:gc:file=gc.log -jar app.jar
Output: GC events written to gc.log.
Question 60. How do you tune G1 GC for low-latency applications?
java -XX:+UseG1GC -XX:MaxGCPauseMillis=50 -jar app.jar
Output: G1 GC tuned for low pause times.
Question 61. How do you trigger a GC and measure its duration?
long start = System.nanoTime();
System.gc();
long end = System.nanoTime();
System.out.println("GC took " + (end - start)/1_000_000 + "ms");
Output: GC took [duration]ms
Question 62. How do you tune G1 GC for throughput?
java -XX:+UseG1GC -XX:G1HeapRegionSize=32M -XX:InitiatingHeapOccupancyPercent=60 -jar app.jar
Output: G1 tuned for throughput.
Question 63. How do you enable GC logging with timestamps?
java -Xlog:gc:gc.log:time -jar app.jar
Output: GC logs include timestamps.
Question 64. What happens if you set a very small heap size?
java -Xmx32m -jar app.jar
Output: May throw OutOfMemoryError if app needs more memory.
Question 65. How do you monitor GC frequency at runtime?
List<GarbageCollectorMXBean> beans = ManagementFactory.getGarbageCollectorMXBeans();
for (GarbageCollectorMXBean bean : beans) {
System.out.println(bean.getName() + ": " + bean.getCollectionCount());
}
Output: GC collection counts printed.
Question 66. How do you set the number of G1 GC threads?
java -XX:ParallelGCThreads=4 -XX:+UseG1GC -jar app.jar
Output: G1 GC uses 4 threads.
Question 67. What flag controls G1 GC region size?
java -XX:G1HeapRegionSize=8m -XX:+UseG1GC -jar app.jar
Output: Region size set to 8MB.
Question 68. How do you tune young generation size for G1?
java -XX:G1NewSizePercent=30 -XX:+UseG1GC -jar app.jar
Output: G1 young gen is 30% of heap.
Question 69. How do you log only full GC events?
java -Xlog:gc+phases=debug -jar app.jar
Output: Logs include full GC phases.
Question 70. How do you check if JVM is using parallel full GC for G1?
java -Xlog:gc+phases=debug -XX:+UseG1GC -jar app.jar
Output: Log shows parallel workers for full GC.
Question 71. How do you reduce pause times for G1 GC?
java -XX:MaxGCPauseMillis=100 -XX:+UseG1GC -jar app.jar
Output: G1 tries to keep pause < 100ms.
Question 72. How do you handle OutOfMemoryError in Java?
try {
byte[] arr = new byte[Integer.MAX_VALUE];
} catch (OutOfMemoryError e) {
System.err.println("OOM: " + e.getMessage());
}
Output: OOM: Java heap space
Question 73. Can you tune GC for a specific application pattern?
java -XX:+UseG1GC -XX:G1ReservePercent=10 -jar batch-app.jar
Output: Reserve 10% heap for promotion failures.
Question 74. How do you monitor GC metrics in a container?
docker stats [container_id]
Output: Shows memory/CPU used by JVM (indirect GC impact).
Question 75. How do you force a GC from command line?
jcmd <pid> GC.run
Output: GC triggered in running JVM.
Question 76. How do you log GC events in JSON format?
java -Xlog:gc:file=gc.json -jar app.jar
Output: GC events in gc.json (parseable).
Question 77. How do you analyze GC logs for tuning?
java -Xlog:gc:file=gc.log -jar app.jar
# Use gcviewer, JClarity, or GCEasy to analyze gc.log
Output: GC analysis with external tool.
Question 78. How do you set minimum heap size for JVM?
java -Xms128m -jar app.jar
Output: Heap starts at 128MB.
Question 79. How do you enable verbose GC details?
java -XX:+PrintGCDetails -jar app.jar
Output: Verbose GC details to stdout.
Question 80. What is the effect of -XX:ConcGCThreads with G1 GC?
java -XX:ConcGCThreads=2 -XX:+UseG1GC -jar app.jar
Output: 2 threads for concurrent G1 GC phases.
Question 81. How do you handle GC tuning for low-latency services?
java -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:G1HeapRegionSize=2m -jar app.jar
Output: G1 tuned for sub-20ms pauses.
Question 82. Can you disable GC logs in Java 10?
java -Xlog:gc:none -jar app.jar
Output: No GC logs printed.
Question 83. How do you monitor GC using JMX?
// Connect with JConsole or VisualVM, inspect GarbageCollectorMXBeans.
Output: GC stats in JMX client.
Question 84. How do you set JVM to exit on OOM?
java -XX:+ExitOnOutOfMemoryError -jar app.jar
Output: JVM exits immediately on OOM.
Question 85. How do you log GC safepoint events?
java -Xlog:safepoint -jar app.jar
Output: Safepoint events logged.
Question 86. What is the effect of -XX:G1MixedGCCountTarget?
java -XX:G1MixedGCCountTarget=8 -XX:+UseG1GC -jar app.jar
Output: G1 does up to 8 mixed GCs after marking.
Question 87. How do you tune G1 for batch jobs?
java -XX:+UseG1GC -XX:G1HeapWastePercent=10 -jar batch-app.jar
Output: G1 allows 10% heap waste before reclaim.
Question 88. How do you troubleshoot excessive GC pauses?
java -Xlog:gc* -jar app.jar
# Review logs for pause cause (long full GCs, promotion failures).
Output: Logs diagnose pause sources.
Question 89. How do you set G1 survivor space size?
java -XX:SurvivorRatio=8 -XX:+UseG1GC -jar app.jar
Output: Survivor space ratio changed.
Question 90. How do you ensure JVM runs with G1 and not another collector?
java -XX:+UseG1GC -XX:+PrintGC -jar app.jar
Output: Logs confirm G1 in use.
Question 91. How do you handle GC overhead limit exceeded error?
try {
// Allocate lots of memory rapidly
} catch (OutOfMemoryError e) {
if (e.getMessage().contains("GC overhead limit exceeded")) {
System.err.println("GC overhead error!");
}
}
Output: GC overhead error!
Question 92. How do you check GC statistics with VisualVM?
// Attach VisualVM to JVM, open GC tab for stats.
Output: Visualized GC metrics.
Question 93. Can you use G1 GC with aggressive heap shrinking?
java -XX:+UseG1GC -XX:+AlwaysPreTouch -XX:G1HeapRegionSize=1m -jar app.jar
Output: G1 can shrink heap aggressively.
Question 94. How do you handle GC configuration errors?
java -XX:BadFlag -jar app.jar
Output: JVM startup error for unknown flag.
Question 95. How do you track GC duration for each collection?
java -Xlog:gc* -jar app.jar
Output: GC duration in logs.
Question 96. How do you disable GC for testing?
// Not possible; JVM always performs GC.
Output: GC cannot be disabled.
Question 97. Can you force JVM to use serial GC in Java 10?
java -XX:+UseSerialGC -jar app.jar
Output: JVM uses Serial GC.
Question 98. How do you check heap usage after GC?
System.gc();
long heap = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
System.out.println("Used heap: " + heap);
Output: Used heap after GC.
Question 99. How do you log GC causes and types?
java -Xlog:gc+cause -jar app.jar
Output: Logs show GC cause/type.
Question 100. How do you set G1 max heap regions?
java -XX:G1HeapRegionSize=32m -XX:+UseG1GC -jar app.jar
Output: Region size set; max regions auto-calculated.
Experimental Java-Based JIT Compiler
Question 101. What is the experimental Java-based JIT compiler in Java 10?
// Graal JIT, enabled as an experimental feature.
Output: Graal JIT available.
Question 102. How do you enable the Graal JIT compiler?
java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -jar app.jar
Output: JVM uses Graal JIT.
Question 103. How can you confirm Graal is being used?
java -XX:+PrintCompilation -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -jar app.jar
Output: Compilation log shows Graal.
Question 104. What is JVMCI?
// Java Virtual Machine Compiler Interface; allows Java-based JIT compilers.
Output: JVMCI enables Graal/other JITs.
Question 105. Can you use Java-based JIT for all Java applications?
// Yes, but Graal is experimental in Java 10.
Output: Any app can use Graal with proper flags.
Question 106. How do you benchmark with and without Graal JIT?
java -jar app.jar
java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -jar app.jar
Output: Compare performance.
Question 107. Can you configure Graal JIT options?
java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -Dgraal.Option=value -jar app.jar
Output: Graal options set.
Question 108. Does Graal JIT support all JVM languages?
// Yes; Java, Scala, Kotlin, etc.
Output: Multi-language support.
Question 109. How do you troubleshoot JVMCI initialization errors?
java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -jar app.jar
Output: Error log shows JVMCI issues.
Question 110. Can you use Graal JIT for AOT compilation?
// Graal supports AOT but not in Java 10's experimental mode.
Output: AOT not available in Java 10.
Question 111. How do you enable JVMCI in Java 10?
java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -jar app.jar
Output: JVMCI enabled.
Question 112. How do you activate Graal as the JIT compiler?
java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -jar app.ja
Output: Graal JIT used for compilation.
Question 113. How can you check if Graal is being used?
java -XX:+PrintCompilation -XX:+UseJVMCICompiler -jar app.jar
Output: Compilation log includes Graal entries.
Question 114. What does JVMCI stand for?
// Java Virtual Machine Compiler Interface
Output: JVMCI: Java Virtual Machine Compiler Interface
Question 115. Can you use Graal with the default Java 10 distribution?
// Yes, but must enable experimental flags.
Output: Graal is available as experimental.
Question 116. How do you run Java with JVMCI debugging enabled?
java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+JVMCIPrintProperties -jar app.jar
Output: JVMCI properties printed at startup.
Question 117. Can you set Graal options via system properties?
java -Dgraal.PrintCompilation=true -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -jar app.jar
Output: Graal prints compilation info.
Question 118. How do you troubleshoot JVMCI initialization errors?
java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -jar app.jar
Output: Error message describes JVMCI issue.
Question 119. Can Graal be used for AOT (Ahead-of-Time) compilation in Java 10?
// No. AOT support is not included in Java 10's experimental Graal.
Output: AOT unavailable in Java 10.
Question 120. How do you benchmark Graal JIT performance?
java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -jar benchmark.jar
Output: Compare results to baseline JVM.
Question 121. Can Graal compile code for languages other than Java?
// Yes; supports JVM languages like Kotlin, Scala, Groovy.
Output: Multi-language compilation supported.
Question 122. How do you get Graal version information?
java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -version
Output: JVM prints version, JVMCI and Graal info.
Question 123. What happens if JVMCI initialization fails?
java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -jar app.jar
Output: JVM falls back to default HotSpot JIT.
Question 124. Can you use JVMCI and Graal in a container?
FROM openjdk:10
CMD java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -jar app.jar
Output: Graal runs in container.
Question 125. How do you enable Graal for specific classes/methods only?
// Use JVMCI compiler options or annotations (advanced, not standard in Java 10).
Output: Selective compilation possible with config.
Question 126. Can Graal be used for performance tuning?
// Yes, experiment with Graal flags and compare performance.
Output: Tune performance using Graal.
Question 127. How do you disable Graal after enabling JVMCI?
java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -jar app.jar
Output: JVM uses default compiler, not Graal.
Question 128. Can JVMCI be used for custom Java-based compilers?
// Yes, JVMCI allows plugging in custom JIT compilers.
Output: Custom JITs possible via JVMCI.
Question 129. What is the effect of -XX:+UseJVMCICompiler?
java -XX:+UseJVMCICompiler -jar app.jar
Output: JVM uses JVMCI-based compiler (e.g., Graal).
Question 130. How do you log Graal compiler events?
java -Dgraal.PrintGraph=true -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -jar app.jar
Output: Graal logs compilation graphs.
Question 131. What are typical JVMCI errors?
// Initialization failures, missing classes, incompatible flags.
Output: Error message with details.
Question 132. How do you monitor JVMCI compilation statistics?
java -Dgraal.PrintCompilation=true -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -jar app.jar
Output: Compilation statistics printed.
Question 133. Can you use JVMCI for native image generation in Java 10?
// No; Native image is not supported in Java 10.
Output: Native image not available.
Question 134. How do you check if JVMCI is active at runtime?
System.out.println(System.getProperty("jvmci.Compiler"));
Output: Shows JVMCI compiler name (e.g., Graal).
Question 135. Can JVMCI work with all JVM arguments and options?
// Most options work; some may conflict with JVMCI/Graal.
Output: Depends on option compatibility.
Question 136. How do you troubleshoot performance regressions with Graal?
java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -Dgraal.PrintCompilation=true -jar app.jar
Output: Analyze logs for slow methods.
Question 137. Can JVMCI be used for research or academic compilers?
// Yes; JVMCI is designed for JIT research.
Output: Academic compilers supported.
Question 138. How do you deploy Java apps using Graal in cloud containers?
FROM openjdk:10
CMD java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -jar app.jar
Output: Cloud container runs Graal JIT.
Question 139. How do you use JVMCI in a multi-language polyglot VM?
// Use GraalVM (not standard in Java 10, but experimental JVMCI can be a base).
Output: Polyglot features with JVMCI base.
Question 140. Can JVMCI be used for production workloads in Java 10?
// Not recommended; JVMCI and Graal are experimental in Java 10.
Output: Experimental only, not for production.
Container Awareness
Question 141. What is container awareness in Java 10?
// JVM recognizes container memory and CPU limits (e.g., Docker, Kubernetes).
Output: JVM limits heap/threads per container specs.
Question 142. How does JVM detect container memory limits?
java -XX:+PrintFlagsFinal -version | grep MaxRAM
Output: MaxRAM flags reflect container memory limits.
Question 143. How do you run Java 10 in a Docker container with memory limits?
FROM openjdk:10
CMD ["java", "-jar", "app.jar"]
# Run container: docker run -m 512m myapp
Output: JVM limits heap to 512MB.
Question 144. How do you verify JVM is respecting container CPU limits?
java -XX:ActiveProcessorCount=2 -jar app.jar
Output: JVM uses only 2 processors.
Question 145. What flags affect container resource detection?
java -XX:+UseContainerSupport -jar app.jar
Output: JVM uses container resource limits.
Question 146. How do you disable container awareness?
java -XX:-UseContainerSupport -jar app.jar
Output: JVM ignores container limits.
Question 147. How do you set custom heap limits in a container?
java -Xmx256m -jar app.jar
Output: Heap set to 256MB regardless of container.
Question 148. Can JVM container awareness be used in Kubernetes?
resources:
limits:
memory: "1Gi"
Output: JVM limits heap to 1GB.
Question 149. How do you log JVM container detection events?
java -Xlog:os+container=info -jar app.jar
Output: Logs show resource detection.
Question 150. What happens if you exceed container memory limits?
// JVM may be killed by container runtime (OOM).
Output: Process terminated (OutOfMemoryError).
Question 151. How does JVM determine available CPUs in a container?
java -XX:+UseContainerSupport -jar app.jar
Output: JVM detects CPU quota and sets thread pool size.
Question 152. Can you override container CPU limits from JVM?
java -XX:ActiveProcessorCount=1 -jar app.jar
Output: JVM uses 1 processor, overrides detected value.
Question 153. How do you test JVM container awareness locally?
docker run -m 256m openjdk:10 java -XshowSettings:vm -version
Output: JVM settings reflect container limits.
Question 154. Can JVM use all host resources if running outside a container?
// Yes; not limited if not in a container.
Output: JVM uses host resources.
Question 155. How do you set thread count according to container CPU quota?
int threads = Runtime.getRuntime().availableProcessors();
System.out.println(threads);
Output: Reflects container CPU limit.
Question 156. Can JVM container awareness be disabled for debugging?
java -XX:-UseContainerSupport -jar app.jar
Output: JVM uses host limits.
Question 157. How do you monitor JVM container resource usage?
top, docker stats, or JVM logs.
Output: Resource usage shown.
Question 158. Does JVM container awareness affect GC behavior?
// Yes; GC sizing adapts to container limits.
Output: GC sizing matches container resources.
Question 159. Can you run multiple JVMs in a single container?
// Yes, but they share container limits.
Output: All JVMs share resources.
Question 160. How does container awareness improve cloud deployments?
// JVM runs efficiently within resource quotas, improving stability and predictability.
Output: Cloud apps scale and run reliably.
Question 161. How do you run a Java 10 app in a Docker container with CPU limits?
docker run --cpus 1 openjdk:10 java -jar app.jar
Output: JVM restricts threads and parallelism to 1 CPU.
Question 162. How do you check JVM heap allocation in a container?
java -XshowSettings:vm -version
Output: Shows heap size and detected container memory limits.
Question 163. How do you override container memory detection with JVM flags?
java -Xmx256m -XX:-UseContainerSupport -jar app.jar
Output: JVM uses 256MB, ignores container memory.
Question 164. What JVM flag enables container awareness by default in Java 10?
java -XX:+UseContainerSupport -jar app.jar
Output: Container support enabled.
Question 165. How does JVM detect container CPU quota on Kubernetes?
resources:
limits:
cpu: "2"
Output: JVM detects and uses 2 CPUs.
Question 166. How do you monitor JVM process resource usage in a container?
docker stats [container_id]
Output: Shows CPU and memory usage.
Question 167. How do you log JVM container awareness events?
java -Xlog:os+container=trace -jar app.jar
Output: Detailed container resource detection logs.
Question 168. Can you run Java 10 on Alpine Linux in containers?
FROM openjdk:10-jre-slim
Output: Java runs in slim container.
Question 169. What happens if JVM is started with more heap than container limit?
docker run -m 128m openjdk:10 java -Xmx256m -jar app.jar
Output: JVM may be killed by container runtime (OOM).
Question 170. How do you ensure JVM respects both CPU and memory limits in Kubernetes?
resources:
limits:
cpu: "1"
memory: "512Mi"
Output: JVM uses 1 CPU, 512MB memory.
Question 171. Can JVM resource detection be affected by cgroups v1 vs v2?
// Yes; JVM reads cgroup files for limits, implementation may differ.
Output: Detection varies by cgroup version.
Question 172. How do you troubleshoot JVM not respecting container limits?
java -XshowSettings:vm -version
Output: Check output; verify flags and container configuration.
Question 173. Can you restrict JVM thread count in containers?
java -XX:ActiveProcessorCount=2 -jar app.jar
Output: JVM uses only 2 threads for parallel tasks.
Question 174. How do you configure JVM for headless operation in containers?
java -Djava.awt.headless=true -jar app.jar
Output: JVM runs in headless mode.
Question 175. How do you check if JVM is running inside a container in code?
boolean isContainer = new File("/.dockerenv").exists();
System.out.println(isContainer);
Output: true (if running in Docker)
Question 176. How do you monitor JVM heap usage in a containerized app?
jcmd <pid> GC.heap_info
Output: Heap usage info.
Question 177. How do you deploy Java 10 apps using Helm charts in Kubernetes?
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- name: app
image: openjdk:10
resources:
limits:
memory: "256Mi"
cpu: "1"
Output: App deployed with resource limits.
Question 178. Can JVM container awareness be used in hybrid cloud deployments?
// Yes; JVM adapts to resource limits in any supported container runtime.
Output: Works in hybrid/multi-cloud.
Question 179. How do you monitor JVM memory from within the application?
long max = Runtime.getRuntime().maxMemory();
System.out.println("Max heap: " + max);
Output: Max heap in bytes.
Question 180. How do you set JVM to exit on out-of-memory in a container?
java -XX:+ExitOnOutOfMemoryError -jar app.jar
Output: JVM exits immediately on OOM.
Question 181. How do you restrict JVM to a single core in Docker?
docker run --cpus 1 openjdk:10 java -XX:ActiveProcessorCount=1 -jar app.jar
Output: JVM runs single-threaded.
Question 182. How do you set JVM to ignore container memory limits for testing?
java -XX:-UseContainerSupport -Xmx2g -jar app.jar
Output: JVM uses up to 2GB if available.
Question 183. How do you verify JVM detects correct container resources after scaling?
kubectl scale deployment app --replicas=5
Output: Each replica uses container limits.
Question 184. How do you handle JVM tuning in multi-tenant containers?
// Set conservative heap, thread, and GC limits for fairness.
Output: JVM settings for multi-tenant use.
Question 185. How do you monitor JVM garbage collection in a container?
java -Xlog:gc -jar app.jar
Output: GC logs in container.
Question 186. Can JVM container awareness be used with Java profiling tools?
// Yes; VisualVM, JMC, and others work in containers.
Output: Profiling supported.
Question 187. How do you handle JVM upgrades in container images?
FROM openjdk:10
# Update image to new Java version for upgrade.
Output: JVM upgraded in container.
Question 188. How do you troubleshoot JVM startup failures in containers?
docker logs [container_id]
Output: Startup error log.
Question 189. How do you set JVM environment variables in a container?
ENV JAVA_OPTS="-Xmx256m"
CMD java $JAVA_OPTS -jar app.jar
Output: JVM uses environment config.
Question 190. Can JVM detect resource limits in container orchestrators other than Kubernetes?
// Yes; Docker Swarm, Mesos, etc., as long as cgroups are used.
Output: Resource detection works.
Question 191. How do you monitor JVM thread usage in containers?
int threads = Thread.activeCount();
System.out.println("Threads: " + threads);
Output: Current thread count.
Question 192. How do you test JVM resource detection with different container runtimes?
docker run ...; podman run ...; containerd ...
Output: JVM adapts to runtime.
Question 193. How do you restrict JVM file descriptor usage in containers?
docker run --ulimit nofile=1024:1024 openjdk:10 java -jar app.jar
Output: JVM limited to 1024 file descriptors.
Question 194. How do you monitor JVM class loading in containers?
ClassLoadingMXBean cl = ManagementFactory.getClassLoadingMXBean();
System.out.println("Loaded classes: " + cl.getLoadedClassCount());
Output: Number of loaded classes.
Question 195. How do you handle JVM shutdown signals in containers?
Runtime.getRuntime().addShutdownHook(new Thread(() -> System.out.println("Shutting down")));
Output: Message printed on container stop.
Question 196. How do you test JVM’s container awareness for memory on different hosts?
docker run -m 512m openjdk:10 java -XshowSettings:vm -version
Output: Shows detected memory limit.
Question 197. Can JVM container awareness be disabled for backwards compatibility?
java -XX:-UseContainerSupport -jar app.jar
Output: Disables detection for legacy support.
Question 198. How do you ensure JVM logs are persisted in containers?
CMD java -jar app.jar > /var/log/app.log 2>&1
Output: Logs written to persistent file.
Question 199. How do you run JVM in a privileged container?
docker run --privileged openjdk:10 java -jar app.jar
Output: JVM can access all host resources.
Question 200. How does JVM container awareness enable elastic scaling in cloud deployments?
// JVM adapts to new resource quotas as containers start/stop, enabling reliable scaling.
Output: Elastic, efficient cloud scaling.
Conclusion
Embracing Java 10’s features accelerates your growth as a modern developer, equipping you with skills to build secure, high-performance, and cloud-ready applications. By mastering innovations like container awareness, improved garbage collection, JVMCI, Graal JIT, and robust security with root certificates, you are not just keeping up with the industry — you’re preparing to lead it. Dive deep into Java 10, experiment with its tools, and leverage its enhancements to solve real-world challenges. The future belongs to those who continually learn and adapt, and Java 10 is a powerful step on that journey.
Happy Learning! 🚀 Stay ahead in your coding journey — follow Byte Coders for the latest tutorials, updates, and tech insights. Don’t miss out — join our community today!
메타데이터
- post_id
- 98e06c1cb603
- slug
- top-1-200-interview-questions-on-java-10-topics-part-2-with-examples-output-98e06c1cb603
- url
- https://medium.com/@bytecoders/top-1-200-interview-questions-on-java-10-topics-part-2-with-examples-output-98e06c1cb603
- canonical_url
- https://medium.com/@bytecoders/top-1-200-interview-questions-on-java-10-topics-part-2-with-examples-output-98e06c1cb603
- author_url
- https://medium.com/@bytecoders
- status
- ok
- fetched_at
- 2026-06-26 03:39:16