If you take Java's primitive numeric types, plus boolean, and compare it to C++ equivalent types, is there any difference what concerns the operators, like precedence rules or what the bit-manipulation operators do? Or the effect of parenthesis?
Asked another way, if I took a Java expression and tried to compile and run it in C++, would it always compile and always give the same result?
C is a procedural, low level, and compiled language. Java is an object-oriented, high level, and interpreted language. Java uses objects, while C uses functions. Java is easier to learn and use because it's high level, while C can do more and perform faster because it's closer to machine code.
Java is a statically typed object-oriented language that uses a syntax similar to (but incompatible with) C++. It includes a documentation system called Javadoc. Extends C with object-oriented programming and generic programming. C code can most properly be used.
For an expression like:
a = foo() + bar();
In Java, the evaluation order is well-defined (left to right). C++ does not specify whether foo()
or bar()
is evaluated first.
Stuff like:
i = i++;
is undefined in C++, but again well-defined in Java.
In C++, performing right-shifts on negative numbers is implementation-defined/undefined; whereas in Java it is well-defined.
Also, in C++, the operators &
, |
and ^
are purely bitwise operators. In Java, they can be bitwise or logical operators, depending on the context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With