First of all, we need to know what is variable and Expression. Ok, let’s see.
Variable: Variable is like a container, it holds the value. Every variable must have a data type that is chosen by a programmer. Java offers some data type such as byte, short, int, long, float, double, char, String, boolean. Every data type has a specific signature. All of them work in a specific field. We declare a variable like that:
int variable_name;- float variable_name;
- char variable_name;
- String variable_name;
To declare variables we must follow some common rules. Those are:
- All variable names must begin with an alphabet or an underscore ( _ ).
- We can use numbers in a variable name except for the first letter.
- Space and special characters are not allowed.
- Formed of two or more words variable can be written in two way. Use uppercase and lowercase letter combination in the variable name, such as variableName or Use an underscore ( _ ) between two words, such as variable_name.
- Try to give a valid and meaningful variable name because a meaningless variable name is hard to understand a program.
Expression: In general what do we mean by expression? Generally, the expression is to express the feelings or actions of our mind. Real life expressions can be either through our speech or body action but in programming languages, we use some operators to express our feelings or particular actions such as arithmetic logic operator, conditional operator, relation operator etc. Have a look at below and know more closely.
Arithmetic logic operator
| Operator | Operation | Expression | Description |
| + | Addition | X + Y | adds two variable |
| – | Subtraction | X – Y | subtract two variable |
| * | Multiplication | X * Y | multiply two variable |
| / | Division | X / Y | This operator uses to divide one variable by other |
| = | Equal or data movement | X = Y | this operator moves value right to the left such as Y to X |
Conditional operator
| Operator | Operation | Expression | Description |
| && | And | X && Y | This express “and condition” Such as X and Y |
| || | Or | X || Y | This express “or condition” such as X or Y |
Equality operator
| Operator | Operation | Expression | Description |
| == | Equal to | X == Y | We use this operator to express one variable equal to other For example X is equal to Y |
| != | Not equal to | X != Y | We use this operator to express one variable is not equal to other For example X is not equal to Y |
Relational operator
| Operator | Operation | Expression | Description |
| > | Greater than | X > Y | It describes X is greater than Y |
| < | Less than | X < Y | It describes X is less than Y |
| >= | Greater than or equal to | X >= Y | To express X is greater than or equal to Y |
| <= | Less than or equal to | X <= Y | To express X is less than or equal to Y |
Now you know what is variable, what is the expression and which operator is used for expressing an action in Java. To know more please keep following the course.
Leave a comment