This is the 1st HTML5 slant canvas

KIWY logo depicting a kiwi bird with a candle

k i w y

Need a light for your site?

This is the 2nd HTML5 slant canvas

Java and C++ Differences -- The Basics

Java vs. C++

C++ and Java have similar syntax, and they're both object oriented. So what's the difference?

Compiling and Running

Some benefits of Java (over C++) -- IMHO

Some benefits of C++ (over Java) -- IMHO

Item C++ Java
Basic Syntax Building Blocks
built-in types bool boolean
char for the usual single-byte type char - 2 bytes (unicode)
byte - 1 byte (numeric)
  no long double type
exact sizes of basic types are system-dependent sizes for each type are fixed
main function int main() public static void main(String[] args)
standalone function method (member function) of a class,
Any class can have a main method
methods functions can be stand-alone all methods (functions) are members of a class
identifiers consist of letters, digits, underscores same, but can also have (and start with) the dollar sign $
declaring constants uses keyword const,
const int SIZE = 10;
uses keyword final,
final int SIZE = 10;
explicit casting uses newer cast operators in C++ standard,
x = static_cast<int>(y);
uses older C-style cast operator,
x = (int)y;
Control Structures
test expressions if (expression)
expression can be anything non-void. 0 = false, anything else = true. Also applies to loop test expressions
if (boolean expression)
must be a boolean expression (true/false only) -- else compile error. Also applies to loop test expressions
Methods
Modifiers modifiers like public, private are labels function modifiers (including public, private, protected) go ON the functions, before the return type
Parameter passing Pass by Value
Pass by Reference
Pass by Address
In Java, there is only Pass By Value
Method calls Functions can be stand-alone (called by name)
Functions can be methods (member functions) -- called with dot-operator from outside a class
All functions are methods (member functions) of a class
If inside the class, can call directly by name
From outside a class, call with dot-operator
Default parameter values C++ can have default value on parameters
void Func(int x, int y = 4);
No default values on parameters