Posts

Showing posts from January, 2010

Hello World EJB 3.1 Application using Netbean

Image
This post explains developing simple Hello world application in Net Bean . It explains ease of EJB 3.1 development using  annotations in you java code. Coding, deploying and using an enterprise bean never been so easy. Here we are going to develop a Stateless Session bean and going to invoke it from a Servlet. A Remote Interface for bean package demo.session; import javax.ejb.Remote; /** * @author Yogesh */ @Remote public interface HelloEJBRemote {    String getMessage(); }   Here @remote annotation is being used for demoting Remote Interface for EJB Module. It declares one public method which is by default business method. Bean Implantation Class - package demo.session; import javax.ejb.Stateless; /** * @author Yogesh */ @Stateless public class HelloEJB implements HelloEJBRemote { public String getMessage() { return "Hello ";     } ...

Graph Searching (BFS&DFS) Implementation

Image
Here is the adjacency matrix representation based implementation of Graph with both graph searching techniques . Following graph has been taken as example Adjacency matrix representation is below int array[][] = {{0,1,1,0,0,0},                      {1,0,0,1,1,0},                      {1,0,0,0,0,1},                      {0,1,0,0,0,0},                      {0,1,0,0,0,0},                      {0,0,1,0,0,0}}; Complete Code is as follows package demo.graph;...

First hand on Servlet 3.0 using Annotation

Image
   This tutorial gives introduction to coding and deploying Servlet as per 3.0 specification. Servlet 3.0 specification introduced Annotations that makes deploying servlet, Lister and Filter easier ever before. Here is the Servlet with Annotation ready to deploy without any web.xml. Here @webservlet annotation is being used to define servlet name, url pattern and init parameters. This annatation is equivalent to following entry in web.xml < servlet > <servlet-name> HelloServlet </servlet-name> <servlet-class> demo.HelloServlet </servlet-class> <init-param> <param-name> name </param-name> <param-value> Yogesh </param-value> </init-param> </servlet> < servlet-mapping > <servlet-name> HelloServlet </servlet-name> <url-pattern> /HelloServlet </url-pattern> </servlet-mapping> Complete Code : /* * To change this tem...

How to avoid NPE while Auto-Unboxing

Auto-Boxing/Unboxing is introduced in Java 5 version. It supports automatic conversion of primitive type (int, boolean, float, double) to their equivalent Objects ( Integer, Boolean, Float, Double) in assignment , method and constructor invocation and other way also. Here is the examples Auto-Boxing Integer i = 10; // Auto-boxing converts primitive int value to Integer Object Auto-Unboxing int i = 0; i= new Integre(10); // Auto-Unboxing converts Integer Object to primitive int There is serious problem with using Auto-bocing/Unboxing, it may result null pointer exception. Take an example of following program package testproject; public class TestAutoUnboxing { private static TestAutoUnboxing test= new TestAutoUnboxing(); //cause Null Pointer Exception public static final Boolean YES = true; // Autoboxing for private boolean amIHappy = YES; // Instance Variable public static void main(String[] args){ System.o...

Matrix Spiral Traversing

This post gives solution for 2D Matrix Spiral Traversing . package testproject; /** * * @author Yogesh */ public class SpriralTraverse {     public static void main(String[] args){         //Sample Array         char[][] array = {{'1','2','3','4','5'},                           {'L','1','2','3','6'},                           {'K','E','1','4','7'},                           {'J','D','2','5','8'},             ...