Some of the differences between Java and C # are sorted.

Source: Internet
Author: User

C # has a unified type system, and all types including primitive types (Int,bool,short,long, etc.) inherit from the object class.

Java is slightly different, its original type is not inherited from object, each primitive type has corresponding package class (inherit from object), such as int's wrapping class integer

C # has unsigned integers, uint, ulong, ushort

Java does not have

C # does not have a high precision decimal.

There are bigdecimal in Java

C # supports complex numbers. Complex structure

Not in Java

There are value types in C #. By using the STRUTCT keyword, you can define a struct, which is passed by value when it is passed, rather than by reference.

Only the original type is in Java.

There are nullable types in C #, Nullable.

There is only a parcel class in Java.

Pointers are allowed in C #.

There are no pointers in Java.

In C #, an enumeration type inherits from an enum type and is a derivative of a value type.

In Java, an enumeration type is a class that is an instance of its value class.

There are delegates in C #

Not in Java

There are types of delay bindings in C #, dynamic

Not in Java

Both C # and Java have strong and weak references.

But there is also a soft reference and a virtual reference Phantom reference in Java.

Soft references are similar to weak references, and objects are accessible, but are still recycled by GC. The difference is that weak references are recycled as long as the GC starts, and soft references are recycled only when the JVM is running out of memory space.

The Get method of a virtual reference always returns NULL, and a virtual reference can be used to refer to the object we are interested in, and the object is added to the referencequeue when the GC is recycled. By observing Referencequeue, you can tell if an object has been recycled. (At this point we can do something else before the GC recycles, such as logging some logs or something)

C # supports two-dimensional rectangular array, singular group int[,] a = new int[5, 2] {{0,0}, {3,6}, {4,8}}, or int[,] a = {{0, 0}, {1, 2}, {2, 4} , {3, 6}, {4, 8}};

Not supported in Java, only arrays of arrays are supported.

In C #, the boxing operation is implicit when the unboxing operation is explicit.

Boxed unpacking is implicit in Java.

C # member variable modifier public, internal, protected, private, protected internal

Public in Java, package, protected, private

In C # classes, inherited methods, default to new, must show override to represent overrides.

Overrides are indicated by default in Java.

Inner classes in C # are class-level and can be instantiated externally at any time.

In Java, the inner class must be static to be class-level in order to be instantiated externally.

C # supports partial classes

Java does not support

In C #, an enumeration type cannot implement an interface.

Java supports enumeration types to implement interfaces.

C # supports operator overloading

Java is not supported.

C # methods support Out,ref Reference parameters

Java is not supported.

C # does not support constant parameters

Java support, Final. The final parameter is marked, and cannot be modified in the method.

Public short GetValue (final short index) {

if (Index < values.length) {

index++; Error, the value of index cannot be modified.

return Values[index];

}

else return-1;

}

C # supports named parameters, optional parameters, partial methods, conditional methods

Java is not supported.

The generics of C # are a new type at run-time.

Java generics are pseudo-generics and are erased at run time.

Some of the differences between Java and C # are sorted.

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.