Java from Perl; Perl from Java

From JmPm

(Difference between revisions)
Jump to: navigation, search
(New page: == Perl - Java Similarities== • Interpreted languages • Platform independent ( write once run anywhere ) • Similar syntax ( procedural languages ) • Garbage collector • Mod...)

Revision as of 07:20, 16 July 2007

Contents

Perl - Java Similarities

• Interpreted languages

• Platform independent ( write once run anywhere )

• Similar syntax ( procedural languages )

• Garbage collector

• Modules and packages structure


Differences

• 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 , 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


Perl2Java

• 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 ( Hi.java )

• Compiles java class ( Hi.java -> Hi.class )

• Extracts the methods signatures to Hi.jdat file


Java2Perl

• 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