Basic core java interview questions and answers for freshers

  Part 2

Basic core java interview questions and answers for freshers covered in this post:


    Basic core java interview questions and answers for freshers


        What is the difference between method and constructor?

     

    Method

    Constructor

    1.

    The method is used to implement the logic.

    Constructor is used to initializing the object.

    2.

    The method can have a return type.

    A constructor cannot have a return type.

    3.

    Method name can be anything or can be class name as well.

    The constructor name must be the same as the class name.

    4.

    The method must invoke explicitly.

    A constructor can invoke automatically.

    5.

    If you don’t have any method then the compiler won’t provide any kind of method like a constructor.

    If you don’t have any constructor then the compiler will provide a default constructor.

    6.

    The method can be overridden or overloaded.

    The constructor can be overloaded but cannot overridden.


        What is the difference between Interface and Abstract Class? Can you tell me one real-time example where Interface and abstract class implementation is the best practice?

     

    Abstract Class

    Interface

    1.

    Abstract class must be declared with abstract keyword.

    An interface can be declared with the Interface keyword.

    2.

    An abstract class can have constructors.

    An interface cannot have constructors.

    3.

    An abstract class can have a concrete method and an abstract method.

    An interface can have only an abstract method. You cannot have a concrete method inside the interface.

    4.

    An abstract class can be declared private, protected, default and public methods.

    An interface can declare only public methods.

    5.

    An abstract class can be declared private, protected and public variables.

    An interface can declare only public variables.

    6.

    An Abstract class can declare non-final and local variables.

    An interface can declare only final variables but not a local variable.

    7.

    An Abstract class can extend one class and implements multiple interfaces.

    An interface can extend one or more interfaces only.

    8.

    An abstract class is a best practice when you have partial implementation and the rest of the implementation is remaining.

    The interface is a best practice when there is no implementation at all.


        Will the code compile if I have declared a single abstract method in class but doesn't declare the class as an abstract class?

    -      No. Your class won’t compile you will get a compile-time error.

    -     If you have declared already an abstract method inside a class then it is mandatory to declare that class as an abstract class.


     

    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 the concrete method in abstract class?

    -          Definitely, we can declare a concrete method inside an abstract class.

    -          Abstract class can have abstract methods as well as concrete methods.


        Can we use static members inside the non-static area?

    -          Yes. We can use static members inside the non-static area.

    -          We can observe this in the following demo.

    package simplifiedjava.crackedInterview; 

    public class Parent {

          static int a = 10;     

          public static void main(String[] args) {

                new Parent().check();

          }     

          public void check(){

                System.out.println("Parent Class check() method = "+ a);         

          }    

    }

    Output : Parent Class check() method = 10


        What are the exceptions?

    -  Exception is an event, can be occurred during the execution of the program that disrupts the normal flow of the program.

    -  You can say an Exception is an abnormal event that can be occurred during the execution of the program.

    -     Exception can stop the execution of the program if not handled.


        Which is the parent class of the Exception hierarchy?

    -    Parent Class of Exception is Throwable.




        What is deserialization?

    -          Deserialization is the reverse process of serialization.

    -      The reverse process of creating the object from a stored sequence of bytes.

    -          Please refer to the above example for deserialization.


        What are the characteristics of List Interface?

    -          List is a child interface of the Collection interface.

    -          Duplicates are allowed.

    -          Insertion order preserved via index.

    -          Index is used to retrieve elements.

    -          Auto growable array.


        What are the characteristics of Map Interface?

    -          Map represents the group of objects as a key-value pair.

    -          Map is not a child interface of the Collection interface.

    -          Both keys and values are objects only.

    -          Characteristics of the map are as follows.

    1.       Underlying data structure is Hashtable.

    2.       Insertion order is not preserved.

    3.       Insertion order is based on Hashcode keys.

    4.       Duplicates keys are not allowed.

    5.       Values can be duplicated.

    6.       Heterogeneous (Different types of Object) objects are allowed for both keys and values.

    7.       Null is allowed for keys only once.

    8.       Null is allowed for values multiple times.

    9.  Hashmap is Serializable because Hashmap implements a Serializable interface.

    10.   Hashmap is Clonable because Hashmap implements a Clonable interface.

    11.    Hashmap 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:

    21. What is the difference between sleep() and wait() in java.

    22. What is the difference between notify and notifyAll().

    23. What are the Implementation classes of List Interface.

    24. What are the implementation classes of Set Interface.

    25. What is the difference between Array and ArrayList.

    26. What is the difference between Stack and Queue.

    27. What is bytecode.

    28. What is the difference between loaders and linkers.

    29. What is predicate functional interface.

    30. What is 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