Cheap web site hosting service by Active-Venture.com
  

 Back to Index


NAME

Tutorial - Perl and Java

SYNOPSIS

Java and Perl have different strengths and complement each other well.

You can connect them at runtime with tools such as JPL, PJC, or ActiveX. In theory, you can convert Perl to Java bytecode, and vice-versa.

Note:

Not actually a conversion.

At this stage, we are generating Java opcodes by walking Perl's syntax tree. This is very different from converting Perl to Java. It's a lot easier!

1.1 Perl and Java, Compared

Perl offers rich text processing features, high-level network APIs, excellent database integration, and a centralized repository of reusable code:

  • Regular expression engine is a powerful sub language that can perform complex text manipulations and extract data.
  • Packages such as libwww-perl (LWP) and libnet are powerful, high-level interfaces to network functionality.
  • The Perl DBI is an interface to SQL data sources.
  • CPAN provides a centralized, organized archive of reusable code.

Java has a powerful graphical API, has numerous embedded implementations, excellent database integration, but no single recognized repository of reusable code.

  • The Swing (JFC) toolkit is a powerful toolkit for developing user interfaces. Java also boasts 2D and 3D graphics APIs.
  • Java comes in embedded flavors, such as:

    • Kaffe http://www.transvirtual.com/ - embedded implementations for different platforms
    • Waba http://www.wabasoft.com/ - a subset of Java for Windows CE and PalmOS
    • It's embedded into web browsers (Netscape and MS Internet Explorer)
    • and more...
  • Java's JDBC is similar to Perl's DBI
  • Java has many different repositories of code. Efforts such as the Giant Java Tree http://www.gjt.org/ attempt to create a unified repository.

1.2 Opportunities to Combine Java and Perl

You have a Java program with a lot of data that needs to be parsed, filed, briefed, debriefed, and numbered.

You want to build your GUI in Java, but let Perl do the heavy lifting.

You've adopted the "Java is a systems language, Perl is a scripting language" paradigm, and it works for you.

You're not sure which regex implementation to use:

org.teeth.green.loony.raving.monster.regex.*;

com.zeppelin.regex.*;

You want the best of both worlds.

1.3 Important Differences between Java and Perl

  • perl compiles and executes programs each time you run them (unless you use the Perl compiler).
  • javac compiles programs in advance, java runs them in the Java interpreter.
  • The Java interpreter supports method overloading (methods can have the same name, but are differentiated on the basis of their argument types). Overloaded methods generally perform the same function, but methods with a shorter argument list often use defaults:

 
    // Draw a circle in the center of the screen
    int drawCircle(int radius);

    // Draw a circle at specified coordinates
    int drawCircle(int radius, int h, int k);  

  • The Perl interpreter doesn't support method overloading. In JPL, when we call Java from Perl, we need to use some tricks to specify the Java method we want to invoke. We'll learn about this when we see JPL's getmeth function.

Note:

At the time this presentation was prepared, JPL did not work with Perl for Win32. However, JPL is in the core Perl distribution, and there are plans to make it work with Perl for Win32.

With that in mind, I'm presenting the JPL material first, because it is of interest to both Win32 and Unix Perl people. The Win32-specific stuff (alternatives to JPL) will come last. I won't be offended if the Unix people leave when I move to this section of the tutorial, since there is no Unix material in that section. I'm perfectly happy to take questions between JPL and ActiveX sections.

A subset of JPL now works on Win32. You can embed Java in Perl, but you cannot embed Perl in Java (yet).

COPYRIGHT

Copyright (c) 1999, Brian Jepson

You may distribute this file under the same terms as Perl itself.

Converted from FrameMaker by Kevin Falcone.

 

  

 

Cheap domain name:
Domain name services from just
$8.95/year only
 


Buy domain name registration and cheap domain transfer at low, affordable price.

2002-2004 Active-Venture.com Web Site Hosting Service

 

Disclaimer: This documentation is provided only for the benefits of our web hosting customers.
For authoritative source of the documentation, please refer to http://www.perldoc.com