Plan to learn Java for a variety of reasons. Himself had done. NET development for almost 10 years, the language level of things to make it easy to estimate. Because. NET and Java similarities, ready to compare. net/c# to learn, one is easy to understand, but also to consolidate. NET of knowledge. The selected reference book is "Java Core technology".
First Program
The first program, Hello World, the code is very simple, more important is to see the principle of code execution.
Start with C #, create the file FirstSample.cs, write the following code and Save:
Using System;public class firstsample{public static void Main (string[] args) {Console.WriteLine ("Hello C # world!") ; }}
HelloWorld's code is always simple, and then it can be compiled. Open a Shell window, navigate to FirstSample.cs's sibling directory, and
CSC FirstSample.cs
A new file is generated under the sibling directory, FirstSample.exe, and can be seen in the shell window "Hello C # world!" The words.
Java's Hello world is very similar, first, create the file Firstsample.java, write the code:
public class firstsample{public static void Main (string[] args) { System.out.println ("Hello Java world!"); }}
The next is also the compilation. Open the Shell window and navigate to the Firstsample.java's sibling directory, typing
Javac Firstsample.java
A new file is also generated under the sibling directory, Firstsample.class. Unlike C #, this cannot be done directly, continue typing in the shell window
Java firstsample
After successful execution, see "Hello Java world!" in the shell window
What happened?
Both Java and. NET work by compiling the source code into intermediate languages (bytecode and IL) and then compiling the virtual machine (JVM and CLR) into native code. The cliché of the content, not much to say here. Here I want to talk about my understanding of how Java and. NET work.
To execute an intermediate language, first start JVM/CLR, the so-called boot, actually creates the process on the OS and then puts the JVM/CLR host on the process.
Recalling the two Hello world,c# compiled exe, the execution of the time actually did all these things: Create a new process, host a CLR instance on the process, load IL code into the CLR, and then start by executing IL code.
Java is actually similar, except that the host JVM's process is created with Java.exe (not firstsample.class).
By the end of the first day of the study, we are ready to look at the data type.
. NET code agronomy Java-1. Start