Sunday, February 12, 2012

Compilation in Java & .NET

The translation of source code written in a programming language to an other machine readable language by a Compiler is known as Compilation.

I will discuss the compilation processes in both Java and .NET (supported languages say C#, VB etc). .NET supportive development is mainly focused for Windows operating system (but the languages supported by .NET are inter-operable) whereas Java development is supported by multiple platforms which means java code written once on any platform can be run on any other platform. This is ONLY possible because of the compilation process both implements underneath.

.NET implements a two-step compilation process. In the first step the respective compilers compile the source code to an intermediate language called MSIL/ CIL. In the second step the Just-In-Time compiler of CLR (common language run-time) converts the CIL to native code for the operating system. So code written in any .NET supportive language is compiled to CIL in the first step which gives the possibility of language inter-interoperability, that means classes written in C# can talk to classes written in VB or vice versa.     

Java also implements a two-step compilation process. In the first step the java compiler compiles the java source code (*.java) into java byte code (*.class). This byte code can be run on any platform using their respective JVM (java virtual machine). Thus by using platform specific JVM java achieves its platform in-dependency. Furthermore there are more languages that run on JVM like Scala, Groovy, JRuby, Jython etc making Java language inter-operable in a way.

Images source: Google Images.

No comments:

Post a Comment

Fork me on GitHub