Computer Applications - Java - Values & Data Types
SeemantaBhowmick1
0 views
41 slides
Sep 14, 2025
Slide 1 of 41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
About This Presentation
Values & Data Types
Size: 390.66 KB
Language: en
Added: Sep 14, 2025
Slides: 41 pages
Slide Content
CH.4: VALUES AND DATA TYPES
CHARACTER SET A character set is a set of valid characters that a language can recognise. A character set is a collection of all letters, digits and or any other special characters that can be used in a program. A character set represents: Letters : A-Z / a-z Digits : 0 to 9 Operators : +, - , *, / , %, &&, <, >, <=, >=, etc. Delimiters : ;, :, ?, ., (, ), {, }, [, ], etc.
UNICODE Java uses the Unicode character set. Unicode is a 2–byte character code set. It represents almost all human alphabets and writing systems around the world. Unicode is an international encoding standard. It represents characters from almost all languages including English, Arabic, Chinese and many more.
TOKENS The smallest individual units in a program are known as tokens. They form the fundamental building blocks in a program.
KEYWORDS Keywords are the words that convey a special meaning to the language compiler. They are reserved words for special purpose and cannot be used as identifiers.
IDENTIFIERS Identifiers are unique names given to identify the different building blocks of a program such as a variable, class, method, etc.
IDENTIFIER FORMING RULES OF JAVA Identifiers can have alphabets, digits, underscore and dollar sign characters. They must not be a keyword or Boolean literal or Null literal. They must not begin with a digit. They can be of any length. Java is case sensitive, that is, upper case letters and lower case letters are treated differently.
INVALID IDENTIFIERS WITH REASONS INVALID IDENTIFIER REASON MY–FILE Contains special character other than _ and $. 40MYFILE Begins with a digit. break Reserved keyword. true / false boolean b = true; Boolean literal.
ASSIGNMENT 2 CH.4: VALUES AND DATA TYPES What is a character set? What is Unicode? What is meant by tokens? Name the tokens available in Java. State whether the following identifiers are valid or invalid. If invalid, state the reason. i ) Data_13 ii) Data – 13 iii) Data13 iv) 13Data 5. What is an identifier? Mention any four identifier forming rules of Java.
LITERALS Literals are data items that are fixed data values. Literals are often referred to as constants . Java allows several kinds of literals: Integer literal Floating literals Boolean literals Character literal String literal Null literal
INTEGER LITERALS Integer Literals are whole numbers (positive or negative) without any fractional part . For example, 16, – 34, 754, etc. Java allows three types of integer literals: Decimal Integer literals (base 10) Octal Integer literals (base 8) Hexadecimal Integer literals ( base 16)
FLOATING LITERALS Floating Literals are numbers having fractional parts. They are also called Real Literals . These may be written in one of the 2 forms called fractional form or exponent form. In fractional form, at least one digit before and after the decimal point must be there. A real literal in fraction form consists of signed or unsigned digits including a decimal point between digits. For example, 3.42, – 4.5, 345.67, etc.
CHARACTER LITERALS A character literal in Java must contain only one character and must be enclosed within single quotation marks . It can be a single letter or a digit or any special symbol. It does not take part in arithmetic operations. For example, ′ S ′ , ′p′ , ′?′ , ′9′, etc.
STRING LITERALS A sequence of zero or more characters enclosed within double quotation marks . A string literal can be a set of any type of characters within a limit of 256 characters. For example , ″ PROCESS″, ″4356″, ″System@4″ , etc.
BOOLEAN LITERALS The Boolean literals is always of type boolean . It is either boolean value true or boolean value false. For example , b oolean a = true; boolean b = false;
NULL LITERAL A null literal denotes the absence of a v alue. The null type has one value, the null reference. For example, int x = null; String str = null;
OPERATORS Operators are the symbols or signs used to specify the operations to be performed in a Java expression. There are three types of operators: Arithmetical Operator +, – , *, /, etc. Relational Operator <, >, ==, !=, etc. Logical Operator ||, &&, !
SEPARATORS Separators are special characters in Java which are used to separate the variables or sequence of codes. For example, Comma (,), Brackets ( ), Curly Brackets { }, Square Brackets [ ], Semicolon (;), etc.
ASSIGNMENT 3 CH.4: VALUES AND DATA TYPES 1. Answer the following: ( a) Name the different type of Literals in Java. (b) Differentiate between Character Literal and String Literal . 2 . Identify the following Literals: (a) 34 (b ) 67.32 (c) – 23 (d ) ′ R ′ (e) ″ Windows@10 ″ ( f) – 5.5 (g) ″ 3456 ″
DATA TYPES Data types refers to the type of data, a memory location can hold. Whenever we need to store a value, the respective data type must be mentioned so that the system may structure the memory location for its proper storage. In Java, data types are of two kinds: Primitive data type Reference data type
PRIMITIVE DATA TYPE Primitive data types are the basic or fundamental data types which come as part of the language. In Java, there are 8 primitive data types: b yte short i nt long f loat d ouble c har boolean
REFERENCE DATA TYPE Reference data types are non–primitive data types which are derived from the primitive data types . Storage mechanism of reference data types is different from that of primitive data types. For example, classes, arrays and interface.
HIERARCY OF PRIMITIVE DATA TYPE
TYPES OF PRIMITIVE DATA TYPES Java supports 4 types of primitive data types: Numeric Integral primitive types Fractional primitive types Character primitive types Boolean primitive types
NUMERIC DATA TYPE Numeric data type are used to declare variables that can store numbers . Based on the types of values that can be stored in a variable, the numeric data type is classified into two types: Integer numeric data type Real or fractional numeric data type
INTEGER NUMERIC DATA TYPES A variable declared under this type contains only integer value. Type Size Description Range byte 8 bits (1 byte) Used to store byte length integer -128 to 127 short 16 bits (2 bytes) Used to store small range of integer -32768 to +32767 int 32 bits (4 bytes) Used to store integer - 2 31 to 2 31 -1 long 64 bits (8 bytes) Used to store large integer - 2 63 to 2 63 -1
REAL OR FRACTIONAL NUMERIC DATA TYPES A variable declared under this type contains floating point data (fractional numbers including a decimal point). Type Size Description Range float 32 bits Used to represent a fractional number with small range -3.4E+38 to +3.4E+38 double 64 bits Used to represent a fractional number with wide range -1.7E+308 to 1.7E+308
NON–NUMERIC DATA TYPE Non–numeric data types do not deal with numbers rather they are used to declare a character or set of characters. They can be classified into two types: Character type Boolean type
CHARACTER NON– NUMERIC DATA TYPES The only character data type is char used to hold a single character value enclosed within single quotes. Type Size Descriptions Range char 16 bits (2 bytes) Single character 0 to 65535
BOOLEAN NON– NUMERIC DATA TYPES The only Boolean primitive data type is boolean used to hold a single value. A boolean value can have only one of the two values : true or false at a time. Type Size Description Range boolean Java reserves 8 bits but only uses 1 bit Logical or boolean values true or false
SAMPLE DATA VALUES WITH DATA TYPES Value Data Type 178 int 88645L long 5S short 32.657 double Value Data Type 34F float 64578l long 5.2f float true boolean Value Data Type 178.8 double ‘R’ char ‘6’ char 32.657d double
ASSIGNMENT 4 CH.4: VALUES AND DATA TYPES 1. Answer the following: (a) What are primitive data types? (b) What are reference data types ? 2. State whether the following data values are primitive data type or reference data type in Java. array char interface byte class
VARIABLE A variable is a named memory location, which holds a data value of a particular data type. The values of variable can be manipulated during program run.
DECLARATION OF VARIABLE The general format of variable declaration is as follows: < data type > < variable name > ; where data type is any Java data type and variable name is the name of the variable. For example, int a, b; float c, d; double e, f;
INITIALIZATION OF VARIABLES A first value or initial value may be specified in the definition of a variable. A variable with a declared first value is said to be an initialized variable. For example, int w = 3010; float x = 0.37; double y= 529.75; long z = 28L;
INITIAL VALUES OF VARIABLES Data Type Initial Value byte 0 (zero) of byte type short 0 (zero) of short type int long 0L float 0.0f double 0.0d char null character i.e., ′ \u0000 ′ boolean false All reference types null
STATIC INITIALIZATION Static initialization is a way to store a value directly to a variable by using assignment operator (=). In this case care should be taken that the data type of the variable must be same as the type of value is to be stored. Data type Declaration Static Initialization int int a a = 10; double double p p= 4.5; char char b c=‘R’;
DYNAMIC INITIALIZATION Dynamic initialization is used to initialize a variable at run time (i.e., during execution of the program ). In this case the variable is initialized with the value which is the outcome of some expression or a function. Data type Declaration Dynamic Initialization int int a,b,c ; c= a+b ; double int d=32; doube e=4.5, s; s= d+e ;
CONSTANTS A variable or memory locations whose values cannot be changed within the program are called constants. The keyword ‘final’ before a variable declaration makes it a constant. The reserved word final tells the compiler that the value will not change. For example, final double PI = 3.142;
ADVANTAGES OF CONSTANTS They make your program easier to read and check for correctness. If a constant needs to be changed then all you need to do is change the declaration. You don’t have to search through your program for every occurrence of a specific variable.
ASSIGNMENT 5 CH.4: VALUES AND DATA TYPES 1. What is a variable? Write the general format of variable declaration in Java. 2. What is static initialization? 3. What is dynamic initialization? 4. What are constants? State the two advantages of constants.