/**The VoxAgent interface acts as a bridge between agents and the game. <BR>Implement all of the methods and Vox will call them at the specified times.*/public interface VoxAgent{/**At the start of the game your agent will be constructed and then the setPrefs() method will becalled. It will tell you your owner ID as well as give you a reference to the VoxWorld objectfor this game. You should store this information, as you will need it later.*/public void setPrefs( int ID, VoxWorld world );/** Each turn this method is called for the agent to send his moves to the VoxWorld. This isthe method where most of your bot smarts will go.*/public void declareMoves(Country[] countries);/** This is the name of your agent. It will identify you in the info window and record books*/public String name();/** The version of your agent. It is used by the plugin manager to notify the user when newversions are made available.*/public float version();/** A description of your agent.*/public String description();/** If your agent wins the game then this method will be called.<BR>Whatever you return will be displayed in big letters across the screen. <P>If you think that you will win a lot please provide many different answers for variety.*/public String youWon();/** This method may be used in the future to send notifications to the VoxAgent.*/public String message( String message, Object data );}// end of the VoxAgent interfaceAbstract classes

•abstract class

is a class that is declared abstract.

•May or may not include abstract methods.

•Abstract classes cannot be instantiated.

•An

abstract method

is a method that is declared without animplementation (without braces, and followed by a semicolon).

abstract

class GraphicObject {

int x, y;

...

void moveTo(int newX, int newY) {

...

}

abstract

void draw();

abstract

void resize();

}

goto

•In the Java programming language, goto is areserved word.

•The Java programming language does nothave a goto statement.

•It is a word reserved for possibleincorporation in a future version.

instanceof

•The instanceof keyword can be used to testif an object is of a specified type.

public class MainClass {

public static void main(String[] a) {

String s = "Hello";

if (sinstanceof

java.lang.String)

System.out.println("is a String");

}

}

Difference between throw and throws in Java

•throw is used to actually throw the exception.

•throws is declarative for the method.

•One declares it, and the other one does it

•They are not interchangeable.

public void myMethod (int param)throws

MyException

{

if (param < 10) {

throw

new MyException("Too low!");

}

//Blah, Blah, Blah...

}

transient

•When an object is transferred through the network,the object needs to be 'serialized'. Serializationconverts the object state to serial bytes. Those bytesare sent over the network and the object is recreatedfrom those bytes. Member variables marked by thejavatransient

keyword are not transferred, they arelost on purpose.

public class Foo

{

private String saveMe;

privatetransient

String dontSaveMe;

privatetransient

String password;

.

.

}

volatile

•It marks a member variable not to be used inoptimization, during compilation.

•Optimizing compilers may insert code to gainrun-time performance.

•This can cause problems when a variable canbe changed by many threads.

•Those variables that can be changed by morethan one thread should be set to volatile.

•E.g.,

privatevolatile

changingVar;

Numeric literals

TOKEN :

{

< INTEGER_LITERAL:

<DECIMAL_LITERAL> (["l","L"])?

| <HEX_LITERAL> (["l","L"])?

| <OCTAL_LITERAL> (["l","L"])?

>

|

< #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >

|

< #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >

|

< #OCTAL_LITERAL: "0" (["0"-"7"])* >

|

< FLOATING_POINT_LITERAL:

(["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?

| "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?

| (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?

| (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]

>

|

< #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >

Separators

TOKEN :

{

< LPAREN: "(" >

| < RPAREN: ")" >

| < LBRACE: "{" >

| < RBRACE: "}" >

| < LBRACKET: "[" >

| < RBRACKET: "]" >

| < SEMICOLON: ";" >

| < COMMA: "," >

| < DOT: "." >

}

Operators

TOKEN :

{

< ASSIGN: "=" >

| < GT: ">" >

| < LT: "<" >

| < BANG: "!" >

| < TILDE: "~" >

| < HOOK: "?" >

| < COLON: ":" >

| < EQ: "==" >

| < LE: "<=" >

| < GE: ">=" >

| < NE: "!=" >

| < SC_OR: "||" >

| < SC_AND: "&&" >

| < INCR: "++" >

| < DECR: "--" >

| < PLUS: "+" >

| < MINUS: "-" >

| < STAR: "*" >

| < SLASH: "/" >

| < BIT_AND: "&" >

| < BIT_OR: "|" >

| < XOR: "^" >

| < REM: "%" >

| < LSHIFT: "<<" >

| < RSIGNEDSHIFT: ">>" >

| < RUNSIGNEDSHIFT: ">>>" >

| < PLUSASSIGN: "+=" >

| < MINUSASSIGN: "-=" >

| < STARASSIGN: "*=" >

| < SLASHASSIGN: "/=" >

| < ANDASSIGN: "&=" >

| < ORASSIGN: "|=" >

| < XORASSIGN: "^=" >

| < REMASSIGN: "%=" >

| < LSHIFTASSIGN: "<<=" >

| < RSIGNEDSHIFTASSIGN: ">>=" >

| < RUNSIGNEDSHIFTASSIGN: ">>>=" >

}

CompilationUnit

void CompilationUnit() :

{ }

{

[ PackageDeclaration() ]

( ImportDeclaration() )*

( TypeDeclaration() )*

<EOF>

}

What is the smallest legal Java program?

Declarations in jj

void PackageDeclaration() : { }

{ "package" Name() ";" }

void ImportDeclaration() : { }

{ "import" Name() [ "." "*" ] ";" } // Eg, import java.io.*;

void TypeDeclaration() : { }

{

LOOKAHEAD( ( "abstract" | "final" | "public" )* "class" )

ClassDeclaration()

| InterfaceDeclaration()

| ";"

}

void ClassDeclaration() : { }

{

( "abstract" | "final" | "public" )* "class"

<IDENTIFIER> [ "extends" Name() ] [ "implements" NameList() ]

"{" ( ClassBodyDeclaration() )* "}"

}

extends vs. implements

•extends

–the new class extends a superclass

–automatically inherits all of the superclass'smethods

–override any of them (except the ones defined"final")

•implements

–implements an interface

–the class must override all of the interface'smethods, since the interface contains onlydefinitions, not code.