-
Notifications
You must be signed in to change notification settings - Fork 0
Variables
#What is a Variable
A variable is a location in memory that that can hold data that may vary. A variable can be anything from a a number to a string of words. An example of this can be seen in the Strings chapter where we made different literal strings. Numbers can also be variables. In fact, numbers are the main type of variables used when programming. This is especially true when you have a program that will do a lot of math.
#Data Types for Variables
A variable can hold many different values. To hold all these values a variable has many different data types. Below is a table of of the data types for a variable.
Data Type | Description |
---|---|
byte | Byte-length integer |
short | Short integer |
int | Integer |
long | long integer |
float | Single-precision floating point |
double | Double-precision floating point |
char | A single character |
boolean | A Boolean value(true or false) |
#Defining a Variable
Defining a variable is just as simple as defining a String. All you do is you declare the data type, give it a name and if need be define a value for it.