Programming Concepts using Java, End Term
ConcurrentHashMap is a hash table implementation that supports full concurrency of retrievals and high expected concurrency for updates. All operations on this collection are thread-safe. Consider the code given below that uses a ConcurrentHashMap, and answer the question that follows.
class Example extends Thread{ Map siMap; //Constructor is defined here public void run(){ siMap.put("D",4); }}public class FClass{ public static void main (String[] args) { Map<String, Integer> siMap = new ConcurrentHashMap<String, Integer>(); String[] str = {"A", "B", "C"}; Integer[] arr = {1, 2, 3}; for(int i = 0; i < str.length; i++){ siMap.put(str[i],arr[i]); }
Example t = new Example(siMap); t.start(); Set s = siMap.entrySet(); Iterator itr = s.iterator(); while(itr.hasNext()){ Map.Entry m = (Map.Entry)itr.next(); System.out.println(m.getKey() + " => " + m.getValue()); } }}Which of the following is NOT true about the given code?
ConcurrentHashMap is a hash table implementation that supports full concurrency of retrievals and high expected concurrency for updates. All operations on this collection are thread-safe. Consider the code given below that uses a ConcurrentHashMap, and answer the question that follows. class Example extends Thread{ Map siMap; //Constructor is defined here public void run(){ siMap.put("D",4); } } public class FClass{ public static void main (String[] args) { Map<String, Integer> siMap = new ConcurrentHashMap<String, Integer>(); String[] str = {"A", "B", "C"}; Integer[] arr = {1, 2, 3}; for(int i = 0; i < str.length; i++){ siMap.put(str[i],arr[i]); } Example t = new Example(siMap); t.start(); Set s = siMap.entrySet(); Iterator itr = s.iterator(); while(itr.hasNext()){ Map.Entry m = (Map.Entry)itr.next(); System.out.println(m.getKey() + " => " + m.getValue()); } } } Which of the following is NOT true about the given code? Consider the code given below. interface Callable{ void call(); } abstract class SmartPhone implements Callable{ //Line 1 public abstract void record(); } class Vivo extends SmartPhone{ public void call() { System.out.println("Vivo call"); } public void record() { System.out.println("Vivo record"); } } class IPhone extends SmartPhone{ public void call() { System.out.println("Iphone call"); } public void record() { System.out.println("Iphone record"); } } public class User { public static void showDetails(SmartPhone obj) { //Line 2 obj.call(); obj.record(); } public static void main(String[] args) { showDetails(new Vivo()); showDetails(new IPhone()); } } Choose the correct option regarding the code. Method Stream.iterate(e, f) returns an infinite sequential ordered Stream produced by iterative application of a function f to an initial element e, producing a Stream consisting of e, f(e), f(f(e)), etc. Based on the above information, consider the code given below, and answer the question that follows. public class Test { public static void main(String[] args) { Stream.iterate(2, n -> n+1) .map(n -> n + 2) .filter(n -> n % 2 != 0) .limit(4) .forEach((x) -> System.out.print(x + " ")); } } What will the output be?