Frank's JTraining Blog

Sharing knowledge on Java
fsalinas
fsalinas

I recall the first oddity that struck me about Java programming is that it seems common practice to test returned objects for null. I find it frustrating and inefficient to scatter if conditions throughout my code just to see if I have a valid object instance returned. 

Receiving null is confusing. When you make a function call and the result is null what does it mean? Was the data not found? Was there an exception in the function that was silently swallowed resulting in the return of a null object? You're not really sure if null is an expected return value. If no exception is thrown then you just kind of assume that null is a valid return value. However, you can't really do anything with the returned null object so what do you do now?

Here are a couple of alternatives to returning null:


Tagged in: Untagged 
fsalinas
fsalinas

When it came time for me to tackle my first web service implementation I ran into a lot of problems. Here I will write a series of articles to address the questions and problems I encountered in hopes of helping you get started in developing web services faster than I did. The following example will show you how to create a web service using JAX-WS and packaged as a servlet.

A Simple Service

To start out you should create an interface defining your business methods. I will keep the implementation extremely simple so we can focus on the details of web services. Here's our interface named SimpleServiceWS

public interface SimpleServiceWS {  
     public String simpleMethod();  
}
The next step is to create a plain java class (POJO) which implements this interface. I'll name it SimpleServiceImpl
public class SimpleServiceImpl implements SimpleServiceWS 
{  
   public String simpleMethod() { return "Simple response"; }  
}

Please note that it is not required to create and implement an interface and almost every web service example I found did not do so. I feel it is good practice and consistent with Java programming practices to program against interfaces.


Tagged in: web service , soap , jaxws
fsalinas
fsalinas

The final keyword is one that I find is under utilized. Use final in your projects as a means of defensive programming. If you are unfamiliar with this keyword here is a great article on its usage.

Renaud Waldura’s The Final Word On the final Keyword .


Tagged in: Untagged 
fsalinas
fsalinas I received an email from someone who liked my technical blog and invited me to join JTraining. So here I am. I look forward to sharing my knowledge with and learning from the members of this community. 

Tagged in: Untagged 

Tags:

Sponsers