DEV Community

Cover image for Java Programming #2: Data Types

Posted on • Updated on

Java Programming #2: Data Types

When talking about programming and coding, it cannot be far away from Data. Data by definition means an individual fact, and one example of a fact is the number. In the context of programming, there is a thing called Data Types. From the name itself, Datatype literally means the type of data. The data types in Java is often be refering as the primitive data types.

1. Primitive data types

There are three most common data types used in Java (you can refer to the rest of the types here), in which are int (Integer), double (Double), and char (Character).

Integer is the type of data that is used to store whole number, in which is the number that consists of 0, 1, 2, 3, 4, ... (contains no fractions). Double is the type of data that is used to store decimal number, in which is the number that consists of 0.1, 0.2, 0.3, 0.4, ... (contains fractions). And finally, Character is the type of data that define a character, such as 'a', 'b', 'c'.

You might ask, how about a text? is there any way that Java can define the datatype of a text? The answer is YES, in Java there is a thing called String, String is a "Wrapper" class and I will cover this in later article.

2. Implementation in Java

The following is the coding along with its explanation:

int chicken;
double cow;
char bird;
Enter fullscreen mode Exit fullscreen mode

The above code is the example of the data type implementation in Java. For you that wondering what is "chicken", "cow", and "bird" are, they are the "variable", and is used to store a data / value. To define the data type of a variable, a certain keyword needs to be placed beforehand.

Let us see the variable chicken in here, this variable is an Integer variable, because the keyword int is placed before the variable name. The same concept is also applied with the cow in which a Double variable and lastly the bird that is a Character variable.

Alright, in this article we have seen what is a data type and how to implement it in a variable in Java. Eventhough the variable is already defined with its own data type, we have not define its value yet!, but do not worry, as in the later article, I will show you how to assign a value to each variable corresponding to their own data type.

I hope that my article helps you to getting started in learning Java programming language. You can give this article some comments, as any feedback is very valuable and important to me (also suggest me some ideas that you think I need to cover). Thank you for reading this article, and have a nice day 😃


Top comments (0)