Primitive Data Types In C# Vs Java

The primitive types are predefined by the language and they are named by reserved keywords. They represent the basic types of the language.

C# Vs Java

In C#,

The most famous primitive data types are: int, string, object, short, char, float, double, char, bool. They are called primitive because they are the main built-in types, and could be used to build other data types.

In C#, primitive data types are actually objects, It means when you write the following code, variable foo is actually an Object.

int foo = 10;

If you are coming from other languages like Java, C++, JavaScript, …etc. this might be confusing, and this is true.

The story is, data types like int, short, char, float, double & bool are actually structs. So, when you create a variable, you are creating an instance from it’s structure.

If you are following from the tutorial on “Understanding the Data types”, You should know that int, short, char, float, double & bool are Value type variables; meaning, they store the actual data rather than a reference to it.

All Value types are derived from ValueType Class, which in turns inherits from System.Object class.

That’s why you can trigger the methods defined in System.Object class using foo variable

int foo = 10;

Ok, Enough, let’s move to Java.

In Java,

There are 8 primitive data types: int, short, char, float, double, boolean, …etc. Unlike C#, In Java, variables of a primitive type aren’t Objects; they aren’t a struct nor an object instantiated from a class.

You will also notice that String is not a primitive data type in Java, It falls into another category, usually called “Complex Objects or Reference” data types.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.