{"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-08-03T08:49:58","modified_gmt":"2026-08-03T08:49:58","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-1 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-2\" 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-3\" 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-4\" 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-5\" 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-6\" 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-7\" 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-8\" 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 (&gt;)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-9\" 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-10\" 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-11\" 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-12\" 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-13\" 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-14\" 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-15\" 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-16\" 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-17\" 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-18\" 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-19\" 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-20\" 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-21\" 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-22\" 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-23\" 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-24 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-25\" style=\"color:#ff8d00\"><strong>23. What is the difference between a constructor and a 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-26\" 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-27\" 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-28\" 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-29\" 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-30\" 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-31\" 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-32\" 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-33\" 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-34\" 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-35\" 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-36\" 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-37\" 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-38\" 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-39\" 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-40\" 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-41\" 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-42\" 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-43\" 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-44\" 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-45\" 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-46\" style=\"color:#ff8d00\"><strong>44. What is an 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-47\" 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-48\" style=\"color:#ff8d00\"><strong>46. What is the 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-49\" 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-50\" 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-51\" 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-52\" 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-53\" style=\"color:#ff8d00\"><strong>51. What is a 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-54\" style=\"color:#ff8d00\"><strong>52. What is a 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-55\" style=\"color:#ff8d00\"><strong>53. What is throw and throws keywords?<\/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-56\" style=\"color:#ff8d00\"><strong>54. Can a finally block execute without a 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-57\" style=\"color:#ff8d00\"><strong>55. What is NullPointerException?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Occurs when accessing a null object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color has-medium-font-size wp-elements-58\" style=\"color:#ff8d00\"><strong>56. What is exception propagation?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Passing an 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-59\" 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-60\" 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-61\" 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-62\" 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-63\" style=\"color:#ff8d00\"><strong>61. What are 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-64\" 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-65\" style=\"color:#ff8d00\"><strong>63. What is a 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-66\" 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-67\" 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-68\" style=\"color:#ff8d00\"><strong>66. What is synchronization?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Prevents multiple threads from 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-69\" 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","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":36,"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/pages\/504\/revisions"}],"predecessor-version":[{"id":1002,"href":"https:\/\/logicnextgen.com\/tutorials\/wp-json\/wp\/v2\/pages\/504\/revisions\/1002"}],"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}]}}