A detailed introduction to syntax differences between Java and C # _java

Source: Internet
Author: User
Tags control characters
From C # to Java for some time, summed up the personal view of the Java and C # Grammar differences between, there are different points of view also hope that you Haihan
When I first learned Java, I think the syntax is roughly the same as C # (it should be said that C # is roughly the same as Java, after all, Microsoft's C # is intended to imitate the syntax of Java)
Bill Gates once said: "Java is the most outstanding programming language."
Anyway, here's a discussion of the difference between Java and C # syntax ...
1. Namespaces and Packages
C # introduces the concept of namespaces in order to organize classes that implement similar functions (namespace)
In Java, this corresponds to something called a package (package)
2, the different access control aspects of the class
C # has only two types: public and default (same internal)
Public can be accessed by all classes (in the same project and in different projects)
Internal (no control in front of the class keyword Fushime think internal), indicating that the class can only be accessed in the same project
There are only two kinds of Java: public and default
Public can be accessed by all classes
Default (no control characters before class keyword) can only be accessed by all classes in the same package
3, access control for class members
There are four kinds of C #: Public,protected,private (default), internal (note here internal and default are different)
Public can be accessed by all classes
Protected can only be accessed by the quilt class
Private (also the default when no control is written) can only be accessed within classes
Internal can be accessed by classes in the same project
Java also has four kinds: public,protected,private and default
Public can be accessed by all classes
Protected can be accessed either by other classes in the same one or by subclasses in different packages
Private can only be used inside a class
The default can be accessed by other classes in this package, and if a subclass is in a different package from the parent class, the subclass also cannot access the default Access control member in the parent class
inheritance of classes in 4,c# by Colon: Implemented in Java with extends
implementing interfaces in C # via colon: implementation, using Implements in Java
The sealed class in C # is implemented with sealed, in Java with final
Constants in C # are implemented in const, in Java with final
In C #, attributes are implemented in Set,get code blocks, typically in Java, similar to fields in C # representing properties, or using the Setter,getter constructor to implement
C # has some of the concepts of classes (partial) that are not in Java
C # has the ReadOnly modifier property read-only, not in Java
There are virtual and override cosmetic virtual methods and overriding methods in C # that are not in Java, and methods in the default parent class in Java are virtual
Java has the concept of static{},synchroized{} code block, C # does not
Java has the concept of tags (such as Labela:), C # does not
C # Neutron classes invoke the parent class in Base.method (), in Java with Super.method ()
In C # use is to determine whether an instance is a class, in Java with instanceof
In C #, a foreach (int i in array) is used to traverse each element of the array in Java, with for (int i:array)

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.