131x Filetype PDF File size 0.90 MB Source: enos.itcollege.ee
Java Interview Questions i Java Interview Questions Java Interview Questions ii Contents 1 Object Oriented Programming (OOP) 1 1.1 Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.3 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.4 Abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.5 Differences between Abstraction and Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2 General Questions about Java 3 2.1 WhatisJVM?WhyisJavacalledthePlatformIndependentProgrammingLanguage? . . . . . . . . . . . . . . 3 2.2 WhatistheDifference between JDK and JRE ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2.3 Whatdoesthe“static” keyword mean ? Can you override private or static method in Java ? . . . . . . . . . . . . 3 2.4 Canyouaccessnonstatic variable in static context ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2.5 WhataretheDataTypessupportedbyJava? WhatisAutoboxingandUnboxing? . . . . . . . . . . . . . . . . 4 2.6 WhatisFunction Overriding and Overloading in Java ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.7 WhatisaConstructor, Constructor Overloading in Java and Copy-Constructor . . . . . . . . . . . . . . . . . . . 4 2.8 DoesJavasupport multiple inheritance ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.9 Whatisthedifference between an Interface and an Abstract class ? . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.10 What are pass by reference and pass by value ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 3 Java Threads 6 3.1 Whatisthedifference between processes and threads ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.2 Explain different ways of creating a thread. Which one would you prefer and why ? . . . . . . . . . . . . . . . . 6 3.3 Explain the available thread states in a high-level. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.4 Whatisthedifference between a synchronized method and a synchronized block ? . . . . . . . . . . . . . . . . 7 3.5 Howdoesthreadsynchronization occurs inside a monitor ? What levels of synchronization can you apply ? . . . 7 3.6 What’s a deadlock ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.7 HowdoyouensurethatNthreadscanaccessNresourceswithoutdeadlock? . . . . . . . . . . . . . . . . . . . 7 Java Interview Questions iii 4 Java Collections 8 4.1 Whatarethebasic interfaces of Java Collections Framework ? . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 4.2 WhyCollection doesn’t extend Cloneable and Serializable interfaces ? . . . . . . . . . . . . . . . . . . . . . . . 8 4.3 WhatisanIterator ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 4.4 Whatdifferences exist between Iterator and ListIterator ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 4.5 Whatisdifference between fail-fast and fail-safe ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.6 HowHashMapworksinJava? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.7 Whatistheimportance of hashCode() and equals() methods ? . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.8 Whatdifferences exist between HashMap and Hashtable ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.9 Whatisdifference between Array and ArrayList ? When will you use Array over ArrayList ? . . . . . . . . . . . 9 4.10 What is difference between ArrayList and LinkedList ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.11 What is Comparable and Comparator interface ? List their differences. . . . . . . . . . . . . . . . . . . . . . . . 10 4.12 What is Java Priority Queue ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.13 What do you know about the big-O notation and can you give some examples with respect to different data structures ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.14 What is the tradeoff between using an unordered array versus an ordered array ? . . . . . . . . . . . . . . . . . . 10 4.15 What are some of the best practices relating to the Java Collection framework ? . . . . . . . . . . . . . . . . . . 11 4.16 What’s the difference between Enumeration and Iterator interfaces ? . . . . . . . . . . . . . . . . . . . . . . . . 11 4.17 What is the difference between HashSet and TreeSet ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 5 GarbageCollectors 12 5.1 Whatisthepurpose of garbage collection in Java, and when is it used ? . . . . . . . . . . . . . . . . . . . . . . 12 5.2 WhatdoesSystem.gc() and Runtime.gc() methods do ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 5.3 Whenisthefinalize() called ? What is the purpose of finalization ? . . . . . . . . . . . . . . . . . . . . . . . . . 12 5.4 If an object reference is set to null, will the Garbage Collector immediately free the memory held by that object ? 12 5.5 Whatisstructure of Java Heap ? What is Perm Gen space in Heap ? . . . . . . . . . . . . . . . . . . . . . . . . 12 5.6 Whatisthedifference between Serial and Throughput Garbage collector ? . . . . . . . . . . . . . . . . . . . . . 13 5.7 WhendoesanObjectbecomeseligibleforGarbagecollection in Java ? . . . . . . . . . . . . . . . . . . . . . . 13 5.8 DoesGarbagecollection occur in permanent generation space in JVM ? . . . . . . . . . . . . . . . . . . . . . . 13 6 Exception Handling 14 6.1 WhatarethetwotypesofExceptions in Java ? Which are the differences between them ? . . . . . . . . . . . . . 14 6.2 Whatisthedifference between Exception and Error in java ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 6.3 Whatisthedifference between throw and throws ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 6.4 Whatistheimportance of finally block in exception handling ? . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 6.5 Whatwill happen to the Exception object after exception handling ? . . . . . . . . . . . . . . . . . . . . . . . . 14 6.6 Howdoesfinallyblockdiffer from finalize() method ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
no reviews yet
Please Login to review.