Thursday, November 30, 2006

Cool Features of Web Services in the Java SE 6 Platform

I tried Java SE 6 webservices today by turning an existing class into webservice and it worked perfectly fine. I got it done both, manually and also using NetBeans 5.5. Watch out for annotation @WebService. If you selectively want to put methods as web services, you could as well use @WebMethod annotation. This is one cool feature thats coming in java se 6.
 
package generalproj;
import javax.jws.WebService;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import javax.xml.ws.Endpoint;
@WebService
public class GeneralClass {
   
    public GeneralClass() {
    }
           
    public void writeToFile( String a_file, String a_content ) {
        if( a_file != null && a_content != null ) {
            try {
                FileOutputStream l_fos = new FileOutputStream( new File( a_file ));
                byte[] l_bytes = a_content.getBytes();
                l_fos.write( l_bytes, 0, l_bytes.length );
                l_fos.close();
            } catch( IOException iox ) {
                iox.printStackTrace();
            }
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {       
        Endpoint.publish(
         "http://localhost:8077/generalproj/GeneralClass",
         new GeneralClass());
    }  
}

Wednesday, November 29, 2006

My java starters for the day!

My java readings for today!

Some of the things I read today include following:
  • Always close IO streams.
  • Model Objects: Core problem domain objects.
  • IO buffering usually appropriate. Prefer IO buffering. Java IO classes for buffering are BufferedReader and BufferedWriter
  • Checked and unchecked exceptions: Checked exceptions are those which are, simply speaking, out of immediate control. For example, FileNotFoundException or network, database problem based exception. They need to be caught or passed to upward classes for compilation to happen successfully. Classes must oblige with checked exceptions. Unchecked exceptions are exceptions generated due to bad programming. Examples are ClassCastException, NullPointerException etc. Class need not to oblige with unchecked exceptions.