You can use expressions like += and -= to change the value of a variable
without having to repeat its name. Hey, less typing. I like it. 2
If you're just adding 1 or subtracting 1, then there's an even easier way of
int health = 50;
health--; // Subtracts 1 from health
health++; // Adds 1 to health
In case you want to get really fancy and use more advanced math, including
trig functions like sine and cosine, constants like pi, and that sort of thing,
Java has libraries with all of that ready for you to use.
Strings of Characters
There's more to the world than numbers, though. While your government or
school may know you as a string of numbers like #132-54-7843, your friends
call you by a name that's a string of characters, like “Jack” or “Jill” or “Notch.”
In Java, you use a String type to handle strings of characters. We'll use strings
in Minecraft a lot, for names of players, names of files, messages—any kind
of text data that can change value, like a number does.
To specify a string in code literally, you put it inside double quotes, which
looks "likethis" . We'll use strings in our plugins and look more at what you can
do with strings as we go along.
You can add strings together using a plus sign:
String first = "Jack" ;
String middle = "D." ;
String last = "Ripper" ;
String name = first + " " + middle + " " + last;
// Now name will be "Jack D. Ripper"
Note that strings are your data , which is different from the characters we use
to give Java instructions (our program code ).
Try This Yourself
It's time to try out some of these ideas: we'll make a simple plugin from
The best programming languages make you type the fewest characters to get something
done while still making sense.