. NET code agronomy Java-1. Start

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.