{"id":504,"date":"2026-04-29T18:15:35","date_gmt":"2026-04-29T18:15:35","guid":{"rendered":"https:\/\/logicnextgen.com\/tutorials\/?page_id=504"},"modified":"2026-05-23T16:33:06","modified_gmt":"2026-05-23T16:33:06","slug":"java-interview-questions-answers","status":"publish","type":"page","link":"https:\/\/logicnextgen.com\/tutorials\/java-interview-questions-answers\/","title":{"rendered":"Java Interview Questions &amp; Answers"},"content":{"rendered":"\n<p class=\"has-text-color has-link-color has-large-font-size wp-elements-1d40ded623f6ceef4c2a5dff08deb920 wp-block-paragraph\" style=\"color:#ff8d00\"><strong>Java Interview Questions &amp; Answers<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-57f6077ca9381f1b7e034ddda21aa08e\" style=\"color:#ff8d00\">1. <strong>What is Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Java is a high-level, object-oriented, platform-independent programming language used for developing web, desktop, mobile, and automation applications.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-eb67947c3ba6c865aaed7ff689ffa47b\" style=\"color:#ff8d00\"><strong>2. What are the features of Java?<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Platform independent<\/li>\n\n\n\n<li>Object-oriented<\/li>\n\n\n\n<li>Secure<\/li>\n\n\n\n<li>Robust<\/li>\n\n\n\n<li>Multithreaded<\/li>\n\n\n\n<li>Portable<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-464604c919c3b51f6f0840bea2fed316\" style=\"color:#ff8d00\"><strong>3. What are variables in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Variables are containers used to store data values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int age = 25;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-741ac22255352bba3ed295f3046a3fe2\" style=\"color:#ff8d00\"><strong>4. What are data types in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Two types:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Primitive \u2192 int, char, boolean<\/li>\n\n\n\n<li>Non-primitive \u2192 String, Array, Class<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-2f894bd3f9d0e6f1deec844d7a6e9477\" style=\"color:#ff8d00\"><strong>5. What is the difference between primitive and non-primitive data types?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Primitive<\/strong><\/td><td><strong>Non-Primitive<\/strong><\/td><\/tr><tr><td>Stores value<\/td><td>Stores reference<\/td><\/tr><tr><td>Fixed size<\/td><td>Dynamic size<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-8306c9963bd09cbc42dfa4a20a7f6ec3\" style=\"color:#ff8d00\"><strong>6. What is type casting in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Converting one datatype into another datatype.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>double d = 10.5;\nint i = (int)d;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-0d4c87965efc1cd7dc0e89b9a9361442\" style=\"color:#ff8d00\"><strong>7. What are operators in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Operators perform operations on variables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Examples:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Arithmetic (+)<\/li>\n\n\n\n<li>Logical (&amp;&amp;)<\/li>\n\n\n\n<li>Relational (>)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-cfaf71136e8057bbd7a6ce8578f1a84f\" style=\"color:#ff8d00\"><strong>8. What is the difference between <\/strong><strong>==<\/strong><strong> and <\/strong><strong>.equals()<\/strong><strong>?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>==<\/strong><\/td><td><strong>.equals()<\/strong><\/td><\/tr><tr><td>Compares memory reference<\/td><td>Compares values<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-d904daef4ffd6806679bc3084c4e82b8\" style=\"color:#ff8d00\"><strong>9. What are OOPs concepts in Java?<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Encapsulation<\/li>\n\n\n\n<li>Inheritance<\/li>\n\n\n\n<li>Polymorphism<\/li>\n\n\n\n<li>Abstraction<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-4c1f4c2fbfd7e5a596bf131d9b809887\" style=\"color:#ff8d00\"><strong>10. What is encapsulation?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Encapsulation means wrapping data and methods together in a single class and restricting direct access using private variables.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-706d2239d556252bf796ba193a147511\" style=\"color:#ff8d00\"><strong>11. What is inheritance?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Inheritance allows one class to acquire properties and methods of another class using extends keyword.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-856e2149a50df2f3550f98415c32c164\" style=\"color:#ff8d00\"><strong>12. What is polymorphism?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Polymorphism means one method can perform different actions based on the object.<br>Types:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Overloading<\/li>\n\n\n\n<li>Overriding<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-4f6e3a84a611d5bdfafa40b5972ecb04\" style=\"color:#ff8d00\"><strong>13. What is abstraction?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Abstraction means hiding implementation details and showing only required functionality.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-160cd8cac78c2ebbde23c7d0f4a34c8e\" style=\"color:#ff8d00\"><strong>14. What is the difference between abstraction and encapsulation?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Abstraction<\/strong><\/td><td><strong>Encapsulation<\/strong><\/td><\/tr><tr><td>Hides implementation<\/td><td>Hides data<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-7cc3fda0dd0cab3c9152cfb48326eed3\" style=\"color:#ff8d00\"><strong>15. What is method overloading?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Method overloading means creating multiple methods with same name but different parameters.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-5f49f3123cdbf178c940444ad6144cbc\" style=\"color:#ff8d00\"><strong>16. What is method overriding?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Method overriding means redefining parent class method in child class with same signature.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-d16b5f2b83d322485f6b17ad24e476ba\" style=\"color:#ff8d00\"><strong>17. What is the difference between overloading and overriding?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Overloading<\/strong><\/td><td><strong>Overriding<\/strong><\/td><\/tr><tr><td>Same class<\/td><td>Parent-child class<\/td><\/tr><tr><td>Different parameters<\/td><td>Same parameters<\/td><\/tr><tr><td>Compile-time polymorphism<\/td><td>Runtime polymorphism<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-c573a663c84b172c7b8aacd448aa0def\" style=\"color:#ff8d00\"><strong>18. What is an interface in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">An interface is a blueprint containing abstract methods that must be implemented by classes.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-6bca31dc821fa86ea637a2e58c3d7eb4\" style=\"color:#ff8d00\"><strong>19. What is an abstract class?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">An abstract class is a class declared using abstract keyword. It can contain abstract and non-abstract methods<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-b6896f5cd0433613310989cc6367e0a8\" style=\"color:#ff8d00\"><strong>20. What is the difference between interface and abstract class?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Interface<\/strong><\/td><td><strong>Abstract Class<\/strong><\/td><\/tr><tr><td>Supports multiple inheritance<\/td><td>Partial abstraction<\/td><\/tr><tr><td>Mostly abstract methods<\/td><td>Can contain concrete methods<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-7744271a252ef8d0d509ba940b56d0cf\" style=\"color:#ff8d00\"><strong>21. What is constructor in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Constructor initializes object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-670bb313106cab2b791c243eb25e84f0\" style=\"color:#ff8d00\"><strong>22. What is constructor overloading?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A constructor is a special method used to initialize objects.<br><\/p>\n\n\n\n<p class=\"has-text-color has-link-color has-medium-font-size wp-elements-ca856cf3b1e21d050c1d79f28d1c11ef wp-block-paragraph\" style=\"color:#ff8d00\"><strong>23. What is constructor overloading?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Creating multiple constructors with different parameters is called constructor overloading<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-3f5463f29bc6cc449cdad25cbc3c02d9\" style=\"color:#ff8d00\"><strong>23. What is the difference between constructor and method?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Constructor<\/strong><\/td><td><strong>Method<\/strong><\/td><\/tr><tr><td>Initializes object<\/td><td>Performs operations<\/td><\/tr><tr><td>Same name as class<\/td><td>Any valid name<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-560c6e61decffbffc92b26298990272b\" style=\"color:#ff8d00\"><strong>24. What is <\/strong><strong>this<\/strong><strong> keyword?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Refers to current class object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-72cb22bae2a38aead63dfd2a5a774693\" style=\"color:#ff8d00\"><strong>25. What is <\/strong><strong>super<\/strong><strong> keyword?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">super refers to parent class object or constructor.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-0e9b1b95c059e0ac992e3e27f14f158a\" style=\"color:#ff8d00\"><strong>26. What is static keyword in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">static belongs to class instead of object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-5beb1152df50bd51741d9c92aaec636d\" style=\"color:#ff8d00\"><strong>27. What is final keyword in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Used to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Prevent inheritance<\/li>\n\n\n\n<li>Prevent overriding<\/li>\n\n\n\n<li>Declare constants<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-21fd52234a496d54ea8c5dfcb5f2da5d\" style=\"color:#ff8d00\"><strong>28. Can we override static or final methods?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No, static and final methods cannot be overridden.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-992a689a140c05e311cd77335bedf455\" style=\"color:#ff8d00\"><strong>29. What is String in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">String is a sequence of characters used to store text.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-2d68fee8f6a17138f6668cdb28524f36\" style=\"color:#ff8d00\"><strong>30. What is the difference between String, StringBuffer, and StringBuilder?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>String<\/strong><\/td><td><strong>StringBuffer<\/strong><\/td><td><strong>StringBuilder<\/strong><\/td><\/tr><tr><td>Immutable<\/td><td>Mutable<\/td><td>Mutable<\/td><\/tr><tr><td>Slow<\/td><td>Thread-safe<\/td><td>Faster<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-b0b26960d15cce543a0faa219b1307d4\" style=\"color:#ff8d00\"><strong>31. Why is String immutable in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For security, thread safety, and performance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-56d16849743a394936b9e44d22a48f82\" style=\"color:#ff8d00\"><strong>32. What is string pooling?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Java stores string literals in common memory called String Pool.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-68f0654e7c098ef406b4823f54a82c93\" style=\"color:#ff8d00\"><strong>33. What is the difference between <\/strong><strong>equals()<\/strong><strong> and <\/strong><strong>equalsIgnoreCase()<\/strong><strong>?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>equals()<\/strong><\/td><td><strong>equalsIgnoreCase()<\/strong><\/td><\/tr><tr><td>Case-sensitive<\/td><td>Ignores case<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-954956a6ccbcb1ef036cb4b36d6a06fe\" style=\"color:#ff8d00\"><strong>34. How do you reverse a string in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Using StringBuilder:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">String rev = new StringBuilder(str).reverse().toString();<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-efa90805f5eec87ef08cd28fba5f3fc7\" style=\"color:#ff8d00\"><strong>35. How do you remove duplicates from a string?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Duplicates can be removed using loops, Set collection, or HashSet.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-fd9da9556b6d3c59a1ddaa48e7ef3694\" style=\"color:#ff8d00\"><strong>36. How do you count characters in a string?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Using length() method.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">str.length();<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-cae3d4b650ee4f7d7170707b5f50f731\" style=\"color:#ff8d00\"><strong>37. What is an array in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">An array is a collection of elements of the same datatype stored in a single variable. It is used to store multiple values together using index positions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-330d825b2a8e193767f6e0a2306f0d0c\" style=\"color:#ff8d00\"><strong>38. What is ArrayList?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">ArrayList is a class in Java Collection Framework used to store dynamic collections of elements. Unlike arrays, its size can grow or shrink automatically.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-9c864d04b78e7d692f41a86efa5759c3\" style=\"color:#ff8d00\"><strong>39. What is the difference between Array and ArrayList?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>Array<\/td><td>ArrayList<\/td><\/tr><tr><td>Fixed size<\/td><td>Dynamic size<\/td><\/tr><tr><td>Stores primitives<\/td><td>Stores objects<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-f834638b81c4995c48257638da2e69a6\" style=\"color:#ff8d00\"><strong>40. What is the difference between List, Set, and Map?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-b58bc8666a890d157aa2759a0b7aa4fc\" style=\"color:#ff8d00\"><strong>41. What is HashMap in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Stores key-value pairs<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-cc123cb1646e0b1dba0454e1784a6496\" style=\"color:#ff8d00\"><strong>42. What is the difference between HashMap and Hashtable?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>HashMap<\/strong><\/td><td><strong>Hashtable<\/strong><\/td><\/tr><tr><td>Not synchronized<\/td><td>Synchronized<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-61bb8b97bc9adff3353fb5545ef5de7d\" style=\"color:#ff8d00\"><strong>43. What is the difference between HashSet and TreeSet?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>HashSet<\/strong><\/td><td><strong>TreeSet<\/strong><\/td><\/tr><tr><td>Unordered<\/td><td>Sorted<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-b251a9cd56feab8df33fee2c5c34437c\" style=\"color:#ff8d00\"><strong>44. What is Iterator in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Used to traverse collection elements.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-a1310316145216c84e0cd8eae44c9cd4\" style=\"color:#ff8d00\"><strong>45. What is the difference between Iterator and ListIterator?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Iterator<\/strong><\/td><td><strong>ListIterator<\/strong><\/td><\/tr><tr><td>Forward only<\/td><td>Forward &amp; backward<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-6b407dc84a515646f766bc9e6c45c323\" style=\"color:#ff8d00\"><strong>46. What is Collection Framework in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Framework containing classes\/interfaces for storing data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-468232f9890808cdbf4a8b1708622138\" style=\"color:#ff8d00\"><strong>47. What is Comparable and Comparator?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Comparable<\/strong><\/td><td><strong>Comparator<\/strong><\/td><\/tr><tr><td>Natural sorting<\/td><td>Custom sorting<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-f40fd8403aef5230ed9ef2a4db48e7aa\" style=\"color:#ff8d00\"><strong>48. What is the difference between ArrayList and LinkedList?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>ArrayList<\/strong><\/td><td><strong>LinkedList<\/strong><\/td><\/tr><tr><td>Faster retrieval<\/td><td>Faster insertion\/deletion<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-e3314b25927fb1eda1c1d42822b84d6d\" style=\"color:#ff8d00\"><strong>49. What is exception handling in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Mechanism to handle runtime errors.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-989497337cfe8f2014f62eb17e14512a\" style=\"color:#ff8d00\"><strong>50. What is the difference between checked and unchecked exceptions?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Checked<\/strong><\/td><td><strong>Unchecked<\/strong><\/td><\/tr><tr><td>Compile-time<\/td><td>Runtime<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-8c3bf2dd770d27bfb1b64e949b6c8dc7\" style=\"color:#ff8d00\"><strong>51. What is try-catch block?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Used to handle exceptions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-b2fd417c5104abda00c0183a5384eee2\" style=\"color:#ff8d00\"><strong>52. What is finally block?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Always executes whether exception occurs or not.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-0f89abab298bc66a4c1de7b71a94e4f3\" style=\"color:#ff8d00\"><strong>53. What is throw and throws keyword?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>throw<\/strong><\/td><td><strong>throws<\/strong><\/td><\/tr><tr><td>Throws exception<\/td><td>Declares exception<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-472ad89d0576a2c7db9e0234447610f5\" style=\"color:#ff8d00\"><strong>54. Can finally block execute without catch block?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-95ded5af2de89b0e59ffce884561bbc8\" style=\"color:#ff8d00\"><strong>55. What is NullPointerException?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Occurs when accessing null object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-d92f5dde464d37d25c98a1f62d367d47\" style=\"color:#ff8d00\"><strong>56. What is exception propagation?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Passing exception from one method to another.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-c0bd7140f87f1f6e337dd08cd9eb6c1c\" style=\"color:#ff8d00\"><strong>57. What is file handling in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Reading and writing files using Java classes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-6104d6ab7f10679e0267aeb495992ef2\" style=\"color:#ff8d00\"><strong>58. How do you read data from a file in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Using:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>BufferedReader<\/li>\n\n\n\n<li>Scanner<\/li>\n\n\n\n<li>FileReader<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-55dc02b8ca9760d3533810225ca3deac\" style=\"color:#ff8d00\"><strong>59. How do you write data into a file?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Using FileWriter or BufferedWriter.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-e640bb41ff096d155c8c15397d94fdc1\" style=\"color:#ff8d00\"><strong>60. What is BufferedReader?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Used to read text efficiently.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-8b6d717e37d06313620f87023260feb0\" style=\"color:#ff8d00\"><strong>61. What is FileInputStream and FileOutputStream?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Used to read\/write byte data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-945094f480a4789f75755d90cd1e1cb0\" style=\"color:#ff8d00\"><strong>62. What is multithreading in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Executing multiple threads simultaneously.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-fd21acfdc703d32a50b226a8f8cc8afd\" style=\"color:#ff8d00\"><strong>63. What is thread in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Smallest unit of execution.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-e4bc3fd74d74e10ca6029f858ff4ccea\" style=\"color:#ff8d00\"><strong>64. What is the difference between process and thread?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Process<\/strong><\/td><td><strong>Thread<\/strong><\/td><\/tr><tr><td>Independent execution<\/td><td>Part of process<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-447750250a020d3106587d264177b064\" style=\"color:#ff8d00\"><strong>65. How do you create a thread in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Using:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Thread class<\/li>\n\n\n\n<li>Runnable interface<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-b32fc63f9f4166b9757e6290b3ec3f41\" style=\"color:#ff8d00\"><strong>66. What is synchronization?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Prevents multiple threads accessing shared resources simultaneously.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-bf9ba2848cc8a78075f60e2685dddce3\" style=\"color:#ff8d00\"><strong>67. What is thread sleep?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Pauses thread execution temporarily.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-9e85bd515c79a2b25f2b2affa28754ad\" style=\"color:#ff8d00\"><strong>68. What is the difference between <\/strong><strong>start()<\/strong><strong> and <\/strong><strong>run()<\/strong><strong>?<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>start()<\/strong><\/td><td><strong>run()<\/strong><\/td><\/tr><tr><td>Creates new thread<\/td><td>Executes normally<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"has-text-color has-link-color has-medium-font-size wp-elements-fa762c150986631cf80a69122f2efe8e wp-block-paragraph\" style=\"color:#ff8d00\">1. <strong>What is a Constructor in Java?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A <strong>constructor in Java<\/strong> is a special block of code used to <strong>initialize an object when it is created<\/strong>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The constructor name must be <strong>the same as the class name<\/strong><\/li>\n\n\n\n<li>It <strong>does not have any return type<\/strong> (not even <code>void<\/code>)<\/li>\n\n\n\n<li>It is <strong>automatically called<\/strong> when an object is created<\/li>\n\n\n\n<li>It is mainly used to <strong>assign initial values to object variables<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If a class does not have any constructor, the <strong>Java compiler automatically provides a default constructor<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Student {\n    int id;\n\n    Student() {   \/\/ Constructor\n        id = 100;\n    }\n}<\/code><\/pre>\n\n\n\n<h6 class=\"wp-block-heading\"><strong>Key Points to Remember (for interview):<\/strong><\/h6>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Constructor \u2260 Method<\/li>\n\n\n\n<li>Used for <strong>object initialization<\/strong><\/li>\n\n\n\n<li>Can be <strong>overloaded<\/strong> (multiple constructors with different parameters)<\/li>\n\n\n\n<li>Types:\n<ul class=\"wp-block-list\">\n<li>Default constructor<\/li>\n\n\n\n<li>Parameterized constructor<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p class=\"has-text-color has-link-color has-medium-font-size wp-elements-eee736a5e1760aa977f816b123ee4607 wp-block-paragraph\" style=\"color:#ff8d00\">2. <strong>What is Inheritance in Java?<\/strong><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Inheritance in Java<\/strong> is an OOP concept where one class (child\/subclass) <strong>acquires the properties and behaviors<\/strong> (variables and methods) of another class (parent\/superclass).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It helps in <strong>code reusability<\/strong> and reduces duplication.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\"><strong>Key Points (Interview Focus):<\/strong><\/h6>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Achieved using the <strong><code>extends<\/code> keyword<\/strong><\/li>\n\n\n\n<li>Promotes <strong>code reuse<\/strong><\/li>\n\n\n\n<li>Supports <strong>method overriding<\/strong><\/li>\n\n\n\n<li>Java supports:\n<ul class=\"wp-block-list\">\n<li>Single inheritance<\/li>\n\n\n\n<li>Multilevel inheritance<\/li>\n\n\n\n<li>Hierarchical inheritance<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Java does <strong>not support multiple inheritance with classes<\/strong> (but supports it using interfaces)<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>class Animal {\n    void eat() {\n        System.out.println(\"Eating...\");\n    }\n}\n\nclass Dog extends Animal {\n    void bark() {\n        System.out.println(\"Barking...\");\n    }\n}\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, Dog inherits the eat() method from Animal.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-98a2eb94ac8b3acde89e07e57a284e0c\" style=\"color:#ff8d00\">3. <strong>What is Polymorphism in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Polymorphism in Java<\/strong> means <strong>\u201cmany forms\u201d<\/strong>\u2014it allows a single method or object to behave in <strong>different ways<\/strong> depending on the context.<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-medium-font-size\">Types of Polymorphism:<\/h2>\n\n\n\n<h3 class=\"wp-block-heading has-medium-font-size\"><strong>1. Compile-time Polymorphism (Method Overloading)<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Same method name<\/li>\n\n\n\n<li>Different parameters<\/li>\n\n\n\n<li>Decided at compile time<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>class Calculator {\n    int add(int a, int b) {\n        return a + b;\n    }\n\n    int add(int a, int b, int c) {\n        return a + b + c;\n    }\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading has-medium-font-size\">2. <strong>Runtime Polymorphism (Method Overriding)<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Same method name<\/li>\n\n\n\n<li>Same parameters<\/li>\n\n\n\n<li>Different implementation in child class<\/li>\n\n\n\n<li>Decided at runtime<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>class Animal {\n    void sound() {\n        System.out.println(\"Animal sound\");\n    }\n}\n\nclass Dog extends Animal {\n    void sound() {\n        System.out.println(\"Bark\");\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading has-medium-font-size\"><strong>Key Points (Interview Focus):<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Achieves <strong>flexibility and reusability<\/strong><\/li>\n\n\n\n<li>Overloading \u2192 compile-time<\/li>\n\n\n\n<li>Overriding \u2192 runtime<\/li>\n\n\n\n<li>Runtime polymorphism uses <strong>inheritance<\/strong><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Java Interview Questions &amp; Answers 1. What is Java? Java is a high-level, object-oriented, platform-independent programming language used for developing web, desktop, mobile, and automation applications. 2. What are the features of Java? 3. What are variables in Java? Variables are containers used to store data values. Example: 4. What are data types in Java? &#8230; <a title=\"Java Interview Questions &amp; Answers\" class=\"read-more\" href=\"https:\/\/logicnextgen.com\/tutorials\/java-interview-questions-answers\/\" aria-label=\"Read more about Java Interview Questions &amp; Answers\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-504","page","type-page","status-publish"],"_links":{"self":[{"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/pages\/504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/comments?post=504"}],"version-history":[{"count":33,"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/pages\/504\/revisions"}],"predecessor-version":[{"id":671,"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/pages\/504\/revisions\/671"}],"wp:attachment":[{"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/media?parent=504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}