NOTE: Although goto and const are Java language keywords they are unused in the Java language.
NOTE: The
[NonSerialized] attribute in C# is equivalent to the transient keyword in Java.
3.
Of Virtual Machines and Language Runtimes
Just like Java is typically compiled to Java byte code which then runs in managed execution environment (the Java Virtual Machine or JVM) so
also is C# code compiled to an Intermediate Language (IL) which then runs in the Common Language Runtime (CLR). Both platforms support
native compilation via Just In Time compilers
.
NOTE: While the Java platform supports interpretation of byte code or byte code being JITed then run natively, the .NET platform only supports
native execution of C# code because the IL code is always natively compiled before running.
4.
Heap Based Classes and Garbage Collection
In Java objects are created on the heap using the new keyword. Most classes in C# are created on the heap by using the new keyword. Also just as
the JVM manages the destruction of objects so also does the CLR via a Mark and Compact garbage collection algorithm
NOTE: C# also supports stack-based classes, called value types, which are discussed further below.
5.
Arrays Can Be Jagged
In languages like C and C++, each subarray of a multidimensional array must have the same dimensions. In Java and C# arrays do not have to be
uniform because jagged arrays can be created as one-dimensional arrays of arrays. In a jagged array the contents of the array are arrays which may
hold instances of a type or references to other arrays. For this reason the rows and columns in a jagged array need not have uniform length as can
be seen from the following code snippet:
int [][]myArray = new int[2][];
myArray[0] = new int[3];
myArray[1] = new int[9];
The above code snippet is valid for both C# and Java.
6.
No Global Methods
Just like Java and unlike C++, methods in C# have to be part of a class either as member or static methods.
7.
Interfaces, Yes. Multiple Inheritance, No
C#, like Java, supports the concept of an interface which is akin to a pure abstract class. Similarly C# and Java both allow only single inheritance
of classes but multiple inheritance (or implementation) of interfaces.
8.
Strings Are Immutable
C# has a System.String class which is analogous to the java.lang.String class. Both classes are immutable meaning that the values of the strings
cannot be changed once the strings have been created. In both instances methods that appear to modify the actual content of a string actually create
a new string to return, leaving the original string unchanged. Thus the following C# and Java code does not modify the string in either case
C# Code
byte N/A for for private private ulong N/A
case case foreach for protected N/A unchecked N/A
catch catch get N/A public public unsafe N/A
char char goto
goto
1
readonly N/A ushort N/A
checked N/A if if ref N/A using import
class class implicit N/A return return value N/A
const
const
1
in N/A sbyte byte virtual N/A
continue continue int int sealed final void void
decimal N/A interface interface set N/A volatile volatile
default default internal protected short short where extends
delegate N/A is instanceof sizeof N/A while while
do do lock synchronized stackalloc N/A yield N/A
double double long long static static : extends
else else namespace package string N/A : implements
enum N/A new new struct N/A N/A strictfp
event N/A null null switch switch N/A throws
explicit N/A object N/A this this N/A
transient
2
评论9
最新资源