Sei sulla pagina 1di 3

Q#02:

Java versus C++: (a) General programming issues


Java C++
Method bodies must be defined inside the Method bodies must be defined inside the
class to class to
which they belong. which they belong.
No forward referencing required. Explicit forward referencing required.
No preprocessor. Heavy reliance on preprocessor.
No comma operator. Comma operator.
No variable-length parameter lists. Variable-length parameter lists.
No optional method parameters. Optional function parameters.
No const reference parameters. const reference parameters.
No goto goto
Labels on break and continue. No labels on break and continue.
Command-line arguments do not include the Command-line arguments do not include the
program name. program name.
Main method cannot return a value. Main function can return a value.
No global variables. Global variables.
Character escape sequences must appear in a
Character escape sequences can appear in a
string
program.
or character literal.
Cannot mask identifiers through scope. Can mask identifiers through scope.

Java versus C++: (b) Object-oriented programming


Java C++
Hybrid between procedural and object-
Pure object-oriented language.
oriented.
All functions (methods) are part of a class. Can have stand-along functions.
No multiple inheritance. Multiple inheritance.
Formal interface specifications. No formal interface specifications.
No parameterized type. Templates as parameterized type.
No operator overloading. Operator overloading.
All methods (except final methods) are
dynamically Virtual functions are dynamically bound.
bound.

Java versus C++: (c) Special characteristics


Java C++
Specifically attuned to network and Web
No relationship to networks or the Web.
processing.
Automatic garbage collection. No automatic garbage collection.
Combination of compiled and interpreted. Compiled.
Slower execution when interpreted. Fast execution.
Architecture neutral. Architecture specific.
Supports multithreading. No multithreading.
Automatic generation of documentation in HTML No automatic documentation
format. generation.

Java versus C++: (d) Primitive types


Java C++
Two type categories. Various type categories.
Separate types for structs, unions, enums, and
All nonprimitive types are objects.
arrays.
All numeric types are signed. Signed and unsigned numeric types.
All primitive types are a fixed size for all
Primitive type size varies by platform.
platforms.
16-bit Unicode characters. 8-bit ASCII characters.
Boolean data type primitive. No explicit boolean data type.
Integer results are interpreted as boolean
Conditions must be boolean expressions.
conditions.
Variables are automatically initialized. No automatic initialization of variables.

Java versus C++: (e) Pointers and data structures


Java C++
References, with no explicit pointer Pointers, with dereferencing (* or ->) and
manipulation address (&)
and no pointer arithmetic. operators.
Array references are not translated to pointer Array references translate to pointer
arithmetic. arithmetic.
Arrays automatically check index limits. No automatically array bounds checking.
Array lengths in multidimensional arrays can Array lengths in multidimensional arrays are
vary all the
from one element to the next within one same size in a give dimension, fixed by the
dimension. declaration.
Strings are objects. Strings are null-terminated character arrays.
String concatenation through a library
Built-in string concatenation operator(+).
function.
Use string concatenation operator for long Use line continuation (\) for long string
string literals. literals.
No typedef. typedef to define types.

----------------Best of Luck------------------------------

Potrebbero piacerti anche