Character Set
27 December 2020 02:25
Character Set
A set of graphical and textual symbol each of which is mapped to a positive integer.
Character Set in Java
Set of alphabets , letters (including special characters)that are valid in Java language.
Java uses Unicode as it's character set.
Unicode is a universal international standard encoding system , that’s capable of
representing most of the world's languages.
ASCII code is the American Standard Code for Information Interchange.
ASCII code Unicode
It is a 7 bit system It is a 16-bit set
It ranges from 0 -255 i.e total 256 It ranges from 0 - 65535 i.e total 65536 charatcers
characters
It comprises of all english alphabets The first 0 -255 characters are same as ASCAII code but it
along with some additonal special also includes characters of many languages apart from
characters english.
Represtend by \uXXXX , where XXXX is 16 bit representation of
the character
Egs:- 'A' -> 65 , '_' -> 32 Egs:- A -> \u0041 , \u0000 -> null character.
Notes Class X Page 1
Escape Sequences
27 December 2020 02:25
A character preceded by \ (backslash) is known as escape sequence and hold a special meaning to the compiler.
Java has a total of 8 escape sequences.
Carriage return , generally moves the output text in
the next line without moving the cursor to the next
line.
Form feed means a page break , (it’s quite old and not
used now)
Questions:-
Output when :-
\\\"
\a
Notes Class X Page 2
Data Types
27 December 2020 03:25
They specify the type of data a variable can hold.
They are of 2 types :-
1. Primitive data type
2. Non Primitive data type / User defined / Referential
Data Types
Primitive Non Primitve
Numeric Non-numeric Class Array Interface String
Integer float double Char Boolean Note: they are referential data type i.e
instead of storing the value of the literal
they store the location of the literal.
Notes Class X Page 3
Data Type
27 December 2020 03:51
Type Size Range 1. Byte
a. It represents 8 bits of storage
byte 8 bits -128 to 127 b. Is used to store very small numbers.
char 16 bits 0 - 255 c. Not used in general
d. Egs:- 10 , -20
short 16 bits -32,768 to 32767
2. Char
int 32 bits -2^31 to 2^31 - 1 a. Represents a single character
long 64 bits -2^63 to 2^63 - 1 b. Surrounded by single quote.
c. Its range is \u0000 to \u65535
float 32 bits upto 7 decimal
d. Egs:- 'a' , '4' , 'A'
double 64 bits upto 16 decimal 3. Short
boolean 1 bit true/false a. It is also used to store numbers in small range
b. Not used generally
c. Egs:- 2000 , - 500
4. Int
a. Generally used for storing integers
b. Means number without decimal point
c. Egs: - 100000 , 200 , 10
5. Long
a. Used when integer can’t meet our needs of range
b. Egs:- 10000L , 200L
c. L represents long.
6. Float
a. Used to store decimal number
b. Not generally in Java
c. Not used when we require precise result as it supports only 7 decimals
d. Egs:- 234.6F
e. F represents float.
7. Double
a. a.generally used to store decimal numbers.
b. It very precise
c. Egs:- 234.6 , 45.0 , -29.2
8. Boolean
a. Used to track conditions.
b. Can be either true or false
Notes Class X Page 4
b. Can be either true or false
c. Egs; true , false
Notes Class X Page 5
Program #1
27 December 2020 04:24
Write a program(WAP) to assign two numbers and then calculate their sum,difference,product,division in sepeate variables and then print
them .
datatype variable=value;
Each line is terminated by a semicolon
Name of the class should start with a alphabet, can be folllowed by number
Assignment vs declaration.
Notes Class X Page 6
Operators
23 December 2020 19:51
2.Assignment Operators
Used to assign values to the variables
Operators are divided into following groups :-
1.Arithmetic Operators
2.Assingment Operators
3.Unary Operators They also have a special type called as short-hand operators
4.Comparison/Relational Operators
5.Logical Operators
6.Bitwise Operators
7.Miscleneous Operators
1.Arithemetic Operators
Used to perform mathematical operations
4.Comparison/Relational Operators
Used to compare 2 values
3.Unary operators
They require only 1 operand.
Notes Class X Page 7
Operators
23 December 2020 20:01
4.Logical Operator's Ternary Operator
Used to determine logic between variable/values. Only conditional operator that takes 3 operands.
Its and replacement for if-then-else
Symbol--> ? :
5.Java Bitwise Operators
Used to perform binary logic with bits of interger
Egs:-
num1 = 10;
num2 = 20;
res=(num1>num2) ? (num1+num2):(num1-num2)
Since num1<num2,
the second operation is performed
res = num1-num2 = -10
Notes Class X Page 8
Since num1<num2,
the second operation is performed
res = num1-num2 = -10
Notes Class X Page 9
Precedence of Operator
27 December 2020 04:22
Certain operators have higher precedence than others and therefore precedence of operator decides how an expression
should be evaluated.
Arithmetic > Relational > Logical
In Arithemtic:- BEDMAS rule is followed ( Bracket Exponent Division/Multiplication Addition/Subtraction
In Logical :- NAO rule ( NOT > AND >OR)
ICSE 2015
Notes Class X Page 10