This is not exactley a tutorial, but rather information you should know before you start using Java. I will be refering to in in future tutorials.
Unlike my favorite web-based programming language, PHP, Java requires you to declare your variable to a type.
int x = 0;
String y = “Hello World”;
Below are a list of all the data types in Java and a brief explanation of each.
char: Has the ability to hold a single letter. I’ve never once used this data type.
String: The data type string can hold any string including numbers, letters, and special characters. However you must note that the number 5 stored as a string is NOT evaluated as a number. Also for the longest time I always wondered why String was the only data type with a capital letter. I recently found out that String is a reference to a class. Its default value is evaluated to be “null.”
byte: This data type can hold any numeric integer from -128 to 127. Its default value is evaluated to be “0.”
short: This data type can hold any numeric integer from -32,768 to 32,767. Its default value is evaluated to be “0.”
int: The data type int can hold any numeric integer from -2,147,483,648 to maximum value of 2,147,483,647. Its default value is evaluated to be “0.”
long: The long data type can hold any numeric integer from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Its default value is evaluated to be “0L.”
float: The float data type is used for decimals. I believe it is 32 bytes and has the ability to hold 754 floating points. Its default value is “0.0f”
double: The double data type is also used for decimals. It has more precision than float and is often referred to as double-precision, hence the name. It is 64 bytes and also holds 754 floating points. Its default value is “0.0d”.
boolean: This data type can either store true or false. It is very useful for state functions and is often used in loops. Its default value is “false”.
For the most part, this information applys to other programing languages, but for our porposes, these are the specific data types in Java.


LinkBack URL
About LinkBacks







Reply With Quote



Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum