Wipro Java interview questions and answers.

Java Interview Questions and Answers covered in this post:

    Java interview questions and answers

        What is the difference between Instance variable and Class Variable?

     

    Instance Variable

    Class Variable

    1.

    The instance variable belongs to the object.

    The Class variable belongs to the class.

    2.

    Every object has its copy of the instance variable.

    The class variable is a common variable among all objects.

    3.

    Instance variable declared with data type only.

    A class variable is declared with data type and static keyword.

    4.

    Instance variable access with reference variable.

    Class variable access with the class name.


        What are the main pillars of OOPs Concepts? Explain the OOPS Concepts?

    -          There are four pillars of OOPs Concepts which are as follows.

    1.       Abstraction:

    Abstraction means hiding the implementation. 

    Real-Life Example: We can take an example of a Car. When we want to start a car we have to just turn keys in the ignition and the engine gets started. For the end-user, there is no need for how the engine is interconnected with different wheels. How the battery supply power. How petrol sprays in the engine. These all implementation is hidden. This is an abstraction. 

    Technical Implementation: Abstract class and Interface implements the abstraction. An abstract class is partial abstraction because abstract class can have concrete methods as well as abstract methods and the interface is full abstraction because the interface contained only abstract methods, not concrete methods.

    2.       Encapsulation:

    Encapsulation means hiding the data. 

    Real Life Example: Capsule is the perfect example of encapsulation. The capsule has different types of small tablets inside a wrapper. 

    Technical Implementation: Bean class is an example of Encapsulation. We declare properties as private and provide public getter and setter methods for each variable.

     

    3.       Inheritance:

    Inheritance means one object can access the properties of other objects. The child class can inherit the properties of the parent class. 

    Real-Life Example: Say suppose your grandfather has agricultural land, farmhouse and your father has flat, some gold and shares and you have racer bike, iPhone and laptop. Ultimately whatever property your grandfathers have will be inherited to your dad and your dad’s property inherited to you. But remember reverse is not possible. 

    Technical Implementation: You can implement inheritance using extends and implementation keywords. If you are extending another class then you have to use extends keyword and If you implement the interface then you have to use the implement keyword.

     

    4.       Polymorphism:

    Polymorphism means one name different form.

    An entity can have different behaviour in different situations. 

    Real-Life Example: A person can have a different role at a time with a different location or context. The person can be a father in the home, the person can be a manager in the company, Person can be a dancer in the movie. 

    Technical Implementation: Polymorphism can be implemented by using Method overloading and method overriding.


     

    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 I declare the final method inside an interface?

    -          We cannot declare the final method inside an interface.

    -          Methods declared inside the interface are by default public abstract.

    -          For your reference, I have given the below example.

    package simplifiedjava.crackedInterview; 

    public interface MyInterface { 

          public final void add(int num1, int num2);

    }

    Error: Illegal modifier for the interface method add() only public, abstract, default, static(For Variable only, not a method) and strictfp are permitted.


        What is constructor chaining?

    -  One constructor can call another constructor internally or explicitly is called constructor chaining.

    -     Constructor can call another constructor using this() and super().


        What is the difference between the final method and the abstract method?

    -          Final method cannot override.

    -          Abstract method must override in its implementation class.


        What is garbage collections? Who is responsible for garbage collection? How java reclaims a memory?

    -    Garbage collection is a process to delete unused objects and reclaim the memory.

    -     JVM is responsible to reclaim the memory.

    -    JVM finds the unused objects and no longer references objects that reside in memory and then JVM invokes finalize() method. This finalize() methods released the resources acquired by that objects.

    -  Once invoked the finalize() method will mark all targeted objects and simply removed them from memory.

    -   There are many GC algorithms that exist to implement GC. One of them is mark and sweep. 


        What is Widening?

    -          When we assign a value of a smaller data type to a bigger data type.

    -          It is possible when two data types are compatible.

    -          Widening Scope: byte -> short -> int -> long -> float -> double.

    package simplifiedjava.crackedInterview; 

    public class WideningDemo { 

          public static void main(String[] args) {

                int i=100;       

                long j = i;      

                float k = j;           

                float k1 = i;

                System.out.println("Value of i = "+ i + " \nValue of j = "+ j + "\nValue of k = "+ k + "\nValue of k1 = "+ k1);

          }

    }


        What is Narrowing?

    -          When we assign a value of a bigger data type to a smaller data type.

    -          It is possible when two data types are compatible.

    -          Narrowing Scope: byte <- short <- int <- long <- float <- double.

    package simplifiedjava.crackedInterview; 

    public class WideningDemo { 

          public static void main(String[] args) {

                float i=100;           

                long j = (long) i;           

                int k = (int) j;       

                int k1 = (int) i;

                System.out.println("Value of i = "+ i + " \nValue of j = "+ j + "\nValue of k = "+ k + "\nValue of k1 = "+ k1);

          }

    }


        Why String is immutable?

    -  String objects are immutable cause string objects are cached in SCP(String Constant pool).

    -       Cached String objects are shared between multiple clients.

    -    If anyone changed the value of the String object then all clients get affected. That’s why String is immutable in java.


        What are the advantages and disadvantages of Inner class?

    -          Advantages:

    1.  An inner class is used to develop maintainable code because they logically group classes and interface in one place.

    2.  Easy access as the inner classes is implicitly available in the outer class.

    3.  Inner classes represent a special type of relationship which allows access to all members.

    -          Disadvantages:

    1.     Code complexity increases.

             2.    Multiple inner classes may decrease the performance.


    • 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. Explain the Term Composition, Aggregation, Association? What is HAS-A and IS-A Relationship?

    2. What are the uses of this keywords. Where it is applicable and what are the rules to use these two keywords.

    3. What are the wrapper classes in java. Why do we require wrapper classes.

    4. What is SCP(String Constant Pool)

    5. What is re-throwing exception in java.

    6. What happen if you don't invoke run() method on Thread class.

    7. What is blocking queue.

    8. Which collection classes implements RandomAccess interface. What are the benefits of RandomAccess interface.

    9. Can you list out some functional interface used in java 6.

    10.What is Constructor Reference. How will you implements Constructor reference.


    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