Sorted parts of Java and C # different points

Source: Internet
Author: User
Tags arrays

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

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

C # has unsigned integers, uint, ulong, ushort

Java does not

C # does not have a high precision of 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 body that, when passed, is passed by value instead of by reference.

Only the original type is in Java.

There are nullable types in C #, Nullable.

In Java, only parcel classes.

Pointers are allowed in C #.

No pointers in Java.

In C #, an enumeration type inherits from the 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 deferred bindings in C #, dynamic

Not in Java

Both C # and Java have strong references and weak references.

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

Soft references and weak references are similar, objects are accessible, but are still collected by GC. The difference is that weak references are reclaimed as soon as the GC begins, and soft references are recycled only when the JVM has insufficient memory space.

A virtual reference's Get method returns null forever, and a virtual reference can be used to reference the object we are interested in, and the object is added to the referencequeue when the GC is recycled. By observing the referencequeue, you can tell if the object is recycled. (At this point we can do other things before GC recycle, such as log some logs or something)

Two-dimensional rectangular arrays are supported in C #. Singular group int[,] a = new int[5, 2] {{0,0}, {1,2}, {2,4}, {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 #, when boxing operations are implicit, the unpacking operation is explicit.

Box unboxing in Java are implicit.

Member variable modifiers public, internal, protected, private, protected internal in C #

Public in Java, package, protected, private

In the C # class, the inherited method, which defaults to new, must display override to represent the overlay.

The default representation of overrides in Java.

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

The internal classes in Java 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 type implementation interfaces.

C # support 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;

}

Note : For more wonderful tutorials, please pay attention to the Triple Web Design Tutorial section,

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.