SlideShare a Scribd company logo
1 of 16
Java Training Center
(No 1 in Training & Placement)
1
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
RMI
(Remote Method Invocation)
1. RMI is distributed technology, which is first attempt of SUN to provide a
solution to distributed programming. RMI use socket. A socket is a transport
mechanism.
2. No extra software is required for developing a distributed application using
RMI other than JDK.
 RMI provides a way for a java program on one machine to communicate with
object residing in different JVM.
 The important part of RMI architecture are the Stubclass object serialization
and Skelton class.
 RMI uses a layered architecture where each of layers can be enhanced without
affected the other layers.
=:-Developing First RMI application-:=
Server Side Steps:-
1. Define a Business Service Interface (B.S.I.).
a. Your Business Service interface has to extends java.rmi.Remote interface.
b. Each Method inside the Business interface has to throw
java.rmi.RemoteException.
2. Provide the implementation class for Business Service Interface.
a. Business Services implements class has to extends “UnicastRemoteObject”
if not extend then implement class is responsible for correct
implementation of hashCode(), equals(), toString().
b. B.S.I. class has to implement Business Interface.
3. Create the Business Service Implement Service Implementation class object.
4. Bind the B.S.I. class object inside RMI registry or JNDI registry.
Java Training Center
(No 1 in Training & Placement)
2
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
-: Steps in Eclipse :-
1. Create a java Project with the name RMIServer.
2. Create package com.jtcindia.rmi
3. Write the following three files in your package.
a. AccountService.java (interface)
b. AccountServiceImpl.java
c. Server.java (for binding object)
If you have more than one Business class for other purpose than that class
object will create in server.java also.
Client Side Steps :-
1. Locate and get the registry reference.
2. Look Up the registry and get the required remote interface stub.
3. Invoke any required business operation on remote Business stub.
1. Create a java Project called RMI.
2. Create a package java.jtcindia.rmi;
3. Write the following in the Package.
a. Client.java
b. AccountServices.java(copy from the server)
Way to create jar file :-
D:/test> Jar cvf jtc.jar com
(Here AccountServices.class file change to jar file)
Java Training Center
(No 1 in Training & Placement)
3
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
File Required:-
1. Package com.jtcindia.rmi;
Import java.rmi.Remote;
Import java.rmi.RemoteException;
Public interface AccountService extends Remote{
Public double getBal(int accno) throws RemoteException;
}
2. AccountServiceImpl.java
packagecom.jtcindia.rmi;
importjava.rmi.*;
importjava.rmi.server.UnicastRemoteObject;
publicclassAccountServiceImplextendsUnicastRemoteObject
implementsAccountService {
publicAccountServiceImpl() throwsRemoteException {
super();
}
publicdouble getBal(int accno) throws
RemoteException{
System.out.println("getBal() with accno :
"+accno);
return 9999.99;
}}
RemoteException :-This is declare as an interface because in this
there are so many private data available. You have interact with
their subclass method also to avoid data duplication
Java Training Center
(No 1 in Training & Placement)
4
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
3. Server.java :-
packagecom.jtcindia.rmi;
importjava.rmi.registry.LocateRegistry;
importjava.rmi.registry.Registry;
public class Server {
public static void main(String[] args) {
try {
Registry reg = LocateRegistry.createRegistry(6789);
AccountServiceasi = new AccountServiceImpl();
reg.bind("ASI", asi);
System.out.println("Server is Running");
} catch (Exception e) {
e.printStackTrace();
}
}
}
4. Client.java :-
packagecom.jtcindia.rmi;
importjava.rmi.registry.LocateRegistry;
importjava.rmi.registry.Registry;
1. Here we need to write a default constructor which throws
RemoteException because in super class UnicastRemoteObject there
is a default constructor without throws ServerException.
2. A remote object is one whose method can be invoke from another
JVM.
Java Training Center
(No 1 in Training & Placement)
5
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
public class Client {
public static void main(String[] args) {
try {
Registry reg = LocateRegistry.getRegistry("localhost", 6789);
AccountService as = (AccountService) reg.lookup("ASI");
doublebal = as.getBal(1);
System.out.println(bal);
bal = as.getBal(2);
System.out.println(bal);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Binding the instance
of the remote object
to the RMI registry.
Java Training Center
(No 1 in Training & Placement)
6
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
=: EJB2/EJB :=
For Developing any Enterprise Edition you need mainly three types
of services.
 EJB is a remote, distributed multi-tier system. An EJB
application server provide mainly services like transaction
management, Security Management, Object Package which
simplifies the programming effect.
 For any Enterprise Edition development you need these Low
Level Services Commonly which you can get freely from EJB.
 High level Service is nothing but your application code business
logic which will change from Enterprise edition to enterprise
edition.
IMP -: To run RMI application you need “JDK” where to run EJB
application you need “application server”.
Java Training Center
(No 1 in Training & Placement)
6
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
=: EJB2/EJB :=
For Developing any Enterprise Edition you need mainly three types
of services.
 EJB is a remote, distributed multi-tier system. An EJB
application server provide mainly services like transaction
management, Security Management, Object Package which
simplifies the programming effect.
 For any Enterprise Edition development you need these Low
Level Services Commonly which you can get freely from EJB.
 High level Service is nothing but your application code business
logic which will change from Enterprise edition to enterprise
edition.
IMP -: To run RMI application you need “JDK” where to run EJB
application you need “application server”.
Java Training Center
(No 1 in Training & Placement)
6
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
=: EJB2/EJB :=
For Developing any Enterprise Edition you need mainly three types
of services.
 EJB is a remote, distributed multi-tier system. An EJB
application server provide mainly services like transaction
management, Security Management, Object Package which
simplifies the programming effect.
 For any Enterprise Edition development you need these Low
Level Services Commonly which you can get freely from EJB.
 High level Service is nothing but your application code business
logic which will change from Enterprise edition to enterprise
edition.
IMP -: To run RMI application you need “JDK” where to run EJB
application you need “application server”.
Java Training Center
(No 1 in Training & Placement)
7
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
 Following are various Application servers available
1. JBOSS(“Red Hat” Linux)
2. Web Logic(“BEA”, Oracle Company)
3. Web sphere(IBM)
Steps to develop and run EJB 2.0 application with JBOSS 4.0
Java Training Center
(No 1 in Training & Placement)
7
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
 Following are various Application servers available
1. JBOSS(“Red Hat” Linux)
2. Web Logic(“BEA”, Oracle Company)
3. Web sphere(IBM)
Steps to develop and run EJB 2.0 application with JBOSS 4.0
Java Training Center
(No 1 in Training & Placement)
7
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
 Following are various Application servers available
1. JBOSS(“Red Hat” Linux)
2. Web Logic(“BEA”, Oracle Company)
3. Web sphere(IBM)
Steps to develop and run EJB 2.0 application with JBOSS 4.0
Java Training Center
(No 1 in Training & Placement)
8
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
Steps to install JBOSS 4.0 :-
1. Click on installer called jems-installer-1.2.0 CRI.jar which is
available in JBOSS-4.0.
2. Select English and OK.
3. Click on next.
4. Click on next.
5. Accept license agreement and next.
6. Provide the location of installation E:/Jboss 4.0.5
7. Click OK on popup.
8. Select the profile all and click on next.
9. Click on next.
10.Provide the server name jtcindia and next.
11. Configure the default and click next.
12. Click next.
13. Provide admin username and password only and click on
next.
14. Click on next.
15. Click on done.
After installing successfully you can see the directory :-
Java Training Center
(No 1 in Training & Placement)
9
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
-: Steps to integrate JBOSS 4.0 with MyEclipse :-
1. Click on window  Preferences
2. My Eclipse workbench  Servers  JBOSS JBOSS 4.x
Integrate means only enable the Plugin.
In “Eclipse” you have to download all the plugin and then
enable if.
3. Select Enable
jBoss home directory: E:/jboss-4.0.5
Server name: jtcindia
Optional program argu:
Optional shutdown arg: -shutdown
4. Expend the JBOSS 4.x
Java Training Center
(No 1 in Training & Placement)
9
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
-: Steps to integrate JBOSS 4.0 with MyEclipse :-
1. Click on window  Preferences
2. My Eclipse workbench  Servers  JBOSS JBOSS 4.x
Integrate means only enable the Plugin.
In “Eclipse” you have to download all the plugin and then
enable if.
3. Select Enable
jBoss home directory: E:/jboss-4.0.5
Server name: jtcindia
Optional program argu:
Optional shutdown arg: -shutdown
4. Expend the JBOSS 4.x
Java Training Center
(No 1 in Training & Placement)
9
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
-: Steps to integrate JBOSS 4.0 with MyEclipse :-
1. Click on window  Preferences
2. My Eclipse workbench  Servers  JBOSS JBOSS 4.x
Integrate means only enable the Plugin.
In “Eclipse” you have to download all the plugin and then
enable if.
3. Select Enable
jBoss home directory: E:/jboss-4.0.5
Server name: jtcindia
Optional program argu:
Optional shutdown arg: -shutdown
4. Expend the JBOSS 4.x
Java Training Center
(No 1 in Training & Placement)
10
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
JDK
Launch
Paths and select the JDK option. And do the following to
add the JDK.
a. Click on add button.
b. Click on Apply.
5. Select the “Launch” under JBOSS 4.x… Run mode and click
Apply.
6. Click on OK of Preference window.
a. By default Port no: 8080 because it take default of
tomcat which is running on 8080.
b. Change that Port no:- if get any error like JVM_8080
i.e. lifecycleException.
-: Stating JBOSS :-
 Change the Port number: 5555.
 Start the JBOSS from myEclipse.
 Open the browser and type http://localhost:5555/imx-console/
 Enter username & password on popup window.
-: Creating EJB Project in myEclipse :-
1. File new  “EJB Project”
Project name: - E2Hello4JB and select J2EE1.4-EJB2.1 and finish.
2. You can see the following directory structure.
Java Training Center
(No 1 in Training & Placement)
11
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
New otherXMLXML(Basic Tem)ejb-jar.xmlnextcreate xml file
from DTD  select category.
To deployselect the Project name and gotodeploy(8th
) Icon. Select
Project E2Hello4JB add to your application server jBoss.
-//sun microsystem, Inc.//DTD Enterprise JavaBeans 3.0
--: Create client Project for EJB :-
1. Create a “Java Project” E2client4JB.
Java Training Center
(No 1 in Training & Placement)
11
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
New otherXMLXML(Basic Tem)ejb-jar.xmlnextcreate xml file
from DTD  select category.
To deployselect the Project name and gotodeploy(8th
) Icon. Select
Project E2Hello4JB add to your application server jBoss.
-//sun microsystem, Inc.//DTD Enterprise JavaBeans 3.0
--: Create client Project for EJB :-
1. Create a “Java Project” E2client4JB.
Java Training Center
(No 1 in Training & Placement)
11
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
New otherXMLXML(Basic Tem)ejb-jar.xmlnextcreate xml file
from DTD  select category.
To deployselect the Project name and gotodeploy(8th
) Icon. Select
Project E2Hello4JB add to your application server jBoss.
-//sun microsystem, Inc.//DTD Enterprise JavaBeans 3.0
--: Create client Project for EJB :-
1. Create a “Java Project” E2client4JB.
Java Training Center
(No 1 in Training & Placement)
12
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
Example:-
File required:-
1. HelloRemote.java
2. HelloBean.java
3. HelloHome.java
4. Ejb-jar.xml
5. Jboss.xml
6. HelloClient.java
Java Training Center
(No 1 in Training & Placement)
12
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
Example:-
File required:-
1. HelloRemote.java
2. HelloBean.java
3. HelloHome.java
4. Ejb-jar.xml
5. Jboss.xml
6. HelloClient.java
Java Training Center
(No 1 in Training & Placement)
12
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
Example:-
File required:-
1. HelloRemote.java
2. HelloBean.java
3. HelloHome.java
4. Ejb-jar.xml
5. Jboss.xml
6. HelloClient.java
Java Training Center
(No 1 in Training & Placement)
13
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
1. HelloHome.java
package com.jtcindia.ejb2;
importjava.rmi.*;
importjavax.ejb.*;
publicinterfaceHelloHomeextendsEJBHome{
publicHelloRemote create() throws createException,
RemoteException;
}
2. HelloRemote.java
package com.jtcindia.ejb2;
importjava.rmi.*;
importjavax.ejb.EJBObject;
publicinterfaceHelloRemoteextendsEJBObject{
public String getMessage(String name)
throwsRemoteException;
}
3. HelloBean.java
package com.jtcindia.ejb2;
importjavax.ejb.*;
publicclassHelloBeanextendsSessionBean{
SessionContentsc=null;
Public void setSessionContent(SessionContentsc){
System.out.println("setSesssionContent");
this.sc=sc;
Java Training Center
(No 1 in Training & Placement)
14
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
}
Public void ejbActivate(){
System.out.println("ejbActivate");
}
publicvoidejbPassivate(){
System.out.println("ejbPassivate()");
}
publicvoidejbRemove(){
System.out.println("ejbReamove");
}
publicvoidejbCreate(){
System.out.println("ejbCreate()");
}
publicStringgetMessage(String name){
String msg="Hi"+name+"welcome to JTC EJB with
JBOSS";
System.out.println(msg);
returnmsg;
}
}
4. HelloClient.java
package com.jtcindia.ejb2;
importjava.util.*;
importjavax.naming.*;
public classHelloClient {
publicstaticvoid main(String[] args) {
try{
Properties p=newProperties();
Java Training Center
(No 1 in Training & Placement)
15
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
p.put("java.naming.factory.initial","org.jnp.interf
aces.NamingContentFactory");
p.put("java.naming.provider.url","localhost:1099");
p.put("java.naming.factory.url.package","org.jboss.
naming");
Contentctx=newInitialContext(p);
Object o=ctx.lookup("JTCHelloHomeJNDI");
HelloHomehh=(HelloHome)o;
HelloRemotehr=hh.create();
String msg=hr.getMessage("Som");
System.out.println(msg);
msg=hr.getMessage("Som");
System.out.println(msg);
}catch(Exception e){
e.printStackTrace();
}
}
}
5. ejb-jar.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEejb-jarPUBLIC"-//Sun MicroSystem,INC.//DTD
Enterprise JavaBean
2.0//EN","http://Java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>HelloEJB</ejb-name>
<home>com.jtcindia.ejb2.HelloHome</home>
<remote>com.jtcindia.ejb2.HelloRemote</remote>
Java Training Center
(No 1 in Training & Placement)
16
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
<ejb-class>com.jtcindia.ejb2.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<trasaction-type>Container</trasaction-type>
</session>
</enterprise-beans>
</ejb-jar>
6. jboss.xml
<jboss>
<enterprise-beans>
<session>
<ejb-name>HelloEJB</ejb-name>
<jndi-name>JTCHelloHomeJNDI</jndi-name>
</session>
</enterprise-beans>
</jboss>

More Related Content

What's hot

What's hot (20)

Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questions
 
Hibernate Advance Interview Questions
Hibernate Advance Interview QuestionsHibernate Advance Interview Questions
Hibernate Advance Interview Questions
 
Java interview-questions-and-answers
Java interview-questions-and-answersJava interview-questions-and-answers
Java interview-questions-and-answers
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
 
Dev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdetDev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdet
 
JDBC
JDBC JDBC
JDBC
 
Java 10 New Features
Java 10 New FeaturesJava 10 New Features
Java 10 New Features
 
Hibernate notes
Hibernate notesHibernate notes
Hibernate notes
 
50+ java interview questions
50+ java interview questions50+ java interview questions
50+ java interview questions
 
[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for Android[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for Android
 
Corejava ratan
Corejava ratanCorejava ratan
Corejava ratan
 
Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013
 
Hibernate3 q&a
Hibernate3 q&aHibernate3 q&a
Hibernate3 q&a
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interview
 
DataFX 8 (JavaOne 2014)
DataFX 8 (JavaOne 2014)DataFX 8 (JavaOne 2014)
DataFX 8 (JavaOne 2014)
 
Best interview questions
Best interview questionsBest interview questions
Best interview questions
 
Certified Core Java Developer
Certified Core Java DeveloperCertified Core Java Developer
Certified Core Java Developer
 
Core java
Core javaCore java
Core java
 
Apache Cordova In Action
Apache Cordova In ActionApache Cordova In Action
Apache Cordova In Action
 
Spring andspringboot training
Spring andspringboot trainingSpring andspringboot training
Spring andspringboot training
 

Similar to EJB Part-1

Distributed Programming using RMI
 Distributed Programming using RMI Distributed Programming using RMI
Distributed Programming using RMI
backdoor
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
backdoor
 
Session 1 Tp1
Session 1 Tp1Session 1 Tp1
Session 1 Tp1
phanleson
 
Travelling Light for the Long Haul - Ian Robinson
Travelling Light for the Long Haul -  Ian RobinsonTravelling Light for the Long Haul -  Ian Robinson
Travelling Light for the Long Haul - Ian Robinson
mfrancis
 
Travelling light for the long haul
Travelling light for the long haulTravelling light for the long haul
Travelling light for the long haul
Ian Robinson
 
JEE Course - EJB
JEE Course - EJBJEE Course - EJB
JEE Course - EJB
odedns
 
Part 3 web development
Part 3 web developmentPart 3 web development
Part 3 web development
techbed
 

Similar to EJB Part-1 (20)

Distributed Programming using RMI
 Distributed Programming using RMI Distributed Programming using RMI
Distributed Programming using RMI
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
 
EJB.docx
EJB.docxEJB.docx
EJB.docx
 
Session 1 Tp1
Session 1 Tp1Session 1 Tp1
Session 1 Tp1
 
Rmi
RmiRmi
Rmi
 
Rmi
RmiRmi
Rmi
 
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
 
Project report for final year project
Project report for final year projectProject report for final year project
Project report for final year project
 
Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)
 
Travelling Light for the Long Haul - Ian Robinson
Travelling Light for the Long Haul -  Ian RobinsonTravelling Light for the Long Haul -  Ian Robinson
Travelling Light for the Long Haul - Ian Robinson
 
Travelling light for the long haul
Travelling light for the long haulTravelling light for the long haul
Travelling light for the long haul
 
Free EJB Tutorial | VirtualNuggets
Free EJB Tutorial | VirtualNuggetsFree EJB Tutorial | VirtualNuggets
Free EJB Tutorial | VirtualNuggets
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.ppt
 
JEE Course - EJB
JEE Course - EJBJEE Course - EJB
JEE Course - EJB
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
 
Part 3 web development
Part 3 web developmentPart 3 web development
Part 3 web development
 
Java interview questions for freshers
Java interview questions for freshersJava interview questions for freshers
Java interview questions for freshers
 
J2ee
J2eeJ2ee
J2ee
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 

Recently uploaded

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 

EJB Part-1

  • 1. Java Training Center (No 1 in Training & Placement) 1 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC RMI (Remote Method Invocation) 1. RMI is distributed technology, which is first attempt of SUN to provide a solution to distributed programming. RMI use socket. A socket is a transport mechanism. 2. No extra software is required for developing a distributed application using RMI other than JDK.  RMI provides a way for a java program on one machine to communicate with object residing in different JVM.  The important part of RMI architecture are the Stubclass object serialization and Skelton class.  RMI uses a layered architecture where each of layers can be enhanced without affected the other layers. =:-Developing First RMI application-:= Server Side Steps:- 1. Define a Business Service Interface (B.S.I.). a. Your Business Service interface has to extends java.rmi.Remote interface. b. Each Method inside the Business interface has to throw java.rmi.RemoteException. 2. Provide the implementation class for Business Service Interface. a. Business Services implements class has to extends “UnicastRemoteObject” if not extend then implement class is responsible for correct implementation of hashCode(), equals(), toString(). b. B.S.I. class has to implement Business Interface. 3. Create the Business Service Implement Service Implementation class object. 4. Bind the B.S.I. class object inside RMI registry or JNDI registry.
  • 2. Java Training Center (No 1 in Training & Placement) 2 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC -: Steps in Eclipse :- 1. Create a java Project with the name RMIServer. 2. Create package com.jtcindia.rmi 3. Write the following three files in your package. a. AccountService.java (interface) b. AccountServiceImpl.java c. Server.java (for binding object) If you have more than one Business class for other purpose than that class object will create in server.java also. Client Side Steps :- 1. Locate and get the registry reference. 2. Look Up the registry and get the required remote interface stub. 3. Invoke any required business operation on remote Business stub. 1. Create a java Project called RMI. 2. Create a package java.jtcindia.rmi; 3. Write the following in the Package. a. Client.java b. AccountServices.java(copy from the server) Way to create jar file :- D:/test> Jar cvf jtc.jar com (Here AccountServices.class file change to jar file)
  • 3. Java Training Center (No 1 in Training & Placement) 3 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC File Required:- 1. Package com.jtcindia.rmi; Import java.rmi.Remote; Import java.rmi.RemoteException; Public interface AccountService extends Remote{ Public double getBal(int accno) throws RemoteException; } 2. AccountServiceImpl.java packagecom.jtcindia.rmi; importjava.rmi.*; importjava.rmi.server.UnicastRemoteObject; publicclassAccountServiceImplextendsUnicastRemoteObject implementsAccountService { publicAccountServiceImpl() throwsRemoteException { super(); } publicdouble getBal(int accno) throws RemoteException{ System.out.println("getBal() with accno : "+accno); return 9999.99; }} RemoteException :-This is declare as an interface because in this there are so many private data available. You have interact with their subclass method also to avoid data duplication
  • 4. Java Training Center (No 1 in Training & Placement) 4 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC 3. Server.java :- packagecom.jtcindia.rmi; importjava.rmi.registry.LocateRegistry; importjava.rmi.registry.Registry; public class Server { public static void main(String[] args) { try { Registry reg = LocateRegistry.createRegistry(6789); AccountServiceasi = new AccountServiceImpl(); reg.bind("ASI", asi); System.out.println("Server is Running"); } catch (Exception e) { e.printStackTrace(); } } } 4. Client.java :- packagecom.jtcindia.rmi; importjava.rmi.registry.LocateRegistry; importjava.rmi.registry.Registry; 1. Here we need to write a default constructor which throws RemoteException because in super class UnicastRemoteObject there is a default constructor without throws ServerException. 2. A remote object is one whose method can be invoke from another JVM.
  • 5. Java Training Center (No 1 in Training & Placement) 5 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC public class Client { public static void main(String[] args) { try { Registry reg = LocateRegistry.getRegistry("localhost", 6789); AccountService as = (AccountService) reg.lookup("ASI"); doublebal = as.getBal(1); System.out.println(bal); bal = as.getBal(2); System.out.println(bal); } catch (Exception e) { e.printStackTrace(); } } } Binding the instance of the remote object to the RMI registry.
  • 6. Java Training Center (No 1 in Training & Placement) 6 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC =: EJB2/EJB := For Developing any Enterprise Edition you need mainly three types of services.  EJB is a remote, distributed multi-tier system. An EJB application server provide mainly services like transaction management, Security Management, Object Package which simplifies the programming effect.  For any Enterprise Edition development you need these Low Level Services Commonly which you can get freely from EJB.  High level Service is nothing but your application code business logic which will change from Enterprise edition to enterprise edition. IMP -: To run RMI application you need “JDK” where to run EJB application you need “application server”. Java Training Center (No 1 in Training & Placement) 6 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC =: EJB2/EJB := For Developing any Enterprise Edition you need mainly three types of services.  EJB is a remote, distributed multi-tier system. An EJB application server provide mainly services like transaction management, Security Management, Object Package which simplifies the programming effect.  For any Enterprise Edition development you need these Low Level Services Commonly which you can get freely from EJB.  High level Service is nothing but your application code business logic which will change from Enterprise edition to enterprise edition. IMP -: To run RMI application you need “JDK” where to run EJB application you need “application server”. Java Training Center (No 1 in Training & Placement) 6 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC =: EJB2/EJB := For Developing any Enterprise Edition you need mainly three types of services.  EJB is a remote, distributed multi-tier system. An EJB application server provide mainly services like transaction management, Security Management, Object Package which simplifies the programming effect.  For any Enterprise Edition development you need these Low Level Services Commonly which you can get freely from EJB.  High level Service is nothing but your application code business logic which will change from Enterprise edition to enterprise edition. IMP -: To run RMI application you need “JDK” where to run EJB application you need “application server”.
  • 7. Java Training Center (No 1 in Training & Placement) 7 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC  Following are various Application servers available 1. JBOSS(“Red Hat” Linux) 2. Web Logic(“BEA”, Oracle Company) 3. Web sphere(IBM) Steps to develop and run EJB 2.0 application with JBOSS 4.0 Java Training Center (No 1 in Training & Placement) 7 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC  Following are various Application servers available 1. JBOSS(“Red Hat” Linux) 2. Web Logic(“BEA”, Oracle Company) 3. Web sphere(IBM) Steps to develop and run EJB 2.0 application with JBOSS 4.0 Java Training Center (No 1 in Training & Placement) 7 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC  Following are various Application servers available 1. JBOSS(“Red Hat” Linux) 2. Web Logic(“BEA”, Oracle Company) 3. Web sphere(IBM) Steps to develop and run EJB 2.0 application with JBOSS 4.0
  • 8. Java Training Center (No 1 in Training & Placement) 8 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC Steps to install JBOSS 4.0 :- 1. Click on installer called jems-installer-1.2.0 CRI.jar which is available in JBOSS-4.0. 2. Select English and OK. 3. Click on next. 4. Click on next. 5. Accept license agreement and next. 6. Provide the location of installation E:/Jboss 4.0.5 7. Click OK on popup. 8. Select the profile all and click on next. 9. Click on next. 10.Provide the server name jtcindia and next. 11. Configure the default and click next. 12. Click next. 13. Provide admin username and password only and click on next. 14. Click on next. 15. Click on done. After installing successfully you can see the directory :-
  • 9. Java Training Center (No 1 in Training & Placement) 9 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC -: Steps to integrate JBOSS 4.0 with MyEclipse :- 1. Click on window  Preferences 2. My Eclipse workbench  Servers  JBOSS JBOSS 4.x Integrate means only enable the Plugin. In “Eclipse” you have to download all the plugin and then enable if. 3. Select Enable jBoss home directory: E:/jboss-4.0.5 Server name: jtcindia Optional program argu: Optional shutdown arg: -shutdown 4. Expend the JBOSS 4.x Java Training Center (No 1 in Training & Placement) 9 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC -: Steps to integrate JBOSS 4.0 with MyEclipse :- 1. Click on window  Preferences 2. My Eclipse workbench  Servers  JBOSS JBOSS 4.x Integrate means only enable the Plugin. In “Eclipse” you have to download all the plugin and then enable if. 3. Select Enable jBoss home directory: E:/jboss-4.0.5 Server name: jtcindia Optional program argu: Optional shutdown arg: -shutdown 4. Expend the JBOSS 4.x Java Training Center (No 1 in Training & Placement) 9 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC -: Steps to integrate JBOSS 4.0 with MyEclipse :- 1. Click on window  Preferences 2. My Eclipse workbench  Servers  JBOSS JBOSS 4.x Integrate means only enable the Plugin. In “Eclipse” you have to download all the plugin and then enable if. 3. Select Enable jBoss home directory: E:/jboss-4.0.5 Server name: jtcindia Optional program argu: Optional shutdown arg: -shutdown 4. Expend the JBOSS 4.x
  • 10. Java Training Center (No 1 in Training & Placement) 10 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC JDK Launch Paths and select the JDK option. And do the following to add the JDK. a. Click on add button. b. Click on Apply. 5. Select the “Launch” under JBOSS 4.x… Run mode and click Apply. 6. Click on OK of Preference window. a. By default Port no: 8080 because it take default of tomcat which is running on 8080. b. Change that Port no:- if get any error like JVM_8080 i.e. lifecycleException. -: Stating JBOSS :-  Change the Port number: 5555.  Start the JBOSS from myEclipse.  Open the browser and type http://localhost:5555/imx-console/  Enter username & password on popup window. -: Creating EJB Project in myEclipse :- 1. File new  “EJB Project” Project name: - E2Hello4JB and select J2EE1.4-EJB2.1 and finish. 2. You can see the following directory structure.
  • 11. Java Training Center (No 1 in Training & Placement) 11 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC New otherXMLXML(Basic Tem)ejb-jar.xmlnextcreate xml file from DTD  select category. To deployselect the Project name and gotodeploy(8th ) Icon. Select Project E2Hello4JB add to your application server jBoss. -//sun microsystem, Inc.//DTD Enterprise JavaBeans 3.0 --: Create client Project for EJB :- 1. Create a “Java Project” E2client4JB. Java Training Center (No 1 in Training & Placement) 11 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC New otherXMLXML(Basic Tem)ejb-jar.xmlnextcreate xml file from DTD  select category. To deployselect the Project name and gotodeploy(8th ) Icon. Select Project E2Hello4JB add to your application server jBoss. -//sun microsystem, Inc.//DTD Enterprise JavaBeans 3.0 --: Create client Project for EJB :- 1. Create a “Java Project” E2client4JB. Java Training Center (No 1 in Training & Placement) 11 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC New otherXMLXML(Basic Tem)ejb-jar.xmlnextcreate xml file from DTD  select category. To deployselect the Project name and gotodeploy(8th ) Icon. Select Project E2Hello4JB add to your application server jBoss. -//sun microsystem, Inc.//DTD Enterprise JavaBeans 3.0 --: Create client Project for EJB :- 1. Create a “Java Project” E2client4JB.
  • 12. Java Training Center (No 1 in Training & Placement) 12 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC Example:- File required:- 1. HelloRemote.java 2. HelloBean.java 3. HelloHome.java 4. Ejb-jar.xml 5. Jboss.xml 6. HelloClient.java Java Training Center (No 1 in Training & Placement) 12 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC Example:- File required:- 1. HelloRemote.java 2. HelloBean.java 3. HelloHome.java 4. Ejb-jar.xml 5. Jboss.xml 6. HelloClient.java Java Training Center (No 1 in Training & Placement) 12 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC Example:- File required:- 1. HelloRemote.java 2. HelloBean.java 3. HelloHome.java 4. Ejb-jar.xml 5. Jboss.xml 6. HelloClient.java
  • 13. Java Training Center (No 1 in Training & Placement) 13 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC 1. HelloHome.java package com.jtcindia.ejb2; importjava.rmi.*; importjavax.ejb.*; publicinterfaceHelloHomeextendsEJBHome{ publicHelloRemote create() throws createException, RemoteException; } 2. HelloRemote.java package com.jtcindia.ejb2; importjava.rmi.*; importjavax.ejb.EJBObject; publicinterfaceHelloRemoteextendsEJBObject{ public String getMessage(String name) throwsRemoteException; } 3. HelloBean.java package com.jtcindia.ejb2; importjavax.ejb.*; publicclassHelloBeanextendsSessionBean{ SessionContentsc=null; Public void setSessionContent(SessionContentsc){ System.out.println("setSesssionContent"); this.sc=sc;
  • 14. Java Training Center (No 1 in Training & Placement) 14 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC } Public void ejbActivate(){ System.out.println("ejbActivate"); } publicvoidejbPassivate(){ System.out.println("ejbPassivate()"); } publicvoidejbRemove(){ System.out.println("ejbReamove"); } publicvoidejbCreate(){ System.out.println("ejbCreate()"); } publicStringgetMessage(String name){ String msg="Hi"+name+"welcome to JTC EJB with JBOSS"; System.out.println(msg); returnmsg; } } 4. HelloClient.java package com.jtcindia.ejb2; importjava.util.*; importjavax.naming.*; public classHelloClient { publicstaticvoid main(String[] args) { try{ Properties p=newProperties();
  • 15. Java Training Center (No 1 in Training & Placement) 15 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC p.put("java.naming.factory.initial","org.jnp.interf aces.NamingContentFactory"); p.put("java.naming.provider.url","localhost:1099"); p.put("java.naming.factory.url.package","org.jboss. naming"); Contentctx=newInitialContext(p); Object o=ctx.lookup("JTCHelloHomeJNDI"); HelloHomehh=(HelloHome)o; HelloRemotehr=hh.create(); String msg=hr.getMessage("Som"); System.out.println(msg); msg=hr.getMessage("Som"); System.out.println(msg); }catch(Exception e){ e.printStackTrace(); } } } 5. ejb-jar.xml <?xmlversion="1.0"encoding="UTF-8"?> <!DOCTYPEejb-jarPUBLIC"-//Sun MicroSystem,INC.//DTD Enterprise JavaBean 2.0//EN","http://Java.sun.com/dtd/ejb-jar_2_0.dtd"> <ejb-jar> <enterprise-beans> <session> <ejb-name>HelloEJB</ejb-name> <home>com.jtcindia.ejb2.HelloHome</home> <remote>com.jtcindia.ejb2.HelloRemote</remote>
  • 16. Java Training Center (No 1 in Training & Placement) 16 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC <ejb-class>com.jtcindia.ejb2.HelloBean</ejb-class> <session-type>Stateless</session-type> <trasaction-type>Container</trasaction-type> </session> </enterprise-beans> </ejb-jar> 6. jboss.xml <jboss> <enterprise-beans> <session> <ejb-name>HelloEJB</ejb-name> <jndi-name>JTCHelloHomeJNDI</jndi-name> </session> </enterprise-beans> </jboss>