Difference between ‘==’ and ‘equals’ operator for comparison:

The comparison operator for objects may confuse some of the java novice programmers. In this article I am going to shed some thoughts on, when and where to use ‘equals’ and ‘==’ operators.

The ‘==’ operator is used to check if the two objects which are being compared are of the same object reference or not. This means to say that comparison is done on the memory location in which the objects are created / located. We use the ‘==’ operator to check whether the objects which we are being compared are the aliases or not. Object alias means, an object which is allocated on the memory and have different names to access the object location. For instance refer the sample code below:

String a = new String(“Bharath”);
 String b = new String(“Bharath”);
System.out.println(String ‘==’ operator output >—-> “ + (a == b)); // always results false, as the reference of object ‘a’ is different  from reference of object ‘b’
  

The ‘equals’ operator is used to compare the value / property contained in the comparing objects. For instance refer the sample code below:

  
String a = new String(“Bharath”);
 String b = new String(“Bharath”);
System.out.println(“String ‘equals’ operator output >—-> “ + a.equals(b));// results true because, the contents/property in both the objects ‘a’ and ‘b’ are the same.
 
example of object reference:


 

String a = new String(“Bharath”);
String b = new String(“Bharath”);
String c= b;
System.out.println(“comparison of ‘c’ and ‘b’ output >—-> “+(c==b)); //results true as object ‘c’ is reference of object ‘b’; in other words ‘c’ is an alias of ‘b’
System.out.println(“comparison of ‘c’ and ‘a’ output >—-> “+(c==a));//results false as object ‘c’ is not a reference of object ‘b’

 

 

 

The header and the footer section incorporation using Struts tiles!

Last week in my project I had an interesting situation; I had to integrate couple of navigation buttons across JSP’s. The buttons had to go into footer section of the pages. But, the existing JSP’s had no footer section. The struts-tiles is in place and had only header and body attributes defined in it. Initially, I was asked to integrate the new requirement at framework level. This decision had made my life easy all I had to do was to follow couple of steps below:

  1. Create a new footer JSP.

  2. Edit the struts-tiles configuration file and add footer attribute into definition node.

  3. If any page demanded no footer; in the value attribute for put node I had to leave it blank.

  4. Last but the least, I had to add the Javascript function for button onclick event into JSP’s.

The life was smart, but, later a decision was made not to make the changes at framework level and had to be integrated only at JSP level. Now, I had to follow few simpler steps as below:

  1. Create a new footer JSP.

  2. Edit each JSP and include the footer JSP after the body tag in JSP.

  3. Last but the least, I had to add the Javascript function for button onclick event into JSP’s.

Though the alter looks simple it’s not a wise thing to do; I thought. The processing time of JSP’s would have reduced if it was made at the framework level, as struts-tiles would have rendered the footer at server start up itself. But, this would have not been a noticeable change. To add bit more to it, the primary concept of adding of navigation into footer section itself seems irrational, as the concept of footer is lost, footer is something which is constant and needs no change when adapted across pages. So, there’s a pain of editing each JSP’s.

Thus, to conclude, I guess the alter decision was wise.

“Use header and footer when the header and footer section are constants, for example, across the pages if the menu is constant, add it into header section. Across the pages if the company details or contact info is to be displaced gracefully embrace them into footer section and it would be the wise decision to adapt them into struts-tiles by doing which we may need not edit individual pages to incorporate header or footer sections.”

SOA Implementation Using Java Skeleton And .Net Stub.

Conversion of POJO’s into Web-Services

SOA: SOA is the abbreviation for Service Oriented Architecture. It is one of the programming styles by which one can create/use and expose the services over a network.

Why do we need SOA?

The world is expanding with knowledge, in the form of data; there is an immense need for few of the legacy applications to be in phase with the new worlds data. Programmers face difficulty in maintaining and updating these legacy applications due to various reasons like internal dependencies, language obscurity, etc… In such a case, SOA seems to be an auxiliary tool which can void the programmer’s night-mare.

Using SOA programmer’s can program in such a way that the legacy system can be in phase with the new technology. SOA does this miracle by sandwiching the new technology and the legacy application with a thin layer which can interact between the two entities.

Not only in case of the legacy applications, SOA show’s it’s commanding position even in case of new technologies/ applications. Whenever two or more application needs to exchange the data, SOA provides a bridge between the applications, which overlays one of the programming challenge language dependency.

What do we achieve by implementing SOA?

By using SOA programmers can easily configure two or more application to interact and to exchange the data.

Which are the different approaches to implement SOA?

There are two approaches to implement SOA:

  1. Top Down approach: in this approach the programmers integrate the SOA structure for the existing application by creating a wrapper layer which interacts between the applications. This approach is usually used only when SOA needs’ to be integrated to the existing systems.

  1. Bottom up approach: in this case the programmers code the application, by keeping a view in the mind that the services being coded will be exposed as a service over the network. This approach is usually followed while developing a new application.

Concerns to be accounted while implement SOA:

  1. While implementing SOA, there is a requirement for the service provider and the service consumer to agree upon the data format being exchanged across the applications.

  2. Security is the main concern which has to be taken care off. Whenever a service is exposed, the system should be intelligent enough to know the consumer’s consuming the service and to log the transactions. As well as, system should expose the service only for the legitimate consumers, System should be protected from the hackers.

Software requirements:

  1. Apache Tomcat Server / JBoss.

  2. Eclipse IDE.

Configuring Eclipse for Axis2 plug-ins:

1) Download Axis2 plug-ins:

axis2-eclipse-codegen-wizard.zip

axis2-eclipse-service-archiver-wizard.zip

2) Unzip the files into eclipse plug-in folder.

1

Configuring Apache Tomcat server with Axis2 plug-in:

1) Download the plug-in:

axis2-1.2.zip

2) Unzip the file into \webapps folder which is present in Apache Tomcat installed directory.

2

3) To confirm whether the Apache Tomcat Server is configured with Axis2, hit the URL: http://localhost:8080/axis2/ .

The below shown page should appear.

3

  1. Conversion of POJO’s into Web-Services:

Steps:

  1. Once Eclipse and Server are configured, the next step will be to identify the services which you will be exposing as Web-Services.

  2. Decide whether a wrapper class is required to expose the service, if required code the wrapper class then, proceed to step 3 to create Axis Archived file (.aar file).

  3. Compile the class to generate the .class files.

  4. Right click on the “Package Explorer” window on Eclipse. Then follow the path
    New >
    Other > Axis2 Wizard.

    45Then click on next.

  5. Select the directory where the .class files for the services are present.

    6

  6. Check the “Skip WSDL” check-box.

    7

  7. Add the entire jar’s which will be required to generate the .aar files.

    8

  8. If the archive file requires any service XML files it can include. Else select the “Generate the service xml automatically” checkbox.

    9

  9. Load the class file and select the methods which you will be exposing as a web-service.

    10

  10. Select the output location where the .aar file, is to be generated.

    11

  11. When you click finish, wait for the confirmation message.

    12

    The .aar file will be successfully generated.

II. Deploying .aar file into Tomcat server using Axis2 service provider:

  1. Login into the axis2 server by accessing the URL: http://localhost:8080/axis2/axis2-admin/

    13

  2. Click on “upload service”

    14

  3. Select the .aar file and click on “upload” button.

    15

  4. Wait for the conformation message!

    16

  5. To confirm the service is uploaded hit the url: http://localhost:8080/axis2/services/listServices

    17

This confirms that the service is deployed successfully.

Finally, make sure that the library files which will be required for the service to work are deployed in lib directory.

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis2\WEB-INF\lib

18

Testing of the service using .net Client:

Steps:

  1. Add the web reference by following the path:
    Project
    Add web References.
    19

  2. Add the web reference by selecting the URL on which the web service is hosted:

    20

  3. Write the client code.

    21

  4. Run the code to see the output:

    22@ .net Client – Courtesy – Deepesh P C – NTL Bangalore.

****************** ******************