Comparison Learning Record of Java and C # (1)

Source: Internet
Author: User

I have studied C language in college, and I have learned C ++ by myself and selected C ++. I have just graduated from college and worked on Jsp for a few days and wrote a few applets. later I switched to delphi for desktop development, and then to C # For Web development. recently, I was relatively idle. I decided to learn about Java to learn from each other. After half a day of busy work, I finally set up a development environment and found an introductory tutorial on the Internet, after several hours of practice (strictly called Review), I am familiar with Java syntax and basic structure. here is a simple comparison between Java and C:
1) History
Java is certainly longer than C #, and Java is born out of C and C ++. It is a typical C style, and C # is also born out of C and C ++, however, since C # is later than Java, it also draws on many Java things. In addition, because C # is also the father of Delphi, the C # architecture is inevitably shadow with Delphi VCL. in terms of language alone, C # Is the integrator of the C series and also of advanced languages.
2) syntax and Style
They are all C-style and almost all are written. As for the placement of curly braces, it is just a habit. Except for some minor differences, the two are basically the same. Below are some differences and comparisons:
A) Inheritance and implementation of classes and interfaces: C # uses the symbol ":" To represent, Java uses the keyword "extends" and "implements"
B) access restriction. Java's default value is equal to the internal of C #, and others are the same.
C) constants: Java does not have the const keyword. Generally, final is used to achieve similar results. In this respect, C # has keywords such as readonly and const, which makes control more flexible.
D) In terms of class polymorphism: Because Java does not have the virtual and override Keywords of C #, the expressions of C # are not detailed and clear. Java's public, protection, and default methods are all virtual methods by default. Therefore, Java is easier to implement dynamic injection (Spring technology). The access security control of C # is much more flexible, but this is also a bad thing, that is, when you want dynamic injection, it may not be possible because it is not a virtual method.
E) static method: the static method of C # cannot be inherited, while the static method of Java can be inherited (but cannot be rewritten and can only be overwritten ). because static methods and attributes belong to the class itself, I think the inheritance of static methods is not necessary, and it is not conducive to the management of program logic.
F) Basic data type: some of the basic keywords are the same, but there are more C # keywords. Here we will not talk about the specific correspondence. Here we will record the following: int and Integer in Java are different, involving the packing and unpacking of basic types. However, you must note that Integer is considered as the reference type, such as Integer i1 = 300, i2 = 300; i1 and i2 are not equal, but Integer i1 = 100, i2 = 100; in i1 and i2 are equal, the difference is that more than 255 of the comparison is not equal, in C #, int and Integer are no different (at least in behavior). in C #, packing and unpacking are related to objects. Although the performance is different, however, there is no difference in the behavior of basic data types.
In addition, an empty type is added for the basic type in C #, which is similar to the reference basic type in java.
G) object clearing: The mechanism is similar. The utility of finalize in Java is equivalent to that of dispose in C.
H) exception mechanism: the two are the same.
I) array: C # is divided into two types of arrays, one is a common array, the other is a sawtooth array, but is not distinguished in java.
J) generics: they all come from the template class and template method of C ++. The usage is almost the same, but the specific details are estimated to be different. I have not learned much about them yet, so I will not make any assertions;
K) Process Control: switch is the difference. Java follows the C ++ practice and the branches can overlap. However, C # requires that each branch must have a break. in terms of error prevention, C # is better, but it will inevitably lose many technical writing methods and flexibility.

 

PS: There are only Syntactic differences between languages, and there is no essential difference.

 

Author: hawksoft

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.