{"id":13261,"date":"2024-01-31T09:00:44","date_gmt":"2024-01-31T09:00:44","guid":{"rendered":"https:\/\/codegnan.com\/?p=13261"},"modified":"2026-05-08T07:27:38","modified_gmt":"2026-05-08T07:27:38","slug":"java-interview-questions","status":"publish","type":"post","link":"https:\/\/codegnan.com\/java-interview-questions\/","title":{"rendered":"120 Important Java Interview Questions and Answers"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">There are endless questions asked in a Java interview depending on the job position and candidates with different skills, experience, and background knowledge.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, some common JAVA questions often get asked and answered repeatedly in Java interviews everywhere.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is why we have asked our Java experts and mentors to share their top interview questions from beginner to experienced level. Also, we have shared the possible answers for each question so you can prepare well for your next interview in 2024.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No matter what Java position you&#8217;re applying for, these 120 Java interview questions and answers might help you showcase your expertise during the interview.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before we dive into the interview questions, check out our one-on-one classroom and online Java courses:<\/p>\n\n\n\n<div class=\"wp-block-group has-background is-layout-constrained wp-block-group-is-layout-constrained\" style=\"background-color:#fff5d8\">\n<p class=\"wp-block-paragraph\"><strong>Offline Java classes by codegnan (4.8\/5 rated by 2200+ students):<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u200dJava full stack classroom training (with <a href=\"https:\/\/codegnan.com\/job-accelerator-program\/\">placement support<\/a>): <a href=\"https:\/\/codegnan.com\/full-stack-java-training-course-in-vijayawada\/\">Vijayawada<\/a>, <a href=\"https:\/\/codegnan.com\/full-stack-java-training-course-in-hyderabad\/\">Hyderabad<\/a>, <a href=\"https:\/\/codegnan.com\/java-full-stack-training-course-in-bangalore\/\">Bangalore<\/a><\/li>\n\n\n\n<li>Core Java classroom training programs: <a href=\"https:\/\/codegnan.com\/core-java-training-course-in-hyderabad\/\">Hyderabad<\/a> and <a href=\"https:\/\/codegnan.com\/core-java-training-course-in-bangalore\/\">Bangalore<\/a><\/li>\n<\/ul>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Enroll in the <\/strong><a href=\"https:\/\/academy.codegnan.com\/learn\/JavaFullStackDevelopment\"><strong>Full-stack Java online course<\/strong><\/a><strong> provided by codegnan.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-java-interview-questions-for-beginners\"><strong>Java interview questions for beginners<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-what-is-java-programming\"><strong>1. What is Java programming?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Java is the most popular and widely used programming language that is defined as a collection of objects. With the use of Java, we can develop software, games, desktop applications, web applications, etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Learn about <a href=\"https:\/\/codegnan.com\/blogs\/java-projects\/\">common Java projects for final-year students<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-2-why-is-java-called-an-object-oriented-language\"><strong>2. Why is Java called an Object-Oriented language?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Java is a purely object-oriented programming language because it is impossible to write any Java program without a class or object. Java is not a pure programming language focused on objects. Java supports non-primitive types of data, such as int, float, boolean, double, long, etc.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-3-state-the-difference-between-jdk-and-jre\"><strong>3. State the difference between JDK and JRE?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">JDK is the acronym for Java Development Kit. It includes the tools and libraries that are used in the creation of Java software. Also, it contains the compilers and debuggers that are needed for Java program compilation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JRE, on the other hand, is an acronym for Java Runtime Environment. It comes with the installation package of JDK as JRE provides libraries and JVM that are used to execute a Java program.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-4-explain-java-virtual-machine\"><strong>4. Explain Java Virtual Machine.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Java Virtual Machine or JVM in short is a conceptual (or abstract) machine that is used to execute bytecode. Both hardware and software platforms have different JVM and for this reason, JVM is platform-independent. JVM is responsible for verifying and executing the bytecode on a platform.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-5-explain-the-jit-compiler\"><strong>5. Explain the JIT compiler.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">JIT or Just in Time compiler in Java is used for performance enhancement. By default, it is enabled. It is a compilation achieved at execution time. The use of the JIT compiler was popularized by Java by using it in the JVM.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-6-it-is-said-that-java-is-a-write-once-and-run-anywhere-language-why-is-it-called-so\"><strong>6. It is said that Java is a \u2018write once and run anywhere\u2019 language. Why is it called so?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Windows helps you to write Java code and compile it on the Windows platform. As it is in the Unix environment, the class and jar files that you get from the Windows platform will run. .<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So it\u2019s a completely autonomous language of the platform. The Java byte code is behind all this portability. Java compiler-generated bytecode can be interpreted by any JVM. So writing programs in Java and expecting them to run on any platform is much simpler. The Javac Java compiler compiles Java code, and the Java JVM compiler runs that code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-7-explain-the-working-of-class-loaders-in-java-programming\"><strong>7. Explain the working of class loaders in Java programming.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, a class loader is a class that is used to load files in JVM. Class loaders load files from their physical file locations e.g. Filesystem, Network location, etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are three main types of class loaders in Java.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Bootstrap class loader: This is the first class loader. It loads classes from the rt.jar file.<\/li>\n\n\n\n<li>Extension class loader: It loads class files from JRE\/lib\/ext location.<\/li>\n\n\n\n<li>Application class loader: This class loader depends on CLASSPATH to find the location of class files. If you specify your jars in CLASSPATH, then this class loader will load them.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-8-is-it-possible-to-write-the-main-method-as-public-void-static-instead-of-the-public-static-void\"><strong>8. Is it possible to write the main method as public void static instead of the public static void?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No, you cannot write it like this. Any method has to first specify the modifiers and then the return value. The order of modifiers can change. We can write static public void main() instead of public static void main().<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-9-in-java-if-no-value-is-assigned-to-the-local-variables-then-what-will-be-the-default-value-of-local-variables\"><strong>9. In Java if no value is assigned to the local variables then what will be the default value of local variables?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Java doesn\u2019t initialize local variables with any default value. Therefore, these variables will be null by default.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-10-state-the-main-principles-of-oops-in-java-or-oops-in-general\"><strong>10. State the main principles of OOPs in Java or OOPs in general.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The following are the main principles of OOPs:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Abstraction<\/li>\n\n\n\n<li>Encapsulation<\/li>\n\n\n\n<li>Inheritance<\/li>\n\n\n\n<li>Polymorphism<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-11-state-the-difference-between-object-oriented-programming-and-object-based-programming-language\"><strong>11. State the difference between Object-Oriented Programming and Object-Based Programming language.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Languages in object-oriented programming such as Java and C++ adopt OOPS ideas such as Encapsulation, Abstraction, Polymorphism, Inheritance, etc. Object-based programming languages adopt certain OOPS functions, but support for polymorphism and inheritance is not provided, for eg. JavaScript, VBScript, etc. Object-based programming languages allow objects to be supported and you can construct objects from the builder. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Encapsulation is also assisted by their languages. They are also regarded as languages that are Prototype-oriented.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-12-what-is-the-use-of-constructors-in-java\"><strong>12. What is the use of constructors in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Java is an object-oriented language, in which we create and use objects. A constructor is a piece of code similar to a method. It is used to create an object and set the initial state of the object. A constructor is a special function that has the same name as the class name. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Without a constructor, there is no other way to create an object. By default, Java provides a default constructor for every object. If we overload a constructor then we have to implement a default constructor.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-13-what-value-is-returned-by-the-constructor-in-java\"><strong>13. What value is returned by the constructor in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When a constructor is called in Java, it returns the object created by it. This is how new objects are created in Java.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-14-what-is-the-use-of-the-this-keyword-in-the-java-language\"><strong>14. What is the use of the \u2018this\u2019 keyword in the Java language?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java,\u2019 this\u2019 keyword corresponds to the object\u2019s current case. It is helpful for discriminating between local variables and instance variables. It can be used for calling constructors or you can use it to refer to an instance. In the case of the overriding method, this is used to drop the existing class method.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-15-what-is-inheritance-java\"><strong>15. What is Inheritance Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Object-Oriented Programming, inheritance is an important concept. Any objects share similar attributes and behavior. We may place the typical actions and features in a base class, which is also known as the superclass, by using Inheritance. And then this base class inherits all properties with similar actions. It is also expressed by the relationship between IS and A. Inheritance enables duplication of code, override of methods, and polymorphism.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-16-what-is-the-reason-that-java-doesn-t-support-multiple-inheritances\"><strong>16. What is the reason that Java doesn\u2019t support multiple inheritances?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Multiple Inheritance suggests that two or more parent classes will inherit actions. The concern with Multiple Inheritance is that with the same form, all parent classes can have separate implementations.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So they\u2019ve got various ways to do the same thing. What implementation does the children\u2019s class pick now?&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Multiple Inheritance, this ends in complexity. This is the key explanation for Java not promoting the introduction of Multiple Inheritance.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s say you\u2019ve got a TV class and another AtomBomb class. They all have the switchOn) (function, but only the TV has the switchOff) (function. If both classes are inherited from your class, then you have a dilemma. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You should change all parents to switchOn), but switchOff can only switchOff TV. But in Java, you can implement several interfaces.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-17-java-doesn-t-support-pointers-what-is-the-reason-behind-this\"><strong>17. Java doesn\u2019t support pointers. What is the reason behind this?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, instead of pointers, there are references. In memory, these references point to objects. But these memory sites do not provide easy entry. The JVM is free to transfer objects into the memory of the VM. The disappearance of pointers allows Java to efficiently handle memory and garbage collection. It also gives developers the ease of not caring about memory allocation and deallocation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-18-if-there-are-no-pointers-in-java-then-why-do-we-getnullpointerexception\"><strong>18. If there are no pointers in Java, then why do we getNullPointerException?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, the pointer equivalent is an Object reference. When we use a. (dot) it points to object reference. So JVM uses pointers but programmers only see object references. In case an object reference points to a null object, and we try to access a method or member variable on it, then we get a NullPointerException.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-19-why-is-it-not-a-good-practice-to-create-static-variables-in-java\"><strong>19. Why is it not a good practice to create static variables in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For all the objects in a class, static variables are common. There is no need to validate the value of a static variable whenever a new object is produced. Any code that uses a static variable can be in any state. It can be inside a new object or at the level of a class. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In a Java class, the scope of the static variable is also open-ended. If we want better control on scope, then variables should be generated at the object development stage. Even specifying static variables is not a reasonable idea since they go against the ideals of Object-Oriented Programming.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">> Learn <strong><a href=\"https:\/\/codegnan.com\/blogs\/how-to-become-a-java-full-stack-developer\/\">how to become a full-stack Java developer<\/a><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-20-what-is-the-main-method-marked-static-in-java\"><strong>20. What is the main method marked static in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, the main method is labeled as static, so the JVM will call it to start the application. If the main method is not static, which builder would the Java process call? <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As such, labeling the key static method in Java is recognized as a convention. But if we delete the static, then the uncertainty will be there. The Java process could not understand which method to call a class to start the program. In the Java process, this convention helps to define the starting code for a class program that is transmitted as an argument to the Java process.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-21-in-which-case-do-we-use-a-static-block\"><strong>21. In which case do we use a static block?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">There is a class that has static member variables at times. Any complex initialization involves these variables. The static block at this time helps to initialize complex static member variable initialization as a function. The static block is executed long before the key block is executed. We may also often substitute a static block with a static class method.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-22-state-the-difference-between-a-static-method-and-an-instance-method-in-java\"><strong>22. State the difference between a static method and an instance method in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes, for a class that is not dependent on member variables of an object, there is a need to specify actions. In a static system, such conduct is caught. If there is an action that depends on an object\u2019s member variables, then we do not label it static, it stays as an instance process. We don\u2019t need to construct an object in order to call the static process. We only mark it by the name of the class. But for an example procedure to be called, we need to first, build\/get an object. A static procedure does not access instance member variables. But both instance variables and static variables can be named by an example process.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-23-how-will-you-implement-method-overloading-java\"><strong>23. How will you implement method overloading Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, a class can have multiple methods with the same name but different arguments. It is called Method Overloading. To implement method overloading we have to create two methods with the same name in a class and do one\/more of the following:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Different number of parameters<\/li>\n\n\n\n<li>The different data type of parameters<\/li>\n\n\n\n<li>A different sequence of the data type of parameters<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-24-what-are-the-types-of-argument-variations-allowed-in-method-overloading-in-java\"><strong>24. What are the types of argument variations allowed in method overloading in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Method Overloading allows two methods with the same name to differ in:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Number of parameters<\/li>\n\n\n\n<li>The data type of parameters<\/li>\n\n\n\n<li>The sequence of the data type of parameters<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-25-can-we-override-a-static-method-in-java\"><strong>25. Can we override a static method in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No, Java does not permit a static process to be overridden. If you build the same-named static method in the subset, it is a different method, not an overridden method.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">26) State the difference between method overloading and method overriding in Java history?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Differences between method overloading and overriding are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Method overloading is static polymorphism. Method overriding is runtime polymorphism.<\/li>\n\n\n\n<li>Method overloading occurs within the same class. Method overriding happens in two classes with hierarchy relationships.<\/li>\n\n\n\n<li>Parameters must be different in method overloading. Parameters must be the same in method overriding.<\/li>\n\n\n\n<li>Method overloading is a compile-time concept. Method overriding is a runtime concept.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-27-what-is-runtime-polymorphism-in-java\"><strong>27. What is Runtime Polymorphism in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The polymorphism that occurs during runtime is Runtime Polymorphism or Dynamic Polymorphism. It is not understood which method will be called at runtime in the case of the overriding method. JVM specifies the exact method that should be titled, depending on the type of entity. So, it is not known at compile time which method would be called at runtime.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-28-state-the-difference-between-static-and-dynamic-binding-in-java\"><strong>28. State the difference between static and dynamic binding in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Static binding references are resolved at compile time. Dynamic binding references are resolved at Run time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>For Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><br>Person p = new Person();<br>p.walk(); \/\/ Java compiler resolves this binding at compile time.<br>public void walk(Object o){<br>((Person) o).walk(); \/\/ this is dynamic binding.<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-29-how-is-abstraction-different-from-encapsulation-in-java\"><strong>29. How is abstraction different from encapsulation in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In class-level programming, abstraction exists. It helps in covering the specifics of the implementation. Encapsulation is often known as \u201cInformation Hiding\u201d. An example of encapsulation is the private labelling of the member variables and having a getter and setter for these member variables.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-30-explain-abstract-class-in-java\"><strong>30. Explain abstract class in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, an abstract class has one or more abstract techniques. In the abstract class, an abstract method is only declared, but it is not implemented. In Java, an abstract class must be generalized and a child class must follow its abstract methods. Java also does not make a new instance of the Abstract type.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-31-what-is-an-interface-in-java\"><strong>31. What is an interface in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">An Interface in Java is an abstract type blueprint of a class. It requires the strategies a class must adopt. Like a protocol, it has signatures and frequent statements of the process.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-32-have-you-heard-about-marker-interfaces-what-is-it\"><strong>32. Have you heard about marker interfaces? What is it?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, there are various interfaces that do not have any data members or methods. Such interfaces are called marker interfaces. Some examples are- serial, cloneable, remote, etc.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-33-if-we-don-t-want-to-use-a-marker-interface-then-what-will-we-use\"><strong>33. If we don\u2019t want to use a marker interface, then what will we use?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Annotations are the alternative to the marker interface.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-34-state-the-difference-between-abstract-class-and-interface-in-java\"><strong>34. State the difference between abstract class and interface in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Several differences between abstract class and interface are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An abstract class may have body methods (non-abstract techniques) applied. Only abstract approaches provide an interface. The interface will provide static\/default methods in an applied form from Java 8 onwards.<\/li>\n\n\n\n<li>An abstract class can have instance member variables. An interface cannot have instance variables. It can only have constants.<\/li>\n\n\n\n<li>An abstract class will have a constructor. The interface can\u2019t provide a constructor. Another class needs to execute it.<\/li>\n\n\n\n<li>A class can extend only one abstract class. A class can implement more than one interface.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-35-is-there-any-way-to-change-the-value-of-a-final-variable-in-java\"><strong>35. Is there any way to change the value of a final variable in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, we cannot change the value of a final variable. Once the value is set or assigned, it cannot be changed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-36-how-can-we-create-a-final-method-in-java\"><strong>36. How can we create a final method in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To create a final method in Java, you need to add a modifier final to that method. A final method cannot be overridden by a child class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-37-why-is-the-integer-class-final-in-java\"><strong>37. Why is the Integer class final in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Integer class is a wrapper for int. If an integer class is not marked final then any other class can extend it and modify the behavior of integer operations. To avoid this scenario, the integer class is marked as final.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-38-what-is-the-motive-or-purpose-of-using-packages-in-java\"><strong>38. What is the motive or purpose of using packages in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A package is used to encapsulate a group of classes, interfaces, and sub-packages. Often, it is a hierarchical structure for storing information. It is easier to organize the related classes and sub-packages in this manner. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A Package also provides access protection for classes and interfaces. A package also helps in removing naming collisions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-java-interview-questions-for-intermediates\">Java Interview Questions for Intermediates<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-39-explain-chain-exceptions-in-java\"><strong>39. Explain chain exceptions in Java.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If the first exception allows another exception to be executed in a program, the Chained Exception is considered such a condition. Chained exceptions help to find the root cause of the exception that happens when the application is executed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Following are the constructors that support chained exceptions in Throwable classes:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Throwable initiate (Throwable)<\/li>\n\n\n\n<li>Throwable (Throwable)<\/li>\n\n\n\n<li>Throwable (String, Throwable)<\/li>\n\n\n\n<li>Throwable getCause()<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-40-what-is-the-difference-between-jar-and-war-files-in-java\"><strong>40. What is the difference between JAR and WAR files in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Following are the differences between the JAR file and the WAR file are the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>JAR file stands for Java Archive file which allows us to combine many files into a single file. Whereas, WAR files stand for Web Application Archive files that store XML, java classes, and JavaServer pages, etc., for Web Application purposes.<\/li>\n\n\n\n<li>JAR files hold Java classes in a library. Whereas, WAR files store the files in the \u2018lib\u2019 directory of the web application.<\/li>\n\n\n\n<li>All the enterprise Java Bean classes and EJB deployment descriptors present in the EJB module are packed and stored in a JAR file with a .jar extension. Whereas, the WAR file contains the web modules such as Servlet classes, GIFs, HTML files, JSP files, etc., with .war extension<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-41-what-is-the-working-of-hashmap-in-java\"><strong>41. What is the working of HashMap in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Through storing key-value pairs, a HashMap in Java works. HashMap uses a hash function to bring items into a collection and extract them from the collection using the hashCode and equals methods. The HashMap determines the hash value of the key on the invocation of the put) (method and then stores the pair within the array in the specific index.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Where there is a key, the value of the key is changed with the new value. Some significant features of a HashMap are its ability, its load factor, and the resizing of the threshold.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-42-state-the-difference-between-hashmap-and-hashtable\"><strong>42. State the difference between HashMap and HashTable.<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Hashtable is synchronized while HashMap is not synchronized. For the same reason, HashMap works better in non-threaded applications, because unsynchronized objects typically perform better than synchronized ones.<\/li>\n\n\n\n<li>Hashtable does not allow null keys or null values whereas HashMap allows one null key and any number of null values.<\/li>\n\n\n\n<li>One of the subclasses of HashMap is LinkedHashMap, so if we want a predictable iteration order in the event, we can easily swap out the HashMap for a LinkedHashMap. But, this would not be as easy using Hashtable.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-43-explain-the-role-of-system-gc-and-runtime-gc-methods-in-java\"><strong>43. Explain the role of System.gc() and Runtime.gc() methods in Java.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The system class includes a static function named GC() to request the Garbage Collector to be run by JVM. Using Runtime .getRuntime() .gc() method, the Runtime class allows the application to interact with the JVM in which the application is running. Both the System.gc() and Runtime.GC() (methods help give the JVM a hint such that the JVM can start a set of garbage.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is up to the Java Virtual Machine (JVM), however, to start the garbage collector immediately or later in time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-44-what-happens-when-we-create-an-object-in-java\"><strong>44. What happens when we create an object in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Following things take place during the creation of an object in Java:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Memory allocation: Memory allocation is carried out to store all the class instance variables and the object\u2019s implementation-specific data.<\/li>\n\n\n\n<li>Initialization: Initialization takes place to initialize the default values of the objects.<\/li>\n\n\n\n<li>Constructor: For their parent classes, constructors invoke the constructors. This method continues until the java.langObject function Object() { [native code] } is called. For all objects in Java, the java.lang. Object class is the foundation class.<\/li>\n\n\n\n<li>Execution: Before the body of the function Object() { [native code] } is executed, all instance variables should be initialised and all initialization blocks must be executed. After that, the function Object() { [native code] }\u2019s body is executed.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-45-in-java-we-can-use-string-in-two-variations-as-a-literal-and-a-new-operator-what-is-the-difference\"><strong>45. In Java, we can use String in two variations- as a literal and a new operator. What is the difference?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When we create an object of String in Java using a new() operator, it is created in a heap memory area and not into the String pool. But when we create a String using literal, then it gets stored in the String pool itself. The String pool exists in the PermGen area of heap memory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>For example,<br>String str = new String(\u201cjava\u201d);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The above statement does not put the String object str in the String pool. We need to call the String. intern() method to put the String objects into the String pool explicitly. It is only possible when we create a String object as String literal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example,<br>String str1 = \u201cjava\u201d;<br><br>Java automatically puts the String object into the String pool.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-46-what-is-the-java-lang-package\"><strong>46. What is the java.lang package?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The java.lang package in Java includes the classes that are important for Java programming language design. The Object Class is the most critical class in this set. It also includes classes of wrappers including- Integer, Boolean, Character, etc. It offers a math class with mathematical activities.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-47-which-is-the-most-important-class-in-java\"><strong>47. Which is the most important class in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">With several answers, it is an open-ended question. In my opinion, the most important Java programming language class is the object class. In Java, it is the origin of all the classes. It offers certain strategies that are really necessary and basic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-48-is-it-necessary-to-import-the-java-lang-package-every-time\"><strong>48. Is it necessary to import the java.lang package every time?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. JVM is loaded internally by default.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you compile and run a Java program, the Java compiler automatically imports the java.lang package by default, even if there is no import statement for java.lang.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Therefore, classes like String, System, and Thread are available by default without needing to be imported.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>For example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Main {\npublic static void main(String&#91;] args) {\nString text = \"Hello World\"; \/\/ String is available\nSystem.out.println(text); \/\/ System is available\n}\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-49-in-java-can-we-import-the-same-package-or-class-twice\"><strong>49. In Java, can we import the same package or class twice?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If we import the same package into a class several times, the compiler only includes it once. So neither JVM nor Compiler gives several times error\/warnings on adding a package. If you have two classes of the same name, you can get a name collision when you incorrectly import the class. Internally, the JVM only loads the class once.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-50-explain-the-locale\"><strong>50. Explain the locale.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, a Locale object represents a specific geographical, political, or cultural region. It is used for locale-sensitive operations in Java. It helps by following the local conventions of a country, a native of the region. These conventions can be for formatting the dates, money, numbers, etc.<\/p>\n\n\n\n<p class=\"has-background wp-block-paragraph\" style=\"background-color:#eef9ff\">\ud83d\udc49 If you want to expand your Java knowledge, <a href=\"https:\/\/codegnan.com\/blogs\/java-course-syllabus\/\"><strong>download our Core Java syllabus<\/strong><\/a> and prepare your learning roadmap accordingly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-pattern-programs-in-java\"><strong>Pattern Programs in Java<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-51-write-a-java-program-to-draw-a-pyramid\"><strong>51. Write a Java program to draw a pyramid.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>*<br>* *<br>* * *<br>* * * *<br>* * * * *<br>public class Codegnan<br>{<br>public static void PyramidPattern(int n)<br>{<br>for (int i=0; i&lt;n; i++) \/\/outer loop for number of rows(n)<br>{ for (int j=n-i; j&gt;1; j\u2013) \/\/inner loop for spaces<br>{<br>System.out.print(\u201d \u201c); \/\/print space<br>}<br>for (int j=0; j&lt;=i; j++ ) \/\/inner loop for number of columns<br>{<br>System.out.print(\u201c* \u201c); \/\/print star<br>}<br>System.out.println(); \/\/ending line after each row<br>}<br>}<br>public static void main(String args&#91;]) \/\/driver function<br>{<br>int n = 5;<br>PyramidPattern(n);<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-52-write-a-java-program-to-draw-a-right-triangle-star-pattern\"><strong>52. Write a Java program to draw a right triangle star pattern.\u200d<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>*<br>* *<br>* * *<br>* * * *<br>* * * * *<br>public class Codegnan<br>{<br>public static void RTriangle(int n)<br>{<br>int i, j;<br>for(i=0; i&lt;n; i++) \/\/outer loop for number of rows(n)<br>{ for(j=2*(n-i); j&gt;=0; j\u2013) \/\/ inner loop for spaces<br>{<br>System.out.print(\u201d \u201c); \/\/ printing space<br>}<br>for(j=0; j&lt;=i; j++) \/\/&nbsp; inner loop for columns<br>{<br>System.out.print(\u201c* \u201c); \/\/ print star<br>}<br>System.out.println(); \/\/ ending line after each row<br>}<br>}<br>public static void main(String args&#91;])<br>{<br>int n = 5;<br>RTriangle(n);<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-53-write-a-java-program-to-draw-a-left-triangle-star-pattern\"><strong>53. Write a Java program to draw a left triangle star pattern.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>*<br>* *<br>* * *<br>* * * *<br>* * * * *<br>public class Codegnan<br>{<br>public static void printStars(int n)<br>{<br>int i, j;<br>for(i=0; i&lt;n; i++) \/\/outer loop for number of rows(n)<br>{ for(j=2*(n-i); j&gt;=0; j\u2013) \/\/ inner loop for spaces<br>{<br>System.out.print(\u201d \u201c); \/\/ printing space<br>}<br>for(j=0; j&lt;=i; j++) \/\/&nbsp; inner loop for columns<br>{<br>System.out.print(\u201c* \u201c); \/\/ print star<br>}<br>System.out.println(); \/\/ ending line after each row<br>}<br>}<br>public static void main(String args&#91;])<br>{<br>int n = 5;<br>printStars(n);<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-54-write-a-java-program-to-draw-a-diamond-pattern-with-5-rows-given\"><strong>54. Write a Java program to draw a diamond pattern with 5 rows given.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>*<br>***<br>*****<br>****************<br>*******<br>*****<br>***<br>*<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String args&#91;])<br>{<br>int n, i, j, space = 1;<br>System.out.print(\u201cEnter the number of rows: \u201c);<br>Scanner s = new Scanner(System.in);<br>n = s.nextInt();<br>space = n \u2013 1;<br>for (j = 1; j&lt;= n; j++)<br>{<br>for (i = 1; i&lt;= space; i++)<br>{<br>System.out.print(\u201d \u201c);<br>}<br>space\u2013;<br>for (i = 1; i &lt;= 2 * j \u2013 1; i++)<br>{<br>System.out.print(\u201c*\u201d);<br>}<br>System.out.println(\u201c\u201d);<br>}<br>space = 1;<br>for (j = 1; j&lt;= n \u2013 1; j++)<br>{<br>for (i = 1; i&lt;= space; i++)<br>{<br>System.out.print(\u201d \u201c);<br>}<br>space++;<br>for (i = 1; i&lt;= 2 * (n \u2013 j) \u2013 1; i++)<br>{<br>System.out.print(\u201c*\u201d);<br>}<br>System.out.println(\u201c\u201d);<br>}<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-55-write-a-java-program-to-draw-a-downward-triangle-star-pattern-with-5-rows-given\"><strong>55. Write a Java program to draw a downward triangle star pattern with 5 rows given.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>* * * * *<br>* * * *<br>* * *<br>* *<br>*<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>Scanner sc = new Scanner(System.in);<br>System.out.println(\u201cEnter the number of rows: \u201c); \/\/takes input from user<br>int rows = sc.nextInt();<br>for (int i= rows-1; i&gt;=0 ; i\u2013)<br>{<br>for (int j=0; j&lt;=i; j++)<br>{<br>System.out.print(\u201c*\u201d + \u201d \u201c);<br>}<br>System.out.println();<br>}<br>sc.close();<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-56-write-a-java-program-to-draw-a-reversed-pyramid-star-pattern-with-5-rows-given\"><strong>56. Write a Java program to draw a reversed pyramid star pattern with 5 rows given.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>* * * * *<br>* * * *<br>* * *<br>* *<br>*<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>Scanner sc = new Scanner(System.in);<br>System.out.println(\u201cEnter the number of rows: \u201c);<br>int rows = sc.nextInt();<br>for (int i= 0; i&lt;= rows-1 ; i++)<br>{<br>for (int j=0; j&lt;=i; j++)<br>{<br>System.out.print(\u201d \u201c);<br>}<br>for (int k=0; k&lt;=rows-1-i; k++)<br>{<br>System.out.print(\u201c*\u201d + \u201d \u201c);<br>}<br>System.out.println();<br>}<br>sc.close();<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-57-write-a-java-program-to-draw-a-right-down-mirror-star-pattern-with-5-rows-given\"><strong>57. Write a Java program to draw a right-down mirror star pattern with 5 rows given.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>*****<br>****<br>***<br>**<br>*<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>Scanner sc = new Scanner(System.in); \/\/ takes input<br>System.out.println(\u201cEnter number of rows: \u201c);<br>int rows = sc.nextInt();<br>for (int i= rows; i&gt;= 1; i\u2013)<br>{<br>for (int j=rows; j&gt;i;j\u2013)<br>{<br>System.out.print(\u201d \u201c);<br>}<br>for (int k=1;k&lt;=i;k++)<br>{<br>System.out.print(\u201c*\u201d);<br>}<br>System.out.println(\u201c\u201d);<br>}<br>sc.close();<br>}<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-58-write-a-java-program-to-draw-a-right-pascal-s-triangle-star-pattern-with-5-rows-given\">58. Write a Java program to draw a right Pascal&#8217;s triangle star pattern with 5 rows given.<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>*<br>* *<br>* * *<br>* * * *<br>* * * * *<br>* * * *<br>* * *<br>* *<br>*<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>Scanner sc = new Scanner(System.in);<br>System.out.println(\u201cEnter the number of rows: \u201c);<br>int rows = sc.nextInt();<br>for (int i= 0; i&lt;= rows-1 ; i++)<br>{<br>for (int j=0; j&lt;=i; j++)<br>{<br>System.out.print(\u201c*\u201d+ \u201d \u201c);<br>}<br>System.out.println(\u201c\u201d);<br>}<br>for (int i=rows-1; i&gt;=0; i\u2013)<br>{<br>for(int j=0; j &lt;= i-1;j++)<br>{<br>System.out.print(\u201c*\u201d+ \u201d \u201c);<br>}<br>System.out.println(\u201c\u201d);<br>}<br>sc.close();<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-59-write-a-java-program-to-draw-a-left-pascal-s-triangle-star-pattern-with-5-rows-given\"><strong>59. Write a Java program to draw a left Pascal&#8217;s triangle star pattern with 5 rows given.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>*<br>**<br>***<br>*********<br>****<br>***<br>**<br>*<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>Scanner sc = new Scanner(System.in);<br>System.out.println(\u201cEnter the number of rows: \u201c);<br>int rows = sc.nextInt();<br>for (int i= 1; i&lt;= rows ; i++)<br>{<br>for (int j=i; j &lt;rows ;j++)<br>{<br>System.out.print(\u201d \u201c);<br>}<br>for (int k=1; k&lt;=i;k++)<br>{<br>System.out.print(\u201c*\u201d);<br>}<br>System.out.println(\u201c\u201d);<br>}<br>for (int i=rows; i&gt;=1; i\u2013)<br>{<br>for(int j=i; j&lt;=rows;j++)<br>{<br>System.out.print(\u201d \u201c);<br>}<br>for(int k=1; k&lt;i ;k++)<br>{<br>System.out.print(\u201c*\u201d);<br>}<br>System.out.println(\u201c\u201d);<br>}<br>sc.close();<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-60-write-a-java-program-to-print-alphabet-a\"><strong>60. Write a Java program to print alphabet A.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;<br>public class Codegnan<br>{<br>\/\/ Java program to print alphabet A<br>void display(int n)<br>{<br>\/\/ Outer for loop for number of lines<br>for (int i = 0; i&lt;=n; i++)<br>{<br>\/\/ Inner for loop for logic execution<br>for (int j = 0; j&lt;= n \/ 2; j++)<br>{<br>\/\/ prints two column lines<br>if ((j == 0 || j == n \/ 2) &amp;&amp; i != 0 ||<br>\/\/ print first line of alphabet<br>i == 0&nbsp; &amp;&amp; j != n \/ 2 ||<br>\/\/ prints middle line<br>i == n \/ 2)<br>System.out.print(\u201c*\u201d);<br>else<br>System.out.print(\u201d \u201c);<br>}<br>System.out.println();<br>}<br>}<br>public static void main(String&#91;] args)<br>{<br>Scanner sc = new Scanner(System.in);<br>Edureka a = new Edureka();&nbsp; &nbsp; a.display(7);<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-61-write-a-java-program-to-print-an-empty-triangle\"><strong>61. Write a Java program to print an empty triangle.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>*<br>* *<br>* * *<br>* * * *<br>* * * * * *<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>Scanner sc = new Scanner(System.in);<br>System.out.println(\u201cEnter the number of rows: \u201c);<br>int rows = sc.nextInt();<br>for (int i=1; i&lt;= rows ; i++)<br>{<br>for (int j = i; j &lt; rows ; j++)<br>{<br>System.out.print(\u201d \u201c);<br>}<br>for (int k = 1; k &lt;= (2*i -1) ;k++)<br>{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( k==1 || i == rows || k==(2*i-1))<br>{<br>System.out.print(\u201c*\u201d);<br>}<br>else<br>{<br>System.out.print(\u201d \u201c);<br>}<br>}<br>System.out.println(\u201c\u201d);<br>}<br>sc.close();<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-62-write-a-java-program-to-print-an-empty-downward-triangle\"><strong>62. Write a Java program to print an empty downward triangle.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>*********<br>* &nbsp; &nbsp; *<br>* &nbsp; *<br>* *<br>*<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>Scanner sc = new Scanner(System.in);<br>System.out.println(\u201cEnter the number of rows: \u201c);<br>int rows = sc.nextInt();<br>for (int i=rows; i&gt;= 1 ; i\u2013)<br>{<br>for (int j = i; j &lt; rows ; j++)<br>{<br>System.out.print(\u201d \u201c);<br>}<br>for (int k = 1; k &lt;= (2*i -1) ;k++)<br>{<br>if( k==1 || i == rows || k==(2*i-1))<br>{<br>System.out.print(\u201c*\u201d);<br>}<br>else<br>{<br>System.out.print(\u201d \u201c);<br>}<br>}<br>System.out.println(\u201c\u201d);<br>}<br>sc.close();<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-63-write-a-java-program-to-print-an-empty-diamond-pattern\"><strong>63. Write a Java program to print an empty diamond pattern.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>*<br>* *<br>*<br>* *<br>**<br>* *<br>*&nbsp; *<br>*<br>* *<br>*<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>Scanner sc = new Scanner(System.in);<br>System.out.println(\u201cEnter the number of rows: \u201c);<br>int rows = sc.nextInt();<br>for (int i=1; i&lt;= rows ; i++)<br>{<br>for (int j = rows; j &gt; i ; j\u2013)<br>{<br>System.out.print(\u201d \u201c);<br>}<br>System.out.print(\u201c*\u201d);<br>for (int k = 1; k &lt; 2*(i -1) ;k++)<br>{<br>System.out.print(\u201d \u201c);<br>}<br>if( i==1) { System.out.println(\u201c\u201d);<br>}<br>else<br>{<br>System.out.println(\u201c*\u201d);<br>}<br>}<br>for (int i=rows-1; i&gt;= 1 ; i\u2013)<br>{<br>for (int j = rows; j &gt; i ; j\u2013)<br>{<br>System.out.print(\u201d \u201c);<br>}<br>System.out.print(\u201c*\u201d);<br>for (int k = 1; k &lt; 2*(i -1) ;k++)<br>{<br>System.out.print(\u201d \u201c);<br>}<br>if( i==1)<br>System.out.println(\u201c\u201d);<br>else<br>System.out.println(\u201c*\u201d);<br>}<br>sc.close();<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-64-write-a-java-program-to-print-the-following-number-pattern\"><strong>64. Write a Java program to print the following number pattern.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>*<br>* *<br>* * *<br>* * * *<br>* * * * *<br>public class Codegnan<br>{<br>public static void printNums(int n)<br>{<br>int i, j,num;<br>for(i=0; i&lt;n; i++) \/\/ outer loop for rows<br>{<br>num=1;<br>for(j=0; j&lt;=i; j++) \/\/ inner loop for rows<br>{<br>\/\/ printing num with a space<br>System.out.print(num+ \u201d \u201c);<br>\/\/incrementing value of num<br>num++;<br>}<br>\/\/ ending line after each row<br>System.out.println();<br>}<br>}<br>public static void main(String args&#91;])<br>{<br>int n = 5;<br>printNums(n);<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-65-write-a-java-program-to-print-the-following-number-pattern\"><strong>65. Write a Java program to print the following number pattern.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>1<br>2 3<br>4 5 6<br>7 8 9 10<br>11 12 13 14 15<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>int i, j, k = 1;<br>for (i = 1; i &lt;= 5; i++){<br>for (j = 1; j&lt; i + 1; j++){<br>System.out.print(k++ + \u201d \u201c);<br>}<br>System.out.println();<br>}<br>}<br>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">66) Write a Java program to print the following number pattern.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\n1 &nbsp; 1\n1 &nbsp; 2 &nbsp; 1\n1 &nbsp; 3 &nbsp; 3 &nbsp; 1\n1 &nbsp; 4 &nbsp; 6 &nbsp; 4 &nbsp; 1\nimport java.util.Scanner;\npublic class Codegnan\n{\npublic static void main(String&#91;] args) {\nint n = 5;\nfor (int i = 0; i &lt; n; i++) {\nint number = 1;\nSystem.out.printf(\u201c%\u201d + (n \u2013 i) * 2 + \u201cs\u201d, \u201c\u201d);\nfor (int j = 0; j &lt;= i; j++) {\nSystem.out.printf(\u201c%4d\u201d, number);\nnumber = number * (i \u2013 j) \/ (j + 1);\n}\nSystem.out.println();\n}\n}\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-67-write-a-java-program-to-print-the-following-number-pattern\">67. Write a Java program to print the following number pattern.<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>1<br>2 2<br>3 3 3<br>4 4 4 4<br>5 5 5 5 5<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>Scanner sc = new Scanner(System.in); \/\/Taking rows value from the user<br>System.out.println(\u201cEnter the number of rows: \u201c);<br>int rows = sc.nextInt();<br>for (int i = 1; i &lt;= rows; i++)<br>{<br>for (int j = 1; j &lt;= i; j++)<br>{<br>System.out.print(i+\u201d \u201c);<br>}<br>System.out.println();<br>}<br>sc.close();<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-68-write-a-java-program-to-print-the-following-number-pattern\"><strong>68. Write a Java program to print the following number pattern.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>5<br>5 4<br>5 4 3<br>5 4 3 2<br>5 4 3 2 1<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>Scanner sc = new Scanner(System.in); \/\/Taking rows value from the user<br>System.out.println(\u201cEnter the number of rows: \u201c);<br>int rows = sc.nextInt();for (int i = rows; i &gt;= 1; i\u2013)<br>{<br>for (int j = rows; j &gt;= i; j\u2013)<br>{<br>System.out.print(j+\u201d \u201c);<br>}<br>System.out.println();}sc.close();<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-69-write-a-java-program-to-print-the-following-number-pattern\"><strong>69. Write a Java program to print the following number pattern.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>1<br>2 1<br>3 2 1<br>4 3 2 1<br>5 4 3 2 1<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>Scanner sc = new Scanner(System.in);<br>System.out.println(\u201cEnter the number of rows: \u201c);<br>int rows = sc.nextInt();<br>for (int i = 1; i &lt;= rows; i++)<br>{<br>for (int j = i; j &gt;= 1; j\u2013)<br>{<br>System.out.print(j+\u201d \u201c);<br>}<br>System.out.println();<br>}<br>sc.close();<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-70-write-a-java-program-to-print-the-following-binary-numbers-pattern\"><strong>70. Write a Java program to print the following binary numbers pattern.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>10101<br>01010<br>10101<br>01010<br>10101<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>Scanner sc = new Scanner(System.in);<br>System.out.println(\u201cEnter the number of rows: \u201c);<br>int rows = sc.nextInt();<br>for (int i = 1; i &lt;= rows; i++)<br>{<br>int num;<br>if(i%2 == 0)<br>{<br>num = 0;<br>for (int j = 1; j &lt;= rows; j++)<br>{<br>System.out.print(num);<br>num = (num == 0)? 1 : 0;<br>}<br>}<br>else<br>{<br>num = 1;<br>for (int j = 1; j &lt;= rows; j++)<br>{<br>System.out.print(num);<br>num = (num == 0)? 1 : 0;<br>}<br>}<br>System.out.println();<br>}<br>sc.close();<br>}<br>}<br>\u200d<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-71-write-a-java-program-to-print-the-following-binary-numbers-pattern\"><strong>71. Write a Java program to print the following binary numbers pattern.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>1<br>10<br>101<br>1010<br>10101<br>import java.util.Scanner;<br>public class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>Scanner sc = new Scanner(System.in);<br>System.out.println(\u201cEnter the number of rows: \u201c);<br>int rows = sc.nextInt();<br>for (int i = 1; i &lt;= rows; i++)<br>{<br>for (int j = 1; j &lt;= i; j++)<br>{<br>if(j%2 == 0)<br>{<br>System.out.print(0);<br>}<br>else<br>{<br>System.out.print(1);<br>}<br>}<br>System.out.println();<br>}<br>sc.close();<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-72-write-a-java-program-to-print-floyd-s-pattern\"><strong>72. Write a Java program to print Floyd\u2019s pattern.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>1<br>2 3<br>4 5 6<br>7 8 9 10<br>public class Floyd<br>{<br>public static void main(String&#91;] args)<br>{<br>int rows = 4, number = 1;<br>for(int i = 1; i &lt;= rows; i++)<br>{<br>for(int j = 1; j &lt;= i; j++)<br>{<br>System.out.print(number + \u201d \u201c);<br>++number;<br>}<br>System.out.println();<br>}<br>}<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-java-logical-interview-questions\"><strong>Java Logical Interview Questions<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-73-write-a-java-program-to-reverse-a-string-without-using-string-built-in-methods\"><strong>73. Write a Java program to reverse a string without using string built-in methods.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ReverseString<br>{<br>public static void main(String&#91;] args)<br>{<br>String str = \u201cReversed String\u201d;<br>StringBuilder str2 = new StringBuilder();<br>str2.append(str);<br>str2 = str2.reverse();<br>\/\/ used string builder to reverse<br>System.out.println(str2);<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-74-write-a-java-program-to-swap-two-variables-using-the-third-variable\"><strong>74. Write a Java program to swap two variables using the third variable.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;<br>public class SwapTwoNumbers<br>{<br>public static void main(String&#91;] args)<br>{<br>int x, y, temp;<br>System.out.println(\u201cEnter x and y\u201d);<br>Scanner in = new Scanner(System.in);<br>x = in.nextInt();<br>y = in.nextInt();<br>System.out.println(\u201cBefore Swapping\u201d + x + y);<br>temp = x;<br>x = y;<br>y = temp;<br>System.out.println(\u201cAfter Swapping\u201d + x + y);<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-75-write-a-java-program-to-swap-two-variables-without-using-the-third-variable\"><strong>75. Write a Java program to swap two variables without using the third variable.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;<br>class SwapNum<br>{<br>public static void main(String args&#91;])<br>{<br>int x, y;<br>System.out.println(\u201cEnter x and y\u201d);<br>Scanner in = new Scanner(System.in);<br>x = in.nextInt();<br>y = in.nextInt();<br>System.out.println(\u201cBefore Swapping\\nx = \u201c+x+\u201d\\ny = \u201c+y);<br>x = x + y;<br>y = x \u2013 y;<br>x = x \u2013 y;<br>System.out.println(\u201cAfter Swapping without third variable\\nx = \u201c+x+\u201d\\ny = \u201c+y);<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-76-write-a-java-program-to-find-a-prime-number\"><strong>76. Write a Java program to find a prime number.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;<br>public class Prime<br>{<br>public static void main(String&#91;] args)<br>{<br>int temp, num;<br>boolean isPrime = true;<br>Scanner in = new Scanner(System.in);<br>num = in.nextInt();<br>in.close();<br>for (int i = 2; i&amp;lt;= num\/2; i++)<br>{<br>temp = num%i;<br>if (temp == 0)<br>{<br>isPrime = false;<br>break;<br>}<br>}<br>if(isPrime)<br>System.out.println(num + \u201cnumber is prime\u201d);<br>else<br>System.out.println(num + \u201cnumber is not a prime\u201d);<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-77-write-a-java-program-to-find-whether-a-number-is-palindrome-or-not\"><strong>77. Write a Java program to find whether a number is palindrome or not.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;<br>public class Palindrome<br>{<br>public static void main (String&#91;] args)<br>{<br>String original, reverse = \u201c\u201d;<br>Scanner in = new Scanner(System.in);<br>int length;<br>System.out.println(\u201cEnter the number or String\u201d);<br>original = in.nextLine();<br>length = original.length();<br>for (int i =length -1; i&gt;;=0; i\u2013)<br>{<br>reverse = reverse + original.charAt(i);<br>}<br>System.out.println(\u201creverse is:\u201d +reverse);<br>if(original.equals(reverse))<br>System.out.println(\u201cThe number is palindrome\u201d);<br>else<br>System.out.println(\u201cThe number is not a palindrome\u201d);<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-78-write-a-java-program-to-find-fibonacci-series\"><strong>78. Write a Java program to find Fibonacci series.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;<br>public class Fibonacci<br>{<br>public static void main(String&#91;] args)<br>{<br>int num, a = 0,b=0, c =1;<br>Scanner in = new Scanner(System.in);<br>System.out.println(\u201cEnter the number of times\u201d);<br>num = in.nextInt();<br>System.out.println(\u201cFibonacci Series of the number is:\u201d);<br>for (int i=0; i&lt;num; i++)<br>{<br>a = b;<br>b = c;<br>c = a+b;<br>System.out.println(a + \u201c\u201d);<br>\/\/if you want to print on the same line, use print()<br>}<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-79-write-a-java-program-to-find-duplicate-characters-in-a-string\"><strong>79. Write a Java program to find duplicate characters in a string.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public class DuplicateCharacters<br>{<br>public static void main(String&#91;] args)<br>{<br>String str = new String(\u201cSakkett\u201d);<br>int count = 0;<br>char&#91;] chars = str.toCharArray();<br>System.out.println(\u201cDuplicate characters are:\u201d);<br>for (int i=0; i&amp;lt;str.length();i++)<br>{<br>for(int j=i+1; j&amp;lt;str.length();j++)<br>{<br>if (chars&#91;i] == chars&#91;j])<br>{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(chars&#91;j]);<br>count++;<br>break;<br>}<br>}<br>}<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-80-write-a-java-program-to-check-armstrong-number\"><strong>80. Write a Java program to check Armstrong number.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>class Armstrong<br>{<br>public static void main(String&#91;] args)<br>{<br>int c=0,a,temp;<br>int n=153;\/\/It is the number to check Armstrong<br>temp=n;<br>while(n&amp;gt;0)<br>{<br>a=n%10;<br>n=n\/10;<br>c=c+(a*a*a);<br>}<br>if(temp==c)<br>System.out.println(\u201carmstrong number\u201d);<br>else<br>System.out.println(\u201cNot armstrong number\u201d);<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-81-explain-the-armstrong-number-concept\"><strong>81. Explain the Armstrong number concept.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Armstrong number is the number which is the sum of the cubes of all its units, tens and hundreds digits for three-digit numbers.<br>153 = 1*1*1 + 5*5*5 + 3*3*3 = 1 + 125 + 27 = 153<br>If you have a four-digit number, for example:<br>1634 = 1*1*1*1 + 6*6*6*6 + 3*3*3*3 + 4*4*4*4 = 1 + 1296 + 81 + 256 = 1634<br>Now, in this program, we have a temp and integers declared. We have initialized c with the value 0. Then, we need to assign the integer value which we are going to check for Armstrong (in our case, let us say 153). Then we have assigned our temp variable with that number which we are going to check.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br>Thereafter, we used conditional check where the remainder is assigned to a and the number is divided by 10 and assigned to n. Now, our c variable which was set to zero initially is assigned with c+ (a*a*a). Suppose we have to evaluate a four-digit number then c should be assigned with c + (a*a*a*a).<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, we have put an if-else statement for conditional checking where we have compared the value contained in c against temp (which has the actual number stored at this point). If it matches, then the number is Armstrong otherwise not. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-82-write-a-java-program-to-remove-all-spaces-from-the-string-using-replace-function\"><strong>82. Write a Java program to remove all spaces from the string using replace() function.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>class Codegnan<br>{<br>public static void main(String&#91;] args)<br>{<br>String str1 = \u201cRemove&nbsp; &nbsp; the white&nbsp; &nbsp; &nbsp; spaces&nbsp; from&nbsp; &nbsp; here.\u201d;<br>\/\/Using replaceAll() function<br>String str2 = str1.replaceAll(\u201c\\\\s\u201d, \u201c\u201d);<br>System.out.println(str2);<br>}<br>}<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-java-interview-questions-for-experienced\"><strong>Java Interview Questions for Experienced<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-83-how-can-you-run-a-java-application-on-the-command-line-and-set-the-classpath-with-multiple-jars\"><strong>83. How can you run a Java application on the command line and set the classpath with multiple jars?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use the -cp or -classpath option to specify the classpath. You can include multiple JAR files separated by the system path separator (: on Linux\/macOS, ; on Windows):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>java -cp \/dev\/myapp.jar:\/dev\/mydependency.jar com.Codegnan.MyApp<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;Here are some additional points you could discuss to elaborate on your example command for an interview:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explain what the -cp option does:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Sets the classpath for the java command, allowing you to specify which JARs and directories are searched for classes and resources<\/li>\n\n\n\n<li>Discuss the advantages of using -cp over CLASSPATH env variable:<\/li>\n\n\n\n<li>Allows you to set classpath explicitly for each command, without modifying global CLASSPATH var<\/li>\n\n\n\n<li>Overrides CLASSPATH rather than extending it, giving more control<\/li>\n\n\n\n<li>Can be used to test classpath changes easily without impacting other processes<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Best practices for structuring the classpath:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keep application JARs separate from library JARs<\/li>\n\n\n\n<li>Order from most application-specific to most general&nbsp;<\/li>\n\n\n\n<li>Use a common convention like putting libs in a `lib` directory<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Discuss organizing code into modules\/JARs:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keeps classes and resources together for dependencies<\/li>\n\n\n\n<li>Allows versioning of modules<\/li>\n\n\n\n<li>Improves encapsulation and reusability<\/li>\n\n\n\n<li>Manages class visibility with exported packages<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Talk about manifest files and setting classpath there<\/li>\n\n\n\n<li>Discuss pros\/cons of using wildcards on classpath<\/li>\n\n\n\n<li>Mention Java 9+ modules as a newer alternative to JARs<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-84-state-the-difference-between-final-finalize-and-finally-methods\"><strong>84. State the difference between final, finalize, and finally methods.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Final is a Java keyword used to indicate that either a method cannot override in a subclass, or a class cannot be extended or a field cannot be modified. finalize is a method that gets called on an instance of an Object when it is garbage collected. finally is a Java keyword used in exception handling to indicate a block of code that should always be run whether an exception is thrown or not.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-85-state-the-difference-between-classnotfoundexception-and-noclassdeffounderror\"><strong>85. State the difference between ClassNotFoundException and NoClassDefFoundError.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A ClassNotFoundException means the class file for a requested class is not on the classpath of the application. A NoClassDefFoundErrormeans that the class file exists at runtime, but for some reason, the class could not be turned into a Class definition. A common cause is an exception being thrown in static initialization blocks.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-86-state-the-difference-between-equals-and-hashcode-of-an-object\"><strong>86. State the difference between equals and hashCode of an object.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The only obligation is that for any objects o1 and o2 then if o1.equals(o2) is true then o1.hashCode() == o2.hashCode() is true.<br>\u200d<br>Note that this relationship goes only one way: for any o1, o2 of some class C, where none of o1 and o2 are null, then it can happen that o1.hashCode() == o2.hashCode() is true BUT o1.equals(o2) is false.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-87-explain-the-concept-of-serialization\"><strong>87. Explain the concept of serialization.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Serialization is a method that transforms an object into an array of bytes. This byte array displays the class, variant, and internal condition object. JVM can transmit\/read the object over a network with this byte array.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-88-why-should-we-use-serialization-in-java\"><strong>88. Why should we use serialization in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Following are the use cases of serialization:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Communication: used for networking of an object between two devices.<\/li>\n\n\n\n<li>Persistence: The object state will be stored and then recovered from the database into a database.<\/li>\n\n\n\n<li>Caching: Caching can be used to boost output using serialization. We might have to create an object for ten minutes, but de-serializing it will take only ten seconds.<\/li>\n\n\n\n<li>Cross jvm syncing: It can be used on different jvm architectures in the same way.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-89-what-is-deserialization\"><strong>89. What is Deserialization?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Deserialization is the process of reconstructing the object from the serialized state. It is the reverse process of serialization.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-90-in-java-is-it-allowed-to-mark-a-method-as-transient\"><strong>90. In Java, is it allowed to mark a method as transient?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No, Java does not allow marking a method as transient. The transient keyword is valid only for member variables. Member variables of an object are marked transient to indicate that they should not be serialized. During the serialization process, the transient variables are not considered part of the persistent state of an object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-91-state-the-difference-between-a-serializable-and-an-externalizable-interface\"><strong>91. State the difference between a Serializable and an Externalizable interface.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Serializable is a marker interface but Externalizable is not a marker interface. When we implement a Serializable interface, the class is serialized automatically by default. We can override writeObject() and readObject() methods to control more complex object Serialization processes.<br>In the case of Externalizable, we use readExternal() and writeExternal() methods to give control to the class for the serialization process of a class.<br>A serializable interface is based on a recursive algorithm. Serializable gives you two options. One option is to provide a custom way of serialization, and the other default way. In Externalizable, you have to always implement readExternal() and writeExternal() methods.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A public no-arg constructor is needed while using an Externalizable interface. In Serialization, we need to define serialVersionUID. If it is not explicitly defined it will be generated automatically based on all the fields, and methods of the class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-92-in-java-how-can-we-access-the-private-methods-of-a-class-from-outside-the-class\"><strong>92. In Java, How can we access the private methods of a class from outside the class?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We can use Reflection to access private methods of a class from outside the class. In Java, we use getDeclaredMethod() to get instances of a private method. Then we mark this method accessible and finally invoke it.<br>In the following sample code, we are accessing the private method message() of class Foo by Reflection. The file name is Foo.java<br><br>public class Foo<br>{<br>private void message()<br>{<br>System.out.println(\u201chello java\u201d);<br>}<br>}FileName: FooMethodCall.java<br>import java.lang.reflect.Method;<br>public class FooMethodCall<br>{<br>public static void main(String[] args)throws Exception<br>{<br>Class c = Class.forName(\u201cFoo\u201d);<br>Object o= c.newInstance();<br>Method m =c.getDeclaredMethod(\u201cmessage\u201d, null);<br>m.setAccessible(true);<br>m.invoke(o, null);}}<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-93-explain-the-concept-of-garbage-collection-in-java\"><strong>93. Explain the concept of garbage collection in Java.<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The mechanism by which Java programs perform automated memory storage is Java garbage collection. Java programs are compiled into bytecodes that can be executed on a virtual Java machine or for short, a JVM.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As Java programs run on the JVM, objects are generated on the heap, which is the dedicated portion of the program\u2019s memory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-94-how-can-an-object-be-unreferenced\"><strong>94. How can an object be unreferenced?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, there are many ways to do that, for example:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><strong>\u2022 By nulling the reference<br><\/strong>Employee e=new Employee();<br>e=null;<br>\u2022 By assigning a reference to another<br>Employee e1=new Employee();<br>Employee e2=new Employee();<br>e1=e2;\/\/now the first object referred by e1 is available for garbage collection<br>\u2022 By anonymous object<br>new Employee();<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-95-write-a-program-to-give-a-simple-example-of-garbage-collection-in-java\"><strong>95. Write a program to give a simple example of garbage collection in Java.<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public class TestGarbage1<br>{<br>public void finalize()<br>{<br>System.out.println(\u201cobject is garbage collected\u201d);<br>}<br>public static void main(String args&#91;])<br>{<br>TestGarbage1 s1=new TestGarbage1();<br>TestGarbage1 s2=new TestGarbage1();<br>s1=null;<br>s2=null;<br>System.gc();<br>}<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-96-what-exactly-is-the-purpose-of-a-garbage-collector\"><strong>96. What exactly is the purpose of a garbage collector?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">There are no pointers in Java. Control and Utilization of Memory is achieved by JVM. Because it is automatic to assign memory after some JVM could go low on memory time. JVM must be free at the moment so that memory from objects that are unused.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To aid in the method of Java offers an automatic method called reclaiming memories, called Collector of Garbage.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-97-what-is-gc\"><strong>97. What is GC()?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Two methods are supported by Java: System.gc() and Runtime.gc()&nbsp; to order the JVM to run the garbage collection. Programmers can directly submit requests for garbage collection when using these tools. But the JVM process will deny this request and wait for the GC to run for some time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-98-explain-the-types-of-references-in-java\"><strong>98. Explain the types of references in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, there are four types of references:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Strong Reference<\/li>\n\n\n\n<li>Soft Reference<\/li>\n\n\n\n<li>Weak Reference<\/li>\n\n\n\n<li>Phantom Reference<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-99-what-is-the-purpose-of-the-runtime-class-in-java\"><strong>99. What is the purpose of the Runtime class in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The purpose of the Runtime class is to provide access to the Java Runtime system. This class provides certain important methods like:<br><strong>Runtime. free memory()<\/strong> \u2013 This method returns the value of free memory in JVM<br><strong>Runtime. max memory() <\/strong>\u2013 This method returns the value of maximum memory that JVM can use.<br>Runtime.gc() \u2013 This method can invoke garbage collection.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-100-how-many-types-of-nested-classes-are-supported-in-java\"><strong>100. How many types of nested classes are supported in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Java supports four types of nested classes:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Member inner class<\/li>\n\n\n\n<li>Local inner class<\/li>\n\n\n\n<li>Anonymous inner class<\/li>\n\n\n\n<li>Static nested class<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-101-what-is-the-difference-between-nested-class-and-inner-class-in-java\"><strong>101. What is the difference between nested class and inner class in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Java\u2019s Inner Class is a non-static class. It is a type of nested class that is identified with a Static modifier in another class but is not eligible.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A Nested class is either a Static Nested class or a non-Static Inner class that may be a class. An Inner Class shall have access, even if declared confidential, to all members of the Enclosing Class. The other members of the enclosing class cannot be accessed by a Static Nesting class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-102-if-i-am-saying-immutable-in-the-context-of-string-what-does-it-mean\"><strong>102. If I am saying Immutable in the context of string, what does it mean?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You cannot edit or alter an Immutable Object in Java. The String is an Immutable Java class. It cannot be modified once the String object is formed. A new object is generated when we allocate a string to a new value.<br>Let say there are 2 String variables A and B that reference a String object \u201cTestData\u201d. All these variables refer to the same String literal. If one reference variable A changes the value of the String literal from \u201cTestData\u201d to \u201creal data\u201d, then it will affect the other variable as well.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Due to which String is considered Immutable. In this case, if one variable A changes the value to \u201creal data\u201d, then a new String literal with \u201creal data\u201d is created and A will point to a new String literal. While B will keep pointing to \u201cTestData\u201d.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-103-how-many-objects-does-the-following-code-create\"><strong>103. How many objects does the following code create?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">String s1=\u201dHelloWorld\u201d;<br>String s2=\u201d HelloWorld \u201c;<br>String s3=\u201d HelloWorld \u201c;<br>The above code creates only one object. Since there is only one String Literal \u201cHelloWorld\u201d created, all the references point to the same object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-104-how-many-objects-does-the-following-code-create\"><strong>104. How many objects does the following code create?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">String s = new String(\u201cHelloWorld\u201d);<br>The above code creates two objects. One object is created in a String constant pool and the other is created on the heap in a non-pool area.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-105-state-the-difference-between-a-string-and-stringbuffer-object\"><strong>105. State the difference between a String and StringBuffer object?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The string is an immutable object. Its value cannot change after creation. StringBuffer is a mutable object. We can keep appending or modifying the contents of a StringBuffer in Java.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-106-how-can-you-create-an-immutable-class-in-java\"><strong>106. How can you create an immutable class in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, we can declare a class final to make it immutable. Following are the detailed steps to make it Immutable:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Add final modifier to class to prevent it from getting extended<\/li>\n\n\n\n<li>Add private modifier to all the fields to prevent direct access<\/li>\n\n\n\n<li>Do not provide any setter methods for member variables<\/li>\n\n\n\n<li>Add final modifier to all the mutable fields to assign value only once<\/li>\n\n\n\n<li>Use Deep Copy to initialize all the fields by a constructor<\/li>\n\n\n\n<li>In the clone method, return a copy of the object instead of the actual object reference<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-107-state-the-use-case-of-the-string-method-in-java\"><strong>107. State the use case of the String() method in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, the Object class has a toString() method. This method can be used to return the String representation of an Object. When we print an object, Java implicitly calls the toString() method. Java provides a default implementation for the toString() method. But we can override this method to return the format that we want to print.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-108-explain-the-concept-of-exception-handling-in-java\"><strong>108. Explain the concept of exception handling in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Java provides an Exception Handling mechanism to handle runtime errors that occur in JVM. There are checked exceptions in a program that we expect to occur in certain situations. The exception handling mechanism catches these checked exceptions and takes relevant actions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-109-state-checked-and-unchecked-exceptions-in-java\"><strong>109. State-checked and unchecked exceptions in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Checked Exceptions extend Throwable class, but they do not extend RuntimeException or Error classes. UncheckedException extends RuntimeException class. Checked Exceptions are checked at compile time in Java. Unchecked Exceptions happen at Runtime, so they are not checked at compile time.<br>IOException, SQLException, etc. are examples of Checked Exceptions. NullPointerException, ArithmeticException, etc. are examples of Unchecked Exceptions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-110-what-is-the-base-class-for-error-and-exception-classes-in-java\"><strong>110. What is the base class for Error and Exception classes in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Error, as well as the Exception class, is derived from the Throwable class in Java.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-111-what-is-a-final-block-in-java\"><strong>111. What is a final block in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Java provides a final block with a try block. This is an optional block. But finally the block is always executed after the execution of the try block. A final block includes all the critical statements that must be executed whether an exception exists or not.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The statements present in this block will still execute regardless of whether an exception exists in a try block or not such as closing a connection, stream, etc.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-112-in-what-scenarios-a-final-block-will-not-be-executed\"><strong>112. In what scenarios, a final block will not be executed??<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">There are two main scenarios in which finally block is not executed:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Program exits by calling the system. exit() call<\/li>\n\n\n\n<li>A fatal error causes JVM to crash<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-113-is-it-possible-to-re-throw-an-exception-in-java\"><strong>113. Is it possible to re-throw an exception in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Using throw keyword:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">try {<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&nbsp;&nbsp;\/\/ code that throws exception\n} catch (Exception e) {\n\n&nbsp;&nbsp;\/\/ handle exception\n\n&nbsp;&nbsp;throw e; \/\/ rethrows same exception\n\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. Calling throw on exception instance:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>try {\n\n&nbsp;&nbsp;\/\/ code that throws exception&nbsp;\n\n} catch (Exception e) {\n\n&nbsp;\/\/ handle exception\n\n&nbsp;throw e; \/\/ rethrows caught exception\n\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. Creating new exception and passing original as cause:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>try {\n\n&nbsp;\/\/ code that throws exception\n\n} catch (IOException e) {\n\n&nbsp;&nbsp;throw new CustomException(\"Error message\", e); \/\/ Wraps and rethrows\n\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-114-state-the-difference-between-throw-and-throws-in-java\"><strong>114. State the difference between throw and throws in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Sr. No.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Key<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">throw<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">throws<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Definition<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Throws is a keyword used in the method signature used to declare an exception that might get thrown by the function while executing the code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The throw is a keyword that is used to throw an exception explicitly in the program inside a function or inside a block of code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Internal implementation<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Internally, the throw is implemented as it is allowed to throw only a single exception at a time i.e we cannot throw multiple exceptions with a throw keyword.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The throw is a keyword that is used to throw an exception explicitly in the program inside a function or inside a block of code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. Type of exception<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Throws is a keyword used in the method signature used to declare an exception that might get thrown by the function while executing the code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The throw is a keyword that is used to throw an exception explicitly in the program inside a function or inside a block of code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4. Syntax<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Throws is a keyword used in the method signature used to declare an exception that might get thrown by the function while executing the code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The throw is a keyword that is used to throw an exception explicitly in the program inside a function or inside a block of code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5. Declaration<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Throws is a keyword used in the method signature used to declare an exception that might get thrown by the function while executing the code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The throw is a keyword that is used to throw an exception explicitly in the program inside a function or inside a block of code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-115-state-the-difference-between-collection-and-collections-framework-in-java\"><strong>115. State the difference between collection and collections framework in Java?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, an object containing many similar elements in a single unit is an array. You may access these few objects by means of an object from the list. A framework that provides standard architecture to build, upgrade and access various types of collections is part of the Java Collections Framework. There are common methods in the collections system that developers mostly use to operate on an item in the array.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-116-state-the-thread-safe-classes-in-java-collections-framework\"><strong>116. State the Thread-safe classes in Java Collections framework?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The Thread-safe classes in the Java Collections framework are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Stack<\/li>\n\n\n\n<li>Properties<\/li>\n\n\n\n<li>Vector<\/li>\n\n\n\n<li>Hashtable<\/li>\n\n\n\n<li>Blocking<\/li>\n\n\n\n<li>Queue<\/li>\n\n\n\n<li>ConcurrentMap<\/li>\n\n\n\n<li>ConcurrentNavigableMap<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-117-what-are-the-advantages-of-using-jsp-in-web-architecture\"><strong>117. What are the advantages of using JSP in web architecture?<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Performance<\/strong>: JSP works very well since it designs many requests with the same code.<\/li>\n\n\n\n<li><strong>Fast<\/strong>: As JSP has been pre-compiled, the server will easily serve pages.<\/li>\n\n\n\n<li><strong>Extendable<\/strong>: JSP is Java-based. This allows JSP architecture to be expanded using other Java technologies such as JDBC, JMS, JNDI etc.<\/li>\n\n\n\n<li><strong>Build<\/strong>: The user interface for JSP is easier to design since the interface is similar to HTML. UI designers can create a mock data JSP, and developers can implement dynamic data at a later date.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-118-what-is-extra-lazy-fetching-in-hibernate\"><strong>118. What is \u2018Extra lazy fetching\u2019 in Hibernate??<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Extra lazy fetching, the database only gathers individual components of a set as necessary.&nbsp; Hibernate does not recall the whole set in this technique until it is necessary. This is a good technique for fetching large object arrays.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-119-what-command-will-you-use-to-package-your-maven-project\"><strong>119. What command will you use to package your Maven project?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To package a project into a distributable format we use the following command:<br>mvn -package<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-120-state-the-primary-use-cases-of-the-maven-plugin\"><strong>120. State the primary use cases of the Maven plugin?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Maven is mainly a plugin execution framework. At the core of Maven, all the work is done by plugins. A Maven plugin can be used for the following purposes:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Cleaning up the code<\/li>\n\n\n\n<li>Compiling the code<\/li>\n\n\n\n<li>Creating a JAR file<\/li>\n\n\n\n<li>Deploying the artifacts<\/li>\n\n\n\n<li>Running the unit tests<\/li>\n\n\n\n<li>Documenting the project<\/li>\n\n\n\n<li>Generating the site of a project<\/li>\n\n\n\n<li>Generating a WAR file<\/li>\n\n\n\n<li>Generate a checkstyle report<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Learn about <strong><a href=\"https:\/\/codegnan.com\/blogs\/react-js-projects\/\">React JS projects<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are endless questions asked in a Java interview depending on the job position and candidates with different skills, experience, and background knowledge. However, some common JAVA questions often get asked and answered repeatedly in Java interviews everywhere. This is why we have asked our Java experts and mentors to share their top interview questions [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":38824,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[],"class_list":["post-13261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v23.3 (Yoast SEO v27.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>120 Important Java Interview Questions and Answers (2024)<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codegnan.com\/java-interview-questions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"120 Important Java Interview Questions and Answers\" \/>\n<meta property=\"og:description\" content=\"There are endless questions asked in a Java interview depending on the job position and candidates with different skills, experience, and background knowledge. However, some common JAVA questions often get asked and answered repeatedly in Java interviews everywhere. This is why we have asked our Java experts and mentors to share their top interview questions [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codegnan.com\/java-interview-questions\/\" \/>\n<meta property=\"og:site_name\" content=\"Codegnan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codegnan\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-31T09:00:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-08T07:27:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codegnan.com\/wp-content\/uploads\/2024\/01\/JAVA-Interview-Questions-by-codegnan-Experts.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sairam Uppugundla\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codegnandotcom\" \/>\n<meta name=\"twitter:site\" content=\"@codegnandotcom\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sairam Uppugundla\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"32 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/java-interview-questions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/java-interview-questions\\\/\"},\"author\":{\"name\":\"Sairam Uppugundla\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/#\\\/schema\\\/person\\\/510a2ce6cfa80a9688733994fe67da52\"},\"headline\":\"120 Important Java Interview Questions and Answers\",\"datePublished\":\"2024-01-31T09:00:44+00:00\",\"dateModified\":\"2026-05-08T07:27:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/java-interview-questions\\\/\"},\"wordCount\":7036,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/java-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codegnan.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/JAVA-Interview-Questions-by-codegnan-Experts.jpg\",\"articleSection\":[\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/codegnan.com\\\/java-interview-questions\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/java-interview-questions\\\/\",\"url\":\"https:\\\/\\\/codegnan.com\\\/java-interview-questions\\\/\",\"name\":\"120 Important Java Interview Questions and Answers (2024)\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/java-interview-questions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/java-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codegnan.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/JAVA-Interview-Questions-by-codegnan-Experts.jpg\",\"datePublished\":\"2024-01-31T09:00:44+00:00\",\"dateModified\":\"2026-05-08T07:27:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/java-interview-questions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/codegnan.com\\\/java-interview-questions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/java-interview-questions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/codegnan.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/JAVA-Interview-Questions-by-codegnan-Experts.jpg\",\"contentUrl\":\"https:\\\/\\\/codegnan.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/JAVA-Interview-Questions-by-codegnan-Experts.jpg\",\"width\":900,\"height\":400},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/java-interview-questions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/codegnan.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/codegnan.com\\\/category\\\/java\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"120 Important Java Interview Questions and Answers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/#website\",\"url\":\"https:\\\/\\\/codegnan.com\\\/\",\"name\":\"Codegnan\",\"description\":\"Where Talent Meets Opportunity\",\"publisher\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/codegnan.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/#organization\",\"name\":\"Codegnan\",\"url\":\"https:\\\/\\\/codegnan.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/codegnan.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/Codegnan-New-Logo.png\",\"contentUrl\":\"https:\\\/\\\/codegnan.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/Codegnan-New-Logo.png\",\"width\":420,\"height\":102,\"caption\":\"Codegnan\"},\"image\":{\"@id\":\"https:\\\/\\\/codegnan.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codegnan\\\/\",\"https:\\\/\\\/x.com\\\/codegnandotcom\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codegnan\",\"https:\\\/\\\/www.instagram.com\\\/codegnan\\\/\",\"https:\\\/\\\/t.me\\\/codegnan\",\"https:\\\/\\\/www.youtube.com\\\/@Codegnan\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/codegnan.com\\\/#\\\/schema\\\/person\\\/510a2ce6cfa80a9688733994fe67da52\",\"name\":\"Sairam Uppugundla\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fb72f4f7eb256ddd452b9939d321540cd244487ff7bb982f98e750e2df959cb6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fb72f4f7eb256ddd452b9939d321540cd244487ff7bb982f98e750e2df959cb6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fb72f4f7eb256ddd452b9939d321540cd244487ff7bb982f98e750e2df959cb6?s=96&d=mm&r=g\",\"caption\":\"Sairam Uppugundla\"},\"description\":\"Sairam Uppugunda is the Founder of Codegnan and a technology educator with expertise in Software Development, Python Programming, Data Science, Artificial Intelligence, Full Stack Development, and emerging IT technologies. He has mentored thousands of engineering students and fresh graduates by focusing on practical learning, real-time projects, coding skills, and industry-ready training. Through Codegnan, he actively helps students build successful careers in technology by sharing insights on career guidance, software industry trends, placement preparation, and in-demand skills required for modern tech jobs in Hyderabad, Vijayawada, and other growing IT hubs.\",\"sameAs\":[\"https:\\\/\\\/codegnan.com\"],\"url\":\"https:\\\/\\\/codegnan.com\\\/author\\\/sairam\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"120 Important Java Interview Questions and Answers (2024)","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codegnan.com\/java-interview-questions\/","og_locale":"en_US","og_type":"article","og_title":"120 Important Java Interview Questions and Answers","og_description":"There are endless questions asked in a Java interview depending on the job position and candidates with different skills, experience, and background knowledge. However, some common JAVA questions often get asked and answered repeatedly in Java interviews everywhere. This is why we have asked our Java experts and mentors to share their top interview questions [&hellip;]","og_url":"https:\/\/codegnan.com\/java-interview-questions\/","og_site_name":"Codegnan","article_publisher":"https:\/\/www.facebook.com\/codegnan\/","article_published_time":"2024-01-31T09:00:44+00:00","article_modified_time":"2026-05-08T07:27:38+00:00","og_image":[{"width":900,"height":400,"url":"https:\/\/codegnan.com\/wp-content\/uploads\/2024\/01\/JAVA-Interview-Questions-by-codegnan-Experts.jpg","type":"image\/jpeg"}],"author":"Sairam Uppugundla","twitter_card":"summary_large_image","twitter_creator":"@codegnandotcom","twitter_site":"@codegnandotcom","twitter_misc":{"Written by":"Sairam Uppugundla","Est. reading time":"32 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codegnan.com\/java-interview-questions\/#article","isPartOf":{"@id":"https:\/\/codegnan.com\/java-interview-questions\/"},"author":{"name":"Sairam Uppugundla","@id":"https:\/\/codegnan.com\/#\/schema\/person\/510a2ce6cfa80a9688733994fe67da52"},"headline":"120 Important Java Interview Questions and Answers","datePublished":"2024-01-31T09:00:44+00:00","dateModified":"2026-05-08T07:27:38+00:00","mainEntityOfPage":{"@id":"https:\/\/codegnan.com\/java-interview-questions\/"},"wordCount":7036,"commentCount":0,"publisher":{"@id":"https:\/\/codegnan.com\/#organization"},"image":{"@id":"https:\/\/codegnan.com\/java-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/codegnan.com\/wp-content\/uploads\/2024\/01\/JAVA-Interview-Questions-by-codegnan-Experts.jpg","articleSection":["Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codegnan.com\/java-interview-questions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codegnan.com\/java-interview-questions\/","url":"https:\/\/codegnan.com\/java-interview-questions\/","name":"120 Important Java Interview Questions and Answers (2024)","isPartOf":{"@id":"https:\/\/codegnan.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codegnan.com\/java-interview-questions\/#primaryimage"},"image":{"@id":"https:\/\/codegnan.com\/java-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/codegnan.com\/wp-content\/uploads\/2024\/01\/JAVA-Interview-Questions-by-codegnan-Experts.jpg","datePublished":"2024-01-31T09:00:44+00:00","dateModified":"2026-05-08T07:27:38+00:00","breadcrumb":{"@id":"https:\/\/codegnan.com\/java-interview-questions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codegnan.com\/java-interview-questions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codegnan.com\/java-interview-questions\/#primaryimage","url":"https:\/\/codegnan.com\/wp-content\/uploads\/2024\/01\/JAVA-Interview-Questions-by-codegnan-Experts.jpg","contentUrl":"https:\/\/codegnan.com\/wp-content\/uploads\/2024\/01\/JAVA-Interview-Questions-by-codegnan-Experts.jpg","width":900,"height":400},{"@type":"BreadcrumbList","@id":"https:\/\/codegnan.com\/java-interview-questions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codegnan.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/codegnan.com\/category\/java\/"},{"@type":"ListItem","position":3,"name":"120 Important Java Interview Questions and Answers"}]},{"@type":"WebSite","@id":"https:\/\/codegnan.com\/#website","url":"https:\/\/codegnan.com\/","name":"Codegnan","description":"Where Talent Meets Opportunity","publisher":{"@id":"https:\/\/codegnan.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codegnan.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codegnan.com\/#organization","name":"Codegnan","url":"https:\/\/codegnan.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codegnan.com\/#\/schema\/logo\/image\/","url":"https:\/\/codegnan.com\/wp-content\/uploads\/2023\/05\/Codegnan-New-Logo.png","contentUrl":"https:\/\/codegnan.com\/wp-content\/uploads\/2023\/05\/Codegnan-New-Logo.png","width":420,"height":102,"caption":"Codegnan"},"image":{"@id":"https:\/\/codegnan.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codegnan\/","https:\/\/x.com\/codegnandotcom","https:\/\/www.linkedin.com\/company\/codegnan","https:\/\/www.instagram.com\/codegnan\/","https:\/\/t.me\/codegnan","https:\/\/www.youtube.com\/@Codegnan"]},{"@type":"Person","@id":"https:\/\/codegnan.com\/#\/schema\/person\/510a2ce6cfa80a9688733994fe67da52","name":"Sairam Uppugundla","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/fb72f4f7eb256ddd452b9939d321540cd244487ff7bb982f98e750e2df959cb6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/fb72f4f7eb256ddd452b9939d321540cd244487ff7bb982f98e750e2df959cb6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fb72f4f7eb256ddd452b9939d321540cd244487ff7bb982f98e750e2df959cb6?s=96&d=mm&r=g","caption":"Sairam Uppugundla"},"description":"Sairam Uppugunda is the Founder of Codegnan and a technology educator with expertise in Software Development, Python Programming, Data Science, Artificial Intelligence, Full Stack Development, and emerging IT technologies. He has mentored thousands of engineering students and fresh graduates by focusing on practical learning, real-time projects, coding skills, and industry-ready training. Through Codegnan, he actively helps students build successful careers in technology by sharing insights on career guidance, software industry trends, placement preparation, and in-demand skills required for modern tech jobs in Hyderabad, Vijayawada, and other growing IT hubs.","sameAs":["https:\/\/codegnan.com"],"url":"https:\/\/codegnan.com\/author\/sairam\/"}]}},"_links":{"self":[{"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/posts\/13261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/comments?post=13261"}],"version-history":[{"count":0,"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/posts\/13261\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/media\/38824"}],"wp:attachment":[{"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/media?parent=13261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/categories?post=13261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codegnan.com\/wp-json\/wp\/v2\/tags?post=13261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}