Basics Theory
Basics Theory
Java Character Set.- Character set is a collection of all the characters that can
be used in a Java program. A character represents any letter (whether capital or small),
digits (0 to 9) or any symbol (%, &, ^, @, $, |, etc). java uses Unicode character set. It
occupies 2 byte to store a character.It can recognize character of most of the language
used in the world.
Token. - Token is the smallest fundamental unit in a program. They are the valid
characters or symbols that can be used in a Java program.The various type of token
available in java is
i. Literals ii. Identifier iii. Keywords. iv puncturators v. operators
Keywords - Keywords are reserved words in Java and thus provide a special
meaning to the Java compiler. Example of keywords are : class, int, for, if etc.
Identifiers - Identifiers are the name given to different parts of the programs e.g.
function names, variable names, class or object names etc.
RULES OF NAMING IDENTIFIERS
It can have any alphabet (capital or small), digits, underscore and dollar sign
characters.
It should not begin with digits or should not contain any special character except(_ , $).
It cannot have a space in between.
It must not be a keyword.
Literals(Constant) - Literals are fixed data value which can not change during
execution of progs. there are 6 types of literals in java.
1. INTEGER LITERALS :- an integer literal are whole numbers have at least
one digit and must not contain and decimal point. It may contain either + or – sign. 43,
0, -76 are integers
2. FLOATING LITERAL: - floating literals are numbers having fractional parts .it
may be + or -. These may be written in one of the two forms fractional form or the
exponent forms. -5.93, 58.0, 1.08, -0.77
3. BOOLEAN LITERALS: - the Boolean type has two values represented by the
literal true and false.
4. CHARACTER LITERALS :- A character literals in java must contain one
character and must be enclosed in single quotation marks. ‘A’, ‘5’, ‘&’ are characters.
5. STRING LITERALs :-is a sequence of zero of more characters surrounded by
double quotes. ”basic”, “abc”, “88”, “@” are strings.
6. NULL LITERALS :- The Null literal (written as null ) represents the one and only
value of the null type
Punctuator -
punctuators are also called Separators. These are symbols and special characters that
make different parts of code separate from each others.
Punctuators used in java program are:- , (comma), ; (semicolon), . (period), (,) (group
of parenthesis), {,} (Pair of braces), [,] (pair of square brackets).
Operator - operator are the symbol which tell the computer which operation to take
place on operands
Operand : - are the data items on which operation takes place.
Category of Operator :-
Unary operator :- uses only one operand(++, --, !,unary(+ , -)
Binary operator :- uses two operand(+, *, /, &&)
Ternay operator :-uses three operand(?:)
TYPE OF OPERATOR :-
• Arithmetical Operator
• Relational Operator
• Logical Operator
• Assignment Operator
• Ternary Operator
ARITHMATICAL OPERATOR: - the operators which are applied to perform
arithmetical calculation in a program are known as arithmetical operator. For example
+, -, *, /, %
%(modulus) is used to find reminder of two operand.(5%2 is 1)
INCREMENT/DECREMENT OPERATOR: - they are used to increment/decrement the
value of a integer variable by 1
x++, ++x will increment value of x by 1
x--, --x will decrement value of x by 1
POSTFIX :- evaluates to the value of the operand after the increment /decrement
operation
e.g if x=5 initially then y=x++; will store 5 into y and x will become 6.
if x=5 initially then y=x--; will store 5 into y and x will become 4.
PREFIX :- evaluates to the value of the operand before the increment /decrement
operation
e.g if x=5 initially then y=++x; will store 6 into y and x will become 6.
if x=5 initially then y=--x; will store 4 into y and x will become 4.
TERNARY OPERATOR :- deal with three operands. It also called condition assignment
statement because the value assigned to a variable depends upon a logical expression.
NON GRAPHIC CHARACTER - are those character which can not be directly type
from the keyboard. E.g. backspace, tabs, carriage return etc.
Type Conversion - process of converting one predefined type into another is called
Type Conversion. It is used in mixed expression where result can be obtained by
converting the various data type into the single type. Two types of type conversion.
1. IMPLICT TYPE CONVERSION :- the data type of the result get converted
automatically into its higher type without intervention of the user. This system of type
conversion is known as implicit type conversion or coercion .
2. EXPLICIT TYPE CONVERSION:- in this type conversion the data type gets
converted to another type of depending upon choice. This means the user forces the
system to get back into the desired data type also called type casting.
Syntax : (type)expression
e.g. int a,b;
float x=(float) (a+b);
final Keyword - This keyword is used while declaring a variable. These variables
are initialised during the declaration and their values cannot be modified further in the
program. This way keyword final makes the variable as constants.
Example:- final double pi=3.14;
ii. ++,--, unary + or unary – are unary ii. Arithmatic operator, Relational
operator operator are Binary operator.
Similarity and Difference between java character set (Unicode) and ASCII
code.
Similarity:- The first 128 characters in the Unicode character set are same as ASCII
character set. i.e. they represent the same characters.
Difference:-
Unicode ASCII code
i. It is a 2 byte character code set i. it is a 7 bit character code set.
ii. It can represent 65536 characters.
ii. ii. It can represent only 128
characters.