Differences between Java and C #

Source: Internet
Author: User

Differences between Java and C #

C # has a unified type system. All types, including the original types (int, bool, short, long, and so on), are inherited from the Object class.

Java is slightly different. Its original type is not inherited from the Object, and each original type has a corresponding package class (inherited from the Object), such as the int package class Integer

C # With or without signed integers, uint, ulong, and ushort

Java does not

C # There is no high-precision decimal.

BigDecimal in Java

C # The plural value is supported. Complex Structure

Java does not

C # has a value type. You can use the strutct keyword to define the struct. This type is passed by value rather than by reference during transmission.

Java only has the original type.

C # has the optional null type, Nullable.

Java only contains the package class.

A pointer is allowed in C.

Java has no pointer.

In C #, the enumeration type inherits from the Enum type and is a family of value types.

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

C # has a delegate

Java does not

C # There are delayed binding types, dynamic

Java does not

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

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

Soft references are similar to weak references. objects are reachable, but are still recycled by GC. The difference is that weak references will be recycled as long as GC starts, and soft references will be recycled only when JVM memory space is insufficient.

The get method of Virtual Reference always returns null. It can be used to reference objects we are interested in. During GC collection, this object will be added to referenceQueue. By observing referenceQueue, you can know whether the object has been recycled. (At this time, we can do other things before gc collection, such as logging or something)

C # supports two-dimensional rectangular arrays, single array int [,] a = new int [5, 2] {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 are supported.

C # is implicitly used in The binning operation and explicitly used in the unpacking operation.

In Java, binning is implicit.

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

Public, package, protected, and private in Java

In C # class, the inherited method is new by default. override must be displayed to indicate overwriting.

By default, Java overwrites data.

The internal classes in C # Are class-level and can be instantiated externally at any time.

In Java, internal classes must be static and class-level before they can be instantiated externally.

C # support for branch classes

Not supported by Java

In C #, the enumeration type cannot implement interfaces.

Java supports Enumeration type implementation interfaces.

C # support for Operator Overloading

Not supported by Java.

C # The method supports out and ref reference parameters.

Not supported by Java.

C # constant parameters are not supported

Java support, final. The final parameter cannot be modified in the method.

Public short getValue (final short index ){

If (index <values. length ){

Index ++; // error. The index value cannot be modified.

Return values [index];

}

Else return-1;

}

Note: For more exciting tutorials, please follow the help houseWebpage Design tutorialTopic,

Related Article

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.