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)