Introduction, Constants, Integer constant, Real Constants, Character Constants, String constant, Backslash character constant, Data Types
Size: 831.02 KB
Language: en
Added: Apr 26, 2014
Slides: 14 pages
Slide Content
CONSTANTS, VARIABLES
AND DATA TYPES
Introduction
•A programming language is designed to process certain
kind of data consisting of numbers, characters and string
and to provide useful output called information
•The task of processing data is accomplished by executing a
sequence of instruction known as program.
•The instructions are formed using certain symbols and
words according to some rigid rules known as syntax rule
or grammar.
•Like any other language java also have its own vocabulary
and grammar. Know we will discuss concepts of constants
and variable and their data type.
Constants
Integer constant
An integer constant refers to a sequence of digits.
There are three types of integers, namely,
decimal integer, octal integer and hexadecimal
integer
•Decimal integer: -consist of a set of digit through
0 to 9, which may be proceeded by optional sign
minus e.g. 7897,-64864, and 0 etc.
•Octal integer: -consist of a set of digit through 0
to 7, with preceding 0. For example: -037, 0
0465, etc.
•Hexadecimal integer: -consist of a set of digit
through 0 to 9 and A through F or a through f,
with preceding 0x or 0X. For example: -0x37, 0x,
0X465AF, 0xfcb23, etc.
Real Constants
The quantities which are
represented by numbers containing
fraction parts are known as Real or
Floating point constant. For example
0.0086, -0.75 etc
•A real number can also be
represented in scientific notation
like 2.15e2 here e2 means 10
2
.
•The general syntax is
Mantissa e exponent
Character Constants
A single character constant contains a single
character enclosed with in a pair of single
quote mark. Example: -
‘a’,’A’,’12’
String constant
A string constant is a sequence of character
enclosed between double quote. Example:
“hello”, ”java”
Backslash character constant
Java Also Supports Backslash Constants those are used in
output methods For Example \n is used for new line
Character. These are also called as escape Sequence or
backslash character Constants.
Backslash CodeDescription
\t tab character
\n new line or line feed character
\r carriage-return character
\f form-feed character
\a alert or bell character
\e escape character
\cx control character corresponding to x
\\ backslash character
\0n character with octal value
\0nn character with octal value
\0mnn character with octal value
\xhh character with hexadecimal value
\uhhhh character with hexadecimal value
Data Types
INTEGER TYPES
•Anintegeris a whole number —that is, a
number with no fractional or decimal portion.
Java has four integer types, which you can use
to store numbers of varying sizes.
Type Number of
Bytes
Range of Values
byte1 –128 to +127
short2 –32,768 to +32,767
int4 –2 billion to +2 billion
long8 -9,223,372,036,854,775,808
to 9,223,372,036,854,775,807
Floating point types
•Floating-pointnumbers are numbers that have
fractional parts (usually expressed with a
decimal point). You use a floating-point type in
Java programs whenever you need a number
with a decimal, such as 19.95 or 3.1415.
•Java has two primitive types for floating-
point numbers:
•float: Uses 4 bytes
•double: Uses 8 bytes
•In almost all cases, you should use
thedoubletype whenever you need
numbers with fractional values.
Character type
•char data type is a single 16-bit Unicode
character.
•Minimum value is '\u0000' (or 0).
•Maximum value is '\uffff' (or 65,535
inclusive).
•Char data type is used to store any character.
•Example . char letterA ='A'
Boolean Type
•Boolean data type represents one bit of
information.
•There are only two possible values: true and
false.
•This data type is used for simple flags that
track true/false conditions.
•Default value is false.
Example : booleanone = true