Java Reference
In-Depth Information
{ }
Braces, used to mark the beginning and end of a section of code.
Dot, used to select a part of something. Most often you use this to
select a function that's part of an object, like System.out.println() or
player.getLocation() .
Semicolon, used to mark the end of a code statement. Leaving the
semicolon off at the end of a line of code is a surefire way to make
Java angry and have it spew hundreds of error messages at you.
Some words you type are special, and you have to use them the way Java
says to. Other words you can make up yourself, and could be anything from
ImmortalPlayer to rathead . So how does this all fit together?
To create a program or a plugin in Java, you use all these bits of text to create
two different kinds of things: data and instructions. That's all there is to any
computer program or to a Minecraft plugin. It's all just data and instructions.
Here's how we work with them.
First I'll show you how you declare and use these things, and then you'll need
to try it yourself in your very first plugin.
Keep Track of Data with Variables
Data are facts—things like your age or the color of your
bicycle. To work with these facts in Java, you hold them in
variables . A variable is a holder of data. Think of it like a
small box you can put things in.
In Minecraft, we use variables to keep track of things like
players in the game, a player's current health and location,
and all the other data we need to know. (In fact, you're going to add some
variables to a piece of code in just a minute—a plugin that will build you a
A variable is the box that holds that data. You can put a label on the box,
but that's just a label for your convenience—it doesn't affect what's inside.
Here's how to use variables. For this example, we'll make a variable called
age , and tell Java to set the value of that variable to 15, either in two steps
or all in one step:
int age;
age = 15;
int age = 15;
Search WWH ::

Custom Search