EJB remote interface

The program given below describes the way of creating a remote interface in EJB.

EJB remote interface


The program given below describes  the way of creating a remote interface in EJB. The meaning of Remote interface in terms of Ejb is the java source file which contain the bean implementation logic. These are very much similar to the RMI Remote interface and provides the business specific functionality of an EJB. Here we have created the Remote interface named SessionBeanRemote.java

@Remote:- This is the annotation which is used to declare the interface as Remote.

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




package ejb;

import javax.ejb.Remote;

public interface SessionBeanRemote {
  String getResult();

  String getAddress();

  String getCompanyname();

SessionBeanBean.java:- This is the session bean in which we will declared all the methods of the Remote interface. This bean is used for controlling the business process and filling the gaps between the data of the entity beans. Here

@Stateless is the annotation which denotes the bean is of  session type.


package ejb;

import javax.ejb.Stateless;

public class SessionBeanBean implements SessionBeanRemote {
 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:- This is the client application from which we can access all the methods of  the session bean.

@EJB:-This is the annotation that configure the EJB values for a field or a method. This annotation is a Resource annotation and is used where it is known that the resultant is an EJB interface.


package ejb_remote;

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

public class Main {
  private static SessionBeanRemote sessionBeanBean;

  public static void main(String[] args) {
  System.err.println("Accessing Remote Interface using EJB:");
  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

Output of the Program

Accessing Remote Interface 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

Share on Google+Share on Google+

EJB remote interface

Posted on: January 12, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: EJB remote interface   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
June 13, 2012
Debug into eclipse

Good example. Is there any way to debug the client into eclipse? I spent a lot of time looking for a way to debug application client project but with no success. My problem is with @EJB's annotation return null object if the client is executed out EE container (like glassfish). Do you know if is possible to run it from eclipse IDE? Thanks.
September 24, 2012
Getting error while running Main.java

Hi, I'm getting error (NULL Pointer exception)while running Main.java. Can you give me the step to running it?