Review these 50 questions to crack your Java programming interview

by javinpaul

Review these 50 questions to crack your Java programming interview

A list of frequently asked Java questions from programming job interviews.

cA9-wkkWif9KjVOo09g1D5s5OiE8KskLLfa- Hello, everybody ! Over the by few years, I have been sharing a batch of Java Interview questions and discussion individually. many of my readers have requested that I bring them together so that they can have them in the lapp spot. This post is the result of that. This article contains more than 50 Java Interview questions covering all important topics like Core Java fundamentals, Java Collection Framework, Java Multithreading and Concurrency, Java IO, JDBC, JVM Internals, Coding Problems, Object-Oriented scheduling, etc. The questions are besides picked up from assorted interviews and they are, by no means, identical unmanageable. You might have seen them already in your telephone or face-to-face round of interviews.

The questions are besides very utilitarian to review significant topics like multithreading and collections. I have besides shared some useful resources for promote learning and improvement like The Complete Java MasterClass to brush up and fill gaps in your Java skills. So what are we waiting for ? here is the tilt of some of the most frequently asked Java questions in interviews for both founder and experienced Java developers .

50+ Java Interview Questions for 2 to 3 years Experienced Programmers

so, without wasting any more of your clock time, here is my list of some of the frequently asked Core Java Interview Question second for novice programmers. This list focuses on beginners and less know devs, like person with 2 to 3 years of feel in Java. 1 ) How does Java achieve platform independence? ( answer )
trace : bytecode and Java Virtual Machine 2 ) What is ClassLoader in Java? ( answer )
hint : separate of JVM that loads bytecodes for classes. You can write your own. 3 ) Write a Java program to check if a number is Even or Odd? ( suffice )
touch : you can use bitwise hustler, like bitwise AND, remember, flush the number has zero at the goal in binary format and an odd number has 1 in the end. 4 ) Difference between ArrayList and HashSet in Java? ( answer )
touch : all differences between List and Set are applicable here, e.g. ordering, duplicates, random search, etc. See Java Fundamentals: Collections by Richard Warburton to learn more about ArrayList, HashSet and other important Collections in Java .ueOwMAd5GBdw4blCOpEBpOdMOtcs-et6nPYA 5 ) What is double checked locking in Singleton? ( answer )
hint : two-time determine whether instances is initialized or not, beginning without locking and second with lock. 6) How do you create thread-safe Singleton in Java? (answer)
hint : many ways, like using Enum or by using double-check lock practice or using a nest static course. 7) When to use the volatile variable in Java? (answer)
touch : when you need to instruct the JVM that a variable can be modified by multiple threads and give hint to JVM that does not cache its value. 8) When to use a transient variable in Java? (answer)
hint : when you want to make a variable non-serializable in a class, which implements the Serializable interface. In other words, you can use it for a variable whose measure you don ’ deoxythymidine monophosphate want to save. See The Complete Java MasterClass to learn about transient variables in Java. 9) Difference between the transient and volatile variable in Java? (answer)
hint : wholly different, one used in the context of serialization while the early is used in concurrence. 10) Difference between Serializable and Externalizable in Java? (answer)
hint : Externalizable gives you more control over the Serialization process. 11) Can we override the private method in Java? (answer)
touch : No, because it ’ s not visible in the subclass, a elementary prerequisite for overriding a method acting in Java. 12) Difference between Hashtable and HashMap in Java? (answer)
hint : respective but most important is Hashtable, which is synchronized, while HashMap is not. It ‘s besides bequest and slow a compared to HashMap. 13) Difference between Listand Set in Java? (answer)
touch : List is ordered and allows double. Set is ungraded and does n’t allow duplicate elements. 14) Difference between ArrayList and Vector in Java (answer)
hint : many, but most important is that ArrayList is non-synchronized and debauched while Vector is synchronized and slow. It ‘s besides bequest class like Hashtable. 15) Difference between Hashtable and ConcurrentHashMap in Java? (answer)
tip : more scalable. See Java Fundamentals: Collections by Richard Warburton to learn more. 16) How does ConcurrentHashMap achieve scalability? (answer)
trace : by dividing the map into segments and lone locking during the write operation. 17) Which two methods you will override for an Object to be used as Key in HashMap? (answer)
hint : equals and hashcode 18) Difference between wait and sleep in Java? (answer)
touch : The wait() method releases the lock or monitor, while sleep does n’t. 19) Difference between notify and notifyAll in Java? (answer)
hint : notify notifies one random string is waiting for that lock while notifyAll inform to all threads waiting for a monitor. If you are certain that only one thread is waiting then consumption notify, or else notifyAll is better. See Threading Essentials Mini-Course by Java Champion Heinz Kabutz to learn more about threading basics. 20) Why you override hashcode, along with equals() in Java? (answer)
tip : to be compliant with equals and hashcode condense, which is required if you are planning to store your object into collection classes, e.g. HashMap or ArrayList. 21) What is the load factor of HashMap means? (answer)
trace : The threshold that triggers the re-sizing of HashMap is by and large 0.75, which means HashMap resize itself if it ‘s 75 percentage broad. 22) Difference between ArrayList and LinkedList in Java? (answer)
trace : same as an array and linked list, one allows random search while early does n’t. Insertion and deletion slowly on the linked list but a search is easy on an array. See Java Fundamentals: Collections , Richard Warburton ’ mho course on Pluralsight, to learn more about essential Collection data structure in Java. 23) Difference between CountDownLatch and CyclicBarrier in Java? (answer)
tip : You can reuse CyclicBarrier after the barrier is broken but you can not reuse CountDownLatch after the count reaches to zero.

24) When do you use Runnable vs Thread in Java? (answer)
touch : constantly 25) What is the meaning of Enum being type-safe in Java? (answer)
hint : It means you can not assign an exemplify of different Enum type to an Enum varying. e.g. if you have a varying like DayOfWeek day then you can not assign it value from DayOfMonth enum. 26) How does Autoboxing of Integer work in Java? (answer)
hint : By using the valueOf() method acting in Java. 27) Difference between PATH and Classpath in Java? (answer)
tip : PATH is used by the engage system while Classpath is used by JVM to locate Java binary star, e.g. JAR files or Class files. See Java Fundamentals: The Core Platform to learn more about PATH, Classpath, and other Java environment variable .io-lPE67oMG1oBh204LvPm61t7kAcLFvp-B6 28) Difference between method overloading and overriding in Java? (answer)
tip : override happens at subclass while overloading happens in the lapp class. besides, overriding is a runtime activity while overloading is resolved at roll up time. 29) How do you prevent a class from being sub-classed in Java? (answer)
touch : just make its builder private 30) How do you restrict your class from being used by your client? (answer)
tip : make the builder private or throw an exception from the builder 31) Difference between StringBuilder and StringBuffer in Java? (answer)
touch : StringBuilder is not synchronized while StringBuffer is synchronized. 32) Difference between Polymorphism and Inheritance in Java? (answer)
touch : inheritance allows code recycle and builds the relationship between class, which is required by Polymorphism, which provides dynamic behavior. See Java Fundamentals: Object-Oriented Design to learn more about OOP features. 33) Can we override static method in Java? (answer)
trace : No, because overriding resolves at runtime while electrostatic method acting call is resolved at roll up time. 34) Can we access the private method in Java? (answer)
hint : yes, in the like class but not outside the class 35) Difference between interface and abstract class in Java? (answer)
trace : from Java 8, the dispute is blurred. however, a Java classify can still implement multiple interfaces but can only extend one class. 36) Difference between DOM and SAX parser in Java? (answer)
hint : DOM loads hale XML File in memory while SAX doesn ’ triiodothyronine. It is an event-based parser and can be used to parse a large file, but DOM is fast and should be preferred for small files. 37) Difference between throw and throws keyword in Java? (answer)
touch : throws declare what exception a method acting can throw in case of error but throw keyword actually throws an exception. See Java Fundamentals: Exception Handling to learn more about Exception handling in Java .QSqKD-b97Dr36kViV1eTdvqNVNgdZRp52D7n 38) Difference between fail-safe and fail-fast iterators in Java? (answer)
tip : fail-safe doesn ’ t throw ConcurrentModificationException while fail-fast does whenever they detect an away change on the underlie solicitation while iterating over it. 39) Difference between Iterator and Enumeration in Java? (answer)
hint : Iterator besides gives you the ability to remove an component while iterating while Enumeration doesn ’ thyroxine let that. 40) What is IdentityHashMap in Java? (answer)
hint : A Map, which uses the == equality hustler to check equality alternatively of the equals() method. 41) What is the String pool in Java? (answer)
hint : A pool of String literals. Remember it ‘s moved to heap from perm gen space in JDK 7. 42) Can a Serializable class contains a non-serializable field in Java? (answer)
hint : Yes, but you need to make it either static or ephemeral. 43) Difference between this and super in Java? (answer)
trace : this refers to the current case while extremely refers to an exemplify of the superclass. 44) Difference between Comparator and Comparable in Java? (answer)
hint : Comparator defines custom ordering while Comparable defines the natural orderliness of objects, e.g. the alphabetic order for String. See The Complete Java MasterClass to learn more about sorting in Java .DOCGFtdTMhjj3faRAiQ69ZSTxf2pffyroFfv 45) Difference between java.util.Date and java.sql.Date in Java? (answer)
touch : early contains both date and time while late contains only date contribution. 46) Why wait and notify method are declared in Object class in Java? (answer)
touch : because they require lock which is entirely available to an object. 47) Why Java doesn’t support multiple inheritances? (answer)
trace : It doesn ’ thyroxine support because of a bad know with C++, but with Java 8, it does in some common sense — only multiple inheritances of Type are not supported in Java now. 48) Difference between checked and unchecked Exception in Java? (answer)
tip : In lawsuit of checked, you must handle exception using catch parry, while in case of unbridled, it ’ s up to you ; compile will not bother you. 49) Difference between Error and Exception in Java? (answer)
tip : I am tired of typing please check the answer

50) Difference between Race condition and Deadlock in Java? (answer)
trace : both are errors that occur in a coincident application, one occur because of weave scheduling while others occur because of hapless cryptography. See Multithreading and Parallel Computing in Java to learn more about deadlock, Race Conditions, and other multithreading issues .

Closing Notes

Thanks, You made it to the conclusion of the article … Good luck with your programming interview ! It ’ s surely not going to be easy, but by following this roadmap and guide, you are one footprint closer to becoming a DevOps engineer. If you like this article, then please share with your friends and colleagues, and don ’ metric ton forget to follow javinpaul on chitter !

Additional Resources

P.S. — If you need some FREE resources to learn Java, you can check out this list of free Java courses to start your preparation.

P. S. S. — I have not provided the answer to the interview questions shared in the image “ How many String objects are created in the code?” can you guess and explain?

source : https://gauday.com
Category : interview

We will be happy to hear your thoughts

Leave a reply

GauDay Crypto news and market tracking in real time
Logo
Enable registration in settings - general