10.java Structure
10.java Structure
TOKENS
Java Tokens are the smallest individual building block or smallest unit
of a Java program
Java program is a collection of different types of comments, white
spaces,identifiers,literals,operators keywords etc.
Identifiers
Identifiers are the names of variables, methods, classes,
packages and interfaces
Identifier must follow some rules.
All identifiers must start with either a letter( a to z or A to
Z ) or currency character($) or an underscore.
They must not begin with a digit
After the first character, an identifier can have any
combination of characters.
A Java keywords cannot be used as an identifier.
Identifiers in Java are case sensitive, idn and Idn are two
different identifiers.
They can be of any length Eg: int a; char name;
Constants or Literals
Constants are fixed values of a particular type of
data,which cannot be modified in a program.
Java language specifies five major type of literals
String
In java, string is basically an object that represents
sequence of char values.
An array of characters works same as java string.
Eg: char[] ch = {'a',‘t',‘h',‘l',‘e',‘t'};
String s = "athlet";
Java String class provides a lot of methods to perform
operations on string such as compare(), concat(),
equals(), split(), length(), replace(), compareTo(),
intern(), substring() etc.
Seperators
In java,some characters are used as seperators.They are:
Brackets[] : Opening and closing brackets are used as array element
reference. These indicate single and multidimensional subscripts.
Parentheses() : These special symbols are used to indicate function calls and
function parameters.
Curly Brackets {} : These opening and ending curly brackets mark the start and
end of a block of code containing more than one executable statement.
semicolon ; : It is used to separate more than one statements like in for loop is
separates initialization, condition, and increment.
comma , : It is an operator that essentially invokes something called an
initialization list.
asterisk * : It is used for multiplication.
assignment operator = : It is used to assign values.
Period . : Used to separate package names from subpackages and
Classes
Colon: used to create a method or constructor reference
Whitespace
Java is a free-form language. This means that you do
not need to follow any special indentation rules
White space in Java is used to separate tokens in the
source file. It is also used to improve readability of the
source code.
Eg: int i = 0;
White spaces are required in some places. For
example between the int keyword and the variable
name.
In java whitespace is a space, tab, or newline