1. | Which of the following are Java reserved words? 1 run |
|||||||
Answer: Option B Explanation: (2) - This is a Java keyword (3) - This is a Java keyword (1) - Is incorrect because although it is a method of Thread/Runnable it is not a keyword (4) - This is not a Java keyword the keyword is implements |
2. | What is the numerical range of char? |
|||||||
Answer: Option B Explanation: The char type is integral but unsigned. The range of a variable of type char is from 0 to 216-1 or 0 to 65535. Java characters are Unicode, which is a 16-bit encoding capable of representing a wide range of international characters. If the most significant nine bits of a char are 0, then the encoding is the same as seven-bit ASCII. |
3. | /* Missing Statement ? */ What line of code should replace the missing statement to make this program compile? |
|||||||
Answer: Option A Explanation: The usual method for using/importing the java packages/classes is by using an import statement at the top of your code. However it is possible to explicitly import the specific class that you want to use as you use it which is shown in the code above. The disadvantage of this however is that every time you create a new object you will have to use the class path in the case "java.io" then the class name in the long run leading to a lot more typing. |
4. | Which is valid declaration of a float? |
|||||||
Answer: Option A Explanation: Option A is valid declaration of float. Option B is incorrect because any literal number with a decimal point u declare the computer will implicitly cast to double unless you include "F or f" Option C is incorrect because it is a String. Option D is incorrect because "d" tells the computer it is a double so therefore you are trying to put a double value into a float variable i.e there might be a loss of precision. |
5. | Which collection class allows you to access its elements by associating a key with an element's value, and provides synchronization? |
|||||||
Answer: Option D Explanation: Hashtable is the only class listed that provides synchronized methods. If you need synchronization great; otherwise, use HashMap, it's faster. |
6. | Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO (first-in, first-out) sequence? |
|||||||
Answer: Option B Explanation: LinkedHashMap is the collection class used for caching purposes. FIFO is another way to indicate caching behavior. To retrieve LinkedHashMap elements in cached order, use the values() method and iterate over the resultant collection. |
7. | Which interface provides the capability to store objects using a key-value pair? |
|||||||
Answer: Option A Explanation: An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. |
8. | Which interface does java.util.Hashtable implement? |
|||||||
Answer: Option A Explanation: Hash table based implementation of the Map interface. |