Why C and Java have many language constructs in common
Java is
a "descendent language" of
C:
Language constructs that are identical in C and Java
Number data types
int
short
long
float
double
|
Language constructs that are identical in C and Java
Syntax to
define variables:
char a; // char data type is byte in Java
short b;
int c;
float x;
double y;
|
Language constructs that are identical in C and Java
The
arithmetic operators:
The
assignment operators:
The
pre/post increment/decrement operators:
Language constructs that are identical in C and Java
The
comparison operators:
The
logical operators:
Language constructs that are identical in C and Java
All the
statements:
Assignment statement:
x = (a + b) * (c + d % e);
Conditional statement:
if ( a > b )
max = a;
else
max = b;
Switch statement:
switch ( x )
{
case 1: y = 1; break;
case 2: y = 2; break;
default: y = 3; break;
}
|
Language constructs that are identical in C and Java
All the
statements:
(continued)
Loop statement:
while ( x < 10 )
x++;
for ( i = 0; i < 10; i++ )
sum += i;
do
{
x = x + 1;
} while (x < 10)
Loop control statements:
continue
break
|
What is
different in
C
Compiler support:
- C
run the
source file
through
a
pre-processor
before it compiles
the program
- The C compiler is
a
one-pass compiler
while the Java compiler is
a two-pass compiler
- A one-pass compiler can
not use
definitions that
occurs
later in the
source file
|
-
The C compiler
only
processes
one C program source file
Consequence:
- C programs must
use
variable and function
declarations
|
|
What is
different in
C
Language features:
- C has
unsigned integer types
(Java
only has
signed integer types)
- C
allows
all integer/float
type conversions
without
explicit casting
- C has
no function overloading
(because C is
not an
OOP language)
- C and
Java have
different
scoping rules
- C has
static (= not dynamic) arrays and
static (= not dynamic) objects
- C does
not have
array bound checks
- C has a
reference
data type with
supporting (reference and de-reference)
operations
|
❮
❯