C # is the weapon that Microsoft uses to compete with Java, because the two are surprisingly similar to a large extent, but there are also many different places, the so-called "see the difference in nuances". So where are the similarities and differences between the two? From today onwards, we will compare the features of C # and Java from various angles, hoping to help friends who are learning and using C #.
1. Overview of C # and. NET Platforms
June 2000, Microsoft releases the C # language and. NET platform. C # language is a strong type, object-oriented language, it has a simple syntax, strong expression of the characteristics, and the. NET platform is composed of Microsoft. NET Plan "is the cornerstone.
. NET platform's core includes two aspects, on the one hand is the famous common language running machine (Common Language Runtime), although this noun has been obscure, but you can compare it with the Java Virtual machine, both accomplish the task is roughly the same On the other hand is a bunch of general-purpose library functions that can be invoked in multiple languages, and compile all produce a common intermediate language (intermediate Language), which can also be likened to Java bytecode, although in some different ways.
2, C # and Java
The following is a simple list of C # and Java similarities, although here we focus on the differences between C # and Java, but it is also necessary to understand the similarities.
Both are compiled into Cross-platform, Cross-language code, and the code can only run in a controlled environment
Automatically reclaims garbage memory and eliminates pointers (pointers can be used in C #, but must be marked with unsafe keywords)
Do not require a header file, all code is limited to a scope by "package (Package)", and because there is no header file, it eliminates the cyclic dependency of the class definition
All classes are derived from objects, and memory must be allocated using the New keyword
Use object locking to support multithreading
Has the concept of an Interface (interface)
Inner class
Inheriting a class is not inherited with a specific access right;
No global function or constant, all must belong to class;
The array or string has its own length calculation and boundary checking;
Use only "." operator, no "-$#@62;" and "::";
"Null", "Boolean" and "bool" became keywords;
Any variables are initialized before use;
You cannot use integers to return to an if conditional statement, you must use a Boolean value;
"Try" module can have "finally";