In this section we will discuss
1. Literals
2. Identifiers
3. Keywords
4. Operators
5. Comments
Literals
In the previous sections I have already clarified what are Literals they are called constants. These are the values that do not change or cannot accept any other value except their own.
int a=0;
In the above Java statement the numeral zero represents a ‘Literal’. It represents a value which cannot be changed thus it is called a ‘Literal’ or ‘Constant’. These values may represent character, integer, float or Boolean type of values. I had told you about two basic types of literals alpha-numeric and numeric. Let’s see these in a bit more detail in relation to Java.(These are known as primitive data type)
Examples of Boolean literal true, false Example of float literals 2.3f , 4.089f Example of double literal 0.0d , 0.5555d Example of int literals 3456, 5678 Example char literal ‘s’, ‘\n’ Identifiers Identifiers are also known as variables. Basically variables are memory locations where we store any value we require for further computation during the program execution. They are like containers, empty by itself but useful when filled with some value. Example a water bottle is empty to begin with but it stores the amount of water you pour in. It depends if you want to fill the whole water bottle or part of it. Same way memory locations on the computer memory are empty by default but can be used to store data you require. Thus each memory location can be given any name. It totally depends on you as long as you follow some simple naming conventions it is ok with the compiler. The rules to for naming a variable are
Some of the good programming practices dictate few more rules, please be advised that rules mentioned below are guidelines and are not implemented or checked by the Java compiler
Keywords These are special words which have been reserved for use in Java and you cannot use them as identifier name. They can be used to perform some task or give a command to the compiler. Some of the Java keywords are
Operators These are mathematical or logical symbols used to perform some operation on one or more values. Java supports the following type of operators Simple Assignment Operator = Simple assignment operator Arithmetic Operators + Additive operator (also used for String concatenation) - Subtraction operator * Multiplication operator / Division operator % Remainder operator Unary Operators + Unary plus operator; indicates positive value (numbers are positive without this, however) - Unary minus operator; negates an expression ++ Increment operator; increments a value by 1 -- Decrement operator; decrements a value by 1 ! Logical compliment operator; inverts the value of a boolean Equality and Relational Operators == Equal to != Not equal to > Greater than >= Greater than or equal to < Less than <= Less than or equal to Conditional Operators && Conditional-AND || Conditional-OR ?: Ternary (shorthand for if-then-else statement) Type Comparison Operator instanceof Compares an object to a specified type Bitwise and Bit Shift Operators ~ Unary bitwise complement << Signed left shift >> Signed right shift >>> Unsigned right shift & Bitwise AND ^ Bitwise exclusive OR | Bitwise inclusive OR Operator Precedence In math’s we have BODMAS which defines precedence of the operators. In the same way Java too has its own rules for operator precedence
Comments Comments are non-executable lines of java code. They are put in the program for documentation and future reference. Java compiler ignores these lines.There are two types of comments a) single line coment These comments begin with a // b) Multi line comments These comments start with /* and end with */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No comments:
Post a Comment