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) |
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).
PaymentCalc 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.
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.
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.