Depending on where a variable is declared it can be either a:
Local variables are declared in sections of Java code such as a block, a loop statement, or a function body. They are created and initialized when the code section execution starts and disappear when it finishes. The declaration consists of the
variable type, name, and optional initialization. The declaration is a statement, so it should end with a semicolon. For example:
double sum = 0; //double variable sum initially 0
int k; //integer variable k, not initialized
String msg = ok ? "OK" : "Not OK"; //string variable msg initialized with expression
Local variables can be declared and used in AnyLogic fields where you enter actions (sequences of statements), such as
code of agent type,
field of events or transitions,
fields of flowchart objects. The variables
are declared in the action code of the event
in the Figure and exist only while this portion of code is being executed.
Local variables declared in the Action code of an event
Java variables (fields) of agent class are part of "memory" or "state" of agents. They can be declared graphically or in code.
To declare a variable of agent (or experiment) class
A variable of an agent declared in the graphical editor
In the Figure a variable income of type int is declared in an agent (or experiment) type. Its access type is public, therefore it will be accessible from anywhere. The initial value of the variable is 10000. The graphical declaration above is equivalent to a line of code of the class, which you can write in Additional class code field in the Advanced Java property section of the agent type, see the Figure:
The same variable declared in the Additional class code field
Graphical declaration of a variable allows you to visually group it together with related functions or objects, and also to view or change the variable value at runtime with one click.