Python | Jython | IRONpython | PyPy | Python Implementation | Platform Independence

Here we will talk about Python and its implementations and the advantages of having different implementations (Majorly Jython).

So initially we should know about the basic flowchart of how does a code run for the C and Java language to get a deeper understanding. 

BLOG EXPLANATION:


IN C)

For a C program refer to the diagram below :



STEPS

1> The code goes to the compiler for compilation purposes.

2> After the code comes out it is converted to machine code (The code understood by machine) that is specific for a given processor, as windows and mac have different processors they will have a different machine code hence will need a different conversion for both systems.
# this brings out a limitation that one cannot use the same machine code for different processors.

3> After conversion the processor does the action and our work is completed.

IN JAVA)

The problem discussed above was resolved by Java by following a different process for the compilation of code.

NOTE: C# (pronounced as C Sharp) and Python have taken the same route making them platform-independent.
 
STEPS

1> The code goes to the compiler for compilation purposes

2> The compiler converts the code to Java Bytecode which is generic for all the systems/processors

NOTE: There are different JVM for different Platforms like mac , windows, Linux , etc. 

3> Then the JVM(Java Virtual Machine) comes into action and takes the Java Bytecode for further conversion.
    The JVM has access to all the libraries of the particular language and uses them to convert it into the machine code

4> After conversion the processor does the action and our work is completed.

IN PYTHON)

Java byte code is not specific to a hardware platform hence making solving the problem of Python 

As there are different implementations of python we will talk about them one by one.
1) CPython)
 
 It follows the same procedure as JAVA you can still refer to the diagram given below.


STEPS) (Same as Java)

1> The code goes to the compiler for compilation purposes.

2> The compiler converts the code to Python Bytecode which is generic for all the systems/processors.

NOTE: There are different JVM for different Platforms like mac, windows, Linux, etc. 

3> Then the PVM(Python Virtual Machine) comes into action and takes the Java Bytecode for further conversion.
    The PVM has access to all the libraries of the particular language and uses them to convert it into the machine code

4> After conversion the processor does the action and our work is completed.

1) Jython) (The most important Part)
 
The most important feature in using Jython is that we can reuse the Java code in a  Python program which helps us use Java Libraries in our Python Code.
 Refer to the chart for further understanding.


STEPS

1> The code goes to the compiler for compilation purposes

2> The compiler converts the code to Java Bytecode rather than Python Bytecode which is generic for all the systems/processors.

3> Then the JVM comes into action rather than PVM and takes the Java Bytecode for further conversion.
    The JVM has access to all the libraries of the particular language and uses them to convert it into the machine code

4> After conversion the processor does the action and our work is completed.

HOW DOES THE MAGIC HAPPEN?

The Trick behind all this is that in Jython implementation of Python one can convert Python code to Java Bytecode rather than Python Bytecode.

due to this one can use Java Code (code that has to be merged/reused) and Java Libraries in the Python Code adding another Plus point in Python and its applications.

  💀    💀   ðŸ’€  💀 💀 💀  💀   ðŸ’€    💀
 ðŸ’€    #CODE_HARD       ðŸ’€
💀    💀   ðŸ’€  💀 💀 💀  💀   ðŸ’€    💀

Comments

Popular posts from this blog

How to NOT write UGLY CODE ? | PEP-8 | Python Enhancement Proposals | VS-Code Plugins | autopep8 | Prettier | Preffered Settings

DC's DSA-CRACKER #3 | Array | Kth Maxima and Minima in an Array

DC's DSA-CRACKER #1 | Array | REVERSE THE ARRAY