J2EE programming (1)

Source: Internet
Author: User
To help beginners in China to compile some J2EE documents, we hope to help Java enthusiasts.
This document describes how to use EJB to develop, deploy, and run a client/server application. The client in the example runs as a Java independent application and is implemented by the ConverterClient. java class. It implements a simple real-time session, mainly through client applications calling the server-side EJB class ConverterEJB. java. If you have installed J2EE, you can find these examples in the doc/guides/ejb/examples/converter directory.
To implement the simple example described in this article, you need to complete the following tasks:
· Compile and compile the EJB program
· Create a J2EE application
· Package EJB (. jar)
· Deploy J2EE applications
· Compile and compile client programs
· Run the client
The following sections briefly describe the tasks and knowledge points involved.
Prerequisites
The premise for implementing the example provided in this article is that you have installed the J2SE SDK downloaded from Javasoft.com or the website of the relevant operating system vendor, and installed the corresponding operating system version of J2EE SDK (www.javasoft.com download) and configured correctly. For more information about J2SE and J2EE installation and configuration, see the product documentation.
EJB encoding
Each EJB program must write the following code:
· Remote interface)
· Local interface)
· Implementation component (Enterprise bean class)
Remote interface code
The remote interface defines the commercial methods that can be called by the client. These commercial methods are implemented by the Enterprise component of the server. The Converter. java code involved in this article is as follows:
Import javax. ejb. EJBObject; // introduce required packages
Import java. rmi. RemoteException;
Public interface Converter extends EJBObject {// you must inherit the EJBObject class
/* Define the methods that can be called by the client */
Public double dollarToYen (double dollars) throws RemoteException;
Public double yenToEuro (double yen) throws RemoteException;
}
Local interface encoding
The local interface defines the method for creating, searching, or moving EJBs on the client. The ConverterHome interface of the local interface involved in this article only defines one create method and returns the remote interface type. The encoding is as follows:
Import java. io. Serializable;
Import java. rmi. RemoteException;
Import javax. ejb. CreateException;
Import javax. ejb. EJBHome;
Public interface ConverterHome extends EJBHome {
Converter create () throws RemoteException, CreateException;
}
Enterprise component class (EJB) encoding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.