Tutorial - Perl and Java
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.
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!
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
- 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.
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:
You want the best of both worlds.
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
- 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
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 (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
Buy domain name registration and cheap domain transfer at low, affordable