JAVA VS PYTHON : COMPILED OR INTERPRETED

  1. Next step is to compile this above program. To compile, run below command:
  • This command would invoke the java compiler and would result in the creation of a file HelloWorld.class. This is nothing but the bytecode of your source code. Now if your program has more than one class defined, then for each class there will be a bytecode file. Note that this bytecode is platform independent since it does not have machine level details specific to platform. Hence this bytecode can be sent to any other machine/Operating System and can be used there.
  • Bytecode Verifier: This component checks the bytecode to avoid any run time errors.
  • JIT: Once the bytecode is verified, JIT (Just In Time) compiler comes into picture. This compiler again transforms the bytecode into machine language
  • Then the machine code is executed and output is displayed. Execution of compiled machine language code is very fast.
  • Note that this JVM is platform specific(for Windows, Mac etc)
  1. Now execution needs JVM to convert bytecode into machine language which is platform dependent.
  2. When you install JDK (any version), it already have compiler and JVM hence no need to worry about execution.
  1. PVM: Execute the source code which will invoke PVM into action. PVM performs below actions:
  • If there are no code errors, then the code is compiled into bytecode which is nothing but HelloWorld.pyc file.
  • In python, this compilation happens line by line as against full code at once in Java. Hence in Python, as soon as compilation step encounters first error, it will be reported and compilation will fail.
  • Once the code is compiled, PVM executes the bytecode, i.e., HelloWorld.pyc file and output is displayed. Since bytecode is directly executed, it is comparatively slow than Java.
  1. This bytecode is executed and output is printed. Bytecode is not converted into machine language.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store