Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Java 1.2 extends Java's distributed object capabilities

Find out what RMI and Java IDL, Java 1.2's seemingly similar distributed object technologies, have to offer you

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

Page 3 of 6

CORBA, meanwhile, benefits from the fact that it is a language-independent solution, but that adds significant complexity to the development cycle and also precludes using Java's garbage collection features and RMI's pass-by-copy parameter passing. While there is currently a formal request for proposals (RFP) out on CORBA pass-by-copy, it will never be at a level supported by RMI, due to the complexities of morphing objects from one language to another.

The following table attempts to summarize many of the features supported by the two architectures. Following this table, we will begin development of two simple Java applications using RMI and Java IDL. Remember, Java IDL is simply an implementation (albeit a subset) of the CORBA specification, therefore Java IDL and CORBA can be compared interchangeably in many areas.

Comparison Of RMI and CORBA Features
Capability CORBA RMI


Server Callbacks Yes Yes
Pass-By-Value No Yes
Dynamic Discovery Yes No
Dynamic Invocations Yes Yes
Multiple Transport Support Yes Yes
URL Naming No (ORB-dependent) Yes
Firewall Proxy No (ORB-dependent) Yes
Language-Independent Yes No
Language-Neutral Wire Protocol Yes (via IIOP) No (Future IIOP?!?)
Persistent Naming Yes No
Wire-level Security Yes (via CORBASecurity) Yes (via SSL)
Wire-level Transaction Yes (via CORBA OTS) Yes (via JTS)


MortgageCalc 1.0 -- one app, two technologies

To highlight the similarities and differences between RMI and Java IDL, I deemed it best to build two versions of the same application -- MortgageCalc 1.0 -- one for each of the technologies (see Resources for the complete source for these two apps). Each application will be comprised of a client and server component used to calculate and display mortgage payments based on a number of initial conditions (length of loan, interest rates, taxes, insurance, and down-payment amount). Because the number-crunching portion of these two applications will be identical, we can encapsulate that calculation code within a single Java class to be shared by both. This will allow us to focus on the specific steps involved in building an application using RMI and Java IDL.

Before we begin, I'll briefly explain the formula we'll be using to perform the calculations. Note: These calculations use the mortgage formula for U.S. mortgages. Other countries, such as Canada, compound interest semi-annually, resulting in a different calculation.

The monthly payment (PMT) represents the principal plus the interest you owe the bank each month. In addition to this payment, your total payment (TOTPMT) will also include city/county taxes (TAX) and home-owner's insurance (INS). In other words, your monthly payment can be represented by the following formula:

TOTPMT = PMT + TAX + INS


The TAX and INS values are simple to calculate (TotalAmounts/12), but PMT proves to be more difficult. Without going into detail, the formula used to calculate this value is as follows:

PMT = BAL * (INT / (1 - (1 + INT) ** -MON))


BAL is the initial amount of the loan, INT is the monthly interest, and MON is the number of months over which the loan is amortized (Years * 12).

The PaymentCalc class

To avoid duplicating the calculation code in both our RMI and Java IDL examples, we will build a simple Java class, PaymentCalc, that can be reused in both applications. If these financial applications were to grow in complexity, we could easily extend the PaymentCalc class without continually duplicating changes to two sets of code. For now, PaymentCalc contains two methods -- PI() and PITI(). The PI() method calculates a payment consisting of principal and interest, while the PITI() method calculates a payment consisting of principal, interest, taxes, and insurance.

class PaymentCalc
{
   /*
    PI calculates only the principal and interest payment
   */
   double PI(double Balance, double AnnualInterestRate, int YearsLength)
   {
      double BAL = Balance;
      double INT = (AnnualInterestRate / 12);
      double MON = (YearsLength * 12);

double PMT = BAL * (INT / (1 - java.lang.Math.pow(1 + INT, -MON)));
return PMT; }
/* PITI calculates the total payment, including insurance and taxes */ double PITI(double Balance, double AnnualInterestRate, int YearsLength, int AnnualInsurance, int AnnualTaxes) { double BAL = Balance; double INT = (AnnualInterestRate / 12); double MON = (YearsLength * 12);
double PMT = BAL * (INT / (1 - java.lang.Math.pow(1 + INT, -MON))); double INS = (AnnualInsurance / 12); double TAX = (AnnualTaxes / 12); double TOTPMT = PMT + INS + TAX;
return TOTPMT; } }


The server portions of the RMI and Java IDL applications will utilize the PaymentCalc class to perform calculations for a variety of term lengths and principals and will return an array of payment options to the client.

The RMI-based MortgageCalc app

Developing an RMI application consists of the following steps:

  1. Define a remote interface
  2. Implement the remote interface by building an implementation class (server app)
  3. Generate client stubs and server skeletons using rmic
  4. Start the RMI registry and register remote objects
  5. Build the client application
  6. Start client application and connect to the server


Note that these steps look vaguely similar to those required when we built our CORBA examples several months ago. The major difference lies in the first step. Using RMI, we can define the remote interface using the Java programming language as opposed to IDL.

Step 1: Define a remote interface
The first step requires us to define the operations we would like to be performed by our server. An extremely simple application could calculate a single payment based on principal, interest, and length, but we'll take this a step further. Instead of calculating a single payment, let's allow our server to calculate a variety of payments based on options such as amount of down-payment (5%, 10%, or 20%) and length of loan (15 year or 30 year). These options will allow us to examine the passing of data types from client and server. In the RMI case, we will return a Vector object to return a list of objects containing the calculated data.

The Calculate interface will be implemented by our server application.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • Download this article and the complete source as a gzipped tar file /javaworld/jw-04-1998/distributed/jw-04-distributed.tar.gz
  • Download this article and the complete source as a zip file /javaworld/jw-04-1998/distributed/jw-04-distributed.zip
  • For another detailed look at CORBA, read Jon Siegel's CORBA Fundamentals and Programming (Wiley Computer Publishing Group, ISBN0-471-12148-7)
  • Another excellent reference on CORBA and Java is Client/Server Programming With Java and CORBA by Robert Orfali and Dan Harkey (Wiley Computer Publishing Group, ISBN 0-471-16351-1)
  • Visigenic VisiBroker for Java http://www.visigenic.com/
  • IONA Technologies OrbixWeb http://www.iona.com/
  • IBM ComponentBroker http://www.software.ibm.com/ad/cb
  • JavaSoft JDK 1.2 Beta2 http://www.javasoft.com/products/jdk/1.2/
  • JavaSoft Java IDL http://java.sun.com/products/jdk/idl/index.html
  • Additional information on the COS naming service http://www.omg.org/corba/sectrans.htm#nam
  • The idltojava compiler is not included with the JDK 1.2 Beta 2 release and must be downloaded separately http://developer.javasoft.com/developer/earlyAccess/jdk12/idltojava.html.