In the JAVA language if you want to use variables, then you have the necessary declaration
JAVA data is divided into two types, one is the basic type, the other is a reference type.
Basic types:
byte (bits 1 byte. 8)
Sort (bit 2 of byte 16)
int (32 Bit 4 bytes)
Long (64 bits 8 bytes)
a float (32 Bit 4 bytes)
Double ( 64 8 bytes)
Boolean (32 4 bytes)
char (2 16 bytes)
mentioned above are generally 32-bit and 64-bit for the operating system
if it is 16-bit operating system bit and byte halved
Reference types: JAVA objects
JAVA variable types
- Instance variables
- Local variables
- Class variables
Local variables
- Statement method, constructor, or block of statements in
- Local variables are created when executed method, construction method statement block, once finished, will immediately be destroyed out
- Access modifier can not modify local variables
- Local variables only, method of construction statement block, the method can be seen
- When local variables created on the stack of open space
- Local variables without initial value, only given an initial value at the time of creation, before you can use
public class Test{
public void pupAge(){
int age = 0;
age = age + 7;
System.out.println("Puppy age is : " + age);
}
public static void main(String args[]){
Test test = new Test();
test.pupAge();
}
}
Instance variables (member variables)
- In the class declaration, but in the method, constructor, an outer block of statements
- When a variable is instantiated, the value of each variable is determined to follow
- In the instance variables created when the object is created, destroyed when the object is destroyed
- Instance variable is referenced at least a method, constructor, or block of statements, so that the external variable information can be acquired by these methods.
- Instance variables can be declared before use or after use
- Access modifier can be modified instance variables
- Instance variables in the general method, constructor, visible statement block, half of the private instance variables set, can be made by accessing the instance variables of the class modifiers visible
- Examples of boolean variables have a default value defaults to false, int default is 0, the default value instance variable is null
- Declare instance variables can be specified by the user other methods;
instance variables can be directly accessed by the variable name. However, static methods and other classes, you should use the fully qualified name: