Lesson 3 - Value and Data Types
Lesson 3 - Value and Data Types
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
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