Previous | Home | Next |
- Identifier is a name of a variable or an array or an method or a class or an interface or a packaged is called as identifier.
- forexample:
int n; int a[]; void m( ); etc.
- identifiers must start with a number ,letter,under score or a dollar sign.
- some valid identifiers are :
$name _pet animal 11123class
- Packages:Package names should be in lowercase.
Example: package myfirstpackage;
- Classes or Interface:class names should be in TitleCase.
Example:class MyFirstClass
- Methods:Names should be in camelcase.
Example: void myFirstMethod();
- Final Variables:Names should be in upeer case.
Example:final int Max=5;
VariablesVariable is named location which is value hold in primary memory whose value keep changed during execution is called as variable. Before variable must be declared after it is used. Variable is a name of memory location. variables are location in memory in which values can be stored you declare the variables after that you assign the values.
- First letter cannot be a digit.
- It can not contain dot(.) ,space and other special symbol
- Variable name can not match with any keyword.
- All identifier are case sensative.
- Their is no limit on length of identifier.
- Types of variables:There are three types of variables in java.
- local variable
- Instance variable
- static variable
forexample:
int abc123; is valid int 7abc;is not valid int _abc; is valid int &abc;
forexample:
int g.s; is not valid int gross salary; is not valid int gross @ salary; is not valid int gross_salary; is valid
forexample:
int a; is valid float if; is not valid float c; is valid
Local Variable: A variable that is declared inside the method is called local variable.
Instance Variable: A variable that is declared inside the class but outside the method is called instance variable. It is not declared as static.
Static variable: A variable that is declared as static is called static variable. It cannot be local.
Example to understand the types of variables
class A { int data=50;//instance variable static int m=100;//static variable void method() { int n=90;//local variable } }//end of class
Previous Home Next