I actually think there is no comparability between the language grammar!
But because the amount has been learned in C + +, and now learn Java, there is Zhao Benshan said: "Knowledge is learned miscellaneous!" ", so I personally summarize, hope to remind myself!"
Java vs. C + +:
In Java:
double to use%f;
Boolean type: boolean;
The character type accounts for two bytes;
If, while,for can only use the logical expression when the true and false judgment, cannot use the number.
A longer integer to add l;
By default all real numbers are of type double;
High security: When an advanced type is converted to a low-level type, an error is added! For example, to convert a double to float, float a=2.0f (F);
When taking the remainder: the divisor and divisor can be real numbers, but the positive and negative of the remainder are the same as the divisor;
There are no pointers in Java:
A *a=new a ();//c++
A a=new a ();//java
When memory is allocated dynamically: C + + uses pointer A in the stack to point to the allocated heap space.
Java, in form, uses the class's object a (equivalent to static pointer variables) to point to memory in the heap, but can use a to represent memory in the heap;
constructor function:
In Java, if you define a constructor that has parameters, you must define the parameterless constructor yourself when you call the parameterless constructor, which is not the case in C + +;
When an object is created, the member variables of each of these types are initialized automatically, the numeric type is initialized, the Boolean is initialized to False, and the reference is initialized to null;
Arrays in C + + and C can be created in the stack, but the arrays in Java are reference types and can only be created in the heap.
Enum types in C and C + + can be used 0,1 ... To express, but not in Java;
Example:enum MyColor {red, green, blue};
MyColor m= red;//c or C + + define enum type new variable in
MyColor m= Mycolor.red;//java define enum type new variable in
There is no string reference type in C, it is represented by a character array and ends with the ' \ n ' table character, while C + + and Java have string reference types;
In addition, the string object in C + + can be manipulated with s[i], while Java does not, you need to convert to char[];
The difference between Java and C + + 's "syntax"!