Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
EJB Hello world example 
 

Creating and testing the "Hello World" Example is the very first step towards learning of any application or programming language.

 

EJB Hello world example

                         

Creating and testing the "Hello World" Example is the very first step towards learning of any application or programming language. In the given example we are going to show you, how to create your first hello world example in EJB and testing it.

You can also create a hello world example to test your EJB environment setup. This simple application will required three different files to print the message.

  1. SessionBeanRemote.java:-  This  is the Remote interface which extends javax.ejb.EJBObject package. These are similar to RMI Remote interface. The use of remote interface is particularly helpful in  providing business-specific functionality of an EJB.Here @Remote is the annotation used to declare the interface as Remote.

           String getAddress(); String getCompanyname(); String getResult():-These are the methods which is to be defined in the bean.

    2.  SessionBeanBean.java:-This is the bean of type session in which we have defined  the body of the method which were declared in the          
         interface named SessionBeanRemote.java.@Stateless is the annotation used to declare the bean as a session type.

   3.  Main.java:-This is the client application from which  we can access the methods which are defined in the bean.@EJB is the annotation         
        used for configuring the EJB values for a field and  method.

SessionBeanRemote.java

package ejb;

import javax.ejb.Remote;


@Remote
public interface SessionBeanRemote {

    String getResult();

    String getAddress();

    String getCompanyname();
}

SessionBeanBean.java

package ejb;

import javax.ejb.Stateless;


@Stateless
public class SessionBeanBean implements SessionBeanRemote,SessionBeanLocal {

    public String getResult() {
        return "Hello World";
    }
    public String getAddress() {
        return "Sec-3,D-16/116,Rohini";
    }
    public String getCompanyname() {
        return "Roseindia.net Pvt.Ltd.";
    }
}

Main.java

package enterpriseappee5;

import ejb.SessionBeanRemote;
import javax.ejb.EJB;

public class Main {

    @EJB
    private static SessionBeanRemote sessionBeanBean;

    public static void main(String[] args) {
        System.out.println("Displaying Message using EJB:");
        System.out.println("=================================");
        System.err.println("Name of the Company is : =" + sessionBeanBean.getCompanyname());
        System.err.println("Address of the Company is : =" + sessionBeanBean.getAddress());
        System.err.println("Message is : =" + sessionBeanBean.getResult());
        System.out.println("=================================");
    }
}

Output of the program

 Displaying Message using EJB:
=================================
Name of the Company is : =Roseindia.net Pvt.Ltd.
Address of the Company is : =Sec-3,D-16/116,Rohini
Message is : =Hello World
=================================

Download Source code

                         
» View all related tutorials
Related Tags: c database data application io find ejb this app simple tab example to base exam ssi e eps li im

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.