Saturday, 16 April 2016

SOAP Web Service Interview Question



1.       Web Services:
  • It is an application component which is access from the web.
  • It can be publish, found and used on the web.
2.       Web Services Features:
  • Platform independent and language independent
  • It is used to communicate between two different applications
  • It is used standardized xml based messaging system
  • Provide Interoperability
3.       Web Services Components:
  • SOAP – Simple Object Access Protocol
  • WSDL – Web Service Description Language
  • UDDI – Universal Description, Discovery and Integration
4.       Purpose of XML in WS:
  • Exchange the data between two different applications
  • WS takes help from XML to tag the data, format the data
5.       Purpose of SOAP in WS:
  • It is XML based protocol for accessing the web services.
  • It is W3C recommendation for communication between applications
  • Platform Independent and language independent
6.       Purpose of WSDL in WS: 
  • It is used for describe the Web Services like method name, parameters and how to access it
  • It is XML document containing information about web services
  • WSDL is a part of UDDI, it act as interface between WS application
7.       Purpose of UDDI in WS:
  • It is xml based framework for describing, discovering and integrating WS
  • UDDI is directory of WS interface described by WSDL 
8.       Benefits of Web Services:
  • Exposing the existing functionality on the web
  • Interoperability
  • Platform Independent and Language Independent
  • Use XML for data exchange or messaging
  • Reusability and Modularity 
9.       What do you mean by Interoperability of Web Services?

Two different type of application like one application is developed in JAVA and another application is developed in PHP so these two application can exchange their data to each other via web service, which is call interoperability.

10.   Do Web services supports Remote Procedure Calls?

YES. SOAP web service can be implement using two ways.
  • RPC Style
  • Document Style
11.   Behavioural characteristics of Web Services?           
  • XML Based
  • Loosely coupled
  • Support RPC and Document Style
  • Ability to Synchronous and Asynchronous
12.   What is Synchronicity?

Client has to be wait till server response back.

13.   What is Asynchronous?

Asynchronous operations allow a client to invoke a service and then execute other functions.

14.   Core roles of Web Services Architecture?
  • Service Provider
  • Service Registry
  • Service Requestor
15.   What is the purpose of service registry in Web Service Architecture?

It is logically centralized directory of services. It provides the centralized place where developer can publish and find the web service.

16.   What are the core layers in Web Service Protocol Stack?

There are four core layers:
  • Service Discovery (UDDI): It is responsible to manage the directory of WS, where it can be publish, find and access.
  • Servicer Description (WSDL): It is responsible to describe the information about web service
  • Service Transport (HTTP, SMTP, FTP, and BEEP): It is responsible to transforming the message between two applications.
  • XML Messaging (SAOP): It is responsible for encoding the message in XML format so both application can understand the messaging format.
17.    What are the primary security issues with web services?
  • Confidentiality
  • Authentication and Authorization
  • Network Security
18.   If client send the SOAP request to service, Can we ensure that the communication remain confidential?

Yes, SOAP message run on top of HTTP. HTTP supports the SSL (Secure Socket Layers) so communication can be encrypted via SSL.

19.   If client connect to WS, How do we identify the user? Is user authorized to use the WS?

There are many ways to do authentication and authorization, but mainly two which I remember right now.
  • HTTP gives in-build support – basic and digest authentication
  • SOAP digital signature – authorized by two parties (client and server)
20.   Advantage and disadvantage of SOAP Web service?

Advantage:
                      WS Security
                      Platform and Language Independent
Disadvantage
                      Slow
                      Strictly flow to standard to create SOAP WS
                      WSDL dependent

21.   What is SOA?

It is service oriented architecture. It is design pattern to provide services to another application through protocol. It is just concept only, not tied to any programming language.

22.   What tools are used to test the web service?
  • SOAP Client
  • Chrome postman
  • Firefox poster
23.   Difference between SOAP and REST Web service?

SOAP
REST
It is a protocol
It is architectural style
Simple Object Access Protocol
Representational State Transfer
It is slow because of  XML parsing is require
It is fast than SOAP
It consume more bandwidth and resource than REST
It consume less bandwidth and resource than SOAP
Data Format – XML only
Data format – XML, Plain Text, HTTP, XSL, JSON and more
SOAP cannot use REST
REST can use SOAP
SOAP uses services interfaces to expose the business logic.
REST uses the URI to expose the Business Logic
JAVA API – JAXA-WS
JAVA API – JAX-RS
Define own security – WS Security
Inherits security measures from the underlying transport.

24.   How do you define web service protocol stack?

There are various set of protocol that can be used to explore and execute the web service and entire stack is divided into four layer
  • Service transport Layer: This Layer is used to transfer messages between different applications, such as HTTP, SMTP, FTP, and BEEP (Blocks Extensible Exchange Protocol).
  • XML messaging Layer: This Layer is used to encodes messages in XML format so that messages can be understood at each end, such as XML-RPC and SOAP
  • Service Description Layer: This Layer is used to describes the user interface to a web service, such as WSDL
  • Service Discovery: This Layer is used to centralize services to a common registry and offer simple publish functionality, such as UDDI.

Friday, 26 February 2016

Understanding toString() method in java


Everything in java is an Object exclude primitive data type. Every class, exception, event and every array extends from Object class. In simple definition we can say that every class has Object as super class.

Object class contains several methods which is used by or override by its child class.

Most common Object class methods are:

Method
Description
boolean equals (Object obj)
Decide two objects are meaningfully equivalent
void finalize()
When any object does not have any reference, then it is called by garbage collector.
int hashcode()
It returns the hashcode integer value for an object
final void notify()
Wakes up a thread that is waiting for this object’s lock
final void notifyAll()
Wakes up all the threads that are waiting for this object’s lock
final void wait()
Causes the current thread to wait until  another thread calls notify or notifyAll method on this object
String toString()
It returns “text representation” of object

We are covering only toString() method in this post.

The toString() Method:

When you want to read something meaningful about the object of the class. Code can call the Object class method’s  toString() on your object when it wants to read useful details about your object.

When you want to pass object reference to System.out.println() method,

For example:

package com.sample.example;

public class DifficultToUnderstand {
               
                public static void main(String[] args) {
                                DifficultToUnderstand difficultToUnderstand = new DifficultToUnderstand();
                                // Now try to read string value of object class
                                System.out.println(difficultToUnderstand);
                }
}

Output:

You will get the above output when you will not override the toString() method of class object.
Above output gives you classname followed by @ symbol, followed by unsigned hexadecimal representation of the object’s hashcode.

getClass().getName() + '@' + Integer.toHexString(hashCode())

But, mostly we override the toString() of Object class , to get the meaningful text of that object. It is recommended that all the subclasses should override the toString() method of Object class.

Let’s take an example:

package com.sample.example;

public class ObjectToStringMethod {
               
                public static void main(String[] args) {
                                ProperTextPresenter properTextPresenter = new ProperTextPresenter(456,"jigar","mumbai");
                                // Now try to read string value of object class
                                System.out.println(properTextPresenter);
                }
}

class ProperTextPresenter {
                int id;
                String name;
                String address;
               
                ProperTextPresenter(int id,String name,String address) {
                                this.id = id;
                                this.name = name;
                                this.address = address;
                }
               
                @Override
                public String toString() {
                                return "This is my  id "+id+" and show my name "+name+" and office address at "+address;                             
                }
               
}

This ought to be bit readable:

This is my id 456 and show my name jigar and office address at mumbai

Now you can read the object in meaningful representational text which is understandable.