-->

IBM Integration Bus (IBM Message Broker)

This site is under construction

Wednesday, February 15, 2017

Java Concepts


OOPS_Concepts: 

Abstraction:
  • It is used to hide the implementation details and it will provide only functionality name. For example, If you have a requirement to get the data from data base based on the date. In this scenario you will provide abstract class and method name which accepts as date a input and will provide data as return type.
  • Abstract class can have abstract and non abstract methods, final, non final variables, static and non static methods.
  • An abstract class can not be instantiated, which means you are not allowed to create an object of it because  these classes are incomplete, they have abstract methods that have no body so if java allows you to create object of this class then if someone calls the abstract method using that object then What would happen?There would be no actual implementation of the method to invoke.
Encapsulation:
  • Encapsulation means hiding the internal implementation details and providing access to the methods where user can access it so that you can change it later. In other words.
  • To achieve Encapsulation we have to use private variables and public methods.
Benefits:
  • Since data members are private so class  have total control over what is stored in its fields.
  • We can make the fields either read only or write only since fields are private.
Difference Between Abstraction and Encapsulation

  Refer

Interface:
  • It is used to achieve multiple inheritance. We can achieve multiple inheritance using interface because interface not a class. 
  • It is also used for loosely coupled. Interface is called loosely coupled because it doesn't any implementation.
  • It is also used to achieve 100% abstraction because interface will have only abstract members.
  • Interface class will have only final, static variables and Abstract methods.
  • In order to provide implementation to the interface we have to use implements keyword


Inheritance:
  • Main use of Inheritance is code re-usability. We can keep common code or functionality in one class and we can reuse it wherever we need it by using key word extends.
  • We can not implement multiple inheritance in java because let us assume you have a classA , ClassB and method called Name() in both class which return Class names. you have created classC which inherites both ClassA and ClassB. When you call Name() method in ClassC which class name it will return. Due to this ambiguity Java doesn't support multiple inheritance.

Polymorphism:
  • Polymorphism means many forms. Technically one method can do multiple things depends on parameters.
  • Polymorphism can be achieved by using concepts called method overloading and overriding.
Different types of Polymorphism:
  1.  Static Polymortphism which can be done at compile time using method overloading over loading the static methods is called static polymorphism
  2. Dynamic Polymorphism which can be achieved through overridding during the run time is called Dynamic Polymorphism.
Over Loading:
  •  Method Over loading means same method name but different type of parameters or number of parameters. Over loading means we have two methods with the same name called getVehicleInfo(). First method getVehicleInfo(int vin) gets the info based on vin number and second method getVehicleInfo(int modelYear, int modelCde) gets the vehicle info based on mdlYear and Mdlcde. When you call getVehicleInfo(12234). This means you are over loading same method with different parameters.

Use:  I have a class called EmployInfo and it is having a method called getEmployInfo(int id) which           pulls the employ details based on the employ id. I want to pull the employ information based is          last name as well so with out overloading concept we have to create one more class and one                more method but with method overloading concept I can create one more method called with               same name getEmployInfo(String lastName) in the same class but different parameter type.    

Over ridding:
  • Over ridding can be achieved through inheritance. I have a parent class called CreditCard1 in that I have offers() I have another class called  CreditCard2. When I inherits CreditCard1 I will get offers provided by CreditCard1 but not CreaditCard2. If I want to provide or change any offers in parent class then I can implement same method in child class I can provide or change offers of CreaditCard2. Changing or overridding the parent class method in child class is called overridding.
 Q) Can we override static method or not ? why?
A)  We can not orverride static methods because static methods not access through the instance variable or object of a class. 

 Q) Can we overload static method or not?
A) Yes, We can overload static method by applying regular Overload principles.



Collections:

AutoBoxing(wrapping):

·         Converting  primitive data types into reference type or a corresponding object wrapper class is called    AutoBoxing
·         Java the compiler performs automatic conversation.
·         Ex:    int a= 10;
          Integer b = a:
·         Here we are assigning primitive value to object type. Internally java compiler converts below conversation operation.
       Integer b = Integer.valueOf (a);

AutoUnBoxing(unwrapping):

·         Converting  reference type or object  of wrapper class into primitive data types is called AutoUnBoxing
·         Java compiler performs automatic conversation.
·         Ex:      Integer a= 100;
             int b = a:
·         Here we are assigning an object to a primitive type. Internally java compiler converts below conversation operation.
       int b =a.intValue();
·         Using the reference type will reduce performance because it has to recreate the object first then memory created in the heap.
·         Primitive types will have default values so need of checking the null check on the primitive types.
Ex: int a;
Means int default value is 0
·         Object types of default values are null. We have to apply null check object/reference types.
·         All primitive types will have corresponding wrapper class.

Generics:

·         Purpose of Generics is to provide Type Safety and to resolve typecasting.
·         Arrays are type safety that means it will stores only specified data type in the array but size is fixed.
Ex: Array[String ]  a = new [String](10);
·         Collections are not type safety which means it can store any kind of data type.
·         To achieve  above  two draw backs in arrays and collections Generics are introduced which generics is type safety and size is not fixed.
Ex:  Box<Integer> integerBox = new Box<Integer>();
·         Generics will accept only object type but not primitive types.
Ex: List<Integer> a = new Arraylist<>();  correct
       List<int> a = new Arraylist<>();  is wrong because int is primitive type.

Q) What is Checked and Unchecked Exceptions?

A)

Checked:

·          Exception which occurred at compile time is called checked exception.
·         While writing the code if you don’t provide try catch or throws for any possible exceptions occur places (like IOException point exception) compile will ask you to provide try catch or throws these type exceptions are called checked exceptions.

Unchecked:

·         Exception which occurred at run time is called unchecked exceptions.
·         While doing operations on java object or String if you don’t check null then it will give null pointer exception in run time if object is null.

       

Q) What is the Difference between throw and throws?

A)
  1. Throw is used in with in the method and Throws is used in method level declaration.
  2. In terms syntax Throw is followed by instance variable and Throws uses Exception class names.
  3. Throws is used to declare an exception and Throw is used to throw exception explicitly I mean to throw custom exception(user define exceptions).
  

Q) What is Web application, Enterprise application and what is the difference between them?

A) Web application:

Application which are developed by using only web technologies like HTML, CSS, JSP, SERVLETS… etc are called web applications.

Enterprise application:

 Applications which are developed by using web technologies + java/J2ee technologies or framework are called Enterprise   applications.
·         J2ee applications are Enterprise compatibility applications.
    

Q) What is the difference between Application server and web server?

  A)  Web Server:

  1. Web Server is provides support for static content where as Application Server provides support for both Static and dynamic content.
  2. Most of the times Web server is used as a proxy to the application server.
      Example:
           Apache, IIS, Google Web Server etc are some web servers and JBoss, IBM Websphere                 Aplication server, Web logic server are some application servers.


 Q) What is the difference between ear, war, jar and when to use these?

A)

    Jar :( java Archive file)

·         Jar means which contains group of .class files.

   War:( Web Archive file)

·     War file represents web application (code) which means war contains web application related technologies inside.
·       War file mostly used for web applications deployments.

  Ear:( Enterprise Archive file)

·  Ear file represents enterprise an applications (code) which means ear contains J2ee frameworks related technologies inside. It may contains web applications related code as well.
·         Ear file mostly used for Enterprise applications deployments.

Q) Command to generate java stubs(SOAP service request and response java class or SOAP service-related class files)?
A) wsimport -keep -verbose <wsdlName>

Q) Difference Between SOAP and REST?
  • SOAP(Simple Object Action Protocol) is a protocol whereas REST is an Architecture.
  • SOAP is overloaded with elements like header, envelope, and Body where REST is lightweight with only content of the message So REST is faster and quicker then SOAP.
  • SOAP supports only XML data type whereas REST supports multiple data types.
  • SOAP follows Web service standers, provides transaction management default where REST doesn't follow, and provides transaction management. 
Q) What are Stack, Heap Memory, and Difference between them?
A)  

     Reference:
             Stack And Heap Memory


Q) How to build the new maven project?

A)  Refer:

No comments :

Post a Comment