Hello and Welcome to Java Blog #2, Java: Data Types. This post will introduce the data types, int, char, String, boolean, and double in Java.
int:
In Java, and many other programming languages, int is for integers.
In Java, the int category is any whole number from - 2,147,483,648 to 2,147,483,647 inclusive. int is usually used when creating a variable, which will be explained in a different post, with a whole number value in this range.
char:
In Java, char basically stands for character. These store a single character, inside quotes. They can only store one character no matter what. For example:
'A' falls under the category of chars, but 'Java' does not. This is because 'A' is a single character, whereas 'Java' is more than one character. When using or defining a char, it goes in quotes.
String:
Strings are similar to chars. Just like chars, Strings go in quotes. However, Strings can store multiple characters. The 'Java' example from chars is a String.
Boolean:
In Java, or any other language, Booleans can only have two possible values. These are true or false. When you do something like define a variable, if you define it as a boolean, then the variable can either be true, or it can be false.
Double:
Finally, doubles. Doubles are numeric, like ints. However, doubles can hold up to 15 decimal places, whereas ints cannot hold decimal places. Doubles' range of values is also way more than that of int. Ints only go up till the positive and negative billions, whereas doubles can go much farther than that.
Thank you for reading, Java: Data Types. Please leave any comments or questions in the comments section! Also, to know how to use these data types to define variables, look out for the Java: Variables post which will come later.
Comments
Post a Comment