<s>
This	O
article	O
compares	O
two	O
programming	O
languages	O
:	O
C#	B-Application
with	O
Java	B-Language
.	O
</s>
<s>
While	O
the	O
focus	O
of	O
this	O
article	O
is	O
mainly	O
the	O
languages	O
and	O
their	O
features	O
,	O
such	O
a	O
comparison	O
will	O
necessarily	O
also	O
consider	O
some	O
features	O
of	O
platforms	B-Device
and	O
libraries	B-Library
.	O
</s>
<s>
For	O
a	O
more	O
detailed	O
comparison	O
of	O
the	O
platforms	B-Device
,	O
see	O
Comparison	O
of	O
the	O
Java	B-Language
and	O
.NET	O
platforms	B-Device
.	O
</s>
<s>
C#	B-Application
and	O
Java	B-Language
are	O
similar	O
languages	O
that	O
are	O
typed	O
statically	O
,	O
strongly	O
,	O
and	O
manifestly	B-Language
.	O
</s>
<s>
Both	O
are	O
object-oriented	B-Language
,	O
and	O
designed	O
with	O
semi-interpretation	O
or	O
runtime	O
just-in-time	O
compilation	B-Language
,	O
and	O
both	O
are	O
curly	O
brace	O
languages	O
,	O
like	O
C	B-Language
and	O
C++	B-Language
.	O
</s>
<s>
Data	O
typesJava	O
C#	B-Application
Arbitrary-size	O
decimals	O
Arbitrary-size	O
integers	O
Arrays	B-Data_Structure
Boolean	O
type	O
Character	O
Complex	O
numbers	O
Date/time	O
;	O
reference	B-Language
type	I-Language
;	O
value	O
type	O
Enumerated	B-Language
types	I-Language
;	O
reference	B-Language
type	I-Language
;	O
scalar	O
High-precision	O
decimal	O
number	O
;	O
but	O
see	O
'	O
Arbitrary-size	O
decimals	O
 '	O
above	O
IEEE	O
754	O
binary32	O
floating	O
point	O
number	O
IEEE	O
754	O
binary64	O
floating	O
point	O
number	O
Lifted	O
(	O
nullable	O
)	O
types	O
;	O
but	O
wrapper	O
types	O
Pointers	O
;	O
only	O
method	O
references	O
Only	O
available	O
in	O
unsafe	O
mode	O
or	O
through	O
IntPtr	O
managed	O
type	O
Reference	B-Language
types	I-Language
Signed	B-Algorithm
integers	I-Algorithm
;	O
8	O
,	O
16	O
,	O
32	O
,	O
64	O
bits	O
;	O
8	O
,	O
16	O
,	O
32	O
,	O
64	O
bits	O
Strings	O
Type	O
annotations	O
Single-root	O
(	O
unified	O
)	O
type	O
system	O
;	O
but	O
wrapper	O
types	O
The	O
type	O
system	O
is	O
unified	O
by	O
default	O
,	O
unless	O
the	O
compiler	B-Language
is	O
switched	O
into	O
unsafe	O
mode	O
where	O
raw	O
pointers	O
are	O
available	O
as	O
a	O
datatype	O
.	O
</s>
<s>
Pointers	O
are	O
not	O
derived	O
from	O
object	O
nor	O
does	O
it	O
have	O
implicit	O
conversions	O
to/from	O
the	O
object	O
data	O
type	O
Tuples	B-Application
;	O
limited	O
3rd	O
party	O
available	O
.	O
</s>
<s>
Unsigned	B-Algorithm
integers	I-Algorithm
;	O
but	O
some	O
method	O
support	O
.	O
</s>
<s>
In	O
Java	B-Language
the	O
primitive	O
types	O
are	O
special	O
in	O
that	O
they	O
are	O
not	O
object-oriented	B-Language
and	O
they	O
could	O
not	O
have	O
been	O
defined	O
using	O
the	O
language	O
itself	O
.	O
</s>
<s>
They	O
also	O
do	O
not	O
share	O
a	O
common	O
ancestor	O
with	O
reference	B-Language
types	I-Language
.	O
</s>
<s>
The	O
Java	B-Language
reference	B-Language
types	I-Language
all	O
derive	O
from	O
a	O
common	O
root	O
type	O
.	O
</s>
<s>
C#	B-Application
has	O
a	O
unified	O
type	O
system	O
in	O
which	O
all	O
types	O
(	O
besides	O
unsafe	O
pointers	O
)	O
ultimately	O
derive	O
from	O
a	O
common	O
root	O
type	O
.	O
</s>
<s>
Consequently	O
,	O
all	O
types	O
implement	O
the	O
methods	B-Language
of	O
this	O
root	O
type	O
,	O
and	O
extension	O
methods	B-Language
defined	O
for	O
the	O
object	O
type	O
apply	O
to	O
all	O
types	O
,	O
even	O
primitive	O
int	O
literals	O
and	O
delegates	O
.	O
</s>
<s>
This	O
allows	O
C#	B-Application
,	O
unlike	O
Java	B-Language
,	O
to	O
support	O
objects	O
with	O
encapsulation	O
that	O
are	O
not	O
reference	B-Language
types	I-Language
.	O
</s>
<s>
In	O
Java	B-Language
,	O
compound	O
types	O
are	O
synonymous	O
with	O
reference	B-Language
types	I-Language
;	O
methods	B-Language
cannot	O
be	O
defined	O
for	O
a	O
type	O
unless	O
it	O
is	O
also	O
a	O
class	O
reference	B-Language
type	I-Language
.	O
</s>
<s>
In	O
C#	B-Application
the	O
concepts	O
of	O
encapsulation	O
and	O
methods	B-Language
have	O
been	O
decoupled	O
from	O
the	O
reference	O
requirement	O
so	O
that	O
a	O
type	O
can	O
support	O
methods	B-Language
and	O
encapsulation	O
without	O
being	O
a	O
reference	B-Language
type	I-Language
.	O
</s>
<s>
Only	O
reference	B-Language
types	I-Language
support	O
virtual	B-Application
methods	I-Application
and	O
specialization	O
,	O
however	O
.	O
</s>
<s>
Java	B-Language
calls	O
these	O
types	O
primitive	O
types	O
,	O
while	O
they	O
are	O
called	O
simple	O
types	O
in	O
C#	B-Application
.	O
</s>
<s>
The	O
C#	B-Application
simple	O
types	O
implement	O
several	O
interfaces	B-Application
and	O
consequently	O
offer	O
many	O
methods	B-Language
directly	O
on	O
instances	O
of	O
the	O
types	O
,	O
even	O
on	O
the	O
literals	O
.	O
</s>
<s>
The	O
C#	B-Application
type	O
names	O
are	O
also	O
merely	O
aliases	O
for	O
Common	O
Language	O
Runtime	O
(	O
CLR	O
)	O
types	O
.	O
</s>
<s>
The	O
C#	B-Application
System.Int64	O
type	O
is	O
exactly	O
the	O
same	O
type	O
as	O
the	O
long	O
type	O
;	O
the	O
only	O
difference	O
is	O
that	O
the	O
former	O
is	O
the	O
canonical	O
.NET	O
name	O
,	O
while	O
the	O
latter	O
is	O
a	O
C#	B-Application
alias	O
for	O
it	O
.	O
</s>
<s>
Java	B-Language
does	O
not	O
offer	O
methods	B-Language
directly	O
on	O
primitive	O
types	O
.	O
</s>
<s>
Instead	O
,	O
methods	B-Language
that	O
operate	O
on	O
primitive	O
values	O
are	O
offered	O
through	O
companion	O
primitive	B-Language
wrapper	I-Language
classes	O
.	O
</s>
<s>
As	O
an	O
example	O
,	O
the	O
Java	B-Language
Long	O
type	O
is	O
a	O
reference	B-Language
type	I-Language
that	O
wraps	O
the	O
primitive	O
long	O
type	O
.	O
</s>
<s>
Both	O
Java	B-Language
and	O
C#	B-Application
support	O
signed	B-Algorithm
integers	I-Algorithm
with	O
bit	O
widths	O
of	O
8	O
,	O
16	O
,	O
32	O
and	O
64	O
bits	O
.	O
</s>
<s>
They	O
use	O
the	O
same	O
name/aliases	O
for	O
the	O
types	O
,	O
except	O
for	O
the	O
8-bit	O
integer	O
that	O
is	O
called	O
a	O
byte	B-Application
in	O
Java	B-Language
and	O
a	O
sbyte	O
(	O
signed	B-Algorithm
byte	B-Application
)	O
in	O
C#	B-Application
.	O
</s>
<s>
C#	B-Application
supports	O
unsigned	B-Algorithm
in	O
addition	O
to	O
the	O
signed	B-Algorithm
integer	O
types	O
.	O
</s>
<s>
The	O
unsigned	B-Algorithm
types	O
are	O
byte	B-Application
,	O
ushort	O
,	O
uint	O
and	O
ulong	O
for	O
8	O
,	O
16	O
,	O
32	O
and	O
64	O
bit	O
widths	O
,	O
respectively	O
.	O
</s>
<s>
Unsigned	B-Algorithm
arithmetic	O
operating	O
on	O
the	O
types	O
are	O
supported	O
as	O
well	O
.	O
</s>
<s>
For	O
example	O
,	O
adding	O
two	O
unsigned	B-Algorithm
integers	I-Algorithm
(	O
uints	O
)	O
still	O
yields	O
a	O
uint	O
as	O
a	O
result	O
;	O
not	O
a	O
long	O
or	O
signed	B-Algorithm
integer	O
.	O
</s>
<s>
Java	B-Language
does	O
not	O
feature	O
unsigned	B-Algorithm
integer	O
types	O
.	O
</s>
<s>
In	O
particular	O
,	O
Java	B-Language
lacks	O
a	O
primitive	O
type	O
for	O
an	O
unsigned	B-Algorithm
byte	B-Application
.	O
</s>
<s>
Instead	O
,	O
Java	B-Language
's	O
byte	B-Application
type	O
is	O
sign	O
extended	O
,	O
which	O
is	O
a	O
common	O
source	O
of	O
bugs	O
and	O
confusion	O
.	O
</s>
<s>
Unsigned	B-Algorithm
integers	I-Algorithm
were	O
left	O
out	O
of	O
Java	B-Language
deliberately	O
because	O
James	O
Gosling	O
believed	O
that	O
programmers	O
would	O
not	O
understand	O
how	O
unsigned	B-Algorithm
arithmetic	O
works.In	O
programming	O
language	O
design	O
,	O
one	O
of	O
the	O
standard	O
problems	O
is	O
that	O
the	O
language	O
grows	O
so	O
complex	O
that	O
nobody	O
can	O
understand	O
it	O
.	O
</s>
<s>
One	O
of	O
the	O
little	O
experiments	O
I	O
tried	O
was	O
asking	O
people	O
about	O
the	O
rules	O
for	O
unsigned	B-Algorithm
arithmetic	O
in	O
C	B-Language
.	O
It	O
turns	O
out	O
nobody	O
understands	O
how	O
unsigned	B-Algorithm
arithmetic	O
in	O
C	B-Language
works	O
.	O
</s>
<s>
Java	B-Language
versions	O
8	O
and	O
9	O
added	O
some	O
limited	O
built-in	O
unsigned	B-Algorithm
integer	O
operations	O
,	O
but	O
they	O
are	O
only	O
exposed	O
as	O
static	B-Language
methods	I-Language
on	O
the	O
primitive	B-Language
wrapper	I-Language
classes	O
;	O
they	O
operate	O
on	O
signed	B-Algorithm
primitive	O
integer	O
types	O
,	O
treating	O
them	O
as	O
if	O
they	O
were	O
unsigned	B-Algorithm
.	O
</s>
<s>
C#	B-Application
has	O
a	O
type	O
and	O
literal	O
notation	O
for	O
high-precision	O
(	O
28	O
decimal	O
digits	O
)	O
decimal	O
arithmetic	O
that	O
is	O
appropriate	O
for	O
financial	O
and	O
monetary	O
calculations	O
.	O
</s>
<s>
While	O
Java	B-Language
lacks	O
such	O
a	O
built-in	O
type	O
,	O
the	O
Java	B-Language
library	O
does	O
feature	O
an	O
arbitrary	B-Algorithm
precision	I-Algorithm
decimal	O
type	O
.	O
</s>
<s>
This	O
is	O
not	O
considered	O
a	O
language	O
type	O
and	O
it	O
does	O
not	O
support	O
the	O
usual	O
arithmetic	O
operators	O
;	O
rather	O
it	O
is	O
a	O
reference	B-Language
type	I-Language
that	O
must	O
be	O
manipulated	O
using	O
the	O
type	O
methods	B-Language
.	O
</s>
<s>
Both	O
languages	O
offer	O
library-defined	O
arbitrary-precision	B-Algorithm
arithmetic	I-Algorithm
types	O
for	O
arbitrary-size	O
integers	O
and	O
decimal	O
point	O
calculations	O
.	O
</s>
<s>
Only	O
Java	B-Language
has	O
a	O
data	O
type	O
for	O
arbitrary	B-Algorithm
precision	I-Algorithm
decimal	O
point	O
calculations	O
.	O
</s>
<s>
Only	O
C#	B-Application
has	O
a	O
type	O
for	O
working	O
with	O
complex	O
numbers	O
.	O
</s>
<s>
C#	B-Application
allows	O
library-defined	O
types	O
to	O
be	O
integrated	O
with	O
existing	O
types	O
and	O
operators	O
by	O
using	O
custom	O
implicit/explicit	O
conversions	O
and	O
operator	O
overloading	O
.	O
</s>
<s>
Both	O
languages	O
treat	O
strings	O
as	O
(	O
immutable	B-Application
)	O
objects	O
of	O
reference	B-Language
type	I-Language
.	O
</s>
<s>
In	O
both	O
languages	O
,	O
the	O
type	O
contains	O
several	O
methods	B-Language
to	O
manipulate	O
strings	O
,	O
parse	O
,	O
format	O
,	O
etc	O
.	O
</s>
<s>
In	O
both	O
languages	O
regular	B-Language
expressions	I-Language
are	O
considered	O
an	O
external	O
feature	O
and	O
are	O
implemented	O
in	O
separate	O
classes	O
.	O
</s>
<s>
Both	O
languages	O
 '	O
libraries	B-Library
define	O
classes	O
for	O
working	O
with	O
dates	O
,	O
times	O
,	O
time	B-Device
zones	I-Device
,	O
and	O
calendars	B-Application
in	O
different	O
cultures	O
.	O
</s>
<s>
Java	B-Language
provides	O
java.util.Date	O
,	O
a	O
mutable	B-Application
reference	B-Language
type	I-Language
with	O
millisecond	O
precision	O
,	O
and	O
(	O
since	O
Java	B-Language
8	O
)	O
the	O
java.time	O
package	B-Language
(	O
including	O
classes	O
such	O
as	O
LocalDate	O
,	O
LocalTime	O
,	O
and	O
LocalDateTime	O
for	O
date-only	O
,	O
time-only	O
,	O
and	O
date-and-time	O
values	O
)	O
,	O
a	O
set	O
of	O
immutable	B-Application
reference	B-Language
types	I-Language
with	O
nanosecond	O
precision	O
.	O
</s>
<s>
In	O
contrast	O
,	O
the	O
C#	B-Application
System.DateTime	O
is	O
an	O
immutable	B-Application
struct	B-Application
value	O
type	O
for	O
date-and-time	O
information	O
with	O
100-nanosecond	O
precision	O
;	O
the	O
.NET	O
6	O
API	O
also	O
added	O
System.DateOnly	O
and	O
System.TimeOnly	O
,	O
similar	O
structures	O
for	O
date-only	O
or	O
time-only	O
operations	O
.	O
</s>
<s>
C#	B-Application
additionally	O
defines	O
a	O
System.TimeSpan	O
type	O
for	O
working	O
with	O
time	O
periods	O
;	O
Java	B-Language
8	O
provides	O
the	O
java.time.Duration	O
class	O
for	O
the	O
same	O
purpose	O
.	O
</s>
<s>
Both	O
languages	O
support	O
date	O
and	O
time	O
arithmetic	O
according	O
to	O
different	O
cultures	O
and	O
time	B-Device
zones	I-Device
.	O
</s>
<s>
C#	B-Application
allows	O
the	O
programmer	O
to	O
create	O
user-defined	O
value	O
types	O
,	O
using	O
the	O
struct	B-Application
keyword	O
.	O
</s>
<s>
Because	O
value	O
types	O
have	O
no	O
notion	O
of	O
a	O
null	O
value	O
and	O
can	O
be	O
used	O
in	O
arrays	B-Data_Structure
without	O
initialization	O
,	O
they	O
always	O
come	O
with	O
an	O
implicit	O
default	O
constructor	O
that	O
essentially	O
fills	O
the	O
struct	B-Application
memory	O
space	O
with	O
zeroes	O
.	O
</s>
<s>
Value	O
types	O
do	O
not	O
have	O
virtual	B-Language
method	I-Language
tables	I-Language
,	O
and	O
because	O
of	O
that	O
(	O
and	O
the	O
fixed	O
memory	O
footprint	O
)	O
,	O
they	O
are	O
implicitly	O
sealed	O
.	O
</s>
<s>
However	O
,	O
value	O
types	O
can	O
(	O
and	O
frequently	O
do	O
)	O
implement	O
interfaces	B-Application
.	O
</s>
<s>
For	O
example	O
,	O
the	O
built-in	O
integer	O
types	O
implement	O
several	O
interfaces	B-Application
.	O
</s>
<s>
Apart	O
from	O
the	O
built-in	O
primitive	O
types	O
,	O
Java	B-Language
does	O
not	O
include	O
the	O
concept	O
of	O
value	O
types	O
.	O
</s>
<s>
Both	O
languages	O
define	O
enumerations	B-Language
,	O
but	O
they	O
are	O
implemented	O
in	O
fundamentally	O
different	O
ways	O
.	O
</s>
<s>
As	O
such	O
,	O
enumerations	B-Language
are	O
one	O
area	O
where	O
tools	O
designed	O
to	O
automatically	O
translate	O
code	O
between	O
the	O
two	O
languages	O
(	O
such	O
as	O
Java	B-Language
to	O
C#	B-Application
converters	O
)	O
fail	O
.	O
</s>
<s>
C#	B-Application
has	O
implemented	O
enumerations	B-Language
in	O
a	O
manner	O
similar	O
to	O
C	B-Language
,	O
that	O
is	O
as	O
wrappers	O
around	O
the	O
bit-flags	O
implemented	O
in	O
primitive	O
integral	O
types	O
(	O
int	O
,	O
byte	B-Application
,	O
short	O
,	O
etc	O
.	O
)	O
.	O
</s>
<s>
This	O
has	O
performance	O
benefits	O
and	O
improves	O
interaction	O
with	O
C/C	B-Language
++	I-Language
compiled	B-Language
code	O
,	O
but	O
provides	O
fewer	O
features	O
and	O
can	O
lead	O
to	O
bugs	O
if	O
low-level	O
value	O
types	O
are	O
directly	O
cast	O
to	O
an	O
enumeration	B-Language
type	O
,	O
as	O
is	O
allowed	O
in	O
the	O
C#	B-Application
language	O
.	O
</s>
<s>
In	O
contrast	O
,	O
Java	B-Language
implements	O
enumerations	B-Language
as	O
full	O
featured	O
collection	O
of	O
instances	O
,	O
requiring	O
more	O
memory	O
and	O
not	O
aiding	O
interaction	O
with	O
C/C	B-Language
++	I-Language
code	O
,	O
but	O
providing	O
additional	O
features	O
in	O
reflection	B-Language
and	O
intrinsic	O
behavior	O
.	O
</s>
<s>
Java	B-Language
C#	B-Application
Definition	O
In	O
Java	B-Language
,	O
the	O
enumeration	B-Language
type	O
is	O
a	O
class	O
,	O
and	O
its	O
values	O
are	O
objects	O
(	O
instances	O
)	O
of	O
that	O
class	O
.	O
</s>
<s>
The	O
only	O
valid	O
values	O
are	O
the	O
ones	O
listed	O
in	O
the	O
enumeration	B-Language
.	O
</s>
<s>
The	O
enumeration	B-Language
type	O
may	O
declare	O
fields	B-Application
,	O
allowing	O
each	O
individual	O
enumerated	O
value	O
to	O
reference	O
additional	O
data	O
associated	O
uniquely	O
with	O
that	O
specific	O
value	O
.	O
</s>
<s>
The	O
enumeration	B-Language
type	O
may	O
also	O
declare	O
or	O
override	B-Language
methods	B-Language
,	O
or	O
implement	O
interfaces	B-Application
.	O
</s>
<s>
Enumerations	B-Language
in	O
C#	B-Application
are	O
implicitly	O
derived	O
from	O
the	O
Enum	B-Language
type	O
that	O
again	O
is	O
a	O
value	O
type	O
derivative	O
.	O
</s>
<s>
The	O
value	O
set	O
of	O
a	O
C#	B-Application
enumeration	B-Language
is	O
defined	O
by	O
the	O
underlying	O
type	O
that	O
can	O
be	O
a	O
signed	B-Algorithm
or	O
unsigned	B-Algorithm
integer	O
type	O
of	O
8	O
,	O
16	O
,	O
32	O
or	O
64	O
bits	O
.	O
</s>
<s>
The	O
enumeration	B-Language
definition	O
defines	O
names	O
for	O
the	O
selected	O
integer	O
values	O
.	O
</s>
<s>
Any	O
value	O
of	O
the	O
underlying	O
primitive	O
type	O
is	O
a	O
valid	O
value	O
of	O
the	O
enumeration	B-Language
type	O
,	O
though	O
an	O
explicit	O
cast	O
may	O
be	O
needed	O
to	O
assign	O
it	O
.	O
</s>
<s>
Combining	O
Java	B-Language
enumeration	B-Language
set	O
and	O
map	O
collections	B-Application
provide	O
functionality	O
to	O
combine	O
multiple	O
enumeration	B-Language
values	O
to	O
a	O
combined	O
value	O
.	O
</s>
<s>
These	O
special	O
collections	B-Application
allows	O
compiler	B-Language
optimization	O
to	O
minimize	O
the	O
overhead	O
incurred	O
by	O
using	O
collections	B-Application
as	O
the	O
combination	O
mechanism	O
.	O
</s>
<s>
C#	B-Application
supports	O
bit-mapped	O
enumerations	B-Language
where	O
an	O
actual	O
value	O
may	O
be	O
a	O
combination	O
of	O
enumerated	O
values	O
bitwise	O
or'ed	O
together	O
.	O
</s>
<s>
The	O
formatting	O
and	O
parsing	O
methods	B-Language
implicitly	O
defined	O
by	O
the	O
type	O
will	O
attempt	O
to	O
use	O
these	O
values	O
.	O
</s>
<s>
In	O
both	O
C#	B-Application
and	O
Java	B-Language
,	O
programmers	O
can	O
use	O
enumerations	B-Language
in	O
a	O
switch	O
statement	O
without	O
conversion	O
to	O
a	O
string	O
or	O
primitive	O
integer	O
type	O
.	O
</s>
<s>
However	O
,	O
C#	B-Application
disallows	O
implicit	O
fall-through	O
unless	O
the	O
case	O
statement	O
does	O
not	O
contain	O
any	O
code	O
,	O
as	O
it	O
is	O
a	O
common	O
cause	O
of	O
hard-to-find	O
bugs	O
.	O
</s>
<s>
C#	B-Application
implements	O
object-oriented	B-Language
method	O
pointers	O
in	O
the	O
form	O
of	O
delegates	O
.	O
</s>
<s>
C#	B-Application
delegates	O
support	O
covariance	O
and	O
contravariance	O
,	O
and	O
can	O
hold	O
a	O
reference	O
to	O
any	O
signature-compatible	O
static	O
method	O
,	O
instance	B-Language
method	I-Language
,	O
anonymous	B-General_Concept
method	I-General_Concept
or	O
lambda	B-General_Concept
expression	I-General_Concept
.	O
</s>
<s>
Delegates	O
should	O
not	O
be	O
confused	O
with	O
closures	B-Language
and	O
inline	O
functions	O
.	O
</s>
<s>
The	O
concepts	O
are	O
related	O
because	O
a	O
reference	O
to	O
a	O
closure/inline	O
function	O
must	O
be	O
captured	O
in	O
a	O
delegate	O
reference	O
to	O
be	O
useful	O
at	O
all	O
.	O
</s>
<s>
But	O
a	O
delegate	O
does	O
not	O
always	O
reference	O
an	O
inline	O
function	O
;	O
it	O
can	O
also	O
reference	O
existing	O
static	O
or	O
instance	B-Language
methods	I-Language
.	O
</s>
<s>
Delegates	O
form	O
the	O
basis	O
of	O
C#	B-Application
events	O
,	O
but	O
should	O
not	O
be	O
confused	O
with	O
those	O
either	O
.	O
</s>
<s>
Delegates	O
were	O
deliberately	O
left	O
out	O
of	O
Java	B-Language
because	O
they	O
were	O
considered	O
unnecessary	O
and	O
detrimental	O
to	O
the	O
language	O
,	O
and	O
because	O
of	O
potential	O
performance	O
issues	O
.	O
</s>
<s>
The	O
wrapper	O
pattern	O
,	O
which	O
resembles	O
the	O
delegates	O
of	O
C#	B-Application
in	O
that	O
it	O
allows	O
the	O
client	O
to	O
access	O
one	O
or	O
more	O
client-defined	O
methods	B-Language
through	O
a	O
known	O
interface	B-Application
,	O
is	O
one	O
such	O
mechanism	O
.	O
</s>
<s>
Another	O
is	O
the	O
use	O
of	O
adapter	O
objects	O
using	O
inner	O
classes	O
,	O
which	O
the	O
designers	O
of	O
Java	B-Language
argued	O
are	O
a	O
better	O
solution	O
than	O
bound	O
method	O
references	O
.	O
</s>
<s>
See	O
also	O
example	O
C#	B-Application
delegates	O
and	O
equivalent	O
Java	B-Language
constructs	O
.	O
</s>
<s>
C#	B-Application
allows	O
value/primitive/simple	O
types	O
to	O
be	O
"	O
lifted	O
"	O
to	O
allow	O
the	O
special	O
null	O
value	O
in	O
addition	O
to	O
the	O
type	O
's	O
native	O
values	O
.	O
</s>
<s>
suffix	O
to	O
the	O
type	O
name	O
;	O
this	O
is	O
equivalent	O
to	O
using	O
the	O
Nullablexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
generic	B-Language
type	I-Language
,	O
where	O
T	O
is	O
the	O
type	O
to	O
be	O
lifted	O
.	O
</s>
<s>
Java	B-Language
does	O
not	O
support	O
type	O
lifting	O
as	O
a	O
concept	O
,	O
but	O
all	O
of	O
the	O
built-in	O
primitive	O
types	O
have	O
corresponding	O
wrapper	O
types	O
,	O
which	O
do	O
support	O
the	O
null	O
value	O
by	O
virtue	O
of	O
being	O
reference	B-Language
types	I-Language
(	O
classes	O
)	O
.	O
</s>
<s>
According	O
to	O
the	O
Java	B-Language
spec	O
,	O
any	O
attempt	O
to	O
dereference	O
the	O
null	O
reference	O
must	O
result	O
in	O
an	O
exception	O
being	O
thrown	O
at	O
run-time	O
,	O
specifically	O
a	O
NullPointerException	O
.	O
</s>
<s>
In	O
C#	B-Application
,	O
the	O
lifted*operator	O
propagates	O
the	O
null	O
value	O
of	O
the	O
operand	O
;	O
in	O
Java	B-Language
,	O
unboxing	O
the	O
null	O
reference	O
throws	O
an	O
exception	O
.	O
</s>
<s>
Not	O
all	O
C#	B-Application
lifted	O
operators	O
have	O
been	O
defined	O
to	O
propagate	O
null	O
unconditionally	O
,	O
if	O
one	O
of	O
the	O
operands	O
is	O
null	O
.	O
</s>
<s>
Specifically	O
,	O
the	O
boolean	O
operators	O
have	O
been	O
lifted	O
to	O
support	O
ternary	B-Language
logic	I-Language
thus	O
keeping	O
impedance	O
with	O
SQL	B-Language
.	O
</s>
<s>
The	O
Java	B-Language
boolean	O
operators	O
do	O
not	O
support	O
ternary	B-Language
logic	I-Language
,	O
nor	O
is	O
it	O
implemented	O
in	O
the	O
base	B-Application
class	I-Application
library	O
.	O
</s>
<s>
C#	B-Application
features	O
a	O
late	O
bound	O
dynamic	O
type	O
that	O
supports	O
no-reflection	O
dynamic	O
invocation	O
,	O
interoperability	O
with	O
dynamic	O
languages	O
,	O
and	O
ad-hoc	O
binding	O
to	O
(	O
for	O
example	O
)	O
document	O
object	O
models	O
.	O
</s>
<s>
The	O
dynamic	O
type	O
resolves	O
member	O
access	O
dynamically	O
at	O
runtime	O
as	O
opposed	O
to	O
statically/virtual	O
at	O
compile	B-Language
time	O
.	O
</s>
<s>
The	O
member	O
lookup	O
mechanism	O
is	O
extensible	O
with	O
traditional	O
reflection	B-Language
as	O
a	O
fall-back	O
mechanism	O
.	O
</s>
<s>
There	O
are	O
several	O
use	O
cases	O
for	O
the	O
dynamic	O
type	O
in	O
C#	B-Application
:	O
</s>
<s>
Less	O
verbose	O
use	O
of	O
reflection	B-Language
:	O
By	O
casting	O
an	O
instance	O
to	O
the	O
dynamic	O
type	O
,	O
members	O
such	O
as	O
properties	B-Language
,	O
methods	B-Language
,	O
events	O
etc	O
.	O
</s>
<s>
can	O
be	O
directly	O
invoked	O
on	O
the	O
instance	O
without	O
using	O
the	O
reflection	B-Language
API	I-Language
directly	O
.	O
</s>
<s>
Creating	O
dynamic	O
abstractions	B-Application
on	O
the	O
fly	O
:	O
For	O
instance	O
,	O
a	O
dynamic	O
object	O
could	O
provide	O
simpler	O
access	O
to	O
document	O
object	O
models	O
such	O
as	O
XML	B-Protocol
or	O
XHTML	B-Language
documents	O
.	O
</s>
<s>
Java	B-Language
does	O
not	O
support	O
a	O
late-bound	O
type	O
.	O
</s>
<s>
The	O
use	O
cases	O
for	O
C#	B-Application
dynamic	O
type	O
have	O
different	O
corresponding	O
constructs	O
in	O
Java	B-Language
:	O
</s>
<s>
For	O
dynamic	O
late-bound	O
by-name	O
invocation	O
of	O
preexisting	O
types	O
,	O
reflection	B-Language
should	O
be	O
used	O
.	O
</s>
<s>
The	O
Java	B-Language
virtual	I-Language
machine	I-Language
platform	O
does	O
have	O
multiple	O
dynamic	O
languages	O
implemented	O
on	O
it	O
,	O
but	O
there	O
is	O
no	O
common	O
standard	O
for	O
how	O
to	O
pass	O
objects	O
between	O
languages	O
.	O
</s>
<s>
Usually	O
this	O
involves	O
some	O
form	O
of	O
reflection	B-Language
or	O
reflection-like	O
API	O
.	O
</s>
<s>
As	O
an	O
example	O
of	O
how	O
to	O
use	O
JavaFX	O
objects	O
from	O
Java	B-Language
.	O
</s>
<s>
For	O
creating	O
and	O
interacting	O
with	O
objects	O
entirely	O
at	O
runtime	O
,	O
e.g.	O
,	O
interaction	O
with	O
a	O
document	O
object	O
model	O
abstraction	B-Application
,	O
a	O
specific	O
abstraction	B-Application
API	O
must	O
be	O
used	O
.	O
</s>
<s>
Java	B-Language
precludes	O
pointers	O
and	O
pointer-arithmetic	O
within	O
the	O
Java	B-Language
runtime	I-Language
environment	O
.	O
</s>
<s>
The	O
Java	B-Language
language	I-Language
designers	O
reasoned	O
that	O
pointers	O
are	O
one	O
of	O
the	O
main	O
features	O
that	O
enable	O
programmers	O
to	O
put	O
bugs	O
in	O
their	O
code	O
and	O
chose	O
not	O
to	O
support	O
them	O
.	O
</s>
<s>
Java	B-Language
does	O
not	O
allow	O
for	O
directly	O
passing	O
and	O
receiving	O
objects/structures	O
to/from	O
the	O
underlying	O
operating	O
system	O
and	O
thus	O
does	O
not	O
need	O
to	O
model	O
objects/structures	O
to	O
such	O
a	O
specific	O
memory	O
layout	O
,	O
layouts	O
that	O
frequently	O
would	O
involve	O
pointers	O
.	O
</s>
<s>
Java	B-Language
's	O
communication	O
with	O
the	O
underlying	O
operating	O
system	O
is	O
instead	O
based	O
upon	O
Java	B-Language
Native	I-Language
Interface	I-Language
(	O
JNI	B-Language
)	O
where	O
communication	O
with/adaptation	O
to	O
an	O
underlying	O
operating	O
system	O
is	O
handled	O
through	O
an	O
external	O
glue	O
layer	O
.	O
</s>
<s>
While	O
C#	B-Application
does	O
allow	O
use	O
of	O
pointers	O
and	O
corresponding	O
pointer	O
arithmetic	O
,	O
the	O
C#	B-Application
language	O
designers	O
had	O
the	O
same	O
concerns	O
that	O
pointers	O
could	O
potentially	O
be	O
used	O
to	O
bypass	O
the	O
strict	O
rules	O
for	O
object	O
access	O
.	O
</s>
<s>
Thus	O
,	O
C#	B-Application
by	O
default	O
also	O
precludes	O
pointers	O
.	O
</s>
<s>
Code	O
blocks	O
or	O
methods	B-Language
that	O
use	O
the	O
pointers	O
must	O
be	O
marked	O
with	O
the	O
unsafe	O
keyword	O
to	O
be	O
able	O
to	O
use	O
pointers	O
,	O
and	O
the	O
compiler	B-Language
requires	O
the	O
/unsafe	O
switch	O
to	O
allow	O
compiling	B-Language
such	O
code	O
.	O
</s>
<s>
Assemblies	O
that	O
are	O
compiled	B-Language
using	O
the	O
/unsafe	O
switch	O
are	O
marked	O
as	O
such	O
and	O
may	O
only	O
execute	O
if	O
explicitly	O
trusted	O
.	O
</s>
<s>
While	O
not	O
directly	O
evident	O
in	O
the	O
language	O
syntax	O
per	O
se	O
,	O
both	O
languages	O
support	O
the	O
concept	O
of	O
weak	B-General_Concept
references	I-General_Concept
.	O
</s>
<s>
An	O
instance	O
that	O
is	O
only	O
referenced	O
by	O
weak	B-General_Concept
references	I-General_Concept
is	O
eligible	O
for	O
garbage	B-General_Concept
collection	I-General_Concept
just	O
as	O
if	O
there	O
were	O
no	O
references	O
at	O
all	O
.	O
</s>
<s>
In	O
both	O
languages	O
this	O
feature	O
is	O
exposed	O
through	O
the	O
associated	O
libraries	B-Library
,	O
even	O
though	O
it	O
is	O
really	O
a	O
core	O
runtime	O
feature	O
.	O
</s>
<s>
Along	O
with	O
weak	B-General_Concept
references	I-General_Concept
,	O
Java	B-Language
has	O
soft	B-General_Concept
references	I-General_Concept
.	O
</s>
<s>
They	O
are	O
much	O
like	O
weak	B-General_Concept
references	I-General_Concept
,	O
but	O
the	O
JVM	B-Language
will	O
not	O
deallocate	O
softly-referenced	O
objects	O
until	O
the	O
memory	O
is	O
needed	O
.	O
</s>
<s>
Arrays	B-Data_Structure
and	O
collections	B-Application
are	O
concepts	O
featured	O
by	O
both	O
languages	O
.	O
</s>
<s>
The	O
syntax	O
used	O
to	O
declare	O
and	O
access	O
arrays	B-Data_Structure
is	O
identical	O
,	O
except	O
that	O
C#	B-Application
has	O
added	O
syntax	O
for	O
declaring	O
and	O
manipulating	O
multidimensional	O
arrays	B-Data_Structure
.	O
</s>
<s>
Java	B-Language
C#	B-Application
Arrays	B-Data_Structure
are	O
implicitly	O
direct	O
specializations	O
of	O
Object	O
.	O
</s>
<s>
Arrays	B-Data_Structure
in	O
C#	B-Application
are	O
implicit	O
specializations	O
of	O
the	O
System.Array	O
class	O
that	O
implements	O
several	O
collection	O
interfaces	B-Application
.	O
</s>
<s>
Arrays	B-Data_Structure
and	O
collections	B-Application
are	O
completely	O
separate	O
with	O
no	O
unification	O
.	O
</s>
<s>
Arrays	B-Data_Structure
cannot	O
be	O
passed	O
where	O
sequences	O
or	O
collections	B-Application
are	O
expected	O
(	O
though	O
they	O
can	O
be	O
wrapped	O
using	O
Arrays.asList	O
)	O
.	O
</s>
<s>
Arrays	B-Data_Structure
can	O
be	O
passed	O
where	O
sequences	O
(	O
IEnumerables	O
)	O
or	O
collections/list	O
interfaces	B-Application
are	O
expected	O
.	O
</s>
<s>
However	O
,	O
the	O
collection	O
operations	O
that	O
alter	O
the	O
number	O
of	O
elements	O
(	O
insert/add/remove	O
)	O
will	O
throw	O
exceptions	O
as	O
these	O
operations	O
are	O
unsupported	O
by	O
arrays	B-Data_Structure
.	O
</s>
<s>
The	O
for	O
statement	O
accepts	O
either	O
arrays	B-Data_Structure
or	O
Iterables	O
.	O
</s>
<s>
All	O
collections	B-Application
implement	O
Iterable	O
.	O
</s>
<s>
The	O
foreach	O
statement	O
iterates	O
through	O
a	O
sequence	O
using	O
a	O
specific	O
implementation	O
of	O
the	O
GetEnumerator	O
method	O
,	O
usually	O
implemented	O
through	O
the	O
IEnumerable	O
or	O
IEnumerablexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
interface	B-Application
.	O
</s>
<s>
Because	O
arrays	B-Data_Structure
always	O
implicitly	O
implement	O
these	O
interfaces	B-Application
,	O
the	O
loop	O
will	O
iterate	O
through	O
arrays	B-Data_Structure
also.In	O
both	O
languages	O
arrays	B-Data_Structure
of	O
reference	B-Language
types	I-Language
are	O
covariant	O
.	O
</s>
<s>
In	O
both	O
languages	O
,	O
the	O
arrays	B-Data_Structure
will	O
perform	O
a	O
type	O
check	O
when	O
inserting	O
new	O
values	O
,	O
because	O
type	O
safety	O
would	O
otherwise	O
be	O
compromised	O
.	O
</s>
<s>
This	O
is	O
in	O
contrast	O
to	O
how	O
generic	B-Language
collections	B-Application
have	O
been	O
implemented	O
in	O
both	O
languages	O
.	O
</s>
<s>
No	O
multidimensional	O
arrays	B-Data_Structure
(	O
rectangular	O
arrays	B-Data_Structure
)	O
,	O
but	O
arrays	B-Data_Structure
of	O
references	O
to	O
arrays	B-Data_Structure
(	O
jagged	B-Data_Structure
arrays	I-Data_Structure
)	O
.	O
</s>
<s>
Multidimensional	O
arrays	B-Data_Structure
(	O
rectangular	O
arrays	B-Data_Structure
)	O
,	O
and	O
arrays	B-Data_Structure
of	O
references	O
to	O
arrays	B-Data_Structure
(	O
jagged	B-Data_Structure
arrays	I-Data_Structure
)	O
.	O
</s>
<s>
Arrays	B-Data_Structure
cannot	O
be	O
resized	O
(	O
though	O
use	O
of	O
the	O
System.arraycopy( )	O
method	O
can	O
allow	O
for	O
multi-step	O
array	O
resizing	O
)	O
Arrays	B-Data_Structure
can	O
be	O
resized	O
while	O
preserving	O
existing	O
values	O
using	O
the	O
Array.Resize( )	O
static	O
array	O
method	O
(	O
but	O
this	O
may	O
return	O
a	O
new	O
array	O
)	O
.	O
</s>
<s>
Implemented	O
as	O
a	O
retrofit	O
for	O
the	O
java.util	O
library	O
having	O
extra	O
features	O
,	O
like	O
data	O
structures	O
like	O
sets	O
and	O
linked	O
sets	O
,	O
and	O
has	O
several	O
algorithms	O
to	O
manipulate	O
elements	O
of	O
a	O
collection	O
,	O
like	O
finding	O
the	O
largest	O
element	O
based	O
on	O
some	O
Comparatorxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
object	O
,	O
finding	O
the	O
smallest	O
element	O
,	O
finding	O
sublists	O
within	O
a	O
list	O
,	O
reverse	O
the	O
contents	O
of	O
a	O
list	O
,	O
shuffle	O
the	O
contents	O
of	O
a	O
list	O
,	O
create	O
immutable	B-Application
versions	O
of	O
a	O
collection	O
,	O
performs	O
sorts	O
,	O
and	O
make	O
binary	O
searches	O
.	O
</s>
<s>
The	O
C#	B-Application
collections	B-Application
framework	O
consists	O
of	O
classes	O
from	O
the	O
System.Collections	O
and	O
the	O
System.Collections.Generic	O
namespaces	O
with	O
several	O
useful	O
interfaces	B-Application
,	O
abstract	B-Application
classes	O
,	O
and	O
data	O
structures	O
.	O
</s>
<s>
NET	O
3.5	O
added	O
System.Linq	O
namespace	O
that	O
contains	O
various	O
extension	O
methods	B-Language
for	O
querying	O
collections	B-Application
,	O
such	O
as	O
Aggregate	O
,	O
All	O
,	O
Average	O
,	O
Distinct	O
,	O
Join	O
,	O
Union	O
and	O
many	O
others	O
.	O
</s>
<s>
Queries	O
using	O
these	O
methods	B-Language
are	O
called	O
Language	B-Language
Integrated	I-Language
Query	I-Language
(	O
LINQ	B-Language
)	O
.	O
</s>
<s>
Multidimensional	O
arrays	B-Data_Structure
can	O
in	O
some	O
cases	O
increase	O
performance	O
because	O
of	O
increased	O
locality	B-General_Concept
(	O
as	O
there	O
is	O
one	O
pointer	O
dereference	O
instead	O
of	O
one	O
for	O
every	O
dimension	O
of	O
the	O
array	O
,	O
as	O
it	O
is	O
the	O
case	O
for	O
jagged	B-Data_Structure
arrays	I-Data_Structure
)	O
.	O
</s>
<s>
However	O
,	O
since	O
all	O
array	B-Data_Structure
element	I-Data_Structure
access	O
in	O
a	O
multidimensional	O
array	O
requires	O
multiplication/shift	O
between	O
the	O
two	O
or	O
more	O
dimensions	O
,	O
this	O
is	O
an	O
advantage	O
only	O
in	O
very	O
random	O
access	O
scenarios	O
.	O
</s>
<s>
Another	O
difference	O
is	O
that	O
the	O
entire	O
multidimensional	O
array	O
can	O
be	O
allocated	O
with	O
a	O
single	O
application	O
of	O
operator	O
new	O
,	O
while	O
jagged	B-Data_Structure
arrays	I-Data_Structure
require	O
loops	O
and	O
allocations	O
for	O
every	O
dimension	O
.	O
</s>
<s>
However	O
,	O
Java	B-Language
provides	O
a	O
syntactic	O
construct	O
for	O
allocating	O
a	O
jagged	B-Data_Structure
array	I-Data_Structure
with	O
regular	O
lengths	O
;	O
the	O
loops	O
and	O
multiple	O
allocations	O
are	O
then	O
performed	O
by	O
the	O
virtual	B-Application
machine	O
and	O
need	O
not	O
be	O
explicit	O
at	O
the	O
source	O
level	O
.	O
</s>
<s>
Both	O
languages	O
feature	O
an	O
extensive	O
set	O
of	O
collection	O
types	O
that	O
includes	O
various	O
ordered	O
and	O
unordered	O
types	O
of	O
lists	O
,	O
maps/dictionaries	B-Application
,	O
sets	O
,	O
etc	O
.	O
</s>
<s>
C#	B-Application
provides	O
two	O
different	O
methods	B-Language
for	O
creating	O
tuple	B-Application
types	O
(	O
also	O
known	O
as	O
product	O
types	O
)	O
.	O
</s>
<s>
The	O
first	O
is	O
via	O
the	O
System.Tuple	O
classes	O
,	O
which	O
are	O
immutable	B-Application
reference	B-Language
types	I-Language
provided	O
by	O
the	O
framework	O
API	O
(	O
starting	O
with	O
.NET	O
Framework	O
4.0	O
)	O
for	O
creating	O
generic	B-Language
tuple	B-Application
types	O
.	O
</s>
<s>
This	O
first	O
method	O
has	O
since	O
been	O
effectively	O
superseded	O
by	O
the	O
second	O
,	O
the	O
System.ValueTuple	O
structs	B-Application
,	O
which	O
are	O
mutable	B-Application
value	O
types	O
provided	O
by	O
the	O
framework	O
API	O
(	O
starting	O
with	O
.NET	O
Framework	O
4.7	O
)	O
.	O
</s>
<s>
While	O
the	O
two	O
methods	B-Language
seem	O
superficially	O
similar	O
,	O
they	O
have	O
multiple	O
notable	O
differences	O
.	O
</s>
<s>
The	O
ValueTuple	O
types	O
are	O
value	O
types	O
,	O
so	O
they	O
have	O
a	O
more	O
compact	O
memory	O
footprint	O
;	O
also	O
,	O
the	O
ValueTuple	O
types	O
expose	O
their	O
contents	O
as	O
mutable	B-Application
fields	B-Application
,	O
compared	O
to	O
the	O
immutable	B-Application
properties	B-Language
of	O
the	O
Tuple	B-Application
classes	O
.	O
</s>
<s>
Finally	O
,	O
since	O
C#	B-Application
version	O
7.0	O
,	O
the	O
language	O
has	O
native	O
syntactical	O
support	O
for	O
the	O
construction	O
,	O
deconstruction	O
,	O
and	O
manipulation	O
of	O
tuples	B-Application
as	O
ValueTuple	O
instances	O
;	O
this	O
also	O
provides	O
for	O
the	O
arbitrary	O
renaming	O
of	O
the	O
tuples	B-Application
 '	O
constituent	O
fields	B-Application
(	O
as	O
opposed	O
to	O
Tuple	B-Application
,	O
where	O
the	O
fields	B-Application
are	O
always	O
named	O
Item1	O
,	O
Item2	O
,	O
etc	O
.	O
</s>
<s>
Java	B-Language
does	O
not	O
provide	O
tuple	B-Application
types	O
as	O
part	O
of	O
its	O
language	O
or	O
standard	O
API	O
;	O
numerous	O
third-party	O
libraries	B-Library
exist	O
which	O
can	O
provide	O
tuple	B-Application
types	O
,	O
but	O
they	O
all	O
are	O
necessarily	O
similar	O
to	O
the	O
C#	B-Application
System.Tuple	O
classes	O
.	O
</s>
<s>
In	O
comparison	O
to	O
C#	B-Application
ValueTuple	O
types	O
and	O
their	O
associated	O
syntax	O
,	O
they	O
are	O
more	O
unwieldy	O
to	O
use	O
(	O
requiring	O
the	O
explicit	O
use	O
of	O
constructors	O
or	O
static	O
factory	O
methods	B-Language
for	O
creating	O
them	O
,	O
requiring	O
individual	O
member	O
access	O
to	O
deconstruct	O
them	O
,	O
and	O
having	O
fixed	O
names	O
for	O
their	O
elements	O
)	O
.	O
</s>
<s>
they	O
allow	O
for	O
implicit	O
casting	O
between	O
any	O
primitive	O
types	O
and	O
the	O
corresponding	O
reference	B-Language
types	I-Language
.	O
</s>
<s>
In	O
C#	B-Application
,	O
the	O
primitive	O
types	O
are	O
subtypes	O
of	O
the	O
Object	O
type	O
.	O
</s>
<s>
In	O
Java	B-Language
this	O
is	O
not	O
true	O
;	O
any	O
given	O
primitive	O
type	O
and	O
the	O
corresponding	O
wrapper	O
type	O
have	O
no	O
specific	O
relationship	O
with	O
each	O
other	O
,	O
except	O
for	O
autoboxing	O
and	O
unboxing	O
,	O
which	O
act	O
as	O
syntactic	O
sugar	O
for	O
interchanging	O
between	O
them	O
.	O
</s>
<s>
This	O
was	O
done	O
intentionally	O
,	O
to	O
maintain	O
backward	B-General_Concept
compatibility	I-General_Concept
with	O
prior	O
versions	O
of	O
Java	B-Language
,	O
in	O
which	O
no	O
automatic	O
casting	O
was	O
allowed	O
,	O
and	O
the	O
programmer	O
worked	O
with	O
two	O
separate	O
sets	O
of	O
types	O
:	O
the	O
primitive	O
types	O
,	O
and	O
the	O
wrapper	O
(	O
reference	O
)	O
type	O
hierarchy	O
.	O
</s>
<s>
First	O
of	O
all	O
,	O
in	O
C#	B-Application
,	O
primitive	O
types	O
can	O
define	O
methods	B-Language
,	O
such	O
as	O
an	O
override	B-Language
of	O
Object	O
's	O
ToString( )	O
method	O
.	O
</s>
<s>
In	O
Java	B-Language
,	O
this	O
task	O
is	O
accomplished	O
by	O
the	O
primitive	B-Language
wrapper	I-Language
classes	O
.	O
</s>
<s>
Secondly	O
,	O
in	O
Java	B-Language
an	O
extra	O
cast	O
is	O
needed	O
whenever	O
one	O
tries	O
to	O
directly	O
dereference	O
a	O
primitive	O
value	O
,	O
as	O
it	O
will	O
not	O
be	O
boxed	O
automatically	O
.	O
</s>
<s>
The	O
expression	O
((Integer )	O
42	O
)	O
.toString( )	O
will	O
convert	O
an	O
integer	O
literal	O
to	O
string	O
in	O
Java	B-Language
while	O
42.ToString( )	O
performs	O
the	O
same	O
operation	O
in	O
C#	B-Application
.	O
</s>
<s>
This	O
is	O
because	O
the	O
latter	O
one	O
is	O
an	O
instance	O
call	O
on	O
the	O
primitive	O
value	O
42	O
,	O
while	O
the	O
former	O
one	O
is	O
an	O
instance	O
call	O
on	O
an	O
object	O
of	O
type	O
java.lang.Integer	O
.	O
</s>
<s>
Finally	O
,	O
another	O
difference	O
is	O
that	O
Java	B-Language
makes	O
heavy	O
use	O
of	O
boxed	O
types	O
in	O
generics	B-Language
(	O
see	O
below	O
)	O
.	O
</s>
<s>
Both	O
languages	O
are	O
considered	O
"	O
curly	O
brace	O
"	O
languages	O
in	O
the	O
C/C	B-Language
++	I-Language
family	O
.	O
</s>
<s>
The	O
syntax	O
at	O
the	O
statement	O
and	O
expression	O
level	O
is	O
almost	O
identical	O
with	O
obvious	O
inspiration	O
from	O
the	O
C/C	B-Language
++	I-Language
tradition	O
.	O
</s>
<s>
At	O
type	O
definition	O
level	O
(	O
classes	O
and	O
interfaces	B-Application
)	O
some	O
minor	O
differences	O
exist	O
.	O
</s>
<s>
Java	B-Language
is	O
explicit	O
about	O
extending	O
classes	O
and	O
implementing	O
interfaces	B-Application
,	O
while	O
C#	B-Application
infers	O
this	O
from	O
the	O
kind	O
of	O
types	O
a	O
new	O
class/interface	O
derives	B-Language
from	O
.	O
</s>
<s>
C#	B-Application
supports	O
more	O
features	O
than	O
Java	B-Language
,	O
which	O
to	O
some	O
extent	O
is	O
also	O
evident	O
in	O
the	O
syntax	O
that	O
specifies	O
more	O
keywords	O
and	O
more	O
grammar	O
rules	O
than	O
Java	B-Language
.	O
</s>
<s>
older	O
code	O
may	O
no	O
longer	O
compile	B-Language
,	O
if	O
presented	O
to	O
a	O
compiler	B-Language
for	O
a	O
later	O
version	O
of	O
the	O
language	O
.	O
</s>
<s>
Java	B-Language
language	I-Language
designers	O
have	O
avoided	O
new	O
keywords	O
as	O
much	O
as	O
possible	O
,	O
preferring	O
instead	O
to	O
introduce	O
new	O
syntactic	O
constructs	O
that	O
were	O
not	O
legal	O
before	O
or	O
to	O
reuse	O
existing	O
keywords	O
in	O
new	O
contexts	O
.	O
</s>
<s>
This	O
way	O
they	O
did	O
n't	O
jeopardize	O
backward	B-General_Concept
compatibility	I-General_Concept
.	O
</s>
<s>
An	O
example	O
of	O
the	O
latter	O
can	O
be	O
found	O
in	O
how	O
the	O
extends	O
and	O
(	O
especially	O
)	O
the	O
super	O
keywords	O
were	O
reused	O
for	O
specifying	O
type	O
bounds	O
when	O
generics	B-Language
were	O
introduced	O
in	O
Java	B-Language
1.5	O
.	O
</s>
<s>
At	O
one	O
time	O
(	O
Java	B-Language
1.4	O
)	O
a	O
new	O
keyword	O
assert	O
was	O
introduced	O
that	O
was	O
not	O
reserved	O
as	O
a	O
keyword	O
before	O
.	O
</s>
<s>
The	O
designers	O
chose	O
to	O
address	O
this	O
problem	O
with	O
a	O
four-step	O
solution	O
:	O
1	O
)	O
Introducing	O
a	O
compiler	B-Language
switch	O
that	O
indicates	O
if	O
Java	B-Language
1.4	O
or	O
later	O
should	O
be	O
used	O
,	O
2	O
)	O
Only	O
marking	O
assert	O
as	O
a	O
keyword	O
when	O
compiling	B-Language
as	O
Java	B-Language
1.4	O
and	O
later	O
,	O
3	O
)	O
Defaulting	O
to	O
1.3	O
to	O
avoid	O
rendering	O
previous	O
(	O
non	O
1.4	O
aware	O
code	O
)	O
invalid	O
and	O
4	O
)	O
Issue	O
warnings	O
,	O
if	O
the	O
keyword	O
is	O
used	O
in	O
Java	B-Language
1.3	O
mode	O
,	O
in	O
order	O
to	O
allow	O
the	O
developers	O
to	O
change	O
the	O
code	O
.	O
</s>
<s>
C#	B-Application
language	O
designers	O
have	O
introduced	O
several	O
new	O
keywords	O
since	O
the	O
first	O
version	O
.	O
</s>
<s>
This	O
means	O
that	O
even	O
when	O
they	O
introduced	O
(	O
among	O
others	O
)	O
the	O
partial	O
and	O
yield	O
keywords	O
in	O
C#	B-Application
2.0	O
,	O
the	O
use	O
of	O
those	O
words	O
as	O
identifiers	O
is	O
still	O
valid	O
as	O
there	O
is	O
no	O
clash	B-Application
possible	O
between	O
the	O
use	O
as	O
keyword	O
and	O
the	O
use	O
as	O
identifier	O
,	O
given	O
the	O
context	O
.	O
</s>
<s>
Thus	O
,	O
the	O
present	O
C#	B-Application
syntax	O
is	O
fully	O
backward	B-General_Concept
compatible	I-General_Concept
with	O
source	O
code	O
written	O
for	O
any	O
previous	O
version	O
without	O
specifying	O
the	O
language	O
version	O
to	O
be	O
used	O
.	O
</s>
<s>
keyword	O
feature	O
,	O
example	O
usage	O
checked	O
,	O
unchecked	O
In	O
C#	B-Application
,	O
checked	O
statement	O
blocks	O
or	O
expressions	O
can	O
enable	O
run-time	O
checking	O
for	O
arithmetic	B-Algorithm
overflow	I-Algorithm
.	O
</s>
<s>
get	O
,	O
set	O
C#	B-Application
implements	O
properties	B-Language
as	O
part	O
of	O
the	O
language	O
syntax	O
with	O
their	O
optional	O
corresponding	O
get	O
and	O
set	O
accessors	O
,	O
as	O
an	O
alternative	O
for	O
the	O
accessor	O
methods	B-Language
used	O
in	O
Java	B-Language
,	O
which	O
is	O
not	O
a	O
language	O
feature	O
but	O
a	O
coding-pattern	O
based	O
on	O
method	B-Language
name	I-Language
conventions	O
.	O
</s>
<s>
goto	O
C#	B-Application
supports	O
the	O
goto	O
keyword	O
.	O
</s>
<s>
This	O
can	O
occasionally	O
be	O
useful	O
,	O
for	O
example	O
for	O
implementing	O
finite	B-Architecture
state	I-Architecture
machines	I-Architecture
or	O
for	O
generated	B-Application
code	I-Application
,	O
but	O
the	O
use	O
of	O
a	O
more	O
structured	O
method	O
of	O
control	O
flow	O
is	O
usually	O
recommended	O
(	O
see	O
criticism	O
of	O
the	O
goto	O
statement	O
)	O
.	O
</s>
<s>
Java	B-Language
does	O
not	O
support	O
the	O
goto	O
statement	O
(	O
but	O
goto	O
is	O
a	O
reserved	O
word	O
)	O
.	O
</s>
<s>
However	O
,	O
Java	B-Language
does	O
support	O
labeled	O
break	O
and	O
continue	O
statements	O
,	O
which	O
in	O
certain	O
situations	O
can	O
be	O
used	O
when	O
a	O
goto	O
statement	O
might	O
otherwise	O
be	O
used	O
.	O
</s>
<s>
}	O
lock	O
In	O
C#	B-Application
,	O
the	O
lock	O
keyword	O
is	O
a	O
shorthand	O
for	O
synchronizing	O
access	O
to	O
a	O
block	O
of	O
code	O
across	O
threads	B-Operating_System
(	O
using	O
a	O
Monitor	O
)	O
,	O
wrapped	O
in	O
a	O
try	O
...	O
finally	O
block	O
.	O
</s>
<s>
out	O
,	O
ref	O
C#	B-Application
has	O
support	O
for	O
output	O
and	O
reference	O
parameters	O
.	O
</s>
<s>
strictfp	B-Language
Java	B-Language
uses	O
strictfp	B-Language
to	O
guarantee	O
the	O
results	O
of	O
floating	O
point	O
operations	O
remain	O
the	O
same	O
across	O
platforms	B-Device
.	O
</s>
<s>
switch	O
In	O
C#	B-Application
,	O
the	O
switch	O
statement	O
also	O
operates	O
on	O
strings	O
and	O
longs	O
.	O
</s>
<s>
Java	B-Language
's	O
switch	O
statement	O
operates	O
on	O
strings	O
(	O
since	O
Java	B-Language
7	O
)	O
but	O
not	O
the	O
long	O
primitive	O
type	O
,	O
and	O
falls	O
through	O
for	O
all	O
statements	O
(	O
excluding	O
those	O
with	O
'	O
break	O
 '	O
)	O
.	O
</s>
<s>
synchronized	O
In	O
Java	B-Language
,	O
the	O
synchronized	O
keyword	O
is	O
a	O
shorthand	O
for	O
synchronizing	O
access	O
to	O
a	O
block	O
of	O
code	O
across	O
threads	B-Operating_System
(	O
using	O
a	O
Monitor	O
)	O
,	O
wrapped	O
in	O
a	O
try	O
...	O
finally	O
block	O
.	O
</s>
<s>
throws	O
Java	B-Language
requires	O
every	O
method	O
to	O
declare	O
the	O
checked	O
exceptions	O
or	O
superclasses	O
of	O
the	O
checked	O
exceptions	O
that	O
it	O
can	O
throw	O
.	O
</s>
<s>
C#	B-Application
has	O
no	O
such	O
syntax	O
.	O
</s>
<s>
}	O
using	O
In	O
C#	B-Application
,	O
using	O
causes	O
the	O
Dispose	B-Application
method	O
(	O
implemented	O
via	O
the	O
IDisposable	O
interface	B-Application
)	O
of	O
the	O
object	O
declared	O
to	O
be	O
executed	O
after	O
the	O
code	O
block	O
has	O
run	O
or	O
when	O
an	O
exception	O
is	O
thrown	O
within	O
the	O
code	O
block	O
.	O
</s>
<s>
In	O
Java	B-Language
SE	O
7	O
a	O
similar	O
construct	O
has	O
been	O
added	O
called	O
try-with-resources	O
:	O
</s>
<s>
Both	O
C#	B-Application
and	O
Java	B-Language
are	O
designed	O
from	O
the	O
ground	O
up	O
as	O
object-oriented	B-Language
languages	I-Language
using	O
dynamic	O
dispatch	O
,	O
with	O
syntax	O
similar	O
to	O
C++	B-Language
(	O
C++	B-Language
in	O
turn	O
derives	B-Language
from	O
C	B-Language
)	O
.	O
</s>
<s>
Neither	O
language	O
is	O
a	O
superset	O
of	O
C	B-Language
or	O
C++	B-Language
,	O
however	O
.	O
</s>
<s>
C#	B-Application
allows	O
a	O
class	O
definition	O
to	O
be	O
split	O
across	O
several	O
source	O
files	O
using	O
a	O
feature	O
called	O
partial	O
classes	O
.	O
</s>
<s>
All	O
the	O
parts	O
must	O
be	O
presented	O
to	O
the	O
compiler	B-Language
as	O
part	O
of	O
a	O
single	O
compilation	B-Language
.	O
</s>
<s>
Parts	O
can	O
implement	O
interfaces	B-Application
and	O
one	O
part	O
can	O
define	O
a	O
base	B-Application
class	I-Application
.	O
</s>
<s>
The	O
feature	O
is	O
useful	O
in	O
code	B-Application
generation	I-Application
scenarios	O
(	O
such	O
as	O
user	B-Application
interface	I-Application
(	O
UI	O
)	O
design	O
)	O
,	O
where	O
a	O
code	O
generator	O
can	O
supply	O
one	O
part	O
and	O
the	O
developer	O
another	O
part	O
to	O
be	O
compiled	B-Language
together	O
.	O
</s>
<s>
Unlike	O
the	O
class	O
extension	O
mechanism	O
,	O
a	O
partial	O
class	O
allows	O
circular	O
dependencies	O
among	O
its	O
parts	O
as	O
they	O
are	O
guaranteed	O
to	O
be	O
resolved	O
at	O
compile	B-Language
time	O
.	O
</s>
<s>
Java	B-Language
has	O
no	O
corresponding	O
concept	O
.	O
</s>
<s>
In	O
Java	B-Language
,	O
unless	O
the	O
inner	O
class	O
is	O
declared	O
static	O
,	O
a	O
reference	O
to	O
an	O
instance	O
of	O
an	O
inner	O
class	O
carries	O
a	O
reference	O
to	O
the	O
outer	O
class	O
with	O
it	O
.	O
</s>
<s>
In	O
C#	B-Application
,	O
an	O
inner	O
class	O
is	O
conceptually	O
the	O
same	O
as	O
a	O
normal	O
class	O
.	O
</s>
<s>
Java	B-Language
provides	O
another	O
feature	O
called	O
local	O
classes	O
or	O
anonymous	O
classes	O
,	O
which	O
can	O
be	O
defined	O
within	O
a	O
method	O
body	O
.	O
</s>
<s>
These	O
are	O
generally	O
used	O
to	O
implement	O
an	O
interface	B-Application
with	O
only	O
one	O
or	O
two	O
methods	B-Language
,	O
which	O
are	O
typically	O
event	O
handlers	O
.	O
</s>
<s>
However	O
,	O
they	O
can	O
also	O
be	O
used	O
to	O
override	B-Language
virtual	B-Application
methods	I-Application
of	O
a	O
superclass	O
.	O
</s>
<s>
The	O
methods	B-Language
in	O
those	O
local	O
classes	O
have	O
access	O
to	O
the	O
outer	O
method	O
's	O
local	O
variables	O
declared	O
final	O
.	O
</s>
<s>
C#	B-Application
satisfies	O
the	O
use-cases	O
for	O
these	O
by	O
providing	O
anonymous	O
delegates	O
;	O
see	O
event	O
handling	O
for	O
more	O
about	O
this	O
.	O
</s>
<s>
C#	B-Application
also	O
provides	O
a	O
feature	O
called	O
anonymous	O
types/classes	O
,	O
but	O
it	O
is	O
rather	O
different	O
from	O
Java	B-Language
's	O
concept	O
with	O
the	O
same	O
name	O
.	O
</s>
<s>
It	O
allows	O
the	O
programmer	O
to	O
instantiate	O
a	O
class	O
by	O
providing	O
only	O
a	O
set	O
of	O
names	O
for	O
the	O
properties	B-Language
the	O
class	O
should	O
have	O
,	O
and	O
an	O
expression	O
to	O
initialize	O
each	O
.	O
</s>
<s>
The	O
types	O
of	O
the	O
properties	B-Language
are	O
inferred	O
from	O
the	O
types	O
of	O
those	O
expressions	O
.	O
</s>
<s>
C#	B-Application
multicast-delegates	O
are	O
used	O
with	O
events	O
.	O
</s>
<s>
Events	O
provide	O
support	O
for	O
event-driven	B-Application
programming	I-Application
and	O
are	O
an	O
implementation	O
of	O
the	O
observer	B-Language
pattern	I-Language
.	O
</s>
<s>
See	O
here	O
for	O
information	O
about	O
how	O
events	O
are	O
implemented	O
in	O
Java	B-Language
.	O
</s>
<s>
By	O
using	O
these	O
features	O
in	O
C#	B-Application
,	O
types	O
such	O
as	O
Complex	O
and	O
decimal	O
have	O
been	O
integrated	O
so	O
that	O
the	O
usual	O
operators	O
like	O
addition	O
and	O
multiplication	O
work	O
with	O
the	O
new	O
types	O
.	O
</s>
<s>
Unlike	O
C++	B-Language
,	O
C#	B-Application
does	O
restrict	O
the	O
use	O
of	O
operator	O
overloading	O
,	O
prohibiting	O
it	O
for	O
the	O
operators	O
new	O
,	O
(	O
)	O
,	O
||	O
,	O
&&	O
,	O
=	O
,	O
and	O
any	O
variations	O
of	O
compound	O
statements	O
like	O
+	O
=	O
.	O
</s>
<s>
Java	B-Language
does	O
not	O
include	O
operator	O
overloading	O
,	O
nor	O
custom	O
conversions	O
in	O
order	O
to	O
prevent	O
abuse	O
of	O
the	O
feature	O
and	O
to	O
keep	O
the	O
language	O
simple	O
.	O
</s>
<s>
C#	B-Application
also	O
includes	O
indexers	O
that	O
can	O
be	O
considered	O
a	O
special	O
case	O
of	O
operator	O
overloading	O
(	O
like	O
the	O
C++	B-Language
operator[]	O
)	O
,	O
or	O
parameterized	O
get/set	O
properties	B-Language
.	O
</s>
<s>
Java	B-Language
does	O
not	O
include	O
indexers	O
.	O
</s>
<s>
The	O
common	O
Java	B-Language
pattern	O
involves	O
writing	O
explicit	O
getters	O
and	O
setters	O
where	O
a	O
C#	B-Application
programmer	O
would	O
use	O
an	O
indexer	O
.	O
</s>
<s>
In	O
both	O
C#	B-Application
and	O
Java	B-Language
,	O
an	O
object	O
's	O
fields	B-Application
can	O
be	O
initialized	O
either	O
by	O
variable	O
initializers	O
(	O
expressions	O
that	O
can	O
be	O
assigned	O
to	O
variables	O
where	O
they	O
are	O
defined	O
)	O
or	O
by	O
constructors	O
(	O
special	O
subroutines	O
that	O
are	O
executed	O
when	O
an	O
object	O
is	O
being	O
created	O
)	O
.	O
</s>
<s>
In	O
addition	O
,	O
Java	B-Language
contains	O
instance	O
initializers	O
,	O
which	O
are	O
anonymous	O
blocks	O
of	O
code	O
with	O
no	O
arguments	O
that	O
are	O
run	O
after	O
the	O
explicit	O
(	O
or	O
implicit	O
)	O
call	O
to	O
a	O
superclass	O
's	O
constructor	O
but	O
before	O
the	O
constructor	O
is	O
executed	O
.	O
</s>
<s>
C#	B-Application
initializes	O
object	O
fields	B-Application
in	O
the	O
following	O
order	O
when	O
creating	O
an	O
object	O
:	O
</s>
<s>
Some	O
of	O
the	O
above	O
fields	B-Application
may	O
not	O
be	O
applicable	O
(	O
e.g.	O
</s>
<s>
if	O
an	O
object	O
does	O
not	O
have	O
static	O
fields	B-Application
)	O
.	O
</s>
<s>
Derived	O
fields	B-Application
are	O
those	O
that	O
are	O
defined	O
in	O
the	O
object	O
's	O
direct	O
class	O
,	O
while	O
base	O
field	O
is	O
a	O
term	O
for	O
the	O
fields	B-Application
that	O
are	O
defined	O
in	O
one	O
of	O
the	O
object	O
's	O
superclasses	O
.	O
</s>
<s>
Note	O
that	O
an	O
object	O
representation	O
in	O
memory	O
contains	O
all	O
fields	B-Application
defined	O
in	O
its	O
class	O
or	O
any	O
of	O
its	O
superclasses	O
,	O
even	O
,	O
if	O
some	O
fields	B-Application
in	O
superclasses	O
are	O
defined	O
as	O
private	O
.	O
</s>
<s>
There	O
is	O
,	O
however	O
,	O
a	O
potential	O
trap	O
in	O
object	O
initialization	O
when	O
a	O
virtual	B-Application
method	I-Application
is	O
called	O
from	O
a	O
base	O
constructor	O
.	O
</s>
<s>
The	O
overridden	O
method	O
in	O
a	O
subclass	O
may	O
reference	O
a	O
field	O
that	O
is	O
defined	O
in	O
the	O
subclass	O
,	O
but	O
this	O
field	O
may	O
not	O
have	O
been	O
initialized	O
because	O
the	O
constructor	O
of	O
the	O
subclass	O
that	O
contains	O
field	O
initialization	O
is	O
called	O
after	O
the	O
constructor	O
of	O
its	O
base	B-Application
class	I-Application
.	O
</s>
<s>
In	O
Java	B-Language
,	O
the	O
order	O
of	O
initialization	O
is	O
as	O
follows	O
:	O
</s>
<s>
Like	O
in	O
C#	B-Application
,	O
a	O
new	O
object	O
is	O
created	O
by	O
calling	O
a	O
specific	O
constructor	O
.	O
</s>
<s>
If	O
this	O
is	O
omitted	O
,	O
the	O
call	O
to	O
the	O
argumentless	O
constructor	O
of	O
the	O
superclass	O
is	O
added	O
implicitly	O
by	O
the	O
compiler	B-Language
.	O
</s>
<s>
In	O
Java	B-Language
,	O
variable	O
initializers	O
are	O
executed	O
according	O
to	O
their	O
textual	O
order	O
in	O
the	O
source	O
file	O
.	O
</s>
<s>
the	O
fields	B-Application
of	O
a	O
base	B-Application
class	I-Application
finish	O
initialization	O
before	O
initialization	O
of	O
the	O
fields	B-Application
of	O
an	O
object	O
class	O
begins	O
.	O
</s>
<s>
There	O
are	O
two	O
main	O
potential	O
traps	O
in	O
Java	B-Language
's	O
object	O
initialization	O
.	O
</s>
<s>
First	O
,	O
variable	O
initializers	O
are	O
expressions	O
that	O
can	O
contain	O
method	B-Language
calls	I-Language
.	O
</s>
<s>
Since	O
methods	B-Language
can	O
reference	O
any	O
variable	O
defined	O
in	O
the	O
class	O
,	O
the	O
method	O
called	O
in	O
a	O
variable	O
initializer	O
can	O
reference	O
a	O
variable	O
that	O
is	O
defined	O
below	O
the	O
variable	O
being	O
initialized	O
.	O
</s>
<s>
Another	O
potential	O
trap	O
is	O
when	O
a	O
method	O
that	O
is	O
overridden	O
in	O
the	O
derived	O
class	O
is	O
called	O
in	O
the	O
base	B-Application
class	I-Application
constructor	O
,	O
which	O
can	O
lead	O
to	O
behavior	O
the	O
programmer	O
would	O
not	O
expect	O
when	O
an	O
object	O
of	O
the	O
derived	O
class	O
is	O
created	O
.	O
</s>
<s>
According	O
to	O
the	O
initialization	O
order	O
,	O
the	O
body	O
of	O
the	O
base	B-Application
class	I-Application
constructor	O
is	O
executed	O
before	O
variable	O
initializers	O
are	O
evaluated	O
and	O
before	O
the	O
body	O
of	O
the	O
derived	O
class	O
constructor	O
is	O
executed	O
.	O
</s>
<s>
The	O
overridden	O
method	O
called	O
from	O
the	O
base	B-Application
class	I-Application
constructor	O
can	O
,	O
however	O
,	O
reference	O
variables	O
defined	O
in	O
the	O
derived	O
class	O
,	O
but	O
these	O
are	O
not	O
yet	O
initialized	O
to	O
the	O
values	O
specified	O
by	O
their	O
initializers	O
or	O
set	O
in	O
the	O
derived	O
class	O
constructor	O
.	O
</s>
<s>
The	O
latter	O
issue	O
applies	O
to	O
C#	B-Application
as	O
well	O
,	O
but	O
in	O
a	O
less	O
critical	O
form	O
since	O
in	O
C#	B-Application
methods	B-Language
are	O
not	O
overridable	O
by	O
default	O
.	O
</s>
<s>
Both	O
languages	O
mainly	O
use	O
garbage	B-General_Concept
collection	I-General_Concept
as	O
a	O
means	O
of	O
reclaiming	O
memory	O
resources	O
,	O
rather	O
than	O
explicit	O
deallocation	O
of	O
memory	O
.	O
</s>
<s>
Both	O
C#	B-Application
and	O
Java	B-Language
offer	O
interfaces	B-Application
for	O
such	O
deterministic	O
disposal	B-Application
and	O
both	O
C#	B-Application
and	O
Java	B-Language
(	O
since	O
Java	B-Language
7	O
)	O
feature	O
automatic	O
resource	O
management	O
statements	O
that	O
will	O
automatically	O
invoke	O
the	O
disposal/close	O
methods	B-Language
on	O
those	O
interfaces	B-Application
.	O
</s>
<s>
Using	O
a	O
special	O
this	O
designator	O
on	O
the	O
first	O
parameter	O
of	O
a	O
method	O
,	O
C#	B-Application
allows	O
the	O
method	O
to	O
act	O
as	O
if	O
it	O
were	O
a	O
member	O
method	O
of	O
the	O
type	O
of	O
the	O
first	O
parameter	O
.	O
</s>
<s>
The	O
method	O
must	O
obey	O
any	O
member	O
access	O
restriction	O
like	O
any	O
other	O
method	O
external	O
to	O
the	O
class	O
;	O
thus	O
static	B-Language
methods	I-Language
cannot	O
break	O
object	O
encapsulation	O
.	O
</s>
<s>
Since	O
Java	B-Language
8	O
,	O
Java	B-Language
has	O
a	O
similar	O
feature	O
called	O
default	O
methods	B-Language
,	O
which	O
are	O
methods	B-Language
with	O
a	O
body	O
declared	O
on	O
interfaces	B-Application
.	O
</s>
<s>
As	O
opposed	O
to	O
C#	B-Application
extension	O
methods	B-Language
,	O
Java	B-Language
default	O
methods	B-Language
are	O
instance	B-Language
methods	I-Language
on	O
the	O
interface	B-Application
that	O
declare	O
them	O
.	O
</s>
<s>
Definition	O
of	O
default	O
methods	B-Language
in	O
classes	O
that	O
implement	O
the	O
interface	B-Application
is	O
optional	O
:	O
If	O
the	O
class	O
does	O
not	O
define	O
the	O
method	O
,	O
the	O
default	O
definition	O
is	O
used	O
instead	O
.	O
</s>
<s>
Both	O
the	O
C#	B-Application
extension	O
methods	B-Language
and	O
the	O
Java	B-Language
default	O
methods	B-Language
allow	O
a	O
class	O
to	O
override	B-Language
the	O
default	O
implementation	O
of	O
the	O
extension/default	O
method	O
,	O
respectively	O
.	O
</s>
<s>
In	O
both	O
languages	O
this	O
override	B-Language
is	O
achieved	O
by	O
defining	O
a	O
method	O
on	O
the	O
class	O
that	O
should	O
use	O
an	O
alternate	O
implementation	O
of	O
the	O
method	O
.	O
</s>
<s>
C#	B-Application
scope	O
rules	O
defines	O
that	O
if	O
a	O
matching	O
method	O
is	O
found	O
on	O
a	O
class	O
,	O
it	O
takes	O
precedence	O
over	O
a	O
matching	O
extension	O
method	O
.	O
</s>
<s>
In	O
Java	B-Language
any	O
class	O
declared	O
to	O
implement	O
an	O
interface	B-Application
with	O
default	O
method	O
is	O
assumed	O
to	O
have	O
the	O
default	O
methods	B-Language
implementations	O
,	O
unless	O
the	O
class	O
implements	O
the	O
method	O
itself	O
.	O
</s>
<s>
Related	O
to	O
partial	O
classes	O
C#	B-Application
allows	O
partial	O
methods	B-Language
to	O
be	O
specified	O
within	O
partial	O
classes	O
.	O
</s>
<s>
This	O
feature	O
allows	O
code	O
to	O
provide	O
a	O
large	O
number	O
of	O
interception	O
points	O
(	O
like	O
the	O
template	O
method	O
GoF	O
design	O
pattern	O
)	O
without	O
paying	O
any	O
runtime	O
overhead	O
if	O
these	O
extension	O
points	O
are	O
not	O
being	O
used	O
by	O
another	O
class	O
part	O
at	O
compile	B-Language
time	O
.	O
</s>
<s>
Java	B-Language
has	O
no	O
corresponding	O
concept	O
.	O
</s>
<s>
Methods	B-Language
in	O
C#	B-Application
are	O
non-virtual	O
by	O
default	O
,	O
and	O
must	O
be	O
declared	O
virtual	B-Application
explicitly	O
,	O
if	O
desired	O
.	O
</s>
<s>
In	O
Java	B-Language
,	O
all	O
non-static	O
non-private	O
methods	B-Language
are	O
virtual	B-Application
.	O
</s>
<s>
Virtuality	O
guarantees	O
that	O
the	O
most	O
recent	O
override	B-Language
for	O
the	O
method	O
will	O
always	O
be	O
called	O
,	O
but	O
incurs	O
a	O
certain	O
runtime	O
cost	O
on	O
invocation	O
as	O
these	O
invocations	O
cannot	O
be	O
normally	O
inlined	O
,	O
and	O
require	O
an	O
indirect	O
call	O
via	O
the	O
virtual	B-Language
method	I-Language
table	I-Language
.	O
</s>
<s>
However	O
,	O
some	O
JVM	B-Language
implementations	O
,	O
including	O
the	O
Oracle	O
reference	O
implementation	O
,	O
implement	O
inlining	O
of	O
the	O
most	O
commonly	O
called	O
virtual	B-Application
methods	I-Application
.	O
</s>
<s>
Java	B-Language
methods	B-Language
are	O
virtual	B-Application
by	O
default	O
(	O
although	O
they	O
can	O
be	O
sealed	O
by	O
using	O
the	O
final	O
modifier	O
to	O
disallow	O
overriding	B-Language
)	O
.	O
</s>
<s>
This	O
means	O
that	O
by	O
default	O
in	O
Java	B-Language
,	O
and	O
only	O
when	O
explicitly	O
enabled	O
in	O
C#	B-Application
,	O
new	O
methods	B-Language
may	O
be	O
defined	O
in	O
a	O
derived	O
class	O
with	O
the	O
same	O
name	O
and	O
signature	O
as	O
those	O
in	O
its	O
base	B-Application
class	I-Application
.	O
</s>
<s>
When	O
the	O
method	O
is	O
called	O
on	O
a	O
superclass	O
reference	O
of	O
such	O
an	O
object	O
,	O
the	O
"	O
deepest	O
"	O
overridden	O
implementation	O
of	O
the	O
base	B-Application
class	I-Application
 '	O
method	O
will	O
be	O
called	O
according	O
to	O
the	O
specific	O
subclass	O
of	O
the	O
object	O
being	O
referenced	O
.	O
</s>
<s>
In	O
some	O
cases	O
,	O
when	O
a	O
subclass	O
introduces	O
a	O
method	O
with	O
the	O
same	O
name	O
and	O
signature	O
as	O
a	O
method	O
already	O
present	O
in	O
the	O
base	B-Application
class	I-Application
,	O
problems	O
can	O
occur	O
.	O
</s>
<s>
In	O
Java	B-Language
,	O
this	O
will	O
mean	O
that	O
the	O
method	O
in	O
the	O
derived	O
class	O
will	O
implicitly	O
override	B-Language
the	O
method	O
in	O
the	O
base	B-Application
class	I-Application
,	O
even	O
though	O
that	O
may	O
not	O
be	O
the	O
intent	O
of	O
the	O
designers	O
of	O
either	O
class	O
.	O
</s>
<s>
To	O
mitigate	O
this	O
,	O
C#	B-Application
requires	O
that	O
if	O
a	O
method	O
is	O
intended	O
to	O
override	B-Language
an	O
inherited	O
method	O
,	O
the	O
override	B-Language
keyword	O
must	O
be	O
specified	O
.	O
</s>
<s>
If	O
the	O
keyword	O
is	O
absent	O
,	O
compiler	B-Language
warning	O
to	O
this	O
effect	O
is	O
issued	O
,	O
which	O
can	O
be	O
silenced	O
by	O
specifying	O
the	O
new	O
keyword	O
.	O
</s>
<s>
This	O
avoids	O
the	O
problem	O
that	O
can	O
arise	O
from	O
a	O
base	B-Application
class	I-Application
being	O
extended	O
with	O
a	O
non-private	O
method	O
(	O
i.e.	O
</s>
<s>
Java	B-Language
has	O
a	O
similar	O
compiler	B-Language
check	O
in	O
the	O
form	O
of	O
the	O
@Override	O
method	O
annotation	O
,	O
but	O
it	O
is	O
not	O
compulsory	O
,	O
and	O
in	O
its	O
absence	O
,	O
most	O
compilers	B-Language
will	O
not	O
provide	O
comment	O
(	O
but	O
the	O
method	O
will	O
be	O
overridden	O
)	O
.	O
</s>
<s>
In	O
Java	B-Language
,	O
it	O
is	O
possible	O
to	O
prevent	O
reassignment	O
of	O
a	O
local	O
variable	O
or	O
method	O
parameter	O
by	O
using	O
the	O
keyword	O
.	O
</s>
<s>
Applying	O
this	O
keyword	O
to	O
a	O
primitive	O
type	O
variable	O
causes	O
the	O
variable	O
to	O
become	O
immutable	B-Application
.	O
</s>
<s>
However	O
,	O
applying	O
to	O
a	O
reference	B-Language
type	I-Language
variable	O
only	O
prevents	O
that	O
another	O
object	O
is	O
assigned	O
to	O
it	O
.	O
</s>
<s>
As	O
of	O
C	B-Language
#7	O
,	O
it	O
is	O
possible	O
to	O
prevent	O
reassignment	O
of	O
a	O
method	O
parameter	O
by	O
using	O
the	O
in	O
keyword	O
,	O
however	O
this	O
keyword	O
cannot	O
be	O
used	O
on	O
local	O
variables	O
.	O
</s>
<s>
As	O
with	O
Java	B-Language
,	O
applying	O
in	O
to	O
a	O
parameter	O
only	O
prevents	O
the	O
parameter	O
from	O
being	O
reassigned	O
to	O
a	O
different	O
value	O
.	O
</s>
<s>
Both	O
languages	O
do	O
not	O
support	O
essential	O
feature	O
of	O
const-correctness	O
that	O
exists	O
in	O
C/C	B-Language
++	I-Language
,	O
which	O
makes	O
a	O
method	O
constant	O
.	O
</s>
<s>
Java	B-Language
defines	O
the	O
word	O
"	O
constant	O
"	O
arbitrarily	O
as	O
a	O
field	O
.	O
</s>
<s>
As	O
a	O
convention	O
,	O
these	O
variable	O
names	O
are	O
capital-only	O
with	O
words	O
separated	O
with	O
an	O
underscore	O
but	O
the	O
Java	B-Language
language	I-Language
does	O
n't	O
insist	O
on	O
this	O
.	O
</s>
<s>
A	O
parameter	O
that	O
is	O
only	O
is	O
not	O
considered	O
as	O
a	O
constant	O
,	O
although	O
it	O
may	O
be	O
so	O
in	O
the	O
case	O
of	O
a	O
primitive	O
data	O
type	O
or	O
an	O
immutable	B-Application
class	I-Application
,	O
like	O
a	O
.	O
</s>
<s>
Any	O
C#	B-Application
method	O
declared	O
as	O
returning	O
IEnumerable	O
,	O
IEnumerator	O
or	O
the	O
generic	B-Language
versions	O
of	O
these	O
interfaces	B-Application
can	O
be	O
implemented	O
using	O
yield	O
syntax	O
.	O
</s>
<s>
This	O
is	O
a	O
form	O
of	O
limited	O
,	O
compiler-generated	O
continuations	O
and	O
can	O
drastically	O
reduce	O
the	O
code	O
needed	O
to	O
traverse	O
or	O
generate	O
sequences	O
,	O
although	O
that	O
code	O
is	O
just	O
generated	O
by	O
the	O
compiler	B-Language
instead	O
.	O
</s>
<s>
The	O
feature	O
can	O
also	O
be	O
used	O
to	O
implement	O
infinite	O
sequences	O
,	O
e.g.	O
,	O
the	O
sequence	O
of	O
Fibonacci	B-Algorithm
numbers	I-Algorithm
.	O
</s>
<s>
Java	B-Language
does	O
not	O
have	O
an	O
equivalent	O
feature	O
.	O
</s>
<s>
Instead	O
,	O
generators	O
are	O
typically	O
defined	O
by	O
providing	O
a	O
specialized	O
implementation	O
of	O
a	O
well-known	O
collection	O
or	O
iterable	O
interface	B-Application
,	O
which	O
will	O
compute	O
each	O
element	O
on	O
demand	O
.	O
</s>
<s>
For	O
such	O
a	O
generator	O
to	O
be	O
used	O
in	O
a	O
for	O
each	O
statement	O
,	O
it	O
must	O
implement	O
interface	B-Application
java.lang.Iterable	O
.	O
</s>
<s>
See	O
also	O
example	O
Fibonacci	B-Algorithm
sequence	I-Algorithm
below	O
.	O
</s>
<s>
C#	B-Application
also	O
has	O
explicit	O
interface	B-Application
implementation	O
that	O
allows	O
a	O
class	O
to	O
specifically	O
implement	O
methods	B-Language
of	O
an	O
interface	B-Application
,	O
separate	O
to	O
its	O
own	O
class	O
methods	B-Language
,	O
or	O
to	O
provide	O
different	O
implementations	O
for	O
two	O
methods	B-Language
with	O
the	O
same	O
name	O
and	O
signature	O
inherited	O
from	O
two	O
base	O
interfaces	B-Application
.	O
</s>
<s>
In	O
either	O
language	O
,	O
if	O
a	O
method	O
(	O
or	O
property	O
in	O
C#	B-Application
)	O
is	O
specified	O
with	O
the	O
same	O
name	O
and	O
signature	O
in	O
multiple	O
interfaces	B-Application
,	O
the	O
members	O
will	O
clash	B-Application
when	O
a	O
class	O
is	O
designed	O
that	O
implements	O
those	O
interfaces	B-Application
.	O
</s>
<s>
An	O
implementation	O
will	O
by	O
default	O
implement	O
a	O
common	O
method	O
for	O
all	O
of	O
the	O
interfaces	B-Application
.	O
</s>
<s>
If	O
separate	O
implementations	O
are	O
needed	O
(	O
because	O
the	O
methods	B-Language
serve	O
separate	O
purposes	O
,	O
or	O
because	O
return	O
values	O
differ	O
between	O
the	O
interfaces	B-Application
)	O
C#'s	O
explicit	O
interface	B-Application
implementation	O
will	O
solve	O
the	O
problem	O
,	O
though	O
allowing	O
different	O
results	O
for	O
the	O
same	O
method	O
,	O
depending	O
on	O
the	O
current	O
cast	O
of	O
the	O
object	O
.	O
</s>
<s>
In	O
Java	B-Language
there	O
is	O
no	O
way	O
to	O
solve	O
this	O
problem	O
other	O
than	O
refactoring	O
one	O
or	O
more	O
of	O
the	O
interfaces	B-Application
to	O
avoid	O
name	O
clashes	B-Application
.	O
</s>
<s>
int	O
,	O
double	O
)	O
to	O
a	O
method	O
are	O
passed	O
by	O
value	O
in	O
Java	B-Language
whereas	O
objects	O
are	O
passed	O
by	O
reference	O
.	O
</s>
<s>
In	O
C#	B-Application
,	O
it	O
is	O
possible	O
to	O
enforce	O
a	O
reference	O
with	O
the	O
ref	O
keyword	O
,	O
similar	O
to	O
C++	B-Language
and	O
in	O
a	O
sense	O
to	O
C	B-Language
.	O
This	O
feature	O
of	O
C#	B-Application
is	O
particularly	O
useful	O
when	O
one	O
wants	O
to	O
create	O
a	O
method	O
that	O
returns	O
more	O
than	O
one	O
object	O
.	O
</s>
<s>
In	O
Java	B-Language
trying	O
to	O
return	O
multiple	O
values	O
from	O
a	O
method	O
is	O
unsupported	O
unless	O
a	O
wrapper	O
is	O
used	O
,	O
in	O
this	O
case	O
named	O
"	O
Ref	O
"	O
.	O
</s>
<s>
Java	B-Language
supports	O
checked	O
exceptions	O
(	O
along	O
with	O
unchecked	O
exceptions	O
)	O
.	O
</s>
<s>
C#	B-Application
only	O
supports	O
unchecked	O
exceptions	O
.	O
</s>
<s>
However	O
Anders	O
Hejlsberg	O
,	O
chief	O
C#	B-Application
language	O
architect	O
,	O
argues	O
that	O
they	O
were	O
to	O
some	O
extent	O
an	O
experiment	O
in	O
Java	B-Language
and	O
that	O
they	O
have	O
not	O
been	O
shown	O
to	O
be	O
worthwhile	O
except	O
in	O
small	O
example	O
programs	O
.	O
</s>
<s>
In	O
Java	B-Language
,	O
this	O
may	O
result	O
in	O
unexpected	O
behavior	O
,	O
if	O
the	O
try	O
block	O
is	O
left	O
by	O
a	O
return	O
statement	O
with	O
some	O
value	O
,	O
and	O
then	O
the	O
finally	O
block	O
that	O
is	O
executed	O
afterward	O
is	O
also	O
left	O
by	O
a	O
return	O
statement	O
with	O
a	O
different	O
value	O
.	O
</s>
<s>
C#	B-Application
resolves	O
this	O
problem	O
by	O
prohibiting	O
any	O
control-passing	O
statements	O
like	O
return	O
or	O
break	O
in	O
the	O
finally	O
block	O
.	O
</s>
<s>
C#	B-Application
features	O
the	O
using	O
statement	O
as	O
a	O
syntactic	O
shorthand	O
for	O
this	O
common	O
scenario	O
,	O
in	O
which	O
the	O
Dispose( )	O
method	O
of	O
the	O
object	O
of	O
the	O
using	O
is	O
always	O
called	O
.	O
</s>
<s>
A	O
rather	O
subtle	O
difference	O
is	O
the	O
moment	O
a	O
stack	B-Language
trace	I-Language
is	O
created	O
when	O
an	O
exception	O
is	O
being	O
thrown	O
.	O
</s>
<s>
In	O
Java	B-Language
,	O
the	O
stack	B-Language
trace	I-Language
is	O
created	O
in	O
the	O
moment	O
the	O
exception	O
is	O
created	O
.	O
</s>
<s>
In	O
C#	B-Application
on	O
the	O
other	O
hand	O
,	O
the	O
stack-trace	O
is	O
created	O
the	O
moment	O
"	O
throw	O
"	O
is	O
executed	O
.	O
</s>
<s>
When	O
catching	O
an	O
exception	O
,	O
there	O
are	O
two	O
options	O
in	O
case	O
the	O
exception	O
should	O
be	O
rethrown	O
:	O
throw	O
will	O
just	O
rethrow	O
the	O
original	O
exception	O
with	O
the	O
original	O
stack	O
,	O
while	O
throw	O
e	O
would	O
have	O
created	O
a	O
new	O
stack	B-Language
trace	I-Language
.	O
</s>
<s>
Java	B-Language
allows	O
flow	O
of	O
control	O
to	O
leave	O
the	O
finally	O
block	O
of	O
a	O
try	O
statement	O
,	O
regardless	O
of	O
the	O
way	O
it	O
was	O
entered	O
.	O
</s>
<s>
C#	B-Application
does	O
not	O
allow	O
any	O
statements	O
that	O
allow	O
control	O
flow	O
to	O
leave	O
the	O
finally	O
block	O
prematurely	O
,	O
except	O
for	O
throw	O
.	O
</s>
<s>
In	O
the	O
field	O
of	O
generics	B-Language
the	O
two	O
languages	O
show	O
a	O
superficial	O
syntactical	O
similarity	O
,	O
but	O
they	O
have	O
deep	O
underlying	O
differences	O
.	O
</s>
<s>
Generics	B-Language
in	I-Language
Java	I-Language
are	O
a	O
language-only	O
construction	O
;	O
they	O
are	O
implemented	O
only	O
in	O
the	O
compiler	B-Language
.	O
</s>
<s>
The	O
generated	O
classfiles	O
include	O
generic	B-Language
signatures	O
only	O
in	O
form	O
of	O
metadata	O
(	O
allowing	O
the	O
compiler	B-Language
to	O
compile	B-Language
new	O
classes	O
against	O
them	O
)	O
.	O
</s>
<s>
The	O
runtime	O
has	O
no	O
knowledge	O
of	O
the	O
generic	B-Language
type	I-Language
system	O
;	O
generics	B-Language
are	O
not	O
part	O
of	O
the	O
JVM	B-Language
.	O
</s>
<s>
Instead	O
,	O
generics	B-Language
classes	O
and	O
methods	B-Language
are	O
transformed	O
during	O
compiling	B-Language
via	O
a	O
process	O
termed	O
type	B-General_Concept
erasure	I-General_Concept
.	O
</s>
<s>
During	O
this	O
,	O
the	O
compiler	B-Language
replaces	O
all	O
generic	B-Language
types	I-Language
with	O
their	O
raw	O
version	O
and	O
inserts	O
casts/checks	O
appropriately	O
in	O
client	O
code	O
where	O
the	O
type	O
and	O
its	O
methods	B-Language
are	O
used	O
.	O
</s>
<s>
The	O
resulting	O
byte	B-Application
code	O
will	O
contain	O
no	O
references	O
to	O
any	O
generic	B-Language
types	I-Language
or	O
parameters	O
(	O
See	O
also	O
Generics	B-Language
in	I-Language
Java	I-Language
)	O
.	O
</s>
<s>
The	O
Java	B-Language
language	I-Language
specification	I-Language
intentionally	O
prohibits	O
certain	O
uses	O
of	O
generics	B-Language
;	O
this	O
is	O
necessary	O
to	O
allow	O
for	O
implementing	O
generics	B-Language
through	O
type	B-General_Concept
erasure	I-General_Concept
,	O
and	O
to	O
allow	O
for	O
migration	O
compatibility	O
.	O
</s>
<s>
Research	O
into	O
adding	O
reified	O
generics	B-Language
to	O
the	O
Java	B-Language
platform	O
is	O
ongoing	O
,	O
as	O
part	O
of	O
Project	O
Valhalla	O
.	O
</s>
<s>
C#	B-Application
builds	O
on	O
support	O
for	O
generics	B-Language
from	O
the	O
virtual	B-Application
execution	O
system	O
,	O
i.e.	O
,	O
it	O
is	O
not	O
just	O
a	O
language	O
feature	O
.	O
</s>
<s>
The	O
language	O
is	O
merely	O
a	O
front-end	O
for	O
cross-language	O
generics	B-Language
support	O
in	O
the	O
CLR	O
.	O
</s>
<s>
During	O
compiling	B-Language
generics	B-Language
are	O
verified	O
for	O
correctness	O
,	O
but	O
code	B-Application
generation	I-Application
to	O
implement	O
the	O
generics	B-Language
are	O
deferred	O
to	O
class-load	O
time	O
.	O
</s>
<s>
Client	O
code	O
(	O
code	O
invoking	O
generic	B-Language
methods/properties	O
)	O
are	O
fully	O
compiled	B-Language
and	O
can	O
safely	O
assume	O
generics	B-Language
to	O
be	O
type-safe	O
.	O
</s>
<s>
During	O
the	O
generation	O
of	O
method	O
implementations	O
all	O
reference	B-Language
types	I-Language
will	O
be	O
considered	O
one	O
type	O
,	O
as	O
reference	B-Language
types	I-Language
can	O
safely	O
share	O
the	O
same	O
implementations	O
.	O
</s>
<s>
Different	O
sets	O
of	O
reference	B-Language
types	I-Language
will	O
still	O
have	O
unique	O
type	O
descriptors	O
;	O
their	O
method	O
tables	O
will	O
merely	O
point	O
to	O
the	O
same	O
code	O
.	O
</s>
<s>
The	O
following	O
list	O
illustrates	O
some	O
differences	O
between	O
Java	B-Language
and	O
C#	B-Application
when	O
managing	O
generics	B-Language
.	O
</s>
<s>
Java	B-Language
C#	B-Application
Type	O
checks	O
and	O
downcasts	O
are	O
injected	O
into	O
client	O
code	O
(	O
the	O
code	O
referencing	O
the	O
generics	B-Language
)	O
.	O
</s>
<s>
Compared	O
to	O
non-generic	O
code	O
with	O
manual	O
casts	O
,	O
these	O
casts	O
will	O
be	O
the	O
same	O
,	O
but	O
compared	O
to	O
compile-time	O
verified	O
code	O
that	O
would	O
not	O
need	O
runtime	O
casts	O
and	O
checks	O
,	O
these	O
operations	O
represent	O
a	O
performance	O
overhead	O
.	O
</s>
<s>
C#	B-Application
/.NET	O
generics	B-Language
guarantee	O
type-safety	O
and	O
are	O
verified	O
at	O
compile	B-Language
time	O
,	O
making	O
extra	O
checks/casts	O
are	O
unnecessary	O
at	O
runtime	O
.	O
</s>
<s>
Hence	O
,	O
generic	B-Language
code	O
will	O
run	O
faster	O
than	O
non-generic	O
(	O
or	O
type-erased	O
)	O
code	O
that	O
require	O
casts	O
when	O
handling	O
non-generic	O
or	O
type-erased	O
objects	O
.	O
</s>
<s>
This	O
incurs	O
extra	O
performance	O
overhead	O
by	O
requiring	O
boxing	O
and	O
unboxing	O
conversions	O
as	O
well	O
a	O
memory	O
and	O
garbage	B-General_Concept
collection	I-General_Concept
pressure	O
,	O
as	O
the	O
wrappers	O
will	O
be	O
heap-allocated	O
as	O
opposed	O
to	O
stack-allocated	O
.	O
</s>
<s>
Primitive	O
and	O
value	O
types	O
are	O
allowed	O
as	O
type	O
parameters	O
in	O
generic	B-Language
realizations	O
.	O
</s>
<s>
At	O
runtime	O
code	O
will	O
be	O
synthesized	O
and	O
compiled	B-Language
for	O
each	O
unique	O
combination	O
of	O
type	O
parameters	O
upon	O
first	O
use	O
.	O
</s>
<s>
Generics	B-Language
that	O
are	O
realized	O
with	O
primitive/value	O
type	O
do	O
not	O
require	O
boxing/unboxing	O
conversions	O
.	O
</s>
<s>
Generic	B-Language
exceptions	O
are	O
not	O
allowed	O
and	O
a	O
type	O
parameter	O
cannot	O
be	O
used	O
in	O
a	O
catch	O
clause	O
Can	O
both	O
define	O
generic	B-Language
exceptions	O
and	O
use	O
those	O
in	O
catch	O
clauses	O
Static	O
members	O
are	O
shared	O
across	O
all	O
generic	B-Language
realizations	O
(	O
during	O
type	B-General_Concept
erasure	I-General_Concept
all	O
realizations	O
are	O
folded	O
into	O
a	O
single	O
class	O
)	O
Static	O
members	O
are	O
separate	O
for	O
each	O
generic	B-Language
realization	O
.	O
</s>
<s>
A	O
generic	B-Language
realization	O
is	O
a	O
unique	O
class	O
.	O
</s>
<s>
}	O
Type	O
parameters	O
represent	O
actual	O
,	O
discrete	O
classes	O
and	O
can	O
be	O
used	O
like	O
any	O
other	O
type	O
within	O
the	O
generic	B-Language
definition	O
.	O
</s>
<s>
}	O
There	O
is	O
no	O
class	O
literal	O
for	O
a	O
concrete	O
realization	O
of	O
a	O
generic	B-Language
type	I-Language
A	O
generic	B-Language
realization	O
is	O
an	O
actual	O
class	O
.	O
</s>
<s>
instanceof	O
is	O
not	O
allowed	O
with	O
type	O
parameters	O
or	O
concrete	O
generic	B-Language
realizations	O
The	O
is	O
and	O
as	O
operators	O
work	O
the	O
same	O
for	O
type	O
parameters	O
as	O
for	O
any	O
other	O
type	O
.	O
</s>
<s>
Cannot	O
create	O
new	O
instances	O
using	O
a	O
type	O
parameter	O
as	O
the	O
type	O
With	O
a	O
constructor	O
constraint	O
,	O
generic	B-Language
methods	B-Language
or	O
methods	B-Language
of	O
generic	B-Language
classes	O
can	O
create	O
instances	O
of	O
classes	O
that	O
have	O
default	O
constructors	O
.	O
</s>
<s>
Type	O
information	O
is	O
erased	O
during	O
compiling	B-Language
.	O
</s>
<s>
Special	O
extensions	O
to	O
reflection	B-Language
must	O
be	O
used	O
to	O
discover	O
the	O
original	O
type	O
.	O
</s>
<s>
Type	O
information	O
about	O
C#	B-Application
generic	B-Language
types	I-Language
is	O
fully	O
preserved	O
at	O
runtime	O
,	O
and	O
allows	O
full	O
reflection	B-Language
support	O
and	O
instantiation	O
of	O
generic	B-Language
types	I-Language
.	O
</s>
<s>
Reflection	B-Language
cannot	O
be	O
used	O
to	O
construct	O
new	O
generic	B-Language
realizations	O
.	O
</s>
<s>
During	O
compilation	B-Language
extra	O
code	O
(	O
typecasts	O
)	O
are	O
injected	O
into	O
the	O
client	O
code	O
of	O
generics	B-Language
.	O
</s>
<s>
Reflection	B-Language
can	O
be	O
used	O
to	O
create	O
new	O
realizations	O
for	O
new	O
combinations	O
of	O
type	O
parameters	O
.	O
</s>
<s>
C#	B-Application
allows	O
generics	B-Language
directly	O
for	O
primitive	O
types	O
.	O
</s>
<s>
Java	B-Language
,	O
instead	O
,	O
allows	O
the	O
use	O
of	O
boxed	O
types	O
as	O
type	O
parameters	O
(	O
e.g.	O
,	O
Listxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
)	O
.	O
</s>
<s>
However	O
,	O
a	O
generic	B-Language
type	I-Language
can	O
be	O
specialized	O
with	O
an	O
array	O
type	O
of	O
a	O
primitive	O
type	O
in	O
Java	B-Language
,	O
for	O
example	O
Listxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
is	O
allowed	O
.	O
</s>
<s>
Several	O
third-party	O
libraries	B-Library
implemented	O
the	O
basic	O
collections	B-Application
in	O
Java	B-Language
with	O
backing	O
primitive	O
arrays	B-Data_Structure
to	O
preserve	O
the	O
runtime	O
and	O
memory	O
optimization	O
that	O
primitive	O
types	O
provide	O
.	O
</s>
<s>
Java	B-Language
's	O
type	B-General_Concept
erasure	I-General_Concept
design	O
was	O
motivated	O
by	O
a	O
design	O
requirement	O
to	O
achieve	O
migration	O
compatibility	O
–	O
not	O
to	O
be	O
confused	O
with	O
backward	B-General_Concept
compatibility	I-General_Concept
.	O
</s>
<s>
In	O
particular	O
,	O
the	O
original	O
requirement	O
was	O
"	O
…	O
there	O
should	O
be	O
a	O
clean	O
,	O
demonstrable	O
migration	O
path	O
for	O
the	O
Collections	B-Application
APIs	O
that	O
were	O
introduced	O
in	O
the	O
Java	B-Language
2	O
platform	O
"	O
.	O
</s>
<s>
This	O
was	O
designed	O
so	O
that	O
any	O
new	O
generic	B-Language
collections	B-Application
should	O
be	O
passable	O
to	O
methods	B-Language
that	O
expected	O
one	O
of	O
the	O
pre-existing	O
collection	O
classes	O
.	O
</s>
<s>
C#	B-Application
generics	B-Language
were	O
introduced	O
into	O
the	O
language	O
while	O
preserving	O
full	O
backward	B-General_Concept
compatibility	I-General_Concept
,	O
but	O
did	O
not	O
preserve	O
full	O
migration	O
compatibility	O
:	O
Old	O
code	O
(	O
pre	O
C#	B-Application
2.0	O
)	O
runs	O
unchanged	O
on	O
the	O
new	O
generics-aware	O
runtime	O
without	O
recompilation	O
.	O
</s>
<s>
As	O
for	O
migration	O
compatibility	O
,	O
new	O
generic	B-Language
collection	O
classes	O
and	O
interfaces	B-Application
were	O
developed	O
that	O
supplemented	O
the	O
non-generic	O
.NET	O
1.x	O
collections	B-Application
rather	O
than	O
replacing	O
them	O
.	O
</s>
<s>
In	O
addition	O
to	O
generic	B-Language
collection	O
interfaces	B-Application
,	O
the	O
new	O
generic	B-Language
collection	O
classes	O
implement	O
the	O
non-generic	O
collection	O
interfaces	B-Application
where	O
possible	O
.	O
</s>
<s>
This	O
prevents	O
the	O
use	O
of	O
new	O
generic	B-Language
collections	B-Application
with	O
pre-existing	O
(	O
non-generic	O
aware	O
)	O
methods	B-Language
,	O
if	O
those	O
methods	B-Language
are	O
coded	O
to	O
use	O
the	O
collection	O
classes	O
.	O
</s>
<s>
Java	B-Language
has	O
use-site	O
variance	O
that	O
allows	O
a	O
single	O
generic	B-Language
class	I-Language
to	O
declare	O
members	O
using	O
both	O
co	O
-	O
and	O
contravariance	O
.	O
</s>
<s>
C#	B-Application
has	O
define-site	O
variance	O
for	O
generic	B-Language
interfaces	B-Application
and	O
delegates	O
.	O
</s>
<s>
Variance	O
is	O
unsupported	O
directly	O
on	O
classes	O
but	O
is	O
supported	O
through	O
their	O
implementation	O
of	O
variant	O
interfaces	B-Application
.	O
</s>
<s>
C#	B-Application
also	O
has	O
use-site	O
covariance	O
support	O
for	O
methods	B-Language
and	O
delegates	O
.	O
</s>
<s>
A	O
closure	B-Language
is	O
an	O
inline	O
function	O
that	O
captures	O
variables	O
from	O
its	O
lexical	O
scope	O
.	O
</s>
<s>
C#	B-Application
supports	O
closures	B-Language
as	O
anonymous	B-General_Concept
methods	I-General_Concept
or	O
lambda	B-General_Concept
expressions	I-General_Concept
with	O
full-featured	O
closure	B-Language
semantics	O
.	O
</s>
<s>
In	O
Java	B-Language
,	O
anonymous	O
inner	O
classes	O
will	O
remain	O
the	O
preferred	O
way	O
to	O
emulate	O
closures	B-Language
until	O
Java	B-Language
8	O
has	O
become	O
the	O
new	O
standard	O
.	O
</s>
<s>
This	O
approach	O
also	O
has	O
some	O
differences	O
compared	O
to	O
real	O
closures	B-Language
,	O
notably	O
more	O
controlled	O
access	O
to	O
variables	O
from	O
the	O
enclosing	O
scopes	O
:	O
only	O
final	O
members	O
can	O
be	O
referenced	O
.	O
</s>
<s>
Java	B-Language
8	O
,	O
however	O
introduces	O
lambdas	B-General_Concept
that	O
fully	O
inherit	O
the	O
current	O
scope	O
and	O
,	O
in	O
fact	O
,	O
do	O
not	O
introduce	O
a	O
new	O
scope	O
.	O
</s>
<s>
C#	B-Application
closures	B-Language
can	O
access	O
any	O
variable/parameter	O
from	O
its	O
lexical	O
scope	O
.	O
</s>
<s>
In	O
Java	B-Language
's	O
anonymous	O
inner	O
classes	O
,	O
only	O
references	O
to	O
final	O
members	O
of	O
the	O
lexical	O
scope	O
are	O
allowed	O
,	O
thus	O
requiring	O
the	O
developer	O
to	O
mark	O
which	O
variables	O
to	O
make	O
available	O
,	O
and	O
in	O
what	O
state	O
(	O
possibly	O
requiring	O
boxing	O
)	O
.	O
</s>
<s>
C#	B-Application
and	O
Java	B-Language
feature	O
a	O
special	O
type	O
of	O
in-line	O
closures	B-Language
called	O
lambdas	B-General_Concept
.	O
</s>
<s>
These	O
are	O
anonymous	B-General_Concept
methods	I-General_Concept
:	O
they	O
have	O
a	O
signature	O
and	O
a	O
body	O
,	O
but	O
no	O
name	O
.	O
</s>
<s>
They	O
are	O
mainly	O
used	O
to	O
specify	O
local	O
function-valued	O
arguments	O
in	O
calls	O
to	O
other	O
methods	B-Language
,	O
a	O
technique	O
mainly	O
associated	O
with	O
functional	B-Language
programming	I-Language
.	O
</s>
<s>
C#	B-Application
,	O
unlike	O
Java	B-Language
,	O
allows	O
the	O
use	O
of	O
lambda	B-General_Concept
functions	I-General_Concept
as	O
a	O
way	O
to	O
define	O
special	O
data	O
structures	O
called	O
expression	B-Data_Structure
trees	I-Data_Structure
.	O
</s>
<s>
Whether	O
they	O
are	O
seen	O
as	O
an	O
executable	O
function	O
or	O
as	O
a	O
data	O
structure	O
depends	O
on	O
compiler	B-Language
type	O
inference	O
and	O
what	O
type	O
of	O
variable	O
or	O
parameter	O
they	O
are	O
assigned	O
or	O
cast	O
to	O
.	O
</s>
<s>
Lambdas	B-General_Concept
and	O
expression	B-Data_Structure
trees	I-Data_Structure
play	O
key	O
roles	O
in	O
Language	B-Language
Integrated	I-Language
Query	I-Language
(	O
LINQ	B-Language
)	O
.	O
</s>
<s>
In	O
C#	B-Application
,	O
namespaces	O
are	O
similar	O
to	O
those	O
in	O
C++	B-Language
.	O
</s>
<s>
Unlike	O
package	B-Language
names	O
in	O
Java	B-Language
,	O
a	O
namespace	O
is	O
not	O
in	O
any	O
way	O
tied	O
to	O
the	O
location	O
of	O
the	O
source	O
file	O
.	O
</s>
<s>
While	O
it	O
is	O
not	O
strictly	O
necessary	O
for	O
a	O
Java	B-Language
source	O
file	O
location	O
to	O
mirror	O
its	O
package	B-Language
directory	O
structure	O
,	O
it	O
is	O
the	O
conventional	O
organization	O
.	O
</s>
<s>
Both	O
languages	O
allow	O
importing	O
of	O
classes	O
(	O
e.g.	O
,	O
import	O
java.util	O
.	O
</s>
<s>
*	O
in	O
Java	B-Language
)	O
,	O
allowing	O
a	O
class	O
to	O
be	O
referenced	O
using	O
only	O
its	O
name	O
.	O
</s>
<s>
To	O
do	O
this	O
,	O
Java	B-Language
allows	O
importing	O
a	O
single	O
class	O
(	O
e.g.	O
,	O
import	O
java.util.List	O
)	O
.	O
</s>
<s>
C#	B-Application
allows	O
importing	O
classes	O
under	O
a	O
new	O
local	O
name	O
using	O
the	O
following	O
syntax	O
:	O
using	O
Console	O
=	O
System.Console	O
.	O
</s>
<s>
It	O
also	O
allows	O
importing	O
specializations	O
of	O
classes	O
in	O
the	O
form	O
of	O
using	O
IntList	O
=	O
System.Collections.Generic.Listxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
.	O
</s>
<s>
Both	O
languages	O
have	O
a	O
static	B-Language
import	I-Language
syntax	O
that	O
allows	O
using	O
the	O
short	O
name	O
of	O
some	O
or	O
all	O
of	O
the	O
static	O
methods/fields	O
in	O
a	O
class	O
(	O
e.g.	O
,	O
allowing	O
foo(bar )	O
where	O
foo( )	O
can	O
be	O
statically	O
imported	O
from	O
another	O
class	O
)	O
.	O
</s>
<s>
C#	B-Application
has	O
a	O
static	O
class	O
syntax	O
(	O
not	O
to	O
be	O
confused	O
with	O
static	O
inner	O
classes	O
in	O
Java	B-Language
)	O
,	O
which	O
restricts	O
a	O
class	O
to	O
only	O
contain	O
static	B-Language
methods	I-Language
.	O
</s>
<s>
C#	B-Application
3.0	O
introduces	O
extension	O
methods	B-Language
to	O
allow	O
users	O
to	O
statically	O
add	O
a	O
method	O
to	O
a	O
type	O
(	O
e.g.	O
,	O
allowing	O
foo.bar( )	O
where	O
bar( )	O
can	O
be	O
an	O
imported	O
extension	O
method	O
working	O
on	O
the	O
type	O
of	O
foo	O
)	O
.	O
</s>
<s>
The	O
Sun	O
Microsystems	O
Java	B-Language
compiler	B-Language
requires	O
that	O
a	O
source	O
file	O
name	O
must	O
match	O
the	O
only	O
public	O
class	O
inside	O
it	O
,	O
while	O
C#	B-Application
allows	O
multiple	O
public	O
classes	O
in	O
the	O
same	O
file	O
,	O
and	O
puts	O
no	O
restrictions	O
on	O
the	O
file	O
name	O
.	O
</s>
<s>
C#	B-Application
2.0	O
and	O
later	O
allows	O
splitting	O
a	O
class	O
definition	O
into	O
several	O
files	O
by	O
using	O
the	O
partial	O
keyword	O
in	O
the	O
source	O
code	O
.	O
</s>
<s>
In	O
Java	B-Language
,	O
a	O
public	O
class	O
will	O
always	O
be	O
in	O
its	O
own	O
source	O
file	O
.	O
</s>
<s>
In	O
C#	B-Application
,	O
source	O
code	O
files	O
and	O
logical	O
units	O
separation	O
are	O
not	O
tightly	O
related	O
.	O
</s>
<s>
Unlike	O
Java	B-Language
,	O
C#	B-Application
implements	O
conditional	B-Application
compilation	I-Application
using	O
preprocessor	B-General_Concept
directives	O
.	O
</s>
<s>
It	O
also	O
provides	O
a	O
Conditional	B-Language
attribute	O
to	O
define	O
methods	B-Language
that	O
are	O
only	O
called	O
when	O
a	O
given	O
compilation	B-Language
constant	O
is	O
defined	O
.	O
</s>
<s>
Since	O
version	O
1.4	O
,	O
Java	B-Language
provides	O
a	O
language	O
feature	O
for	O
assertions	O
,	O
which	O
are	O
turned	O
off	O
at	O
runtime	O
by	O
default	O
but	O
can	O
be	O
enabled	O
using	O
the	O
-enableassertions	O
or	O
-ea	O
switch	O
when	O
invoking	O
the	O
JVM	B-Language
.	O
</s>
<s>
Both	O
languages	O
include	O
thread	B-Operating_System
synchronization	O
mechanisms	O
as	O
part	O
of	O
their	O
language	O
syntax	O
.	O
</s>
<s>
Threading	B-Operating_System
and	O
Synchronization	O
Java	B-Language
C	B-Language
#Threads	O
Thread	B-Operating_System
pool	I-Operating_System
Task-based	O
parallelism	O
Fork-join	O
framework	O
included	O
with	O
Java	B-Language
version	O
7	O
.	O
</s>
<s>
In	O
C#	B-Application
5	O
a	O
set	O
of	O
language	O
and	O
compiler	B-Language
extensions	O
was	O
introduced	O
to	O
make	O
it	O
easier	O
to	O
work	O
with	O
the	O
task	O
model	O
.	O
</s>
<s>
These	O
language	O
extensions	O
included	O
the	O
notion	O
of	O
async	O
methods	B-Language
and	O
the	O
await	O
statement	O
that	O
make	O
the	O
program	O
flow	O
appear	O
synchronous	O
.	O
</s>
<s>
From	O
this	O
syntactic	O
sugar	O
the	O
C#	B-Application
compiler	B-Language
generates	O
a	O
state-machine	B-Architecture
that	O
handles	O
the	O
necessary	O
continuations	O
without	O
developers	O
having	O
to	O
think	O
about	O
it	O
.	O
</s>
<s>
Java	B-Language
supports	O
threads	B-Operating_System
since	O
JDK	O
1.0	O
.	O
</s>
<s>
Java	B-Language
offers	O
a	O
high	O
versatility	O
for	O
running	O
threads	B-Operating_System
,	O
often	O
called	O
tasks	O
.	O
</s>
<s>
This	O
is	O
done	O
by	O
implementing	O
a	O
functional	O
interface	B-Application
(	O
a	O
java.lang.Runnable	O
interface	B-Application
)	O
defining	O
a	O
single	O
void	O
no-args	O
method	O
as	O
demonstrated	O
in	O
the	O
following	O
example	O
:	O
</s>
<s>
Similar	O
to	O
C#	B-Application
,	O
Java	B-Language
has	O
a	O
higher	O
level	O
mechanism	O
for	O
working	O
with	O
threads	B-Operating_System
.	O
</s>
<s>
All	O
the	O
threads	B-Operating_System
of	O
an	O
ExecutorServices	O
instance	O
are	O
handled	O
in	O
a	O
pool	B-General_Concept
.	O
</s>
<s>
This	O
is	O
how	O
the	O
first	O
thread-example	O
looks	O
like	O
using	O
executors	O
:	O
</s>
<s>
The	O
ExecutorService	O
instance	O
also	O
supports	O
a	O
Callable	O
interface	B-Application
,	O
another	O
single	O
method	O
interface	B-Application
like	O
Runnable	O
but	O
the	O
signature	O
of	O
the	O
contained	O
method	O
of	O
Callable	O
returns	O
a	O
value	O
.	O
</s>
<s>
In	O
this	O
way	O
,	O
the	O
lambda	B-General_Concept
expression	I-General_Concept
must	O
also	O
return	O
a	O
value	O
,	O
like	O
the	O
below	O
example	O
of	O
calling	O
a	O
website	O
asynchronously	O
as	O
the	O
C#	B-Application
example	O
.	O
</s>
<s>
Calling	O
the	O
method	O
get( )	O
blocks	O
the	O
current	O
thread	B-Operating_System
and	O
waits	O
until	O
the	O
callable	O
completes	O
before	O
returning	O
the	O
value	O
(	O
in	O
the	O
example	O
,	O
a	O
web	O
page	O
content	O
)	O
:	O
</s>
<s>
This	O
wrap	O
it	O
's	O
just	O
to	O
be	O
similar	O
to	O
the	O
C#	B-Application
example	O
since	O
Java	B-Language
does	O
not	O
have	O
keywords	O
like	O
async	O
for	O
the	O
method	O
signature	O
.	O
</s>
<s>
Java	B-Language
's	O
strictfp	B-Language
keyword	O
enables	O
strict	O
floating-point	O
calculations	O
for	O
a	O
region	O
of	O
code	O
.	O
</s>
<s>
This	O
ensures	O
that	O
strict	O
floating-point	O
calculations	O
return	O
exactly	O
the	O
same	O
result	O
on	O
all	O
platforms	B-Device
.	O
</s>
<s>
Without	O
strict	O
floating-point	O
,	O
a	O
platform	O
implementation	O
is	O
free	B-Application
to	O
use	O
higher	O
precision	O
for	O
intermediate	O
results	O
during	O
calculation	O
.	O
</s>
<s>
C#	B-Application
allows	O
an	O
implementation	O
for	O
a	O
given	O
hardware	O
architecture	O
to	O
always	O
use	O
a	O
higher	O
precision	O
for	O
intermediate	O
results	O
if	O
available	O
,	O
i.e.	O
</s>
<s>
C#	B-Application
does	O
not	O
allow	O
the	O
programmer	O
to	O
optionally	O
force	O
intermediate	O
results	O
to	O
use	O
the	O
potential	O
lower	O
precision	O
of	O
single/double	O
.	O
</s>
<s>
Although	O
Java	B-Language
's	O
floating-point	O
arithmetic	O
is	O
largely	O
based	O
on	O
IEEE	O
754	O
(	O
Standard	O
for	O
Binary	O
Floating-Point	O
Arithmetic	O
)	O
,	O
certain	O
features	O
are	O
unsupported	O
even	O
when	O
using	O
the	O
strictfp	B-Language
modifier	O
,	O
such	O
as	O
Exception	O
Flags	O
and	O
Directed	O
Roundings	O
,	O
abilities	O
mandated	O
by	O
IEEE	O
Standard	O
754	O
(	O
see	O
Criticism	O
of	O
Java	B-Language
,	O
Floating	O
point	O
arithmetic	O
)	O
.	O
</s>
<s>
C#	B-Application
provides	O
a	O
built-in	O
decimal	O
type	O
,	O
which	O
has	O
higher	O
precision	O
(	O
but	O
less	O
range	O
)	O
than	O
the	O
Java/C	O
#	O
double	O
.	O
</s>
<s>
The	O
structure	O
uses	O
C#	B-Application
operator	O
overloading	O
so	O
that	O
decimals	O
can	O
be	O
manipulated	O
using	O
operators	O
such	O
as	O
+	O
,	O
-,*	O
and	O
/	O
,	O
like	O
other	O
primitive	O
data	O
types	O
.	O
</s>
<s>
The	O
and	O
types	O
provided	O
with	O
Java	B-Language
allow	O
arbitrary-precision	B-Algorithm
representation	O
of	O
decimal	O
numbers	O
and	O
integer	O
numbers	O
,	O
respectively	O
.	O
</s>
<s>
Java	B-Language
standard	O
library	O
does	O
not	O
have	O
classes	O
to	O
deal	O
with	O
complex	O
numbers	O
.	O
</s>
<s>
The	O
BigInteger	O
,	O
and	O
Complex	O
types	O
provided	O
with	O
C#	B-Application
allow	O
representation	O
and	O
manipulation	O
of	O
arbitrary-precision	B-Algorithm
integers	O
and	O
complex	O
numbers	O
,	O
respectively	O
.	O
</s>
<s>
The	O
structures	O
use	O
C#	B-Application
operator	O
overloading	O
so	O
that	O
instances	O
can	O
be	O
manipulated	O
using	O
operators	O
such	O
as	O
+	O
,	O
-	O
,	O
*	O
,	O
and	O
/	O
,	O
like	O
other	O
primitive	O
data	O
types	O
.	O
</s>
<s>
C#	B-Application
standard	O
library	O
does	O
not	O
have	O
classes	O
to	O
deal	O
with	O
arbitrary-precision	B-Algorithm
floating	O
point	O
numbers	O
(	O
see	O
software	O
for	O
arbitrary-precision	B-Algorithm
arithmetic	I-Algorithm
)	O
.	O
</s>
<s>
C#	B-Application
can	O
help	O
mathematical	O
applications	O
with	O
the	O
checked	O
and	O
unchecked	O
operators	O
that	O
allow	O
the	O
enabling	O
or	O
disabling	O
of	O
run-time	O
checking	O
for	O
arithmetic	B-Algorithm
overflow	I-Algorithm
for	O
a	O
region	O
of	O
code	O
.	O
</s>
<s>
C	B-Language
#s	O
Language	B-Language
Integrated	I-Language
Query	I-Language
(	O
LINQ	B-Language
)	O
is	O
a	O
set	O
of	O
features	O
designed	O
to	O
work	O
together	O
to	O
allow	O
in-language	O
querying	O
abilities	O
and	O
is	O
a	O
distinguishing	O
feature	O
between	O
C#	B-Application
and	O
Java	B-Language
.	O
</s>
<s>
LINQ	B-Language
consists	O
of	O
the	O
following	O
features	O
:	O
</s>
<s>
Extension	O
methods	B-Language
allow	O
existing	O
interfaces	B-Application
or	O
classes	O
to	O
be	O
extended	O
with	O
new	O
methods	B-Language
.	O
</s>
<s>
Implementations	O
can	O
be	O
shared	O
or	O
an	O
interface	B-Application
can	O
have	O
a	O
dedicated	O
implementation	O
.	O
</s>
<s>
Lambdas	B-General_Concept
allow	O
for	O
expression	O
of	O
criteria	O
in	O
a	O
functional	O
fashion	O
.	O
</s>
<s>
Expression	B-Data_Structure
trees	I-Data_Structure
allow	O
a	O
specific	O
implementation	O
to	O
capture	O
a	O
lambda	B-General_Concept
as	O
an	O
abstract	B-Data_Structure
syntax	I-Data_Structure
tree	I-Data_Structure
rather	O
than	O
an	O
executable	O
block	O
.	O
</s>
<s>
in	O
the	O
form	O
of	O
an	O
SQL	B-Language
where	I-Language
clause	I-Language
as	O
is	O
the	O
case	O
with	O
e.g.	O
</s>
<s>
Linq	B-Language
,	I-Language
LINQ	I-Language
to	I-Language
SQL	I-Language
.	O
</s>
<s>
Query	O
expressions	O
to	O
support	O
a	O
syntax	O
familiar	O
to	O
SQL	B-Language
users	O
.	O
</s>
<s>
SQL	B-Language
.	O
</s>
<s>
The	O
Java	B-Language
Native	I-Language
Interface	I-Language
(	O
JNI	B-Language
)	O
feature	O
allows	O
Java	B-Language
programs	O
to	O
call	O
non-Java	O
code	O
.	O
</s>
<s>
However	O
,	O
JNI	B-Language
does	O
require	O
the	O
code	O
being	O
called	O
to	O
follow	O
several	O
conventions	O
and	O
imposes	O
restrictions	O
on	O
types	O
and	O
names	O
used	O
.	O
</s>
<s>
This	O
means	O
that	O
an	O
extra	O
adaption	O
layer	O
between	O
legacy	O
code	O
and	O
Java	B-Language
is	O
often	O
needed	O
.	O
</s>
<s>
This	O
adaption	O
code	O
must	O
be	O
coded	O
in	O
a	O
non-Java	O
language	O
,	O
often	O
C	B-Language
or	O
C++	B-Language
.	O
</s>
<s>
Java	B-Language
Native	I-Language
Access	I-Language
(	O
JNA	B-Language
)	O
allows	O
easier	O
calling	O
of	O
native	O
code	O
that	O
only	O
requires	O
writing	O
Java	B-Language
code	I-Language
,	O
but	O
comes	O
at	O
a	O
performance	O
cost	O
.	O
</s>
<s>
In	O
addition	O
,	O
third	O
party	O
libraries	B-Library
provide	O
Java-Component	O
Object	O
Model	O
(	O
COM	O
)	O
bridging	O
,	O
e.g.	O
,	O
JACOB	O
(	O
free	B-Application
)	O
,	O
and	O
J-Integra	O
for	O
COM	O
(	O
proprietary	B-Application
)	O
.	O
</s>
<s>
.NET	O
Platform	O
Invoke	O
(	O
P/Invoke	O
)	O
offers	O
the	O
same	O
ability	O
by	O
allowing	O
calls	O
from	O
C#	B-Application
to	O
what	O
Microsoft	O
terms	O
unmanaged	O
code	O
.	O
</s>
<s>
Through	O
metadata	O
attributes	O
the	O
programmer	O
can	O
control	O
exactly	O
how	O
the	O
parameters	O
and	O
results	O
are	O
marshalled	B-Application
,	O
thus	O
avoiding	O
the	O
external	O
glue	O
code	O
needed	O
by	O
the	O
equivalent	O
JNI	B-Language
in	O
Java	B-Language
.	O
</s>
<s>
P/Invoke	O
allows	O
almost	O
complete	O
access	O
to	O
procedural	O
APIs	O
(	O
such	O
as	O
Win32	O
or	O
POSIX	O
)	O
,	O
but	O
limited	O
access	O
to	O
C++	B-Language
class	O
libraries	B-Library
.	O
</s>
<s>
C#	B-Application
also	O
allows	O
the	O
programmer	O
to	O
disable	O
the	O
normal	O
type-checking	O
and	O
other	O
safety	O
features	O
of	O
the	O
CLR	O
,	O
which	O
then	O
enables	O
the	O
use	O
of	O
pointer	O
variables	O
.	O
</s>
<s>
JNI	B-Language
,	O
P/Invoke	O
,	O
and	O
"	O
unsafe	O
"	O
code	O
are	O
equally	O
risky	O
features	O
,	O
exposing	O
possible	O
security	O
holes	O
and	O
application	O
instability	O
.	O
</s>
<s>
An	O
advantage	O
of	O
unsafe	O
,	O
managed	O
code	O
over	O
P/Invoke	O
or	O
JNI	B-Language
is	O
that	O
it	O
allows	O
the	O
programmer	O
to	O
continue	O
to	O
work	O
in	O
the	O
familiar	O
C#	B-Application
environment	O
to	O
accomplish	O
some	O
tasks	O
that	O
otherwise	O
would	O
require	O
calling	O
out	O
to	O
unmanaged	O
code	O
.	O
</s>
<s>
An	O
assembly	O
(	O
program	O
or	O
library	O
)	O
using	O
unsafe	O
code	O
must	O
be	O
compiled	B-Language
with	O
a	O
special	O
switch	O
and	O
will	O
be	O
marked	O
as	O
such	O
.	O
</s>
<s>
Java	B-Language
(	O
the	O
programming	O
language	O
)	O
is	O
designed	O
to	O
execute	O
on	O
the	O
Java	B-Language
platform	O
via	O
the	O
Java	B-Language
Runtime	I-Language
Environment	O
(	O
JRE	O
)	O
.	O
</s>
<s>
The	O
Java	B-Language
platform	O
includes	O
the	O
Java	B-Language
virtual	I-Language
machine	I-Language
(	O
JVM	B-Language
)	O
and	O
a	O
common	O
set	O
of	O
libraries	B-Library
.	O
</s>
<s>
The	O
JRE	O
was	O
originally	O
designed	O
to	O
support	O
interpreted	O
execution	O
with	O
final	O
compiling	B-Language
as	O
an	O
option	O
.	O
</s>
<s>
Most	O
JRE	O
environments	O
execute	O
fully	O
or	O
at	O
least	O
partially	O
compiled	B-Language
programs	O
,	O
possibly	O
with	O
adaptive	O
optimization	O
.	O
</s>
<s>
The	O
Java	B-Language
compiler	B-Language
produces	O
Java	B-Language
bytecode	I-Language
.	O
</s>
<s>
Upon	O
execution	O
the	O
bytecode	O
is	O
loaded	O
by	O
the	O
Java	B-Language
runtime	I-Language
and	O
either	O
interpreted	O
directly	O
or	O
compiled	B-Language
to	O
machine	O
instructions	O
and	O
then	O
executed	O
.	O
</s>
<s>
C#	B-Application
is	O
designed	O
to	O
execute	O
on	O
the	O
Common	O
Language	O
Runtime	O
(	O
CLR	O
)	O
.	O
</s>
<s>
The	O
CLR	O
is	O
designed	O
to	O
execute	O
fully	O
compiled	B-Language
code	O
.	O
</s>
<s>
The	O
C#	B-Application
compiler	B-Language
produces	O
Common	O
Intermediate	O
Language	O
instructions	O
.	O
</s>
<s>
Upon	O
execution	O
the	O
runtime	O
loads	O
this	O
code	O
and	O
compiles	B-Language
to	O
machine	O
instructions	O
on	O
the	O
target	O
architecture	O
.	O
</s>
<s>
Java	B-Language
C	B-Language
#import	O
java.nio.file	O
.	O
</s>
<s>
}	O
Notes	O
on	O
the	O
Java	B-Language
implementation	O
:	O
</s>
<s>
Files.write	O
method	O
writes	O
byte	B-Application
array	O
or	O
into	O
an	O
output	O
file	O
,	O
indicated	O
by	O
a	O
Path	O
object	O
.	O
</s>
<s>
Files.write	O
method	O
also	O
takes	O
care	O
of	O
buffering	O
and	O
closing	O
the	O
output	O
stream.Notes	O
on	O
the	O
C#	B-Application
implementation	O
:	O
</s>
<s>
The	O
ReadLines	O
method	O
returns	O
an	O
enumerable	O
object	O
that	O
upon	O
enumeration	B-Language
will	O
read	O
the	O
file	O
one	O
line	O
at	O
a	O
time	O
.	O
</s>
<s>
The	O
WriteAllLines	O
method	O
takes	O
an	O
enumerable	O
and	O
retrieves	O
a	O
line	O
at	O
a	O
time	O
and	O
writes	O
it	O
until	O
the	O
enumeration	B-Language
ends	O
.	O
</s>
<s>
C#	B-Application
allows	O
library-defined	O
types	O
to	O
be	O
integrated	O
with	O
existing	O
types	O
and	O
operators	O
by	O
using	O
custom	O
implicit/explicit	O
conversions	O
and	O
operator	O
overloading	O
as	O
illustrated	O
by	O
the	O
following	O
example	O
:	O
</s>
<s>
var	O
c	B-Language
=	O
a.flatMap	O
( aa	O
->	O
b.map	O
( bb	O
->	O
aa	O
*	O
bb	O
)	O
)	O
;	O
int	O
?	O
</s>
<s>
c	B-Language
=	O
a	O
*	O
b	O
;	O
</s>
<s>
This	O
example	O
illustrates	O
how	O
Java	B-Language
and	O
C#	B-Application
can	O
be	O
used	O
to	O
create	O
and	O
invoke	O
an	O
instance	O
of	O
class	O
that	O
is	O
implemented	O
in	O
another	O
programming	O
language	O
.	O
</s>
<s>
The	O
"	O
Deepthought	O
"	O
class	O
is	O
implemented	O
using	O
the	O
Ruby	B-Language
programming	I-Language
language	I-Language
and	O
represents	O
a	O
simple	O
calculator	O
that	O
will	O
multiply	O
two	O
input	O
values	O
(	O
a	O
and	O
b	O
)	O
when	O
the	O
Calculate	O
method	O
is	O
invoked	O
.	O
</s>
<s>
In	O
addition	O
to	O
the	O
conventional	O
way	O
,	O
Java	B-Language
has	O
GraalVM	B-Language
,	O
a	O
virtual	B-Application
machine	O
capable	O
to	O
run	O
any	O
implemented	O
programming	O
language	O
.	O
</s>
<s>
Value	O
rubyArray	O
=	O
polyglot.eval( "ruby",	O
"[1,2,42,4]"	O
)	O
;	O
</s>
<s>
Value	O
rArray	O
=	O
polyglot.eval	O
(	O
"	O
R	O
"	O
,	O
"	O
c(1,2,42,4 )	O
"	O
)	O
;	O
</s>
<s>
//LLVM	O
(	O
in	O
this	O
case	O
C	B-Language
,	O
but	O
could	O
be	O
C++	B-Language
,	O
Go	O
,	O
Basic	O
,	O
etc	O
...	O
)	O
</s>
<s>
var	O
answer	O
=	O
invocable.invokeMethod(calc, "Calculate" )	O
;	O
Notes	O
for	O
the	O
Java	B-Language
implementation	O
:	O
</s>
<s>
Ruby	B-Language
accessors	O
names	O
are	O
generated	O
from	O
the	O
attribute	O
name	O
with	O
a	O
=	O
suffix	O
.	O
</s>
<s>
When	O
assigning	O
values	O
,	O
Java	B-Language
developers	O
must	O
use	O
the	O
Ruby	B-Language
accessor	O
method	B-Language
name	I-Language
.	O
</s>
<s>
Dynamic	O
objects	O
from	O
a	O
foreign	O
language	O
are	O
not	O
first-class	O
objects	O
in	O
that	O
they	O
must	O
be	O
manipulated	O
through	O
an	O
API.Notes	O
for	O
the	O
C#	B-Application
implementation	O
:	O
</s>
<s>
Objects	O
returned	O
from	O
properties	B-Language
or	O
methods	B-Language
of	O
dynamic	O
objects	O
are	O
themselves	O
of	O
dynamic	O
type	O
.	O
</s>
<s>
Dynamic	O
,	O
late-bounds	O
objects	O
are	O
first-class	O
citizens	O
that	O
can	O
be	O
manipulated	O
using	O
C#	B-Application
syntax	O
even	O
though	O
they	O
have	O
been	O
created	O
by	O
an	O
external	O
language	O
.	O
</s>
<s>
This	O
example	O
illustrates	O
how	O
the	O
Fibonacci	B-Algorithm
sequence	I-Algorithm
can	O
be	O
implemented	O
using	O
the	O
two	O
languages	O
.	O
</s>
<s>
The	O
C#	B-Application
version	O
takes	O
advantage	O
of	O
C#	B-Application
generator	O
methods	B-Language
.	O
</s>
<s>
The	O
Java	B-Language
version	O
takes	O
the	O
advantage	O
of	O
Stream	O
interface	B-Application
and	O
method	O
references	O
.	O
</s>
<s>
Both	O
the	O
Java	B-Language
and	O
the	O
C#	B-Application
examples	O
use	O
K&R	O
style	O
for	O
code	O
formatting	O
of	O
classes	O
,	O
methods	B-Language
and	O
statements	O
.	O
</s>
<s>
}	O
Notes	O
for	O
the	O
Java	B-Language
version	O
:	O
</s>
<s>
The	O
Java	B-Language
8	O
Stream	O
interface	B-Application
is	O
a	O
sequence	O
of	O
elements	O
supporting	O
sequential	O
and	O
parallel	O
aggregate	O
operations	O
.	O
</s>
<s>
The	O
forEach	O
method	O
performs	O
an	O
action	O
for	O
each	O
element	O
of	O
this	O
stream	O
,	O
this	O
action	O
could	O
be	O
a	O
lambda	B-General_Concept
or	O
a	O
method	O
reference	O
.	O
</s>
<s>
The	O
same	O
example	O
above	O
,	O
but	O
using	O
a	O
method	O
returning	O
an	O
Iterable	O
to	O
maintain	O
greater	O
similarity	O
with	O
the	O
C#	B-Application
example	O
.	O
</s>
<s>
Anything	O
that	O
implements	O
the	O
iterable	O
interface	B-Application
can	O
be	O
iterated	O
in	O
a	O
foreach	O
.	O
</s>
<s>
This	O
could	O
be	O
returned	O
from	O
a	O
method	O
like	O
the	O
C#	B-Application
example	O
,	O
but	O
it	O
's	O
unnecessary	O
and	O
could	O
be	O
used	O
directly	O
by	O
just	O
collecting	O
the	O
Stream	O
.	O
</s>
<s>
Also	O
,	O
custom	O
collectors	O
could	O
be	O
created	O
by	O
implementing	O
the	O
Collector	O
interface	B-Application
or	O
describing	O
the	O
implementation	O
as	O
a	O
lambda	B-General_Concept
expression	I-General_Concept
,	O
both	O
cases	O
passing	O
it	O
as	O
arguments	O
to	O
the	O
collect	O
method	O
of	O
the	O
Stream	O
object	O
.	O
</s>
<s>
Both	O
examples	O
could	O
also	O
be	O
done	O
with	O
IntStream	O
and	O
IntSupplier	O
and	O
avoid	O
the	O
Integer	O
generic	B-Language
in	O
the	O
Supplier	O
interface	B-Application
implementation	O
,	O
but	O
the	O
generic	B-Language
is	O
used	O
to	O
preserve	O
greater	O
similarity	O
with	O
the	O
C#	B-Application
example	O
.	O
</s>
<s>
.forEach(System.out::println )	O
;	O
Notes	O
for	O
the	O
C#	B-Application
version	O
:	O
</s>
<s>
The	O
method	O
is	O
defined	O
as	O
returning	O
instances	O
of	O
the	O
interface	B-Application
IEnumerablexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
,	O
which	O
allows	O
client	O
code	O
to	O
repeatedly	O
request	O
the	O
next	O
number	O
of	O
a	O
sequence	O
.	O
</s>
<s>
The	O
yield	O
return	O
statement	O
returns	O
the	O
next	O
number	O
of	O
the	O
sequence	O
and	O
creates	O
a	O
continuation	O
so	O
that	O
subsequent	O
invocations	O
of	O
the	O
IEnumerable	O
interface	B-Application
's	O
MoveNext	O
method	O
will	O
continue	O
execution	O
from	O
the	O
following	O
statement	O
with	O
all	O
local	O
variables	O
intact	O
.	O
</s>
<s>
Tuple-assignment	O
avoids	O
the	O
need	O
to	O
create	O
and	O
use	O
a	O
temporary	O
variable	O
when	O
updating	O
the	O
values	O
of	O
the	O
variables	O
a	O
and	O
b	O
.	O
</s>
