1. Which one of the following is NOT a reserved word in Java?
2. What will be the output of program? class Ab { public static void main(String[] ar) {System.out.print("hi"); } static { System.out.print("how"); } }
3. The Core Java platform provides many benefits to developers, including:
4. What is the correct way to create an instance of a class?
5. True of False? The strictfp keyword ensures that you get the same result on every platform if you perform operations in the floating point variable.
6. Given following code, what will be the output: import java.lang.reflect.Method; class Bar { private int bar(int a) { return a * a; } } public class Foo { public static void main(String[] args) { try { Bar bar = new Bar(); Method method = bar.getClass().getDeclaredMethod("bar", int.class); method.setAccessible(true); System.out.println(method.invoke(bar, new Integer(5))); } catch (Exception e) { e.printStackTrace(); System.out.println("Error"); } } }
7. Interfaces are useful for...
8. The Object.wait() method:
9. Which will legally declare, construct, and initialize an array?
10. A java class which extends another class is usually described with the word:
11. Finally is used to....
12. If a method or variable is marked as having the "private" access level, then it can only be accessed from:
13. What is an example of proper capitalization for a class name?
14. The "javac" command line tool is used to:
15. Java handles memory allocation and reuse using a process called:
16. Which additional keyword may be used with try-catch blocks?
17. The most reliable way to compare two Strings for equality is by:
18. The part of a "try" block that is always executed is:
19. To define a child class from the Parent class following is used:
20. What is the correct syntax for importing java.util.Scanner?
21. If we want a class not to be overridden,the class must be done as
22. To document an API, which tool do you use?
23. Which of these are advantages of encapsulation in Java?
24. What is the most efficient way to concatenate a large number of strings in Java?
25. Which of the following is a valid constructor signature?
26. The Thread.sleep() method:
27. How can you stop your class from being inherited by another class?
28. public class SomeClass { public static void main(String[] args) { System.out.println((String) null); } } Does this code compile without errors?
29. When you create a thread with the “new” operator – which one of the following statements is true about its state
30. What method should you always override when you have overridden the equals() method?
31. Which of these is true?
32. Can an abstract class be a final class?
33. Keyword used to access members or methods of superclass?
34. What is auto boxing?
35. Reflection mechanism allows to:
36. package test; class Test { } ---------------- package test; class SubTest extends Test{ } Does this code compile without errors if the classes are in separate files?
37. What will be the output of the program? public class Foo { public static void main(String[] args) { try { return; } finally { System.out.println( "Finally" ); } } }
38. How can we use the class or jar files kept on the network path, within our projects?
39. What will below method return? public foo(){ int x = 5; return x; }
40. What is the output of the below code ? int a = 0; int b = 0; if (a++ == 1 || b++ == 1) {} System.out.println(a + " " + b);
41. How should you create a new class that maps keys to values, using the Java Collections Framework?
42. What is the benefit of ConcurrentHashMap<K,V>?
43. The "java" command line tool is used to:
44. JDBC addresses the issue of transactions.
45. Is it a good pratcice to catch "Throwable"?
46. The "static" keyword marks something as:
47. What are all the different types of access modifiers in Java
48. On which Java major release were Lambdas introduced?
49. When creating a user defined class for storing objects in a HashMap, which method(s) should be overridden?
50. The instanceof operator can be used to determine if an object is:
51. You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?
52. When the == comparator is used on two objects, it checks to see if they:
53. An "overloaded" method has what in common with one (or more) methods on the same class?
54. Why is it important to override hashCode() when you override equals()?
55. What is the name of the method used to start a thread execution?
56. Which is the correct command to run an executable JAR file named program.jar?
57. Which one of the following statements is true about Java Beans?
58. Calling System.gc() when using a modern JVM :
59. What is the output? int[] xxx = {10, 20}; List<String> list = new ArrayList<String>(10); list.add("01"); list.add("02"); System.out.println(xxx.length + ", " +list.size());
60. A class may extend:
61. Immutable objects are always...
62. What is the correct statement for handling RuntimeException?
63. Java provides a class for mutable sequences of characters, called:
64. What is the difference between a checked and unchecked exception?
65. Which class/classes is/are thread safe among these?
66. Which one of these lists contains only Java programming language keywords?
67. In addition to CORBA, Core Java also supports network services using:
68. A method without an access modifier (i.e. public, private, protected) is...
69. Which is a reserved word in the Java programming language?
70. The List interface has which superinterfaces?
71. enum Example { ONE, TWO, THREE } Which statement is true?
72. Which of the following is used to see the details of compilation
73. Which option is true for StringBuffer and StringBuilder
74. After the following code fragment, what is the value in a? String s; int a; s = "Foolish boy."; a = s.indexOf("fool");
75. Java's automatic memory management:
76. public class SomeClass { public static void main(String[] args) { System.out.println((String) null); } } What is the result of the following program?
77. Java's String class is
78. Output of Program: class Test {public static void main(String[] ar) {int i=0; if(i) System.out.print("hi"); else System.out.print("bye"); } }
79. Which of the following is true about overloading vs overriding methods?
80. enum Example { ONE, TWO, THREE } Which statement is true?
81. ’blank" final variable (defined without an initial value:
82. How do you convert int[] to a ArrayList<Integer>?
83. What is a weak reference?
84. Which is a valid keyword in java?
85. A class implementing a singleton pattern has...
86. What is the direct parent of "Error" class?
87. Java source code is compiled into
88. What is the issue with the following code? String s = ""; for(int i = 0; i < 1000000; i++) { s += Integer.toString(i); }
89. Java variables are passed into methods as:
90. Can the "main" method be overloaded
91. What will be printed out if you attempt to compile and run the following code? int i=9; switch (i) { default: System.out.println("default "); case 0: System.out.println("zero "); break; case 1: System.out.println("one "); case 2: System.out.println("two "); }
92. Which of the following statements about static inner classes is true?
93. class X implements Runnable { public static void main(String args[]) { /* Missing code? */ } public void run() {} } Which of the following line of code is suitable to start a thread ?
94. Does interrupt() always force all threads to terminate?
95. What type should you use for floating point monetary calculations?
96. Is "Method" a part of Java Reflection API
97. To create a single instance of a class, we can go with
98. Which statement is true?
99. In your program, you need to read a zip file (myfile.zip) containing several other data files containing basic Java objects. Which of the following will allow you to construct a InputStream for the task?
100. Float p = new Float(3.14f); if (p > 3) { System.out.print("p is bigger than 3. "); } else { System.out.print("p is not bigger than 3. "); } finally { System.out.println("Have a nice day."); } What is the result?
101. All of the classes in the Java Collections Framework:
102. Anonymous inner classes have access to...
103. What's the output of following error ? class A { public Number getNumber(){ return 1; } } class B extends A { public int getNumber(){ return 2; } } public class Main{ public static void main(String []args){ A a = new B(); System.out.println(a.getNumber()); } }
104. java.util.Collection is:
105. Does Java 8 allow static methods in interfaces?
106. LinkedBlockingQueue is useful for...
107. Which four options describe the correct default values for array elements of the types indicated? 1. int -> 0 2. String -> "null" 3. Dog -> null 4. char -> '\u0000' 5. float -> 0.0f 6. boolean -> true
108. Which one of the following statements is true about threads in Java
109. Given the code: Integer i= new Integer("1"); if (i.toString() == i.toString()) System.out.println("Equal"); else System.out.println("Not Equal");
110. which statement is True ?
111. The keyword that ensures a field is coherently accessed by multiple threads is:
112. A "blank" final variable (defined without an initial value):
113. The TreeMap class is Java's implementation of which data structure?
114. Which two are valid constructors for Thread? 1. Thread(Runnable r, String name) 2. Thread() 3. Thread(int priority) 4. Thread(Runnable r, ThreadGroup g) 5. Thread(Runnable r, int priority)
115. I would implement a LRU cache using only JDK classes by...
116. What is the output of the following program? import java.lang.reflect.Method; class TestImpl { public void method() {} public static void main(String[] args) { Method method = TestImpl.class.getMethod("method", null); System.out.println(method.getName()); } }
117. Which code fragments correctly create and initialize a static array of int elements?
118. True or false: Lambdas allow you to change single instance's method logic
119. Which of the following are not a valid declarations?
120. You need to keep a list of one million objects sorted at all times having 100 random inserts and delete per second. Reads from the list are always done in sorted order. You would:
121. What is the output? public static void main(String[] args) { int x=10; if(x++ > 9 && x++ == 12){ ++x; } System.out.println(x); }
122. What is the output of the below code ? int a = 0; int b = 0; if (a++ == 1 && b++ == 1); System.out.println(a + " " + b);
123. public class Test{ public static void main(String [] arg){ int x=10; if(x++ > 10 && x++ == 12){ ++x; } System.out.println(x); } } What is the Output of this code?
124. You want to listen TCP connections on port 9000. How would you create the socket?
125. The TreeMap and LinkedHashMap classes:
126. Which of the following is true about the Cloneable interface?
127. @Inject annotation belongs to
128. Livelock describes a situation in which two or more threads block each other, because:
129. Given a class containing the following pieces of code: ---------------------- public static <T> List getList() { return new ArrayList<T>(); } // ... List<?> list = new ArrayList<Integer>(); ---------------------- Adding which of the following lines would cause the class to not compile?
130. What will be the output of this code? class Main { static abstract class Base { protected Base() { init(); } abstract void init(); } static class Child extends Base { private final int value; public Child() { value = 5; } @Override public void init() { System.out.println("value = " + value); } } public static void main(String[] args) { Child c = new Child(); } }
131. A Guarded Block is a concurrency idiom in which:
132. What is super class of all classes in Java?
133. ConcurrentModificationException extends .......
134. HTML based Java Documentary help can be accessed using.. ?
135. HashMap is non-synchronized ?
136. Do Hashtable allow null keys and null values?
137. Which one is most suitable to implement an LRU cache?
138. ConcurrentModificationException will be thrown only when an object is concurrently modified.
139. The data members of interface in java are:
140. What is @Override annotation used for?
141. which is the default package in every java program?
142. What is a LinkedHashSet?
143. which of the following is correct syntax of varargs
144. The JVM allows programmers to manipulate the registers of the underlying system
145. how java is platform independent?
146. Given a class containing the following pieces of code: public static <T> List getList() { return new ArrayList<T>(); } // ... List<?> list = new ArrayList<Integer>(); Adding which of the following lines would cause the class to not compile?
147. what is order of preference in method overloading
148. A RuntimeException is...
149. java.lang.Object is the super class of all the interfaces in java
150. True or False: All classes that can be instantiated must implement the class Object
151. Which of the following statements is false about objects?
152. What is the difference between HashMap and HashTable?