0% found this document useful (0 votes)
2 views28 pages

Lesson 3 - Value and Data Types

Chapter 3 covers fundamental concepts in Java, including character sets, Unicode, ASCII, escape sequences, tokens, constants, variables, operators, keywords, and data types. It explains the differences between Unicode and ASCII, the types of literals and identifiers, and the process of type conversion. Additionally, it discusses the naming conventions for variables and the use of punctuators and separators in Java programming.

Uploaded by

k.anany1750
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
2 views28 pages

Lesson 3 - Value and Data Types

Chapter 3 covers fundamental concepts in Java, including character sets, Unicode, ASCII, escape sequences, tokens, constants, variables, operators, keywords, and data types. It explains the differences between Unicode and ASCII, the types of literals and identifiers, and the process of type conversion. Additionally, it discusses the naming conventions for variables and the use of punctuators and separators in Java programming.

Uploaded by

k.anany1750
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 28

Chapter -3

Values & Data Types


Topics to be covered
1. Character sets in java
2. Unicode
3. ASCII code
4. Escape sequences
5. Tokens and its types
6. Constant and variables
7. Punctuators
8. Separators
9. Operators
10. Keywords
11. Data Types
12. Type Conversion
LANGUAGE AND CHARACTER SETS

Language is a
medium of
communication
for human beings.
LANGUAGE AND CHARACTER SETS
Java is computer language to communicate with computer
characters make a language. What are character sets in
java??
1. LETTERS(all English alphabets A-Z and a-z)
2. DIGITS(0-9)
3. OPERATORS
Arithmetic(+, - ,*,/,%)
Logical {||(or) &&(and) !(not)}
Relational <,<=,>,>=,== ,!=
4.DELIMITERS -sequence of characters to specify
boundaries like :,;,{,},[,] etc
UNICODE
When we enter a character from keyboard, a specific code
is assigned by system for its storage in memory. Machine
can understand only in codes.
Unicode is the latest coding system after ISO and IEC
systems.
It contains hexadecimal digits (0x0000 up to 0xFFFF) that
is 16 bits code
A code for each character set in any language is available
in UNICODE. F is 1111 and 0 is 0000 in hexadecimal
system.
ADVANTAGES OF UNICODE
• It is universal coding system
• More efficient than other ISO or IEC
• Supports uniform coding width(16 bits) for all characters
• Each character has only one unique code
ASCII CHARACTERS AND CODES
ASCII (American Standard Code for information
interchange). Characters used in computer are said to
be ASCII characters. ASCII codes are decimal numbers
(7 binary bits). Its range is less than UNICODE range.
Only limited characters are covered in ASCII(0 to 127)
A is coded as 65 and B as 66 respectively
Differences between Unicode and ASCII code

UNICODE ASCII CODE

It is generalised form of It is for specific coding


coding scheme for scheme and used for
numerous characters of limited characters
different scripts
Represents higher Limited range of codes
range of codes It It is represented by 7 binary
is represented by bits
16 bits
ESCAPE SEQUENCES
a.Some non graphic characters are used as commands to
direct the cursor while printing
b.These characters are escape sequences
c.It begins with backslash (\) followed by one more character
d.\t
is for horizontal tab,\v is for vertical tab ,\n for new line
feed
e.It controls cursors movement in Java programming
TOKEN
Cell is a fundamental unit of human body
Similarly, token is a portion amongst the various components of
computer program It carries some meaning and takes part in effective
execution of the program
Types of tokens :
Literals
Assignments
Identifiers
Separators
Operators
keywords
LITERALS(CONSTANTS)

These are constants in a Java program. Some quantities remain fixed throughout the
execution of program, which are known as literals in a program. Some of the types of
literals are:
1. Integral :whole numbers having positive negative values like 14,-400,18, -91 etc
2. Real :numbers with decimal points also called floating point like -3.6,24.500,etc
3. Character : alphabets, upper case, lower case ,digits ,special characters like A, m,4,*,+
etc
4. String :it is set of alphanumeric characters. Characters enclosed within pair of open
and
5. closed double quotes like “computers”,”year2020” etc
6. Boolean: The representation of true or false is known as a boolean. It checks if
logical condition is true or not in java program.
7. Null : It marks the end of a string by ‘\0’
IDENTIFIERS
These are used to identify the various components of a program. These
represent the program elements like function name or class name.
Example -
class add
{
int a, b,c;
}
Here add, a, b and c are the identifiers.
VARIABLES
Variable is a named memory locationwhich contains a value .it can
change depending on circumstances and problems in a program.
It can be the combination of letters without space.
Value assigned to variable is stored at specific location in memory .
If value is changed the new value replaces the old one in the same
location
Suppose,
int x =5; is stored in location B
Int x=x*x =25 replaces 5 in location B
HOW WE NAME VARIABLES??
May have any number of characters.
May have alphabets , digits, dollar sign, underscore.
Underscore can be used between two characters also.
Variable names should be meaningful or self depict the purpose.
Assignment (=)
Storing constants in variables using token ‘=‘ symbol. This
equal to is assignment operator
Data type of constant should match the variable type. An
integer variable cannot have character constant.
Eg, int m =15;
When we initialize a variable it may have garbage value
which can create problem in execution of program. Even if
program logic is correct we can get inappropriate answer.
So, we initialize a variable by assigning specific value .
1. STATIC INITIALIZATION :We directly assign a value
to variable at time of declaration.
Example , int a =0;
1. DYNAMIC INITIALIZATION: When variable is initialised at
run time (at time of execution)
Example, int a,b,c ;
c=a+b;
Punctuators
These are the punctuation signs used as
special symbols in Java. Examples of
Punctuators are:-
a) Dot operator(.) -> It represents a function
belonging to an object or a class. For
Example :- System.out.println() -> println()
is a function belongs to out class.
b) Semicolon (;) -> It represents the
termination of a statement.
c) Question Mark(?) -> It represents the action
to be taken when the given condition is
true. It is used in Ternary Operator.
Separators
These are the special characters which are
used to separate the variables or the
characters. Examples of separators are:-
a) comma(,)
b) curly brace ({ })
c) brackets( () )
d) square brackets ([ ])
An operator, in Java, is a special symbol
performing specific operations on one, two or
three operands and then returning a result.
There are mainly three types of operators.
a)Arithmetic Operators -> +, - , *, / ,%
b)Logical Operators -> AND, OR, NOT
c)Relational Operators -> ==, <,>,<=, >=, !=
Keywords
These are the reserved words which are
preserved and carry out the special meaning for
the Java Compiler.
These are used to identify what type of data can be
inserted into a variable.
There are two types of data types:-
a) Primitive Data types:- predefined in the Java
programming language. int, float, char, double, byte,
short, long are the various primitive data types.
b) Non- Primitive Data type :- These are defined by the
user according to his/her requirements. Class, array
and interface are user-defined data types.
Primitive Types

Data Data Min Max Bit size Format


type
1 byte byte -127 128 1 byte byte age;
2 short short -32767 32768 2 bytes short sales;
3 integer int – 231 +231–1 4 bytes/32 int balance;
bits

long 8 bytes /64 long dist=54582;


4 long – 263 +263–1
integer bits
Bit
Data Data Min Max Format
size
type
-3.4E+ 4 bytes /
1 float float +3.4E+38 32 bits float a;
38
-1.7E+ +1.7 E+ 8 bytes / double
2 double double 64 bits
308 308 b=54.582;

Data Data Bit size Format


type
1 Character char 2 bytes /16 char a=‘A’;
bits

1 String String >2 bytes />16 String a=“MUMBAI”;


bits
ASCII code of Character data type
The characters which we type in our program are getting
stored in ASCII format.
Character ASCII code
A-Z 65-90
a–z 97-120
char ch = ‘A’; 0–9 48 - 57
int x = ch;
The value of x will be 65.
Type Conversion
The process of converting one predefined to
another is called as Type conversion
a) Implicit conversion -> is done by the compiler
where the smaller data types is promoted
into higher data types implicitly. This is called
as Type promotion.
The following conversion takes place implicitly.
byte->short-> int->long->float->double
char->int->long->float->double
Explicit Conversion
Explicit conversion is a forced conversion done by the
programmer using (type) operator. This process is
also called as Type casting.
General form :
(typename)value
For Example: -
double x = 8.0;
double y =20.0;
int b = (int) ((x+y)/2);
Convert Algebraic Expression into
Java Expression

Write a Java expression for the following:


5
1. ax + bx3+c 2. 5x3+2y/(x+y)

You might also like