boolean
: 1 bit, true or false
char
: 16 bits
byte
: 8 bit signed integer
short
: 16 bit signed
integer
int
: 32 bit signed integer
long
: 64 bit signed integer
float
: 32 bit floating
point
double
: 64 bit floating
point
C++ vs Java
Java uses packages
java.applet, java.io, java.net, java.util, java.awt
no unsigned integers
no operator overloading (can’t redefine +)
no all functions are virtual
no standalone functions (must be a method)
no explicit friend functions (everything in a package
is a friend)
no multiple inheritance
restricted casting
0 != false and 0 != null
args[0] is not the program name
methods are defined within a class#include "strings.h"
becomes
import java.lang.String
struct, union, enum,
typedef
, or bitfields
Java Objects & Classes
implements (has interface only)
No Pointers: can’t find the address of anything
Objects are always passed by reference
Be careful of aliasing and when trying to copy
Non initialized objects are set to null
=, ==, clone(), and equals()
constructors are the same as C++ (use new
)
no explicit destructors: Java uses garbage collection
instanceof
function checks
an object’s type
final
: class can never be subclassed
public, private, protected, package(default)