Purpose?
I'm currently learning about JAVA and I'm getting confused about data types, so I organize what I'm understanding in this page. Also This is my English practice to explain something about programming in English. So if there's any wrong points for choosing words, welcome to comment.
First, What is a data type?
In Java, Data type should be declared when Value is declared.
Why does data type needs to be declared?
Declaring data type is not necessary actually. Some languages are not needed to declare the datatype. It's called Dynamically typed and statically typed Languages. Dynamically typed Languages doesn't need to declare the data type and Statically typed languages needs to declare the datatype.
- Dynamically typed Languages : JavaScript / Python / Ruby /
- Statically typed languages : C / C++ / C# / Java / Scala / Swift
There are different advantages to declare or not to declare the datatypes. I summarized it in the another article.
What's advantages of declaring variables?
When I learn Java, I was wondering why variables should be declared.
There are two categories of data type
JAVA is roughly divided into two data types: Primitive types and Reference types.
What is primitive types?
Primitive types are types that contain specific values such as numbers and characters. There are eight types.
Primitives | Values |
boolean | True or False (1 Bit) |
byte | whole numbers from -128 to 127(8bit) |
char | a word (Express 16 bit numbers of Unicode) |
short | whole numbers from -32,768 to 32,767(16 bit) |
int | whole numbers from -2,147,483,648 to 2,147,483,647(16 bit) |
long | whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807(32 bit) |
float | fractional numbers / Sufficient for storing 6 to 7 decimal digits(32 bit) |
double | fractional numbers / Sufficient for storing 15 decimal digits(64 bit) |
What is reference types?
Primitive types specifies type of values, reference types refer to objects. In this types, the programmer creates the value by themselves unlike Primitive types. (primitive types are already defined by Java).