C # vs. Java learning: type judgment, class and interface inheritance, code specification and coding habits, constant definition (reprint)

Source: Internet
Author: User
Tags constant definition

C # vs. Java learning: type judgment, class and interface inheritance, code specification and coding habits, constant definitions
Type judgment symbol:

C#:object A; if (A is int) {} Judged by the IS symbol

Java:object A; if (a instanceof Integer) {} is judged by the instanceof symbol

Class-To-Interface inheritance:

C #: public class Mdatarow:list<mdatacell>, IDataRecord, ICustomTypeDescriptor

Java:Publicclass Mdatarow extends arraylist<mdatacell> implements Set


The common denominator is in the order, first base class, after interface.

C # Inheritance and implementation, first with ":" Start, and then "," separated, where interfaces are standardized with I start.

Java class inherits with extends, the interface implements with the implements, the interface does not have "I" the beginning specification, is easy to be silly to divide is the class or the interface.


Code specifications and Coding habits:

Look at a small piece of Java code:

PackageTest;
Importjava.lang.*;

PublicclassDemo {
intId
PublicintGetId () {
returnId
}
PublicvoidSetId (intID) {
This. id = ID;
}

PublicDemo (intID) {
Super();
This. id = ID;
}

voidWrite () {
System.out.print (ID);
}
}

The basic comparison is as follows:

C#:namespace;Using;Method capitalize the first letter;Base calls the associated members of the underlying class;The default parentheses are newline java:package;import;method first letter lowercase;Super calls the relevant members of the base class;Default bracket No Line break

C # Some of the more attributes and syntax:

Because C # is the language that is generated after learning Java, C # will be more than Java, which is the relationship between and without, only to mention:

attributes, enumerations, delegates, events,Unsafe (code pointers), overloaded overlay methods related operators (Override,virtual, new), Reference arguments (ref, out), Character escapes (@) and so on.

Constant definition:


C#:const string name; or static readonly string name;

Java:final string name;

It's more than that today.

Original link This article by Bean John Blog Backup expert remote One click release

C # vs. Java learning: type judgment, class and interface inheritance, code specification and coding habits, constant definition (reprint)

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.