Java from Perl; Perl from Java

From JmPm

Jump to: navigation, search


Perl - Java Similarities

  • Interpreted languages
  • Platform independent (write once run anywhere)
  • Similar syntax (procedural languages)
  • Garbage collector
  • Modules and packages structure


  • Java 100% object oriented, in Perl OO is optional (function overloading does not exist)
  • Java requires compilation, Perl doesn’t
  • Java does not allow multiple inheritance, Perl does. (Object == UNIVERSAL)
  • Java has strong typing ( requires variable declaration ), Perl has not – variable gets it type after first assignment.
  • autoload mechanism
  • Do we need strong typing? (strong testing ?)
  • Java is rigid, Perl has many ways to say same thing
  • Perl has many shell like features (variable interpolation, file test operators). Java has none.
  • In Java execution starts in main(), Perl has no main, (__DATA__ feature)
  • Perl is much FASTER in development and execution

Why do we need it ?

  • Legacy components access
  • Code transition from some language to perl
  • Speed (C , not Java)
  • Component exist in other language and we want to use it in Perl


  • Inline, Inline::Java
  • Easy installation
  • Short learning curve
  • Hides all details (compilation, glue files)
  • Inline has extension to many other languages – C , C++ , Python ...
  • Older tools XS, SWIG.

• Manual steps, long learning curve, only perl to XXX direction


  • Methods invocation ( regular and static )
  • Member variables access
  • Study
  • Script or package code layout

inline::java steps

  • Creates java source file from the embedded code ( )
  • Compiles java class ( -> Hi.class )
  • Extracts the methods signatures to Hi.jdat file


  • Implemented by Inline::Java::PerlInterpreter
  • Alternative implementation based on
    • JNI defines a standard naming and calling convention so the Java virtual machine can locate and invoke native methods
    • perl from C invocation , modified examples code from O’Reilly Advanced Perl Programming
  • Two basic problems :
    • Functions in perl can be called with variable number of parameters and output variable number of values
    • Parameters can have different types
Personal tools