Arguments on which operation is performed are known as operand.
Operator is a special symbol used for performing a specific task. e.g. A+B. Here + symbol represents the operator.
A sequence of operands connected by operators is known as expression. e.g. A+B*5.
variable and datatypes in java
Variable is the name of reserved memory location. It means when we declare a variable some part of memory is reserved.
e.g. int var1 = 35;
var1 is a variable here.
A variable that is declared within the method, constructor, or block is known as local variable.
No Access modifier is used for local variables. Scope of local variable is limited to that method, constructor, or block only in which it declared.
A variable that is declared within the class but outside of method, constructor, or block is known as instance variable (Non static). They are associated with object. Access modifiers can be used with instance variables. Inside class you can access instance variable direct by variable name without any object reference.
A variable that is declared within the class with static keyword but outside of method, constructor, or block is known as Static/class variable. They are associated with class. Static variable are accessed by ClassName.VariableName.
As we discussed when a variable is declared some part of memory is reserved. But how much memory will be reserved. It depends upon the data type of the variable. i.e. how much memory will be reserved and which type of data can be stored in reserved memory is depends upon data type of the variable.
Data types in java:
1. Primitive data types:
Primitive data types are predefined in the language.
2. Referenced or object data types:
Any class object or array type. Default value of object data types is null.
1. Compiler never initialize local variable with default values. So you have to initialize local variable before using otherwise it will result in compile-time error.
2. Char in java takes 2 bytes because java uses Unicode system (UTF-16) which needed a minimum of 2 bytes memory to store a character.