0% found this document useful (0 votes)
135 views7 pages

Material 2

The document outlines some key differences between Java and C# in terms of syntax, concepts, and language features. Specifically, it discusses differences in how the main method is declared, print statements are written, constants are defined, inheritance is specified, and primitive types are handled. Overall, the document shows that while Java and C# are similar, C# modifies some existing concepts and includes additional language features not present in Java.

Uploaded by

Soo Lian Kei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
135 views7 pages

Material 2

The document outlines some key differences between Java and C# in terms of syntax, concepts, and language features. Specifically, it discusses differences in how the main method is declared, print statements are written, constants are defined, inheritance is specified, and primitive types are handled. Overall, the document shows that while Java and C# are similar, C# modifies some existing concepts and includes additional language features not present in Java.

Uploaded by

Soo Lian Kei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Material 2

Differences with JAVA!


1.

2.

3.

Subtle Differences in terms of syntax of


Java and C#
Slight modification of concepts in C# that
already exist in Java
Language features and concepts that do not
exist in Java at all.

1.

Differences in terms of Syntax:

Java main C# Main


Java:
public static void main(String[] args)

C#:
static void Main(string[] args)

string is shorthand for the System.String class in C#. Another


interesting point is that in C#, your Main method can actually be
declared to be parameter-less

static void Main()

1.

Differences in terms of Syntax:

Print statements
Java:
System.out.println("Hello world!");

C#:
System.Console.WriteLine("Hello world!");
or
Console.WriteLine("Hello again!");

1.

Differences in terms of Syntax:

Declaring Constants
Java:

In Java, compile-time constant values are declared inside a class as

static final int K = 100;

C#:

To declare constants in C# the const keyword is used for compile time


constants while the readonly keyword is used for runtime constants. The
semantics of constant primitives and object references in C# is the same as
in Java.

const int K = 100;

1.

Differences in terms of Syntax:

Inheritance

C# uses C++ syntax for inheritance, both for class inheritance and interface
implementation as opposed to the extends and implements keywords.

Java:
class B extends A implements Comparable
{

C#:
class B:A, IComparable
{

1.

Differences in terms of Syntax:

Primitive Types

In Java, all integer primitive types (byte, short, int, long) are signed by
default.
In C# there are both signed and unsigned varieties of these types:
Unsigned
Signed
Size
byte
sbyte
8 bits
ushort
short
16 bits
uint
int
32 bits
ulong
long
64 bits
The only significantly different primitive in C# is the decimal type, a type
which stores decimal numbers without rounding errors. Eg:
decimal dec = 100.44m;

You might also like