We know that Java, like C #, is run on a virtual machine-based environment. Virtual machines in Java are called JVMs (Java Virtual machine), while C # is called the CLR (Common Language Runtime). With virtual machines, these two programming languages enable the so-called cross-platform functionality.
Let's do a simple experiment to review how Java and C # compile the source files.
One, the Java compilation source file
The premise of compiling is to install the JDK (Java development Kit), if the installation of the JRE (Java Runtime Environment) can not be compiled, only run.
After the installation, for ease of operation, we need to add the D:\Program files\java\jdk1.7.0_25\bin (see your install directory) directory to the environment variable, and then you can directly use the CMD command Window Javac, Java and other commands.
Take HelloWorld as an example:
Create a Java source file named Test.java on the D drive, and then edit the content as:
public class test{public static void Main (String [] args) {System.out.println ("Hello World");} }
As shown above, the Execute Javac command generates a Test.class file under the D disk, and the Java Test command runs the generated test.class file.
This completes the compilation of the Java source files.
Ii. C # compiling source files
Similar to Java, C # performs file compilation operations that require the CSC command, provided that the. NET Framework is installed.
Also, to facilitate the use of the CSC command directly in the CMD command window, we add the directory to the environment variable of the Windows system.
The directory where I have the. NET Framework for this machine is: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319, or you can select a different version of the. NET Framework.
Or take HelloWorld as an example:
We build a C # source file named TestCSharp.cs in D, and then edit the content as:
Using System;namespace test{public class testcsharp{public static void Main (string [] args) {Console.WriteLine ("Hello World. ");}}}
Executing the CSC TestCSharp.cs command generates a TestCSharp.exe executable file in the current directory and then directly enters the file name to run. As to why the CSC can be understood this way, CSC (C sharp compile,c# compiles).
For more options on the C # csc command, refer to: http://msdn.microsoft.com/zh-cn/library/78f4aasd.aspx
PostScript: Java, like C #, is an object-oriented, compiled programming language. They are all based on virtual machine programming languages and can theoretically be implemented across platforms. By compiling, Java generates a class bytecode file, and C # generates the corresponding IL intermediate language, which is the same design idea.
Java vs C # compiled source files