MindTree Java interview questions and answers.

Java Interview Questions and Answers covered in this post:

    Java interview questions and answers

        Can we access non-static members inside the static area either method or block?

    -    No. We cannot access non-static members inside static area either block or method.


        What is the difference between enum, Enum and Enumeration?

    -    enum : enum is a keyword that can be used to define a group of named constants.

    -  Enum: Enum is a class in java, present.lang package, Every Enum in java should be a direct child class of Enum class. Hence this class is a base class.

    -  Enumeration: Enumeration is an interface in java that is present in java.util package. We can use Enumeration to get an object step by step.


     

    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 Assertion? What is the role of Assertion in java development?

    -          Assertion is a statement that can be used to test the assumption of your program.

    -          Assertion is used for debugging purposes.

    -          Role of Assertion is:

    1. There is a very common way usage of System.out.println() statement for debugging but the problem of this statement degrades the performance of the application. To overcome this problem sun people introduced assertions.

    2. The advantage of assertion is, we don’t require removing all print statements you can simply enable or disable assertions.


        Can you explain why OutOfMemoryError occurred and how to handle it?

    -  OutofMemoryError occurs when your program is expecting more memory than JVM has available.

    -  OutOfMemoryError normally occurs when you have a code with an infinite loop.

    -  You can handle OutOfMemoryError by avoiding infinite loop.

    -  Allocate more heap space to JVM. Perm-Gen Space must increase but recently it has changed to meta-space.


        What are the advantages of Multithreading?

    -  Multithreading in java is a process of executing multiple threads simultaneously.

    -    Advantages of multithreading.

    1.       Perform multiple operations at a time.

    2.   The Performance will be improved if multiple threads are executing the shared resources.

    3.       It saves time if multiple threads are executing at a time.


        What is the volatile keyword in java?

    -  If you declare a variable as volatile, JVM will store those variables on main memory.

    -  We can make sure every time JVM reads the value from the main memory.

    -   Every time JVM writes the value it will write on the main memory.

    -  Volatile keyword ensures that variable will be visible to all thread and thread can read the value from main memory.


        Why wait(), notify() and notifyAll() method must called/invoke from synchronized area? What will happen if I invoked outside synchronized block?

    -  Threads uses wait(), notify() and notifyAll() method for inter-thread communication.

    -   Thread can get a lock either synchronized method or synchronized block. Thread must get a lock to call wait(), notify() and notifyAll() method.

    -  If you invoke these methods outside the synchronized block or method then you will get IllegalMonitorStateException.


        What is the difference between Serialization and Externalization?

     

    Serialization

    Externalization

    1.

    Serialization is default Serialization.

    Externalization is customizing Serialization.

    2.

    Everything takes care of by JVM in serialization.

    Everything takes care of by the Programmer in Externalization.

    3.

    Serialization is not capable to save the required part of the object.

    It’s also possible to save part of the object or full object in Externalization.

    4.

    Performance is low as compared to Externalization.

    Performance is high as compared to serialization.

    5.

    If you want to serialize a full object then serialization is a good option.

    If you want to serialize a partial object then externalization is a good option.

    6.

    For serialization, we have to implement a Serializable interface.

    For externalization, we have to implement an Externalizable interface.

    7.

    The transient keyword is required if you don’t want to make a particular field serialize.

    The transient keyword is not required because this is customizing serialization.

    8.

    A No-arg constructor is not required.

    A No-arg constructor is required at the time of deserialization otherwise we will get InvalidClassException.


        ArrayList is more flexible than Array but still where will you use Array over Arraylist?

    -   When you require the fixed size of homogeneous element then we must go for an Array instead of an ArrayList.

    -  Using Collection classes for primitives is appreciably slower since they have to use autoboxing and wrappers.

    -  We should prefer a more straightforward [] syntax for accessing elements over ArrayList's get(). This becomes more important when I need multidimensional arrays.

    -  ArrayLists usually allocate about twice the memory you need now in advance so that you can append items very fast. So there is wastage if you are never going to add any more items.

    -  ArrayList accesses are slower than plain arrays in general. The ArrayList implementation uses an underlying array, but all accesses have to go through the get(), set(), remove(), etc. methods which mean it goes through more code than simple array access.


        What are the characteristics of LinkedList?

    -          Insertion order preserved.

    -       Duplicates objects are allowed.

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

    -       The NULL insertion is possible.

    -       LinkedList is Clonable because LinkedList implements a Clonable interface.

    -       LinkedList is Serializable because LinkedList implements a Serializable interface.

    -        LinkedList is the worst choice if want to perform a serach or sort operation.

    -       LinkedList has not implemented RandomAccess.


    • 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. Why main method is static and public.

    2. What is the difference between instance method and static method.

    3. What is the difference between relative path and absolute path.

    4. Can you explain why StackOverflowError occurred and how to handle it?

    5. What is the difference between Synchronous and Asynchronous programming.

    6. What is the difference between CyclicBarrier and CountDownLatch.

    7. What are the scenarios where InvalidClassException can be thrown.

    8. What is the TreeSet? How the object will be stored in Treeset. 

    9. What is keySet?

    10.What is Hashtable?


    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