13. final Path path = Paths.get(...);
Files.lines(path).forEach(System.out::println);
Question 12:
What is the problem with this code:
14. What will be the contents of the list after this
operation and why?
Question 13:
final List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.remove(2);
15. Write a function to detect if two strings are
anagrams (for example, SAVE and VASE)
Question 14:
16. What is the contract between equals and
hashCode of an object?
Question 15:
19. How does a JVM handle storing local
variables vs storing objects?
Question 18:
20. Identify the problem in the following code:
Question 19:
public class Foo {
public Foo() {
doSomething();
}
public void doSomething() {
System.out.println("do something acceptable");
}
}
public class Bar extends Foo {
public void doSomething() {
System.out.println("yolo");
Zoom zoom = new Zoom(this);
}
}
21. When do you use volatile variables?
Question 20:
22. Why do you need to use synchronized
methods or blocks?
Question 21:
23. What is the difference between HashMap and
ConcurrentHashMap?
Question 22:
24. When do you need to override the equals
and hashCode methods in Java?
Question 23:
29. What are checked and unchecked
exceptions? When do you use them?
Question 28:
30. int a = 1L; Won’t compile and
int b = 0; b += 1L; compiles fine.
Why ?
Question 29:
31. Why aren’t you allowed to extend more than
one class in Java but are allowed to
implement multiple interfaces?
Question 30:
32. Question 31:
Test t = null;
t.someMethod();
public static void someMethod() {
...
}
Why doesn’t the following code generate a
NullPointerException even when the
instance is null?
33. Question 32:
public class Test
{
public static void main(String[] args)
{
Integer a = 1000, b = 1000;
System.out.println(a == b);
Integer c = 100, d = 100;
System.out.println(c == d);
}
}
why does the first case print false while the
second case prints true?