In this chapter we'll take care of a lot of the basics of writing Java
code. With these tools in your toolbox, you'll know the following:
• What the funny characters mean in Java
• How to use variables to hold number and character string val-
• How to declare and use functions : lists of Java instructions
• How to control code with if , for , and while statements
Plugins Have Variables,
Functions, and Keywords
As you may have noticed, there's a lot of text in the plugin source code that
I haven't explained yet. Let's dig deeper into Java and take a look at what all
that text means—it's the raw material of programming plugins.
As you saw in Chapter 3, Build and Install a Plugin , on page 31 , a program
in Java is just a text file. Look at the text in HelloWorld.java : there's a lot of sort-
of English words, and some strange-looking punctuation. All of it means
something, and the Java compiler is mighty picky when it's reading your text.
First of all, spelling counts. Entity is not the same as Entitee . Player is not the
same as player , so uppercase and lowercase matter, too. There are times when
you use uppercase, and times you need to use lowercase.
Each of those odd characters you see has a special meaning, and they're used
for different things. Here are some examples (don't worry much about the
Comment, used to leave a note for yourself or others. Java will
ignore anything you type from after the double slash to the end of
/* longer comment */
Used for longer comments, either on one line or spanning multiple
Parentheses, used when calling a function and passing data to it,
like this: System.out.println("Hello,Creeper"); .
Brackets, used for choosing one item from a list of items, like this: