C # comparison and learning with Java: Type judgment, class and interface inheritance, code specifications and coding habits, constant definition

Source: Internet
Author: User
Tags constant definition

Type judgment symbol:

C #: object a; if (a is int) {} is judged by the is symbol

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


Class and interface inheritance:

C #: public class MDataRow: List <MDataCell>, IDataRecord, ICustomTypeDescriptor

Java: public class MDataRow extends ArrayList <MDataCell> implements Set


The similarities are in order, first base class, and then interface.

The Inheritance and Implementation of C # are separated by ":", and ",". Interfaces must start with I.

Java class inheritance uses extends, and the interface implementation uses implements. The interface does not have a specification starting with "I", so it is easy to tell whether it is a class or an interface.


Code specifications and coding habits:

Take a look at the small Java code:

Package Test;
Import java. lang .*;

Publicclass Demo {
Int id;
Publicint getId (){
Return id;
}
Publicvoid setId (int id ){
This. id = id;
}

Public Demo (int id ){
Super ();
This. id = id;
}

Void write (){
System. out. print (id );
}
}

The basic comparison is as follows:

C #: namespace; using; uppercase method letters; base call base class members; Wrap Java: package; import; lowercase method letters; super call base class members; no line breaks in the brackets by default.


C # some additional attributes and Syntax:

Since C # is a language generated after learning Java, C # will have more things than Java. These are irrelevant to each other. It is only mentioned below:

Attribute, enumeration, Delegate, event, unsafe code pointer), override, virtual, new) Operators related to the overload override method, reference passing parameter ref, out), character escape @), etc.


Constant definition:


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

Java: final string name;


Today, we have a lot of things.

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.