A computer is a machine that executes a list of instructions called a program. An Android device is a computer and an app is a program.
A variable is a container that can hold a value such as a number or a piece of text. A big variable that can contain smaller variables inside of it is called an object, and the smaller variables are the fields of the object. Attached to an object we can have a short list of instructions called a method — in effect, a little program.
There are many classes of objects. For each class, we have to write a definition: a listing of the fields and methods that belong to the objects of the class.
A local variable is one that is created by an instruction in a method of an object. The variable’s name can be mentioned only in the instructions of that method, and the variable exists only as long as the device is executing the method.
A global variable is a field of an object. It is created by the object itself, not by a method. The variable’s name can be mentioned in any method of the object, so the the value contained in the variable is accessible to all of these methods. A global variable exists as long as the object that contains it exists.