Why Java Sucks and C # Rocks (2): underlying type and object-oriented

Source: Internet
Author: User
Tags arrays compact inheritance multiple inheritance in c

Now that we have talked about the meaning and purpose of this language comparison, and the complete slides and recordings have been released, then it is natural to discuss them in detail. In this article, I will briefly describe the basic features of the two languages and mainly discuss how they are treated for the underlying type. In my opinion, the Java language is not as appropriate for the underlying type as the value type in C #. If you have any comments that you feel are inappropriate or want to add, please do not hesitate to reply. Since C # 1.0 was published in 2002, this article will be based on Java 1.4 and C # 1.0.

Java language Simple description

Java is both a complete platform and a language. The Java language is a language that was designed by James Gosling in the Sun Microsystems Company in 1995 as part of the Java platform. The Java platform has two components, the virtual machine (JVM) and the class library, in addition to the language. In this series of articles, however, I will focus on the individual aspects of the Java language, occasionally talking to a little JVM, and hardly involving the class library.

The Java language refers to the design of C and C + +, so it is similar to them in the overall code style. However, compared to C + +, the Java language design is more compact, simple and reliable. There are two types of Java: Classes (Class) and basic types (primitive type), and no struct and union types in C + +. At the same time, Java also provides a Boolean type and limits the definition and use of Boolean types. In addition, developers are not allowed to perform operator overloading in Java, but provide language features such as synchronize for concurrency control.

One of the main goals of the Java language design is reliability, so in Java, the abstraction level of some elements is raised, for example, arrays are instances of predefined classes in Java, not in C + +. In addition, for example, the subscript range is detected in array access, and also the unsafe language features such as pointers are removed. Although "References" in Java are also meant to be "pointers", it is more secure, for example, that programmers cannot perform arithmetic operations on pointers, thus avoiding some error-prone practices.

In the design of object-oriented type systems, Java does not allow multiple inheritance in C + +, because many people think that multiple inheritance brings many complexities and confusions, which can do more harm than good. However, Java allows developers to define "interfaces", a "contract" that does not include implementations, and, to some extent, the benefits of some multiple inheritance.

In general, the Java language eliminates a large number of complex or insecure features in C + +, which makes Java a flexible, powerful, yet more compact, simple, and reliable language. From the present point of view, the Java language has greatly reduced the complexity of C + + itself, making programming work more simple, with high historical significance.

C # language Simple description

The C # language is a language designed by Anders Hejlsberg for Microsoft. NET Platform. Unlike the Java language, C # 's positioning is just. NET platform--still, from now on, it's one of many languages. NET platform and Java platform, although the start is different, but it is the same. Similar to the Java platform. NET platform has a corresponding virtual machine (CLR) and Basic Class library (BCL), in addition to multiple languages.

C # language design is also based on C and C + +, but also includes a number of Delphi and VB ideas. Many people find the Java language superior to C + + as "simple," but it seems that C # designers think that the Java language is a bit too simplistic, so C # includes pointers (restricted), struct, enum, operator overloading, and Goto language features in the C # language. However, C # designers have also improved these features, such as the type of enum in C # that cannot be implicitly converted to an integer type. Also, in the struct of C #, we can define constructors and members for it, and we can implement interfaces.

C # also provides a data type "delegate (Delegate)", which can be considered a type-safe function pointer. A delegate is also an object that explicitly defines the signature of a function and can be used to hold a function that contains the context required by the call. In a. NET program, a callback function is often represented by a delegate, whereas in Java, an interface is generally used.

C # also provides some features that are easy to develop, such as foreach,using, and the use of params to define variable-length arrays, and so on. In addition, C # provides member types for both the event and Property objects. Properties can be simply understood as fields with a read-write (or read-only or write-only). Although the Java language does not contain attributes, a convention is established early that will treat the GETXYZ/SETXYZ method as a property, and many development tools and class libraries are processed in this way.

The purpose of the C # language is to become a general-purpose programming language superior to C + + and Java. After years of development, C # is indeed far ahead of the Java language design, which is the fact that I write this series of articles.

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.