From CPP to Java
Some differences between c++ and java:
-
Java compiled code is platform independent whereas c++ compiled code is platform dependent
-
Java interpreter reports the run-time error that caused the execution to halt unlike in c/c++ programs which may simply crash
-
c/c++ do not have strict sizes for the fundamental datatypes(varies from machine to machine) whereas Java defines strict sizes for their datatypes
-
Java has additional positive and negative zeros, positive and neagtive infinites and “nan”(not a number values)
-
c/c++ has functions while Java has methods.In c/c++ functions can be defined outside a class Java doesnot allow methods to be defined outside a class.
-
Unlike c++ arrays, Java arrays are objects.
-
Unlike c++, strings are immutable in Java.
-
While in c++ classes “public”, “private” and “protected” are labels , in Java they are modifiers. Each member has its own access modifier. Java also has a no-modifier(a.k.a package-private) option which makes the member visible only within its own package.
-
Unlike c++, Java method definitions do not have semicolon at the end of their closing brackets.
-
Java uses the “extends” keyword while inherting features of a class to specify the superclass.
-
Java does not support multiple inheritance but supports multiple interfaces.
-
Unlike c++ Java has interfaces which is a bit different from abstract class.
-
In Java superclass constructors are callled using the keyword “super”.
-
Unlike c++ Java has class hierarchy. The “Object” class is the root of this hierarchy. All classes are subclasses of this root class.