Top [1–200] Interview Questions on Java 10 (Part-1) Topics with Examples & Output.
Hello, Welcome Readers !!! A Comprehensive Guide that covers below critical Java 10 Topics as below for your reference.
🚀 Top 200 Java 10 Interview Questions (Part 1) — With Real Examples & Output!
Welcome Readers !!
Kickstart your interview prep with the ultimate set of Java 10 questions! Discover key topics, hands-on code examples, and actual outputs to master the latest features and ace your next interview with confidence.
✨ Key Java 10 Features You Can’t Miss! ✨
Topics Covered :
Java 10 brought several critical updates that further modernized Java programming, focusing on developer productivity, performance, and maintainability. This comprehensive set of interview questions covers the most important Java 10 features:

Java 10 Topics
Question & Answers
Local Variable Type Inference (var keyword)
Question 1. How do you declare an integer using var in Java 10?
var x = 10;
System.out.println(x);
Output: 10
Question 2. How do you declare a string using var?
var message = "Hello Java 10";
System.out.println(message);
Output: Hello Java 10
Question 3. What is the inferred type of var y = 42L;?
var y = 42L;
System.out.println(((Object)y).getClass().getSimpleName());
Output: Long
Question 4. Can you use var for method parameters?
// No; Compilation error
Output: Compilation error
Question 5. Can you use var for instance variables?
// No; Compilation error
Output: Compilation error
Question 6. Can you use var for constructor parameters?
// No; Compilation error
Output: Compilation error
Question 7. Can you use var in enhanced for-loops?
List<String> list = List.of("A", "B");
for (var item : list) {
System.out.println(item);
}
Output: A B
Question 8. Can you use var in traditional for-loops?
for (var i = 0; i < 3; i++) {
System.out.println(i);
}
Output: 0 1 2
Question 9. Can you use var in try-with-resources?
try (var br = new java.io.BufferedReader(new java.io.StringReader("test"))) {
System.out.println(br.readLine());
}
Output: test
Question 10. What is the type of var list = List.of(1,2,3);?
var list = List.of(1,2,3);
System.out.println(list.getClass().getName());
Output: (java.util.ImmutableCollections$ListN or similar)
Question 11. Can var be used for lambda expressions?
// No; Compilation error
Output: Compilation error
Question 12. Can you use var for array declarations?
var arr = new int[]{1,2,3};
System.out.println(arr.length);
Output: 3
Question 13. What is the type of var arr = new String[]{"a","b"};?
var arr = new String[]{"a","b"};
System.out.println(arr.getClass().getSimpleName());
Output: String[]
Question 14. What is the output of var z = true;?
var z = true;
System.out.println(((Object)z).getClass().getSimpleName());
Output: Boolean
Question 15. How do you use var with generic types?
var map = new HashMap<String, Integer>();
map.put("A", 1);
System.out.println(map.get("A"));
Output: 1
Question 16. What is the type of var set = Set.of("x","y");?
var set = Set.of("x","y");
System.out.println(set.getClass().getName());
Output: (java.util.ImmutableCollections$SetN or similar)
Question 17. Can you assign null to a var variable?
// No; Compilation error because type cannot be inferred
var n = null;
Output: Compilation error
Question 18. Can you use var for anonymous inner classes?
var r = new Runnable() { public void run() { System.out.println("Hello"); } };
r.run();
Output: Hello
Question 19. Can you use var for interface references?
Runnable r = () -> System.out.println("Hi");
var r2 = r;
r2.run();
Output: Hi
Question 20. Can you use var for casting?
Object o = "Test";
var s = (String) o;
System.out.println(s);
Output: Test
Question 21. Can you use var for multiple declarations on a single line?
// No; Compilation error
var x = 1, y = 2;
Output: Compilation error
Question 22. Can you use var with diamond operator?
var list = new ArrayList<>();
list.add("X");
System.out.println(list.get(0));
Output: X
Question 23. Does var work with method return types?
// No; must use explicit type or inference in variable assignment
var foo() { return 3; }
Output: Compilation error
Question 24. Can you use var with primitive types?
var i = 99;
var d = 1.23;
System.out.println(i + " " + d);
Output: 99 1.23
Question 25. Can you use var with conditional assignment?
boolean flag = true;
var result = flag ? "yes" : "no";
System.out.println(result);
Output: yes
Question 26. Can you use var for static fields?
// No; Compilation error
Output: Compilation error
Question 27. Can you use var for local class declarations?
// No; Compilation error
var class Local { }
Output: Compilation error
Question 28. When is var resolved?
// At compile time
Output: Compile-time type inference
Question 29. Can you use var for method reference assignments?
var ref = System.out::println;
ref.accept("Method Ref");
Output: Method Ref
Question 30. How do you use var with streams?
var stream = List.of(1,2,3).stream();
stream.forEach(System.out::println);
Output: 1 2 3
Question 31. Can you use var for a method reference with inferred type?
var printer = System.out::println;
printer.accept("Hello");
Output: Hello
Question 32. What is the inferred type of var s = new StringBuilder("abc");?
var s = new StringBuilder("abc");
System.out.println(s.getClass().getSimpleName());
Output: StringBuilder
Question 33. Can you use var for declaring a variable outside a block and assign inside?
var x; // Compilation error
x = 5;
Output: Compilation error
Question 34. Can you use var in catch blocks?
try { throw new Exception("Oops"); } catch (var e) { System.out.println(e.getMessage()); }
Output: Oops
Question 35. Can you use var in multi-catch blocks?
// No; Compilation error
try { throw new IOException(); } catch (var | Exception e) { }
Output: Compilation error
Question 36. Can you use var for loop indices in a for-each loop over a map?
Map<String, Integer> map = Map.of("A", 1, "B", 2);
for (var entry : map.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
Output: A:1 B:2
Question 37. Can you use var for the elements in a for-each loop over an array?
var arr = new int[]{1,2,3};
for (var el : arr) {
System.out.println(el);
}
Output: 1 2 3
Question 38. What happens if you try to redeclare a var variable?
var a = 5;
// var a = "again"; // Compilation error: duplicate local variable
Output: Compilation error
Question 39. Can you use var for a generic method's return value?
List<String> getList() { return List.of("A"); }
var list = getList();
System.out.println(list.get(0));
Output: A
Question 40. Can you use var with constructors returning different types?
// No; type must be determinable at compile time
var obj = Math.random() > 0.5 ? new ArrayList<>() : new HashSet<>();
Output: Compilation error
Question 41. What is the inferred type for var n = new Integer[]{1,2,3};?
var n = new Integer[]{1,2,3};
System.out.println(n.getClass().getSimpleName());
Output: Integer[]
Question 42. Can you use var in static initializer blocks?
static {
var x = 42;
System.out.println(x);
}
Output: 42
Question 43. Can you use var for local inner class instantiation?
class Outer {
void test() {
class Inner { String msg = "Hi"; }
var i = new Inner();
System.out.println(i.msg);
}
}
new Outer().test();
Output: Hi
Question 44. Can you use var for a ternary operator with both branches same type?
var result = true ? 1.1 : 2.2;
System.out.println(result);
Output: 1.1
Question 45. Can you use var for a ternary operator with branches of different types?
// No; Compilation error
var result = true ? 1 : "str";
Output: Compilation error
Question 46. Can you use var for a method return value in a lambda?
Function<String, Integer> f = s -> {
var len = s.length();
return len;
};
System.out.println(f.apply("abcd"));
Output: 4
Question 47. Can you use var for a stream filter predicate?
var list = List.of("a", "bb", "ccc");
var filtered = list.stream().filter(s -> { var len = s.length(); return len > 1; }).toList();
System.out.println(filtered);
Output: [bb, ccc]
Question 48. Can you use var for a multidimensional array?
var arr = new int[][]{{1,2},{3,4}};
System.out.println(Arrays.deepToString(arr));
Output: [[1, 2], [3, 4]]
Question 49. Can you use var for a raw type collection?
var list = new ArrayList();
list.add("raw");
System.out.println(list.get(0));
Output: raw
Question 50. Can you use var for a collection with inferred generics?
var list = new ArrayList<String>();
list.add("abc");
System.out.println(list.get(0));
Output: abc
Question 51. Can you use var in a switch block?
var num = 1;
switch (num) {
case 1: System.out.println("One"); break;
default: System.out.println("Other");
}
Output: One
Question 52. Can you use var for a collection created by stream operations?
var result = List.of(1,2,3).stream().map(x -> x*2).toList();
System.out.println(result);
Output: [2, 4, 6]
Question 53. Can you use var for a stream?
var stream = Stream.of("x", "y", "z");
stream.forEach(System.out::println);
Output: x y z
Question 54. Can var be used for a map entry reference in for-each loop?
var map = Map.of("A", 1, "B", 2);
for (var e : map.entrySet()) System.out.println(e);
Output: A=1 B=2
Question 55. Can you use var for a lambda variable declaration?
// No; Compilation error
var f = x -> x+1;
Output: Compilation error
Question 56. Can you use var for an Optional type?
var opt = Optional.of("val");
System.out.println(opt.isPresent());
Output: true
Question 57. Can you use var for an array element in a loop?
var arr = new String[]{"a", "b"};
for (var el : arr) System.out.println(el);
Output: a b
Question 58. Can you use var for a collection element in a loop?
var list = List.of(1,2,3);
for (var i : list) System.out.println(i);
Output: 1 2 3
Question 59. Can you use var for a stream map operation?
var result = List.of(1,2).stream().map(x -> x * 10).toList();
System.out.println(result);
Output: [10, 20]
Question 60. Can you use var for an object returned by a method?
String getStr() { return "Hello"; }
var s = getStr();
System.out.println(s);
Output: Hello
Question 61. Can you use var for an array returned by a method?
int[] getArr() { return new int[]{1,2}; }
var arr = getArr();
System.out.println(Arrays.toString(arr));
Output: [1, 2]
Question 62. Can you use var for a generic method return type?
<T> List<T> getList(T t) { return List.of(t); }
var list = getList("abc");
System.out.println(list.get(0));
Output: abc
Question 63. Can you use var for a nested generic type?
var map = new HashMap<String, List<Integer>>();
map.put("A", List.of(1,2));
System.out.println(map.get("A"))
Output: [1, 2]
Question 64. Can you use var for collection streams with filter and collect?
var nums = List.of(1,2,3,4,5);
var evens = nums.stream().filter(x -> x%2==0).collect(Collectors.toList());
System.out.println(evens);
Output: [2, 4]
Question 65. Can you use var for inferred type in a method body?
void test() {
var s = "abc";
System.out.println(s);
}
test();
Output: abc
Question 66. Can you use var for a value returned from a static method?
static int getVal() { return 100; }
var v = getVal();
System.out.println(v);
Output: 100
Question 67. Can you use var when the initializer is a method returning different types?
// No; type must be resolvable at compile time
var val = Math.random() > 0.5 ? 1 : "str";
Output: Compilation error
Question 68. Can you use var for a Map.Entry in iteration?
var map = Map.of("A", 1);
for (var entry : map.entrySet()) System.out.println(entry.getKey());
Output: A
Question 69. Can you use var for a functional interface variable?
var r = (Runnable) () -> System.out.println("Run");
r.run();
Output: Run
Question 70. Can you use var with final modifier?
final var x = 5;
System.out.println(x);
Output: 5
Question 71. Can you use var for chaining method calls?
var s = "abc".toUpperCase().substring(1);
System.out.println(s);
Output: BC
Question 72. Can you use var for inferred type in try-with-resources with AutoCloseable?
try (var br = new java.io.BufferedReader(new java.io.StringReader("test"))) {
System.out.println(br.readLine());
}
Output: test
Question 73. Is var a reserved keyword?
// Yes. Cannot use 'var' as variable, method, or class name.
Output: Compilation error if used as identifier
Question 74. Can you use var for inferring type of an enum?
enum Day { MON, TUE }
var d = Day.MON;
System.out.println(d.name());
Output: MON
Question 75. Can you use var for inferring type of a record (Java 16+)?
// Yes, but not in Java 10
Output: Not available in Java 10
Question 76. Can you use var with generics in enhanced for-loops?
List<List<String>> lists = List.of(List.of("A"), List.of("B"));
for (var l : lists) System.out.println(l);
Output: [A] [B]
Question 77. Can you use var for a stream of Optionals?
var stream = Stream.of(Optional.of("x"), Optional.empty());
stream.forEach(System.out::println);
Output: Optional[x] Optional.empty
Question 78. Can you use var for an OutputStream in try-with-resources?
try (var os = new java.io.ByteArrayOutputStream()) {
os.write("Hello".getBytes());
System.out.println(os.toString());
}
Output: Hello
Question 79. Can you use var for assigning a primitive from a boxed value?
Integer i = 5;
var j = i;
System.out.println(j + 1);
Output: 6
Question 80. Can you use var for catching checked exceptions in try-catch?
try { throw new IOException("IO"); } catch (var e) { System.out.println(e.getMessage()); }
Output: IO
Unmodifiable Collections Enhancements
Question 81. How do you create an unmodifiable list in Java 10?
List<String> list = List.of("A", "B");
System.out.println(list.getClass().getName());
Output: (java.util.ImmutableCollections$ListN or similar)
Question 82. Can you modify a list created by List.of()?
List<String> list = List.of("A", "B");
list.add("C");
Output: java.lang.UnsupportedOperationException
Question 83. How do you create an unmodifiable set using Set.copyOf()?
Set<String> orig = Set.of("x", "y");
Set<String> copy = Set.copyOf(orig);
System.out.println(copy.contains("x"));
Output: true
Question 84. How do you create an unmodifiable map using Map.copyOf()?
Map<String, Integer> orig = Map.of("A", 1);
Map<String, Integer> copy = Map.copyOf(orig);
System.out.println(copy.get("A"));
Output: 1
Question 85. What happens if you pass a modifiable collection to Set.copyOf()?
Set<String> modSet = new HashSet<>();
modSet.add("Z");
Set<String> unmodSet = Set.copyOf(modSet);
unmodSet.add("Y");
Output: java.lang.UnsupportedOperationException
Question 86. Can you use List.copyOf() with an empty list?
List<String> empty = new ArrayList<>();
List<String> unmod = List.copyOf(empty);
System.out.println(unmod.isEmpty());
Output: true
Question 87. What happens if you pass a collection with null to List.copyOf()?
List<String> list = new ArrayList<>();
list.add(null);
List<String> unmod = List.copyOf(list);
Output: java.lang.NullPointerException
Question 88. Can you use Map.copyOf() for a map with null keys?
Map<String, Integer> map = new HashMap<>();
map.put(null, 99);
Map<String, Integer> unmod = Map.copyOf(map);
Output: java.lang.NullPointerException
Question 89. What exception is thrown when removing from an unmodifiable set?
Set<String> set = Set.copyOf(Set.of("A"));
set.remove("A");
Output: java.lang.UnsupportedOperationException
Question 90. Can you use List.copyOf() on a List created by Arrays.asList()?
List<String> orig = Arrays.asList("A", "B");
List<String> unmod = List.copyOf(orig);
System.out.println(unmod.get(1));
Output: B
Question 91. Can you use List.copyOf() for a List with duplicates?
List<String> orig = List.of("A", "A", "B");
List<String> unmod = List.copyOf(orig);
System.out.println(unmod);
Output: [A, A, B]
Question 92. Can you use Set.copyOf() for a Set with duplicates?
Set<String> set = new HashSet<>();
set.add("A");
set.add("A");
Set<String> unmod = Set.copyOf(set);
System.out.println(unmod)
Output: [A]
Question 93. Is List.copyOf() always unmodifiable?
List<String> orig = List.of("A");
List<String> unmod = List.copyOf(orig);
unmod.add("B");
Output: java.lang.UnsupportedOperationException
Question 94. Can you create an unmodifiable collection from a stream?
List<String> orig = List.of("A", "B");
List<String> unmod = List.copyOf(orig.stream().collect(Collectors.toList()));
System.out.println(unmod.get(0));
Output: A
Question 95. Can you nest unmodifiable collections?
List<Set<String>> lists = List.of(Set.of("A"), Set.of("B"));
List<Set<String>> copy = List.copyOf(lists);
copy.get(0).add("X");
Output: java.lang.UnsupportedOperationException
Question 96. What happens if the source collection for copyOf is changed after copy?
List<String> orig = new ArrayList<>();
orig.add("A");
List<String> unmod = List.copyOf(orig);
orig.add("B");
System.out.println(unmod.size());
Output: 1
Question 97. Can you use copyOf on a sorted collection?
SortedSet<String> sorted = new TreeSet<>(Set.of("A", "B"));
Set<String> unmod = Set.copyOf(sorted);
System.out.println(unmod.contains("A"));
Output: true
Question 98. Can you use copyOf on a synchronized collection?
Set<String> syncSet = Collections.synchronizedSet(Set.of("A"));
Set<String> unmod = Set.copyOf(syncSet);
System.out.println(unmod.getClass().getName());
Output: (java.util.ImmutableCollections$SetN or similar)
Question 99. Can you use copyOf on a collection with custom objects?
class Node { int id; Node(int i) { id = i; } }
List<Node> nodes = List.of(new Node(1), new Node(2));
List<Node> unmod = List.copyOf(nodes);
System.out.println(unmod.size());
Output: 2
Question 100. Can you use copyOf on a collection with primitive arrays?
List<int[]> arrays = List.of(new int[]{1,2}, new int[]{3,4});
List<int[]> copy = List.copyOf(arrays);
System.out.println(Arrays.toString(copy.get(1)));
Output: [3, 4]
Question 101. Can you use List.copyOf() to create an unmodifiable list from a Set?
Set<String> set = Set.of("A", "B");
List<String> list = List.copyOf(set);
System.out.println(list);
Output: [A, B] (order not guaranteed)
Question 102. What happens if you use Set.copyOf() with a List containing duplicates?
List<String> list = List.of("A", "A", "B");
Set<String> set = Set.copyOf(list);
System.out.println(set);
Output: [A, B]
Question 103. How do you create an unmodifiable map with nested unmodifiable lists as values?
Map<String, List<String>> map = Map.of(
"A", List.of("a1", "a2"),
"B", List.of("b1")
);
Map<String, List<String>> unmodMap = Map.copyOf(map);
unmodMap.get("A").add("a3");
Output: java.lang.UnsupportedOperationException
Question 104. What is returned by List.copyOf(List.of())?
List<String> orig = List.of();
List<String> unmod = List.copyOf(orig);
System.out.println(unmod.isEmpty());
Output: true
Question 105. Can you use Map.copyOf() on a Map with mutable values?
Map<String, List<String>> map = new HashMap<>();
map.put("A", new ArrayList<>(List.of("a")));
Map<String, List<String>> unmod = Map.copyOf(map);
unmod.get("A").add("b")
Output: Allowed (the map is unmodifiable, but values are still mutable if not made unmodifiable first)
Question 106. What happens if you use Set.copyOf() with a synchronized set?
Set<String> syncSet = Collections.synchronizedSet(Set.of("A", "B"));
Set<String> unmodSet = Set.copyOf(syncSet);
unmodSet.add("C");
Output: java.lang.UnsupportedOperationException
Question 107. What is the type returned by List.copyOf() and Set.copyOf()?
List<String> list = List.copyOf(List.of("A"));
Set<String> set = Set.copyOf(Set.of("B"));
System.out.println(list.getClass().getName());
System.out.println(set.getClass().getName());
Output: (java.util.ImmutableCollections$ListN or similar) (java.util.ImmutableCollections$SetN or similar)
Question 108. Can you use List.copyOf() for a List with null elements?
List<String> list = new ArrayList<>();
list.add(null);
List<String> unmod = List.copyOf(list);
Output: java.lang.NullPointerException
Question 109. Can you remove elements from a Map created by Map.copyOf()?
Map<String, Integer> map = Map.copyOf(Map.of("A", 1));
map.remove("A");
Output: java.lang.UnsupportedOperationException
Question 110. Can you use List.copyOf() with a collection created by Collections.unmodifiableList()?
List<String> orig = Collections.unmodifiableList(List.of("A", "B"));
List<String> unmod = List.copyOf(orig);
System.out.println(unmod.equals(orig));
Output: true
Question 111. Can you use Set.copyOf() with a NavigableSet?
NavigableSet<String> navSet = new TreeSet<>(Set.of("A", "B"));
Set<String> unmodSet = Set.copyOf(navSet);
System.out.println(unmodSet.contains("A"));
Output: true
Question 112. What happens if you use Map.copyOf() with a map containing null values?
Map<String, Integer> map = new HashMap<>();
map.put("A", null);
Map<String, Integer> unmod = Map.copyOf(map);
Output: java.lang.NullPointerException
Question 113. Can you use Set.copyOf() on a collection of custom objects?
class Obj { int id; Obj(int i) { id = i; } }
Set<Obj> set = new HashSet<>();
set.add(new Obj(1)); set.add(new Obj(2));
Set<Obj> unmodSet = Set.copyOf(set);
System.out.println(unmodSet.size());
Output: 2
Question 114. Can you use List.copyOf() for a List with mixed types?
List<Object> list = List.of("A", 1, 2.2);
List<Object> unmod = List.copyOf(list);
System.out.println(unmod);
Output: [A, 1, 2.2]
Question 115. What happens if you use Map.copyOf() with duplicate keys?
Map<String, Integer> map = new HashMap<>();
map.put("A", 1); map.put("A", 2);
Map<String, Integer> unmod = Map.copyOf(map);
System.out.println(unmod.get("A"));
Output: 2 (latest value for duplicate key)
Question 116. Can you use List.copyOf() with a list containing itself?
List<Object> list = new ArrayList<>();
list.add(list);
List<Object> unmod = List.copyOf(list);
System.out.println(unmod.get(0) == unmod);
Output: true
Question 117. Can you use Set.copyOf() on a collection with nulls?
Set<String> set = new HashSet<>();
set.add(null);
Set<String> unmodSet = Set.copyOf(set);
Output: java.lang.NullPointerException
Question 118. Can you use Map.copyOf() for a Map created by Collections.unmodifiableMap()?
Map<String, Integer> orig = Collections.unmodifiableMap(Map.of("A", 1));
Map<String, Integer> unmod = Map.copyOf(orig);
System.out.println(unmod.equals(orig));
Output: true
Question 119. Can you use List.copyOf() with a LinkedList?
LinkedList<String> linked = new LinkedList<>(List.of("A", "B"));
List<String> unmod = List.copyOf(linked);
System.out.println(unmod.get(1));
Output: B
Question 120. Can you use Set.copyOf() for a collection with sorted order?
SortedSet<String> sorted = new TreeSet<>(Set.of("C", "A", "B"));
Set<String> unmod = Set.copyOf(sorted);
System.out.println(unmod);
Output: [A, B, C] (iteration order not guaranteed, but elements preserved)
Application Class Data Sharing (CDS)
Question 121. What is Application Class Data Sharing (CDS) in Java 10?
// CDS allows sharing common class metadata across JVM processes for faster startup and reduced memory footprint.
Output: Faster startup, lower memory usage
Question 122. How do you create a CDS archive?
java -Xshare:dump -XX:SharedArchiveFile=app-cds.jsa -cp app.jar
Output: app-cds.jsa (class data archive created)
Question 123. How do you use a CDS archive when starting a Java app?
java -XX:SharedArchiveFile=app-cds.jsa -cp app.jar MainClass
Output: App starts with shared class data
Question 124. Can CDS be used with user-defined classes?
// Yes, Java 10 supports application classes in CDS archive.
Output: User classes loaded from archive
Question 125. How do you check if CDS is enabled?
java -Xshare:on -XX:SharedArchiveFile=app-cds.jsa -cp app.jar MainClass
Output: JVM uses CDS archive
Question 126. What happens if CDS archive is missing?
java -XX:SharedArchiveFile=missing.jsa -cp app.jar MainClass
Output: Error: Unable to open shared archive file
Question 127. Can you use CDS with JVM options?
java -XX:SharedArchiveFile=app-cds.jsa -Xmx512M -cp app.jar MainClass
Output: App runs with specified JVM options and CDS
Question 128. Can CDS be used with modular JARs?
// Yes; CDS supports modules in Java 10
Output: Modules loaded from CDS
Question 129. Can you use CDS for multiple applications?
// No; one archive per application/classpath
Output: Separate archive needed per app
Question 130. Can you use CDS for faster JVM startup time?
// Yes; CDS improves startup performance
Output: Faster startup
Question 131. Can CDS archive be reused across JVM restarts?
// Yes; as long as classpath is unchanged
Output: Archive reused
Question 132. Can CDS work with dynamic class loading?
// No; only classes in archive are shared
Output: Dynamically loaded classes not shared
Question 133. Can you use CDS with different JVM versions?
// No; archive must match JVM version
Output: Version mismatch error
Question 134. Can CDS reduce memory usage for microservices?
// Yes; shared metadata reduces footprint
Output: Lower memory use across JVMs
Question 135. Can CDS be used with containerized Java apps?
// Yes; improves performance for containers
Output: Containers start faster
Question 136. How do you disable CDS?
java -Xshare:off -cp app.jar MainClass
Output: CDS not used
Question 137. Can you update a CDS archive?
// Must recreate archive after code changes
Output: Archive updated after code change
Question 138. Can CDS be used with security policies?
// Yes; works with Java security manager
Output: Security manager functions normally
Question 139. Can you inspect contents of a CDS archive?
jcmd <pid> VM.classloaders
Output: Class loader info displayed
Question 140. Can CDS be used with JVM debugging?
// Yes; debug mode works with CDS
Output: Debugging enabled
Question 141. Can you use CDS with a custom class loader?
// No; only classes loaded by the system class loader are supported by CDS.
Output: Custom class loaders not supported.
Question 142. How do you troubleshoot a CDS archive not being used?
java -Xlog:cds -XX:SharedArchiveFile=app-cds.jsa -cp app.jar MainClass
Output: Logs CDS events; can help identify why archive is not loaded.
Question 143. Can you use CDS with classpath wildcards?
java -XX:SharedArchiveFile=app-cds.jsa -cp "lib/*" MainClass
Output: CDS archive must be generated with the same classpath including wildcards.
Question 144. How do you verify which classes are included in a CDS archive?
java -XX:SharedArchiveFile=app-cds.jsa -Xlog:cds -cp app.jar MainClass
Output: CDS logs show which classes are loaded from the archive.
Question 145. Can you use CDS with exploded (unpacked) JARs?
java -XX:SharedArchiveFile=app-cds.jsa -cp classes/ MainClass
Output: Yes, if archive was created with the same classpath.
Question 146. Can you use CDS with multiple JARs in the classpath?
java -XX:SharedArchiveFile=app-cds.jsa -cp "a.jar:b.jar" MainClass
Output: Archive must be created with both JARs in classpath.
Question 147. How do you regenerate a CDS archive after updating a dependency?
java -Xshare:dump -XX:SharedArchiveFile=app-cds.jsa -cp updated_app.jar
Output: New archive includes updated classes.
Question 148. Can you use CDS in a Docker container?
FROM openjdk:10
COPY app.jar .
COPY app-cds.jsa .
CMD ["java", "-XX:SharedArchiveFile=app-cds.jsa", "-cp", "app.jar", "MainClass"]
Output: CDS works inside the container if paths match.
Question 149. Can you share a CDS archive between containers?
# Mount app-cds.jsa from shared volume
VOLUME /cds
CMD ["java", "-XX:SharedArchiveFile=/cds/app-cds.jsa", ...]
Output: Yes, as long as classpath and JVM version are identical.
Question 150. Can you use CDS for rapid scaling in cloud deployments?
// Yes; pre-generated CDS archives reduce startup time for new containers/VMs.
Output: Faster scaling in cloud environments.
Question 151. How do you handle CDS archive corruption?
rm app-cds.jsa
java -Xshare:dump -XX:SharedArchiveFile=app-cds.jsa -cp app.jar
Output: Recreate archive after deletion.
Question 152. Can CDS be used for applications with dynamically generated classes?
// No; only classes known at archive creation time are shared.
Output: Dynamic classes not included.
Question 153. Can you use CDS in mixed deployment (some JVMs with, some without archive)?
// Yes; JVMs without archive fall back to normal class loading.
Output: App runs with/without CDS, but startup differs.
Question 154. How do you optimize CDS usage for microservices?
// Create a shared archive for common libraries used by all microservices.
Output: Improved memory efficiency and startup for all services.
Question 155. Can you use CDS in JVM debugging sessions?
java -XX:SharedArchiveFile=app-cds.jsa -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -cp app.jar MainClass
Output: CDS works with JDWP debugging enabled.
Question 156. How do you troubleshoot “Unable to use shared archive” errors?
java -Xlog:cds -XX:SharedArchiveFile=app-cds.jsa -cp app.jar MainClass
Output: Check logs for version mismatch, classpath differences, or corruption.
Question 157. Can you use CDS with Java agents?
java -javaagent:agent.jar -XX:SharedArchiveFile=app-cds.jsa -cp app.jar MainClass
Output: Yes, but agents may load classes not included in the archive.
Question 158. Can you use CDS for performance benchmarking?
// Yes; compare startup and memory with/without CDS enabled.
Output: Benchmark shows performance improvement.
Question 159. Can you inspect CDS archive contents post-creation?
jcmd <pid> VM.classloaders
Output: Shows which classes are loaded from CDS.
Question 160. Can you use CDS for mixed Java versions in the same infrastructure?
// No; each Java version requires its own archive.
Output: Archives are JVM-version specific.
Thread-Local Handshake
Question 161. What is Thread-Local Handshake in Java 10?
// JVM can execute a callback on threads without needing a global stop-the-world pause.
Output: Improved JVM responsiveness
Question 162. How does Thread-Local Handshake improve garbage collection?
// Allows JVM to pause threads individually for GC safepoints
Output: Shorter GC pause times
Question 163. Can Thread-Local Handshake pause only one thread?
// Yes; JVM targets specific threads
Output: Single thread paused
Question 164. Is Thread-Local Handshake used for all safepoints?
// Used for many safepoint operations, not all
Output: More granular JVM pauses
Question 165. Can you trigger Thread-Local Handshake programmatically?
// No; managed internally by JVM
Output: Not exposed to user code
Question 166. Does Thread-Local Handshake affect thread scheduling?
// Can momentarily pause thread for safepoint
Output: Minimal impact on scheduling
Question 167. Is Thread-Local Handshake beneficial for large JVMs?
// Yes; reduces pause times
Output: Better scalability
Question 168. Can Thread-Local Handshake be disabled?
// No; core JVM feature
Output: Always active
Question 169. Does Thread-Local Handshake affect performance?
// Generally improves performance for JVM operations
Output: Faster JVM operations
Question 170. How does Thread-Local Handshake help with JVM safepoint polling?
// Enables targeted polling and callback per thread
Output: Efficient safepoint polling
Question 171. Is Thread-Local Handshake visible in JVM logs?
// May be visible with appropriate GC/safepoint logging
Output: Details in verbose logs
Question 172. Does Thread-Local Handshake require code changes?
// No; transparent to developers
Output: No code changes required
Question 173. Can Thread-Local Handshake improve JVM pause distribution?
// Yes; avoids global pauses
Output: Finer-grained pauses
Question 174. Does Thread-Local Handshake affect JVM startup?
// No direct impact on startup
Output: Startup unaffected
Question 175. Is Thread-Local Handshake relevant for single-threaded apps?
// Less benefit for single-threaded JVM
Output: Minimal impact
Question 176. Can Thread-Local Handshake help with thread termination?
// Yes; can execute callbacks before thread exit
Output: Safer thread termination
Question 177. Does Thread-Local Handshake interact with native threads?
// Works for JVM-managed threads
Output: Native thread support as managed by JVM
Question 178. Can Thread-Local Handshake be tuned?
// No; internal JVM feature
Output: No tuning options
Question 179. Is Thread-Local Handshake used by all JVM vendors?
// Implemented in OpenJDK, may vary by vendor
Output: Vendor-specific support
Question 180. Can Thread-Local Handshake reduce overall JVM latency?
// Yes; by reducing global pauses
Output: Lower latency
Question 181. Can Thread-Local Handshake improve throughput?
// By enabling more concurrent operations
Output: Potential throughput gain
Question 182. Is Thread-Local Handshake visible to monitoring tools?
// Only via JVM internal logs
Output: May be visible in GC/safepoint logs
Question 183. Does Thread-Local Handshake affect JIT compilation?
// Can be used for JIT safepoints
Output: Improved JIT responsiveness
Question 184. Can Thread-Local Handshake help with deadlock detection?
// Not directly; helps JVM operations
Output: No direct impact
Question 185. Is Thread-Local Handshake relevant for GC tuning?
// Can reduce GC pause time
Output: Helps with GC tuning
Question 186. Does Thread-Local Handshake affect Java thread API?
// No effect on Thread API
Output: API unchanged
Question 187. Can Thread-Local Handshake pause threads for other JVM events?
// Used for safepoints in various events
Output: Pauses for safepoint events
Question 188. Does Thread-Local Handshake require JVM flags?
// No; enabled by default
Output: No flags needed
Question 189. Can Thread-Local Handshake pause threads at arbitrary points?
// Pauses at JVM-defined safepoints
Output: Controlled by JVM
Question 190. Is Thread-Local Handshake a Java language feature?
// No; JVM implementation detail
Output: Not a language feature
Question 191. Can Thread-Local Handshake be observed in thread dumps?
// May be visible if thread is at safepoint
Output: Possible in thread dump
Question 192. Does Thread-Local Handshake affect JVM garbage collector choice?
// Works with all modern GCs
Output: GC-independent
Question 193. Can Thread-Local Handshake improve stop-the-world events?
// Yes; minimizes global impact
Output: Fewer global pauses
Question 194. Is Thread-Local Handshake used in Java 8?
// No; introduced in Java 10
Output: Not in Java 8
Question 195. Can Thread-Local Handshake benefit multi-core systems?
// Yes; concurrent thread pause
Output: Better multi-core scaling
Question 196. Does Thread-Local Handshake affect JVM crash recovery?
// No direct effect
Output: Crash recovery unchanged
Question 197. Can Thread-Local Handshake help with JVM profiling?
// Can aid safepoint-based profiling
Output: Improved profiling accuracy
Question 198. Is Thread-Local Handshake exposed in Java Management APIs?
// No; internal JVM process
Output: Not exposed
Question 199. Does Thread-Local Handshake affect thread priorities?
// No; priorities unchanged
Output: Priority unaffected
Question 200. Can Thread-Local Handshake improve JVM pause distribution in cloud deployments?
// Yes; enables more scalable cloud JVMs
Output: Better cloud JVM scalability
Conclusion & Benefits :
Mastering Java 10 features like local variable type inference (var), unmodifiable collections, Application Class Data Sharing (CDS), and Thread-Local Handshake empowers you to write cleaner, safer, and more efficient code. These updates help reduce verbosity, improve data integrity, optimize performance in modern deployments (such as containers and cloud), and make the JVM more responsive and scalable. Understanding and applying these enhancements will elevate your Java development skills and prepare you for advanced, real-world challenges.
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
- 1cdda1ace459
- slug
- top-1-200-interview-questions-on-java-10-part-1-topics-with-examples-output-1cdda1ace459
- url
- https://medium.com/@bytecoders/top-1-200-interview-questions-on-java-10-part-1-topics-with-examples-output-1cdda1ace459
- canonical_url
- https://medium.com/@bytecoders/top-1-200-interview-questions-on-java-10-part-1-topics-with-examples-output-1cdda1ace459
- author_url
- https://medium.com/@bytecoders
- status
- ok
- fetched_at
- 2026-06-26 03:39:16