0% found this document useful (0 votes)
5 views4 pages

Data Types

The document provides an overview of Java tokens, including identifiers, keywords, literals, operators, punctuators, and separators. It explains primitive and non-primitive data types, type conversion, and the concept of variables and constants. Additionally, it covers local, instance, and static variables, as well as character sets used in Java, specifically ASCII and Unicode.

Uploaded by

ruchisaxena2516
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Data Types

The document provides an overview of Java tokens, including identifiers, keywords, literals, operators, punctuators, and separators. It explains primitive and non-primitive data types, type conversion, and the concept of variables and constants. Additionally, it covers local, instance, and static variables, as well as character sets used in Java, specifically ASCII and Unicode.

Uploaded by

ruchisaxena2516
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

TOKENS

A token is the smallest element of a program that is meaningful to the compiler. The
different types of tokens in Java are:
1. Identifiers
2. Literals
3. Operators
4. Separators
5. Keywords
6. Punctuators

IDENTIFIERS
Identifiers are the names of variable, methods, classes to identify them .
Rules while writing an identifiers.
Name of the variable should be a sequence of alphabets, digits, underscore and
dollar sign characters only.
It should not start with a digit.
It should not be a keyword or a boolean or null literal.

KEYWORDS
Keywords are reserved words that convey a special meaning to the Java compil-
[Link] are predefined , ie the meaning of the keywords has already been de-
scribed to the Java Compiler.

LITERALS
A literal is a sequence of characters used in a program to represent a constant
value. They are made of digits, letters and other character.

Integer Literal - are values that represent whole numbers only. They can be +ve or
-ve.

Real Literals- are also called floating point literals as they represent values with
decimal point. A real literal is in the fractional form consists of +ve or -ve digits , in-
cluding a decimal point between the digits.

Character literal - A single character enclosed in single quotes.

String Literals - one or more characters enclosed in double quotes.

Boolean Literals - The logical values true or false, during a logical evaluation, the
true/ false literals are used.

Null Literals - This is special kind of literals which is represented by the keyword
null or escape sequence ‘\0’.

OPERATORS
An operator is a symbol that tells the compiler to perform specific mathematical ,re-
lational and logical functions. For ex + - * / %
PUNCTUATORS
Punctuators are the punctuation signs are used in java program.
. (Dot/Period) It is used to separate the package name from the sub-package name
and class name. It is also used to access member variable.
; (semicolon) it is used to terminate a statement in Java.

SEPRATORS
Separators are used to separate the variable or the character.
() (Parenthesis) Hold the list of parameters, used in control statements and type
casting
{} (braces) used to define the block, classes and methods.
[] (square brackets) It is used in array declaration .
, (comma) It is used to separate the multiple variables under the same decla-
ration.

DATA TYPES

PRIMITIVES (BY VALUE) NON PRIMITIVE


(BUILT-IN) (INTRINSIC) (COMPOSITE) (BY
REFERENCE)

NUMERIC NON - NUMERIC

INTEGER REAL char (2 bytes) Class

byte (1 byte )(8 float( 4 bytes)(32 bits) boolean (1 bit) Array


bits)

short (2 bytes)(16 double( 8 bytes)(64 Interface


bits) bits)

int (4 bytes)(32 bits)

long (8 bytes) (64


bits)

DATATYPE SIZE RANGE DEFAULT VALUES

byte (1 byte )(8 bits) -128 to +127 0


-27 to + 27-1

short (2 bytes) (16 bits) -32768 to +32767 0


-215 to + 215-1

int (4 bytes) (32 bits) -231 to + 231-1 0

long (8 bytes) ( 64 bits) -263 to + 263-1 0

float (4 bytes) (32 bits) -3.4E38 to +3.4E38 0.0f

double (8 bytes) ( 64 bits) -1.7E308 to + 0.0


1.7E308

char (2 bytes) (16 bits) \u0000’ to ‘\uFFFF’ ‘\u0000’

boolean 1 bit true or false false


What do you understand by primitive data type? Give two examples.
Primitive data types are the basic or fundamental data types used to declare a vari-
able. Examples of primitive data types in Java are byte, short, int, long, float, dou-
ble, char, boolean.

What do you mean by non-primitive data type? Give examples.


A non-primitive data type is one that is derived from Primitive data types. A number
of primitive data types are used together to represent a non-primitive data type. Ex-
amples of non-primitive data types in Java are Class and Array.

TYPE CONVERSION
The process of converting one type of data to another type of data is known as type
conversion.

IMPLICIT/ COERCION / WIDENING/ TYPE PROMOTION / AUTOMATIC TYPE


CONVERSION
In a mixed-mode expression, the process of promoting a data type into its higher
most data type available in the expression without any intervention by the user is
known as Coercion.
FOR eg
byte a=10;
int b=a ;

EXPLICIT / TYPECASTING
When the datatype gets converted to another type manually through user interven-
tion , it is known as explicit conversion.
For eg
int a=10;
byte b=(byte)a;

Define variable with an example.


A variable represents a memory location through a symbolic name which holds a
known or unknown value of a particular data type. This name of the variable is used
in the program to refer to the stored value.
Example:
int mathScore = 95;

What do you mean by constant? Explain with an example.


The keyword final before a variable declaration makes it a constant. Its value can't
be changed in the program.
Example:
final int DAYS_IN_A_WEEK = 7;
TYPES OF VARIABLE

LOCAL VARIABLE
A variable that is declared inside the body of the method is called a local variable.
You can use this variable only within that method and the other methods in the
class will not be able to access the variable
INSTANCE VARIABLE
A variable declared inside the class but outside the body of the method is called an
instance variable. It is called an instance variable because its value is specific to
the particular instance and is not shared among other instances.
STATIC VARIABLE
A variable that is declared as static is called static variable. It creates a single copy
of the static variable and it will be shared among all the instances of the class.

CHARACTER SET
There are two standard character set ASCII and UNICODE

ASCII American Standard Code for Information Interchange


Developed by BOB BEMER
ASCII- 7 bit character set contains 128 chars from (0-127)
ASCII-8 bit character set contains 256 chars from (0-255)

UNICODE Universal Code


UNICODE is a 16 bit character encoding standard contains 65536 chars
JAVA USES UNICODE char set

Escape Sequence
An Escape Sequence is a set of characters that has a special meaning to Java
Compiler. In an Escape sequence , a character is preceded by a backslash
(\).

You might also like