Which is the Best Java Web Framework ?

Java - Interview Questions and Answers - Multiple Choice - Objective Test

Q1. Which access specifiers can be used with top level class ?

a. public or default
b. public or private
c. public or protected
d. protected or default
show Answer

Ans. public or default



Q2. Which of the following can be marked static ?

a. Methods , Variables and Initialization Blocks.
b. Methods , Variables , Initialization Blocks and Outer Classes and nested Classes.
c. Methods , Variables , Initialization Blocks and Outer Classes.
d. Methods , Variables , Initialization Blocks and nested Classes
show Answer

Ans. Methods , Variables , Initialization Blocks and nested Classes



Q3. Which of the following cannot be marked static ?

a. Constructors , Classes ( Outer ) , Classes ( nested ), Interfaces , Local variables , Inner Class methods and instance variables.
b. Constructors , Classes ( Outer ) , Interfaces , Local variables , Class variables , Class Methods , Inner Class methods and instance variables.
c. Constructors , Classes ( Outer ) , Interfaces , Local variables , Inner Class methods and instance variables.
d. Constructors , Classes ( Outer ) , Classes (Nested), Interfaces , Local variables , Inner Class methods and instance variables
show Answer

Ans. Constructors , Classes ( Outer ) , Interfaces , Local variables , Inner Class methods and instance variables.



Q4. Which is of the following is NOT TRUE for JVM ?

a. JVM reads Byte Code and generates Machine Code.
b. JVM is a virtual Machine that acts as a intermediary between Java Application and Host Operating System.
c. JVM reads Source Code and generates Byte Code.
d. JVM acts as a translator that translates different Machine code ( on the basis of Host Machine ) for a common Byte Code.
show Answer

Ans. JVM reads Source Code and generates Byte Code.



Q5. Interface can only have ...

a. Member elements and Methods.
b. Static Variables and Static Methods.
c. Static Final Variables and Instance Method Declarations.
d. Member Elements , Instance Methods, Static variables and Static Methods.
show Answer

Ans. Static Final Variables and Instance Method Declarations.



Q6. Which of the following collection maintain its elements in Natural Sorted order ?

a. HashMap
b. TreeMap
c. LinkedHashMap
d. LinkedMap
show Answer

Ans. TreeMap



Q7. Which of the following collections stores its elements in insertion Order ?

a. HashMap
b. TreeMap
c. LinkedHashMap
d. LinkedMap
show Answer

Ans. LinkedHashMap



Q8. If we add Enum constants to a sorted collection ( Treemap , TreeSet ), What will be the order in which they will be maintained ?

a. Sorted Collection wont maintain them in any order.
b. Insertion Order
c. Order in which constants are declared.
d. Natural Sorting Order.
show Answer

Ans. Order in which constants are declared.



Q9. If we try to add duplicate key to the HashMap, What will happen ?

a. It will throw an exception.
b. It won't add the new Element without any exception.
c. The new element will replace the existing element.
d. Compiler will identify the problem and will throw an error.
show Answer

Ans. The new element will replace the existing element.



Q10. In what order the elements of a HashSet are retrieved ?

a. Random Order
b. Insertion Order
c. Natural Sorting Order
d. Inverse Natural Sorting Order
show Answer

Ans. Random Order



Q11. Which of the following is not type of inner classes ?

a. Simple Inner Class
b. Static Nested Inner Class
c. Method Nested Static Inner Class
d. Anonymous Inner Class
show Answer

Ans. Method Nested Static Inner Class



Q12. Which of the following was not introduced with Java 5 ?

a. Generics
b. Strings within Switch
c. Enums
d. Annotations
show Answer

Ans. Strings within Switch



Q13. Which interface does java.util.Hashtable implement ?

a. List
b. Set
c. Collection
d. Map
show Answer

Ans. Map



Q14. Which of the following is false ?

a. HashMap came before HashTable.
b. HashMap allows null values whereas Hashtable doesn’t allow null values.
c. HashTable and HashMap allow Key-Value pairs.
d. Hashtable is synchronized whereas HashMap is not.
show Answer

Ans. HashMap came before HashTable.



Q15. Which of the following is true ?

a. We can serialize static variables
b. We can serialize transient variables
c. We can serialize final variables
d. We can serialize instance methods
show Answer

Ans. We can serialize final variables



Q16. Which of the following is not the use of this keyword ?

a. Passing itself to another method
b. To call the static method
c. Referring to the instance variable when local variable has the same name
d. Calling another constructor in constructor chaining
show Answer

Ans. To call the static method



Q17. Which of the collections allows null as the key ?

a. HashTable
b. HashMap
c. TreeMap
d. LinkedHashMap
show Answer

Ans. HashTable



Q18. What is the initial state of a thread when it is created and started ?

a. Wait
b. Running
c. Ready
d. Sleep
show Answer

Ans. Ready



Q19. What state does a thread enter when it terminates its processing?

a. Wait
b. Ready
c. Dead
d. Running
show Answer

Ans. Dead



Q20. How many bits are used to represent Unicode ?

a. 8 bits
b. 16 bits
c. 24 bits
d. 32 bits
show Answer

Ans. 16 bits



Q21. Overridden methods must have the same ...

a. name
b. name and argument list
c. name, argument list, and return type
d. name, argument list, return type and belong to the same class
show Answer

Ans. name and argument list



Q22. Which of the following annotation is used to avoid executing Junits ?

a. @explicit
b. @ignore
c. @avoid
d. @NoTest
show Answer

Ans. @ignore



Q23. Which of the following is usually not part of EAR file ?

a. Server Configuration files
b. HTML and Media Files
c. Application Configuration files
d. Class files
show Answer

Ans. Server Configuration files



Q24. Which of the following file is called deployment descriptor ?

a. application.xml
b. project.xml
c. web.xml
d. build.xml
show Answer

Ans. web.xml



Q25. How can we execute a Java class independently if it doesn't have a static main method ?

a. By initiating the flow in any of the static method
b. By initiating the flow in any of static block
c. By initiating the flow in any other instance method named as main
d. By initiating the flow in any other instance method named as main and making it final
show Answer

Ans. By initiating the flow in any of static block



Q26. What is the size of long data type ?

a. 16 bit
b. 32 bit
c. 64 bit
d. 128 bit
show Answer

Ans. 64 bit



Q27. What is the size of double type ?

a. 16 bit
b. 32 bit
c. 64 bit
d. 128 bit
show Answer

Ans. 64 bit



Q28. What is the size of short type ?

a. 8 bit
b. 16 bit
c. 32 bit
d. 128 bit
show Answer

Ans. 16 bit



Q29. Which keyword is used to provide explicit access of a code block to single thread ?

a. Transient
b. Final
c. Explicit
d. Synchronized
show Answer

Ans. Synchronized



Q30. Which of the following exception is thrown when we try to access element which is beyond the size ?

a. NullPointerException
b. ArrayIndexOutOfBoundException
c. ArithmeticException
d. ParseException
show Answer

Ans. ArrayIndexOutOfBoundException



Q31. Checked exception needs to be ...

a. Caught
b. Method needs to declare that it throws these exception
c. Either A or B
d. Both A and B
show Answer

Ans. Either A or B



Q32. Collections.sort can only be performed on ..

a. Set
b. List
c. Map
d. Any Collection implementation
show Answer

Ans. List



Q33. Effective Java 6 , TreeMap implements ...

a. Map Interface
b. SortedMap Interface
c. NavigableMap Interface
d. SortedNavigableMap Interface
show Answer

Ans. SortedMap Interface



Q34. Which of the following is not possible ?

a. try block followed by catch
b. try block followed by finally
c. try block followed by catch block and then finally
d. try block without catch or finally block
show Answer

Ans. try block without catch or finally block



Q35. Which of the following is not the difference between Singleton and Static class ( Class with static members only ) ?

a. Only one object can be created for Singleton class whereas No objects are created for static class.
b. Singleton class instance is initiated using new keyword whereas static class instance is created using static method.
c. Singleton class can be serialized whereas Static class cannot be.
d. Singleton Class can participate in runtime Polymorphism whereas Static class cannot.
show Answer

Ans. Singleton class instance is initiated using new keyword whereas static class instance is created using static method.



Q36. Which of the following is false about main method ?

a. It should be declared public and static
b. it should have only 1 argument of type String array
c. We can override main method
d. We can overload main method
show Answer

Ans. We can override main method



Q37. Which of the following is false about Constructors ?

a. Constructor can be overloaded
b. A no argument constructor is provided by the compiler if we declare only constructors with arguments.
c. Constructors shouldn't have any return types , not even void.
d. If super is not explicitly called, still super() is intrinsically added by the compiler.
show Answer

Ans. A no argument constructor is provided by the compiler if we declare only constructors with arguments.



Q38. Variables of an interface are intrinsically ...

a. transient
b. final
c. public
d. static
show Answer

Ans. transient



Q39. Which of the following class creates mutable objects ?

a. Boolean
b. File
c. String
d. StringBuffer
show Answer

Ans. StringBuffer



Q40. Which of the following is not true for final variables ?

a. They cannot be changed after initialization
b. They can be initialized within static method
c. They can be declared and initialized together at the same place
d. They can be initialized within constructor
show Answer

Ans. They can be initialized within static method



Q41. Which of the following is false for final ?

a. Final methods cannot be overriden
b. Final methods cannot be overloaded
c. Final classes cannot be subclassed
d. Final class cannot be abstract
show Answer

Ans. Final methods cannot be overloaded



Q42. Invoking start twice on same thread leads to ..

a. ClassCastException
b. NullPointerException
c. InterruptedException
d. IllegalStateException
show Answer

Ans. IllegalStateException



Q43. Which of the following is false about var args ?

a. Var Args argument should have data type followed by three dots
b. Three dots should be consecutive and not separated by even space
c. We cannot have space before and after the dots
d. If there is a var args in the method, it should be only one and the last one.
show Answer

Ans. We cannot have space before and after the dots



Q44. Which of the following is not valid var args declaration ?

a. int sum (int... numbers)
b. int sum (.int .. numbers)
c. int sum (int ... numbers)
d. int sum (int x, int ... numbers)
show Answer

Ans. int sum (.int .. numbers)



Q45. Strings in switch were introduced in Which Java version ?

a. Java 5
b. Java 6
c. Java 7
d. Java
show Answer

Ans. Java 6



Q46. Which of the following doesn't extend Collection interface ?

a. Set
b. List
c. Map
d. Queue
show Answer

Ans. Map



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus




×

Try our new Java Interview Questions Search Tool.

There are more than 1000 questions with practice tests.

It's updated daily and It's Awesome.


×

Try our new Java Practice Test tool.

There are more than 200 questions and expanding quickly. It's updated daily and It's Awesome.