Core java interview questions and answers for 3-5 years experience

Part 6

Core java interview questions and answers for 3-5 years experience covered in this post:


    Core java interview questions and answers for 3-5 years experience

        Can we create a try block inside a try block?

    -          Yes. You can have any number of nested try-catch blocks.

    -          Please refer to the below example.

    package simplifiedjava.crackedInterview; 

    public class NestedTryCatchDemo { 

          public static void main(String[] args) {

                try {

                            try {

                                        try {

                                             

                                        }catch(Exception e) {

                                              e.printStackTrace();

                                        }                                  

                            }catch(Exception e) {

                                  e.printStackTrace();

                            }

                }catch(Exception e) {

                      e.printStackTrace();

                }

          }

    }

     

        Can I apply transient keyword to primitive, static and reference variables?

    -  Primitive Variables: transient keyword is applicable to primitive variables.

    -   Static Variables: technically you can declare static variable as a transient but, it doesn’t make a sense to make static variable as a transient because, transient key word is used when you don’t want to consider a particular field for serialization. Static variables by default not considered for serialization.

    -      Reference variable: Reference variable can be null and this variable doesn’t have any value it has an address. So transient keyword is not applicable to reference variables.


     

    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

        Can we declare constructor inside inner class?

    -          Yes, we can declare a constructor inside the inner class.

    -          Please refer to the below example. 

    package simplifiedjava.crackedInterview; 

    public class Outer { 

          public static void main(String[] args) {           

          }     

          class Inner{

                int a;

                int b;           

                public Inner(int a, int b) {

                      this.a = a;

                      this.b = b;

                }          

          }

    }


        Which Collection objects implements Queue interface?

        -    LinkedList implements Queue interface.


        What is the difference between SortedSet and TreeSet?

     

    SortedSet

    TreeSet

    1.

    SortedSet is an interface.

    TreeSet is a concrete class.

    2.

    SortedSet is an interface so cannot be instantiated.

    TreeSet can be instantiated.


        What is the difference between Fail-Fast and Fail-Safe?

     

    Fail-Fast

    Fail-Safe

    1.

    While traversing the collection object if someone is trying to modify the value of the collection object, the iterator gets failed immediately which is called Fail-Fast.

    While traversing the collections object if someone is trying to modify the value of the collection object, the iterator never failed immediately which is called Fail-Safe.

    2.

    It throws ConcurrentModificationException while modifying the collection object during the iteration process.

    It doesn’t throw ConcurrentModificationException while modifying the collection object during the iteration process.

    3.

    Performance is higher as compared to Fail-safe iterator.

    Performance is low as compared to Fail-fast iterator.

    4.

    Memory utilization of Fail-Fast iterator is lower.

    Memory utilization of Fail-Safe iterator is higher.

    5.

    E.g. ArrayList, LinkedList, HashSet.

    E.g. ConcurrentHashMap, CopyOnWriteArrayList, CopyOnWriteArraySet.


        What is the difference between HashTable and ConcurrentHashMap?

     

    HashTable

    ConcurrentHashMap

    1.

    Thread will get whole object lock.

    Thread will get a bucket level or Setment level lock instead of whole object lock.

    2.

    Only one thread is allowed to perform thread safe operation.

    Multiple threads are allowed to perform thread-safe operation at a time.

    3.

    Every read and write operation require object level lock.

    Read operation can perform without lock and write operation can perform by getting bucket level or Segment level lock.

    4.

    When one thread is performing read operation no other threads are allowed to perform any operation on same object otherwise you will get ConcurrentModificationException.

    When one thread is performing read operation other threads are allowed to perform write operation on same object still you won’t get ConcurrentModificationException.

    5.

    Iterator is Fail-Fast

    Iterator is Fail-Safe.

    6.

    Introduced in Java 1.0

    Introduced in Java 1.5.


        List out some web servers and application servers?

    -          Web Servers.

    1.       Apache Tomcat.

    2.       Lightpd.

    3.       Microsoft Internet Information Service.

    4.       Sun Java System Web Server.

    5.       Nginx.

    6.       Jagsaw.

    -          Application Servers.

    1.       JBoss

    2.       WebLogic

    3.       WebSphere

    4.       Glassfish

    5.       Oracle OC4J


        Can you compare Inner classes and lambda expression?

     

    Inner class

    Lambda Expression

    1.

    An inner class can have a name.

    Lambda expression doesn’t have any name.

    2.

    An inner class can extend the abstract class.

    Lambda expression cannot extend the abstract class.

    3.

    An inner class can extend the concrete class.

    Lambda expression cannot extend the concrete class.

    4.

    An inner class can implement an interface that has multiple abstract methods.

    Lambda expression can’t implement an interface that has multiple abstract methods.



        What is Supplier functional interface?

    -   The Supplier interface represents an operation that takes no argument and returns a result.

    -     Please refer to the below example.

    @FunctionalInterface

    public interface Supplier<T> {

     

    }


    • 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:

    61. Does finally block get executed if try or catch block has return statement. how the control flows in this situation. 

    62. What is the difference between Synchronization block and Synchronized method.

    63. If your child class is serializable and parent class is not and child class is inheriting some properties of parent class, in that case can you serialize child class.

    64. Can we declare constructor inside anonymous inner class.

    65. What is SortedSet? What is the purpose of SortedSet?

    66. What do you mean by Concurrency Level?

    67. What is Generic Type Parameter.

    68. What is the return type of apply method in Consumer functional interface.

    69. What is the difference between Abstract class and Interface with Default methods.

    70. What are the default methods defined in Function functional interface.


    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