Tuesday, April 10, 2018

Java Programming Interview Questions Series 03 - OOP Concepts


1. What are the main reasons to use Java Packages?
          Packages are used in Java, to evade name conflictions, to control access to class, interface, enumeration etc, to make it easier to locate the related classes and to provide a good structure for the projects with a huge amount of classes. 

2. What are the types of Packages?
          There are two types of Packages.
               1. Built-in Package:  Predefined Java Packages (java.lang, java.util)
               2. User-defined Package: Java Package that is created by the programmer to group his project's classes and interfaces.

3. What are the things to follow when using Java Packages?
          1. The Package statement should be at the first line in every class that belongs to the same Package.
          2. A Package is always defined as a separate folder containing the same name of the Package name.
          3. All the classes should be in the same Package folder.
          4. All classes of the Package must be compiled before execution.

4. What is an Abstract Class?
          To provide abstraction, use Abstract classes. It may have both abstract methods and concrete methods. Therefore it does not provide 100% abstraction. An abstract class is never initiated.

5. When to use Abstract class? 
          Abstract classes are used to define generic types of behaviours at the top of an OOP class hierarchy, and use its subclasses to provide implementation details of the abstract class.

6. When to use Abstract methods?
          Abstract methods are declared where two or more subclasses are going to do a similar case in many ways. To do that subclasses extend the same Abstract class and apply unique implementations for the abstract methods.

7. What is the difference between an Abstract class and an Interface?
     
8. What are the Nested Classes and what are the types of Nested Classes?
          A class is defined within another class is called as Nested Class. Which means the scope of the inner class is covered by the scope of its outer class.

There are 2 types of Nested Classes.
1.     Non-static Nested
2.     Static Nested

9. What are advantages of using Nested Classes?
          1. It increases encapsulation.
          2. It is a way of logically grouping classes that are only used in one place.
          3. It can lead to more readable and maintainable.

10. What is an Immutable object?
          An object that cannot be altered once it created is called immutable object. String, Integer, Float, Double, Byte are examples for the Immutable objects.

11. What is StringBuffer Class?
          The StringBuffer class is used to represent characters that can be modified. This is used when there are lots of modifications to the particular string. And this is thread safe.

12. What is StringBuilder Class?

          StringBuilder is unique to StringBuffer except one thing. That is it is not synchronized, means it is not thread safe. Therefore StringBuilder operates faster than the StringBuffer. 


13. What is meant by Exception Handling?
          To prevent abrupt termination of a program, we use Exception Handling. It is a mechanism to handle runtime malfunctions. There are many things such as programmer error, hardware error, files cannot be found that can be lead to an exception.

14. What are the categories in Exceptions?
          1. Checked Exception: That can be predicted by the programmer at the compile time.
          2. Unchecked Exception: These are the class which extends RuntimeExcpetion. This kind of exceptions are ignored at the compile time.
          3. Error: These are normally ignored in the code because you can rarely do anything about an error.

15. What are Uncaught Exceptions?

          When we do not handle exceptions, they lead to unexpected program termination. Therefore this will lead to an exception at runtime. These are called Uncaught Exceptions.    









Copyright © iTecTricks | Powered By Blogger

Design by Shehan Vanderputt