< > <= >= instanceof (Java-specific)
Explain that when you get a reference to an object (such as a parameter), you may need to judge the class that the reference really points to. So you need to start at the bottom of the tree and use the instanceof operator to judge that the first class that evaluates to TRUE is the one that the reference really points to.
In Java, a package is a collection of classes, interfaces, or other packages that are primarily used to organize classes into groups to
Class for management.
Not like the #region in VS, #endregion一样的代码段区域
In Java, declare "properties":
Declaring two private fields
private String name;
private int age;
Implement set and Get methods separately
public void SetName (String name)
{
This.name= name;
}
Public String GetName ()
{
return this.name;
}
public void Setage (int.)
{
This.age= age;
}
C#
private string name;
private int age;
Method One: Declaring accessors
public string Name
{
set {this.name = value;}
get {return this.name;}
}
public int Age
{
set {this.age = value;}
get {return this.age;}
}
In Java, both the definition and access are used by the get and set methods, and can be paired up.
C # is a real property, when you define the get and set must appear at the same time, the room when asked. No get,set.
In C #, when no scope modifier is used, the default is protect, and therefore cannot be accessed outside the class.
Because Java stipulates that there can be only one public class in a file, and the name of the class must be exactly the same as the file name, this is a difference
For a For loop, Java and C # are used the same way, but the foreach statement is different in Java,
public static void Main (string[] args) {
Int[] array1={1,2,3,4,5};
for (int item:array1) {
SYSTEM.OUT.PRINTLN (item)
}
}
public void Main (string[] args)
{
foreach (int item in array1) {
Cosole.writeline (item);
}
}
= = In C # is not the same as Java = = =, Java = = can only compare references to objects
For example: "1" ==1.tostring (), which results in C # and Java are different.
C # also adds four new integers, namely Sbyte,ushort,uint,ulong
Java, like C #, is a strongly typed (or explicitly typed) language, so data type conversions are required when different data types are being manipulated simultaneously.
In C #, the method names are generally named by Pascal Pascal, i.e. each word is capitalized, whereas in Java, the method name is generally named Camel Camel, that is, the first letter is lowercase and the first letter of the following words is capitalized.
As you can see, the concept of access modifiers Java and C # are similar, except that C # includes not only the following three modifiers, but also more modifiers such as internal. In addition, there is a conceptual difference that requires us to note that the package in Java (that is, the jar package), in C # is generally called an assembly (that is, a DLL).
The class implementation interface in Java uses the Implements keyword to implement inheritance using extends, which is implemented in. NET with the symbol ":"
The package is unique to Java, and import is somewhat similar to the using in. Net.
Unlike. NET, Java references a parent class with super, whereas in C # it uses base.
The access modifier in C # corresponds to the basic in Java, but there is an extra internal. Internal: Members can only be accessed from within the same assembly.
Because there is no final keyword in C #, if you want a class that is no longer derived, you can use the SEALED keyword
Java interfaces can define variables
Interface ABC
{
int num=1;
}
Java has more than one >>> operator (the shifted binary highest bit either 0 or 1, the vacant bit is 0 complement)
The inheritance is different. Java inherits the class through the extends, implements the interface through the implements, the interface inherits the interface through extends C # all through ":"
The different interfaces
Interfaces in Java can define variables, C # can not, C # can only be properties, methods, indexers.
Differences in array definitions
int myint[][]=new int[5][10]; Java
int[,] myint=new int[5,10]; C#
Three main Features-package
Encapsulation: In order to hide the internal implementation details, to achieve the protection of data security and the effect of code reuse a means.
Encapsulation is ubiquitous, seemingly simple but infinitely extensible. There is no explicit keyword to represent the encapsulation. Since it is thought and means, there is no grammatical difference between Java and C #. The access modifiers are not the same in both languages when they use the access modifier to achieve the encapsulated effect.
In Java:
Private: Only the internal can be accessed
Dufault: Default, the internal of the same package can be accessed.
Protected: Protected, accessible in the same package or in a subclass of a different package.
Public: accessible from anywhere.
Features: Clear size subordinate relationship: Private < Default < protected < public
In C # (introduces the concept of an assembly.) A namespace is similar to a package in Java, but it is a logical grouping unlike a package in Java that is a physical grouping, an assembly that resembles a project):
Private: Only the internal can be accessed.
Intenal: Internally, the same assembly can be accessed internally, with default.
Protected: Protected, sub-class accessible, and Java in protected is different, where the scope is smaller, the same assembly is not a subclass of access.
Proteted intenal: Is the set of intenal and protected access scopes.
Public: accessible from anywhere.
Features: No definite size subordinate relationship, intenal and protected Access range size is not clear.
In Java: Using extends to represent the use of inheritance
Overriding requirements: A, method name, return value type, parameter is the same, B, access modifier access scope is greater than or equal to the parent class method access modifier;
Access to the parent class member: Use Super keyword, which can be used to specify a constructor method for calling the parent class in the constructor method.
Three major features-inheritance
In C #: using: Representing the use of inheritance
Overriding requirements: A, method name, return value type, parameter, access modifier is the same; B, parent method is modified by virtual, subclass method is overridden by override
Access to the parent class succeeds: Use the base keyword after the method is constructed: base (parameter), specify to call the parent class construction method, base cannot be used in a static environment, the parent class static member cannot be called.
Overwrite: Use the new keyword. The overridden content is introduced in C #, and the non-virtual method of the parent class, which is a method that cannot be overridden, overrides the parent class's method. To cover my view is to make up for the need to be modified by the virtual method to rewrite the limitations may bring problems, but can not use it, coverage is not significant, or I have not really realized the actual role of coverage and use of occasions, there is a man can comment on the doubts.
Determines whether the rewrite succeeds by using a reference to the parent class to point to the object of the subclass, if the method calls the parent class method that the override is unsuccessful, and if the call to the subclass method, the rewrite succeeds.
The differences between Java C #. NET and C C + + cross-platform
1, Windows system WP8 on the main support VB, C #, C + +,
2, Apple system iOS support OBJECT-C, C + +
3, Android system support Java, C + +
2.
The cross-platform of C #. NET Java means that the bytecode (byte code) files of the intermediate files that they generate in the "compiling system" do not need to be recompiled and can be used directly by the "running system";
The cross-platform of C + + is not to be re-written code, need to recompile the "running system" corresponding to the machine code (binary code), can be used by "operating system";
3.
Ava, C # 's cross-platform is limited by "virtual machines", such as:
1.. NET environment is only available on Windows, Linux (Android) and Unix (iOS) are not supported;
2, Java mobile phone platform is mainly Android support, Windows (WP8) and Mac (iOS system) are not supported;
3,. NET, and Java virtual machines are not installed by default on XP systems;
4. The XP system does not support high versions of. NET, such as. NET 4.5
C + + is not limited by the virtual machine, as long as it can be compiled into a "running system" of "Machine Code", which is why a large number of cross-platform applications to develop the use of C + + reasons;
C # and Java syntax differences