Data Types
A data type is an important step in creating a variable. Data types are used to declare what type of specific data the variable can hold. For example, in my short film I use four different primitive data types, these are: int, which holds numbers without decimal places; float, which holds numbers with decimal places, this also means float can hold whole numbers, for example if the number was 1, float would store it as 1.0; boolean, which holds true or false; and String, which holds sentences contained by quotes.
Once the data type has been declared, it needs to be named. Data names must only include alphanumeric characters and underscores, with no spaces. In my short film the characters (data types) are named as follows:
int Ivy
float Francine
boolean Barry
String Sadie
(Please note that they do not need alliteration, I have only done this for the purpose of the film.)
Once the data type has been declared and named, it is then possible to assign a value to it, or leave it empty until you know what you wish to assign to it. For example if we take String, the variable would be created as follows:
String Sadie = “Remember String Sadie can only hold words”;
The data stored in this variable is “Remember String Sadie can only hold words”.
Data types and variables go together to create what is essentially the computer’s memory. They are used to remember information, change that information and use that information.
No comments:
Post a Comment