[View INPRISE Home Page][View Product List][Search This Web Site][View Available Downloads][Join Inprise Membership][Enter Discussion Area][Send Email To Webmaster]

Order Now

Register

*Product Info
.Product Brief
.Feature List
.Description
.Technical
Papers
.Companion Tools
.System
Requirements
.Awards
.Manuals
.Application
.Server
.Previous
.Versions
*Additional
Resources
.Tools and
.Components
.Books
.JBuilder Listserv
.Other JBuilder
.Websites
*Support
.FAQ
*Quotes
*Case Studies
*News & Press
.News Articles
.Press Releases
.Publications
*Newsgroups
.Other Groups
*JBuilder Home
*borland.com

Inprise
 Inprise Info
 World Wide
JBuilder 3

Delphi/Java is a reality with Delphi2J and JBuilder
By Russell E. Frey
E-mail: support@javadelphi.com

Information for special savings and a chance for a weekly free copy of Delphi2J.

NOTE: The views and information expressed in this document represent those of its author(s) who is solely responsible for its content. Inprise does not make or give any representation or warranty with respect such content.

Easily adding Java to a Delphi programmers toolkit

Delphi programmers frequently consider Delphi to be the worldÆs easiest and most powerful compiler for Windows. However, no tool should be considered the optimal solution for every requirement. The ability to create portable code for running programs across the Internet and various operating systems is beyond the capabilities of Delphi. You may simply want to run your Delphi program on an Internet server running Unix, or actually run it inside of a browser. Luckily you can do just that using two tools, Delphi2J and JBuilder! Delphi programmers have dreamed about a Delphi version for the Mac, Linux, Sun, or Java. Finally the dream has met reality!

Delphi2J is a compiler, which inputs Delphi projects, and creates 100% Java portable code that can be quickly recompiled with JBuilder. The majority of Delphi2J customers have chosen JBuilder for their Java needs. This is not a coincidence! Delphi users have come to expect nothing less than a performance driven development environment. Later on, youÆll find out why JBuilder is the best Java compiler available, particularly for Delphi users.

There are many reasons that Delphi users will find Delphi2J to meet their needs along with JBuilder:

  • Delphi2J allows you to achieve the highest possible productivity for your current and future products. You can reuse your code in JBuilder while at the same time maintaining it and offering a Delphi version as well.
  • Ability to create platform-independent versions of your products.
  • Easy to integrate your programs over secure environments.
  • Delphi2J has been exhaustively optimized to create the most efficient running code. Since Java versions will run slower than Delphi, this can be a major concern.
  • Delphi2J simplifies JBuilder development. Using Delphi2J, you will not get confused over syntax such as implementing pointers, parameters by values or parameters by reference.

 

AUTOMATING PROJECT MIGRATION

Delphi2J can automatically make the migration to JBuilder for you. For example, if you thought pointers could not be implemented in Java, you would be wrong. Java does not support pointers in the form that most programmers are familiar with. However, Java really supports pointers in much of the same way Delphi handles pointers with classes such as a TForm. The Delphi compiler automatically dereferences class pointers for you, so you do not even discern your use of pointers. When you pass classes in Delphi though as parameters, you have to understand that it is a pointer.

Java classes work nearly the same as Delphi classes, which is why Java really supports pointers. The only thing that Java does not support is to allow you to actually manipulate memory addresses directly or execute pointer-arithmetic operations. However, none of that is needed to implement pointer data structures such as linked list as well as any other data structure.

Where Java gets tricky, is the handling of parameters. Java does not offer the flexibility of reference and value parameters. Consider the following code:

procedure parms(var A: String; B: String; var C: Integer; D: Integer; var E: PMyRecord; F: PMyRecord); begin end;

where PMyRecord is defined as follows:

PMyRecord = ^MyRecord;

MyRecord = Record

Name: String;

Id: Integer;

Next: PMyRecord;

End;

In case you think the above is simple to do in JavaàThink again! Consider how productive you will be when the following code is spit out from Delphi2J and can be reused immediately in JBuilder:

final public void parms(StringBuffer a, StringBuffer b_orig, dvars c, short d, myrecord e, myrecord f)

{

StringBuffer b = null;

if (b_orig!=null) b = new StringBuffer(b_orig.toString());

if (e==null) {e = new myrecord(global.G, 0);

e.objectcopy = null; } e.objectcopy = e;

{myrecord T = null; if (f!=null) T = f.Ptr; f = new myrecord(global.G, 0); f.Ptr = T; f.objectcopy = T;}

try {

}

catch (Exception E) {

System.out.println("Exception in tform1.parms "+E);

}

}

The above code will properly implement the Pascal code in a way that is compliant with Java:

  • Integers, chars, and other basic types are only passed by value in Java. In order to pass them by reference, a dummy class has to be used when calling the procedure.
  • Non-basic types (including StringBuffer, which is a standard Java class) are always passed by reference, much like a var parameter.
  • If you want to change a var parameter to a reference parameter in Java, you need to make a cloned object (a copy of it).
  • If you need to implement a pointer to a class, Delphi2J automatically utilizes the ptr Object that it creates inside of the code.

Not all pointer manipulations may seem intuitive in Java. Consider the simple Pascal block:

var

D, F: ^MyRecord;

D2: MyRecord;

G2: SuperClassOfMyRecord;

begin

D := @D2;

D^ := D2;

D := F;

G2 := D2;

end;

How would you think to implement this in Java? Hopefully you would not just create two variables in Java and assign them to each other, because that will not work! If you still do not see the productivity advantage of using Delphi, Delphi2J, and JBuilder, consider the last statement G2 := D2; In Java, if you cast the value from a derived class and want to call a method inside of the casted variable, you may not be calling the correct method!

Pointers are just one of the many differences between Delphi and Java, that Delphi2J will handle automatically. In fact, there are many of basic ideas in Delphi that Delphi2J will automatically migrate to JBuilder including:

  • All of the basic Delphi components are converted to Swing compatible JDK components
  • Property manipulations are converted either to a direct variable or the read/write methods
  • Support for sets
  • Automatically creates classes for global procedures and variables
  • and moreà

Java Product of Choice for Delphi Programmers

Delphi users will be quickly at home with JBuilder, since JBuilder features the same visual look and feel of Delphi. In fact the IDE is so similar to Delphi, that you will only need to focus on the difference in programming language and various components.

Perhaps the part of JBuilder that really sets it apart from other products, is its uniqueness in providing a robust and productive environment. This is most apparent when doing a simple compiler task on a project, which is probably the most important task needed for Delphi users who would first simply like to compile their programs in Java. Our use has shown that only JBuilder is well equipped to handle any sizeable program, which is important since Delphi2J users are usually dealing with real-world applications.

JBuilder 3 includes more than 300 JavaBean components, with source code! The relative ease of using these various components to enhance and build applications is really driving programming to its next level.

Delphi Database users will find it very easy to take advantage of the Java JDBC API in JBuilder. Borland really continues its rich tradition of providing extensive database tools and code through its technology in JBuilder. The DataExpress data access components in JBuilder are very similar to the VCL data aware components in Delphi.

Example of a large Delphi application

Consider an educational software package written in Delphi. This program was written over a few years, and includes everything from linked lists to graphical manipulations to printing. Given the need for portability among the Mac and Unix, a Java version was created using Delphi2J. To create the Java code with Delphi2J, only the Delphi project source code name needs to be selected. Delphi2J will then read the source code, much like any other compiler, and create the Java code.

The program consists of nearly 4.8MB of Delphi code, and when translated to Java results in 5.5MB of Java code. What quickly became apparent with such a large project, was that not all Java compilers are alike. In fact, just the ability to compile this project in Java makes JBuilder the clear winner among its peers. Some day traders may even consider non-JBuilder compiler times to be long-term investing! Consider the difference in time to just simply compile this program:

SunÆs JDK 705 seconds

Symantec Café v3 289 seconds

JBuilder 161 seconds

The sluggishness of other compilers seems to indicate that their focus cannot go beyond anything but a trivial Java Applet. If you plan on doing anything remotely serious with Java, my opinion is to avoid marketing hype and use JBuilder.

That is all you need to do to create a JBuilder compatible version of your Delphi code. Now you have a JBuilder version, you are free to really begin to take advantage of the technology and environment of JBuilder.

Speed cannot be an afterthought in a Java program

Most Delphi programmers have never bothered profiling their programs, and probably would even anonymously admit their use of bubble sort from time to time. A Java program cannot be written without attention given to some of the differences in their Java run-time equivalent. While a Java program will run slower than a Delphi program, the good news is that common knowledge can make the speed of a Java program quite comparable.

If you do not understand the differences between Delphi and Java, not only do you risk creating a program that is unbearably sluggish, but quite possibly one that does not even work as you planned! Delphi2J will make the use of the most efficient methods to making a JBuilder compatible version of your code, but you still need to understand some issues.

Speed Example #1

Consider a subtle difference in a Java program. The following code in Delphi and Java are NOT equivalent:

Pascal: For X := 1 to length(S) do

Java: for (x=1; x <= S.length(); x++)

In Delphi the value length(S) will be calculated only once at the start of the loop. Conversely, Java will call S.length() as many times as the loop is executed. The equivalent Java code is really:

int m = S.length();

for (x=1; x <= m; x++)

Speed Example #2

Creating new objects in Java is a costly operation. Delphi programmers may be accustomed to creating excess objects in Java. Since Java was written to be a simple programming language, many times an operation performs more operations than may be apparent. Try to figure out how many objects are created with the following Java code:

String S = "initial value";

S = "so" + " has changed";

Although Java tries to optimize String manipulations, it needs some way to handle string concatenations. It accomplishes this by actually translating the second line into something that looks like this:

S = (new StringBuffer()).append("so").append("has changed");

If these routines are abused, it can have a drastic effect on performance. One way Delphi2J tries to optimize your JBuilder code is by only allocating and using only one StringBuffer throughout the entire program. It can then manipulate the above code to:

S.setLength(0);

S.append("so");

S.append("has changed");

This not only eliminates the need to create a new StringBuffer, but it also has another side benefit. By only creating a StringBuffer once, you can use a StringBuffer as a parameter more efficiently by reference. This was demonstrated in the previous example: final public void parms(StringBuffer a, StringBuffer b_orig, dvars c, short d, myrecord e, myrecord f).

Profiling

Delphi2J may provide some useful optimizations of your Delphi code, but if your code still relies on too much efficient code, you will probably still run into speed problems. JBuilder will continue to optimize your code even further, but you will still probably want to analyze your code. Since profiling technology is rapidly changing, I would suggest you reference http://www.borland.com for the latest technology available.

 

Latest Technology

Delphi2J will create code for JBuilder that relies on the latest Java technology. One of the most exciting aspects of Java v2 technology is Swing. The ability to include Swing in JBuilder is simply the difference between using a different set of components. Delphi2J also makes the transition easy by encapsulating the basic components in a replaceable set of classes. This layout makes it easy to swap between Swing and the AWT if needed for quicker browser display, or quite possibly for future technology options.

It seems an untold truth that JBuilder is always ahead of the pact in integrating the latest technology. If you consider the speed of new Java technologies, this is certainly not an easy task. Just some Java technology that Delphi users will welcome, include:

  • JDBC, which is really transparent to the user as it is in JBuilderÆs data aware components.
  • RMI
  • Collections
  • Easy creation of JARs, which is used for distributing your program
  • JNI
  • Accessibility APIs

Technical Support

JBuilder and the Borland newsgroups are just one of the many resources to take for granted as a JBuilder owner. These areas are great places to spruce up your skills and to get past any difficult programming tasks. There are also public newsgroups that are helpful, but the on-line Borland newsgroups are the best.

Conclusion

Delphi users will encounter a smooth transition to Java with Delphi2J and JBuilder. The Delphi2J compiler will create Java equivalent code from your Delphi code, which JBuilder can then compile. The ability to create platform-independent Delphi programs and Java servlets, makes this a powerful combination.

JBuilder is really the Java twin of Delphi. It features a Delphi like IDE, which will make any Delphi programmer immediately productive. JBuilderÆs collection of 300 components, including source, is a tremendous resource for any developer.

Delphi2JÆs capabilities to create large Java programs really can stress a Java compiler. I was surprised at the difference in compile times among compilers. It takes Symantec Café 80% longer than JBuilder to just compile a large Java program.

JBuilder is simply the no-brainer Java development choice for Delphi users, and Delphi2J (http://www.javadelphi.com/borland.htm) will get you there.

Top of Page
 

Trademarks & Copyright © 1999 INPRISE Corporation