IBM Java interview questions and answers.

Java Interview Questions and Answers covered in this post:

    Java interview questions and answers


        What is platform-independent? Why java is platform-independent?

    -   Platform independent means “write once run anywhere”. In short, once you write a program on any platform can run it on any platform.  e.g. If you wrote a program on Unix can run it on windows or any other platform or operating system.

    Once the Java program compiles that program converts into byte code. Byte code is not platform dependent so Java is platform-independent.


        What is static import?

    -    Static import means we are importing static members from another class.

    -      Once we import static members then we can use those members without the class name.

    -  Generally, we use static members with the class name but once you import then there is no need to use the class name. You can directly access those members.


        Where the static variables are stored in java?

    -    The static variables were stored in the Perm-Gen space (also called the method area).

    -      The static variables are stored in the Heap itself.

    -    Java 8 onwards the Perm-Gen Space has been removed and a new space named Meta-Space is introduced which is not part of Heap memory anymore unlike the previous Perm-Gen Space.


     

    Click here to Purchase on AmazonClick here to Purchase on Amazon

    Click here to Purchase on Amazon

    Note: Please click on Image to Purchase the books from Amazon.in

        What is variable shadowing?

    -   Shadowing means a variable declared within a certain scope (Declared inside method or block) has the same name as a variable declared in an outer scope.

    -    In short, we have the same variable name in block or method and class level variable.

    -     For a demonstration please refer to the below example.

    package simplifiedjava.crackedInterview; 

    public class VariavleShadowingDemo { 

          int num = 10;     

          public void printNum() {

                int num = 20;

                System.out.println("Num Value "+ num);

          }         

          public static void main(String[] args) {

                new VariavleShadowingDemo().printNum();

          }

    }

    Output : 20. Because local variable has highest priority inside method.


        What is the diamond problem in Java?  Why java doesn't support multiple inheritance?

    -      Diamond problem comes into the picture in multiple inheritance.

    -    When one class is inheriting the same property from multiple classes. This is called the diamond problem.

    -    E.g. There are 3 classes. Class A, Class B and Class C. Class A and Class B have add() method and when class C extends class A and class B. Class C is trying to override add() method then which method compiler will refer for overriding. There is ambiguity. This is a diamond problem. That’s why java doesn’t support multiple inheritance.


        Can we skip the finally block to execute? if yes then how?

    -      Yes we can skip the finally block to execute.

    -   We can skip using System.exit(0). Once you execute this method then your program terminates.

    -      Please refer to the below example.

    package simplifiedjava.crackedInterview; 

    public class SkipFinallyBlockDemo { 

          public static void main(String[] args) {

                try {

                            System.out.println("Inside try Block");

                            System.exit(0);

                            System.out.println("After Excecuting exit() method");

                }catch(Exception e) {

                      System.out.println("Inside catch Block");

                      e.printStackTrace();

                }finally {

                      System.out.println("Inside finally Block");

                }

          }

    }

    Output: Inside try Block


        What is an unreachable catch block error?

    -   Unreachable catch block error comes when we have multiple catch blocks in exception handling.

    -  Catch block of Exceptions sequence must follow. Most child Exception classes must be declared first and then its parent. Must be in ascending order.

    -    Please refer to the below example.

    package simplifiedjava.crackedInterview; 

    import java.sql.Connection; 

    public class NestedTryCatchDemo { 

          public static void main(String[] args) {

                try {                       

                }catch(ArrayIndexOutOfBoundsException e) {                 

                }catch(IndexOutOfBoundsException e) {                 

                }catch(Exception e) {                 

                }

          }

    } 

    Explanation: 

    If you observe in the above program. We have declared ArrayIndexOutOfBoundsException exception first which is the child class of IndexOutOfBoundsException which is the child class of Exception.


        What are the characteristics of Hashset?

    -          Duplicate objects are not allowed.

    -          Insertion order not preserved.

    -          Based on Hashcode of Object.

    -          Only one null insertion is possible.

    -          Heterogeneous (Different types of Object) objects are allowed.

    -    HashSet is Serializable because HashSet implements a Serializable interface.

    -          HashSet is Clonable because HashSet implements a Clonable interface.

    -          HashSet has not implemented RandomAccess.

             -       Duplicate objects are not allowed and still, you are trying to add duplicate objects then you won’t get any compile-time or run-time exception just simply return false if the object is present and return true when the object is not presented.


        What is the default size and load factor of HashSet?

    -          The default size of HashSet is 16.

    -          Load Factor of HashSet is 75%.


        Can you override default method?

    -          Yes, we can override the default method in the implementation class.

    -          Please refer to the below example.

    package simplifiedjava.crackedInterview.java8; 

    public interface InterfaceForDefaultMethod { 

          default void m1() {

                System.out.println("interface m1() method called.");

          }

    } 

    package simplifiedjava.crackedInterview.java8; 

    public class DefaultMethodDemo implements InterfaceForDefaultMethod{ 

          public void m1() {

                System.out.println("Class m1() method called.");

          }         

          public static void main(String[] args) {

                InterfaceForDefaultMethod demo = new DefaultMethodDemo();

                demo.m1();       

                DefaultMethodDemo demo1 = new DefaultMethodDemo();

                demo1.m1();

          }

    }

    Output:

    Class m1() method called.

    Class m1() method called. 


    • Java interview questions and answers all MNC - Click here
    • Basic core java interview questions and answers for freshers - Click here
    • Core java interview questions for 3 years experience - Click here
    • Core java interview questions and answers for 3-5 years exp - Click here
    • Core java interview questions and Answers for 5 - 7 Years exp - Click here
    • Basic Java Interview Questions and Answers - Click here
    • Java interview questions and answers on oops - Click here
    • Java interview questions and answers on Strings - Click here
    • Java interview questions on exception handling - Click here
    • Interview questions on multithreading in java for experienced - Click here
    • Interview questions on serialization in java for experienced - Click here

    • Interview questions on inner class in java for experienced - Click here
    • Interview questions on Collections in java for experienced - Click here

    Upcoming questions in next post:

    1. What is Actual Parameter and what is formal paramter?

    2. Can you overload private method.

    3. Can we modify existing String object. If I tried to change existing String object then what will happen. 

    4. What is the difference between throw and throws.

    5. Explain the thread life cycle.

    6. What is the ThreadGroup.

    7. What is Thread pool.

    8. What is ConcurrentHashMap? What are the Characteristics of ConcurrentHashMap.

    9. What is bounded type parameter.

    10.What is JVM. 


    Previous Post                                                                    Next Post




    Thank you techies for visiting this blog. I hope you enjoyed this blog and got more technical knowledge. I have tried to cover all types of questions and provided examples tested on eclipse as much as I can. Guys, please don’t just mug up the questions and answers. Try to clear your concepts with examples. Try to write a code on eclipse once you read the concepts. It will help you to memorize the concepts for a very long time. Simultaneously you will be prepared for interview programs as well. It will help you to survive in the IT sector for a long time. It may be easy to crack an interview but it's really tough to survive in the IT industry with inadequate knowledge and skills. 

    I have collected all the questions from actual interviews attended by my friends, colleagues, college mate and classmate. I have covered frequently asked questions as well as challenging questions. I have included many programs to understand the concept thoroughly. I will try to explain the concept with the help of a real-time program in eclipse. 

    You can share more questions which are not covered in this blog or post. Always welcome your suggestions and queries. I will definitely try to resolve it. 

    Please comment your queries and new set of questions under the comment sections. I will create a new post for those questions. 

    My total experience is 10. Initially I had worked on some support projects and then I moved to java projects. I had worked with many multi-national companies like R-Systems, Tata Consultancy Services, Cybage Softwares.  Fortunately, TCS and Cybage has given me an opportunity to take interviews for experienced candidates. I have conducted more than 1000 interviews by now.

    Mock sessions will be conducted for minimal charges. I will guide you personally on how to crack interviews. All sessions will be online sessions only. My interview book will be provided free of cost if you enroll for personal training. Once you have done practice then I assured you will definitely crack almost all java interviews. 

    I have published my book named with "All MNC Java Interview" which is available on amazon. You can go through it or you can directly contact to me if you are interested to read the book. I will give you special discount. I have covered near about 550 questions and answers with program tested on eclipse and necessary diagram. 

    I have covered interview questions asked in all reputed MNC like TCS, Infosys, Capgemini, Tech Mahindra, Cognizant, City Bank, Barclays, Amdocs, Mindtree etc. My purpose behind this book is, help you to get a job in your dream company. I can understand this is a struggling period for job seekers and freshers. Everybody must have gone from this phase. so never give up. Keep upgrading yourself. I am sure you will get a job in your dream company. All the best!!! 

    Please reach out to me for personal training for interview preparation. 

    You can reach out to me at mncjavainterview@gmail.com.

     


    Post a Comment

    0 Comments