Search This Blog

Tuesday, December 10, 2019

Web Services in Java


Web Service:
·         Web services are client and server applications that communicate over the World Wide Web’s (WWW) HyperText Transfer Protocol (HTTP).
·         As described by the World Wide Web Consortium (W3C), web services provide a standard means of interoperating between software applications running on a variety of platforms and frameworks.
·         Web services are characterized by their great interoperability and extensibility, as well as their machine-processable descriptions, thanks to the use of XML.
·         Web services can be combined in a loosely coupled way to achieve complex operations. Programs providing simple services can interact with each other to deliver sophisticated added-value services.

Loosely Coupled:

In computing and systems design a loosely coupled system is one in which each of its components has, or makes use of, little or no knowledge of the definitions of other separate components.
Subareas include the coupling of classes, interfaces, data, and services.[1] Loose coupling is the opposite of tight coupling.

Types of Web Services in Java

1.       Java API for XML Web Services (JAX-WS)
·         Big web services use XML messages that follow the Simple Object Access Protocol (SOAP) standard, an XML language defining a message architecture and message formats.
·         systems often contain a machine-readable description of the operations offered by the service, written in the Web Services Description Language (WSDL), an XML language for defining interfaces syntactically.
A SOAP-based design must include the following elements.
·         A formal contract must be established to describe the interface that the web service offers.
·         WSDL can be used to describe the details of the contract, which may include messages, operations, bindings, and the location of the web service
·         The architecture must address complex nonfunctional requirements.  Examples include transactions, security, addressing, trust, coordination, and so on.
·         The architecture needs to handle asynchronous processing and invocation.

1.       Java API for RESTful Web Services (JAX-RS).

In Java EE 6, JAX-RS provides the functionality for Representational State Transfer (RESTful) web services. 
RESTful web services, often better integrated with HTTP than SOAP-based services are, do not require XML messages or WSDL service–API definitions.
                A RESTful design may be appropriate when the following conditions are met.
·         The web services are completely stateless. A good test is to consider whether the interaction can survive a restart of the server
·         A caching infrastructure can be leveraged for performance. If the data that the web service returns is not dynamically generated and can be cached, the caching infrastructure that web servers and other intermediaries inherently provide can be leveraged to improve performance.
·         The service producer and service consumer have a mutual understanding of the context and content being passed along.
·         Bandwidth is particularly important and needs to be limited.
·         Web service delivery or aggregation into existing web sites can be enabled easily with a RESTful style
·         Developers can use such technologies as JAX-RS and Asynchronous JavaScript with XML (AJAX) and such toolkits as Direct Web Remoting (DWR) to consume the services in their web applications.


Saturday, May 17, 2014

Simulate Java StackOverFlow Exception



Stack memory:
  Let me describe  high level detail of stack memory, To execute any program we need to allocate two type of memory in processor(RAM).
     One is stack Memory -  The memory used for executing the program in processor.
   Second is Heap Memory- This memory is nothing but to Store the data(Object) in processor.


Stack Memory  will be start used, when program start from main method to the other  method execution.

Example :
Start using stack memory:  main-> method1-> Method 2->..... > Method N
Release stack memory :Method N (execution Over) -> Method N-1 ->  .............. > Method1->main

Below Program  stack memory are not released due to recursive   call of method1(). So it will throw stack over flow exception.




package com.blogspot.microtechinfo;

public class JavaStackOverFlow {

          private static int count=0;
         
          /**
           * @param args
           */
          public static void main(String[] args) {
                   // TODO Auto-generated method stub
                  
                             method1();
                  
          }
          private static void method1()
          {
                  
                   try{
                            
                             System.out.println("count="+ ++count);
                  method1();
                   }
                   catch (Exception e) {
                             // TODO: handle exception
                             e.printStackTrace();
                             System.exit(1);
                   }
                  
                  
          }
         
}


 Output:
  count=4484
count=4485
count=4486
count=4487
count=4488
count=4489
count=4490
Exception in thread "main" java.lang.StackOverflowError
          at sun.nio.cs.SingleByteEncoder.encodeArrayLoop(Unknown Source)
          at sun.nio.cs.SingleByteEncoder.encodeLoop(Unknown Source)
          at java.nio.charset.CharsetEncoder.encode(Unknown Source)
          at sun.nio.cs.StreamEncoder.implWrite(Unknown Source)
          at sun.nio.cs.StreamEncoder.write(Unknown Source)
          at java.io.OutputStreamWriter.write(Unknown Source)
          at java.io.BufferedWriter.flushBuffer(Unknown Source)
          at java.io.PrintStream.write(Unknown Source)
          at java.io.PrintStream.print(Unknown Source)
          at java.io.PrintStream.println(Unknown Source)

          at com.blogspot.microtechinfo.JavaStackOverFlow.method1(JavaStackOverFlow.java:21)