Think of a variable like a box that has a label and something inside.
The label tells you which box you are referring to, and inside the box you find the contents. In this analogy the box is the variable and the contents inside the box are the "value" of that variable.
Pictured above we have a variable called
x that has a value of
With the power of variables, the same line of code broadcasts two different messages!
The first time we call
bukkit.broadcastMessage(text); the value of
text is `"Minecraft is fun!"
Then we change the value of
Then, when we call
bukkit.broadcastMessage(text); a second time, the value of
For now we are going to focus on Strings and Numbers
A string is a series of characters like "Hello World".
Strings are written with quotes. You can use single or double quotes.
Numbers can be written with or without decimals.
Data types are important because they tell the computer how to handle certain operations such as
For the computer to evaluate the expression
6 + 6 it needs to first identify
6 as a number. Then, once it knows it is combining two numbers, it can add them together to get
To evaluate the expression
"Hello" + "Goodbye" the computer first identifies
"Goodbye" as strings (denoted by the double quotes) and then will concatenate the strings (link them together) to get
As you can see, data types are important because we wouldn't want
6 + 6 to evaluate to
66, and who knows what
"Hello" + "Goodbye" would evaluate to if we tried to add them up!
If we try to combine a number with a string using
+ the computer will treat the number as a string.
6 + "Hello" will be evaluated as
"6" + "Hello" and result in