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 102.
• 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 Code Description
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
• An integer is 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
byte 1 –128 to +127
short 2 –32,768 to +32,767
int 4 –2 billion to +2 billion
long 8 -9,223,372,036,854,775,808
to 9,223,372,036,854,775,807
Floating point types
• Floating-point numbers 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
the double type 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 : boolean one = true
ITFT-Constants, variables and data types in java

ITFT-Constants, variables and data types in java

  • 1.
  • 2.
    Introduction • A programminglanguage 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.
  • 3.
  • 4.
    Integer constant An integerconstant 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.
  • 5.
    Real Constants The quantitieswhich 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 102. • The general syntax is Mantissa e exponent
  • 6.
    Character Constants A singlecharacter constant contains a single character enclosed with in a pair of single quote mark. Example: - ‘a’,’A’,’12’
  • 7.
    String constant A stringconstant is a sequence of character enclosed between double quote. Example: “hello”, ”java”
  • 8.
    Backslash character constant JavaAlso 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 Code Description 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
  • 9.
  • 10.
    INTEGER TYPES • Aninteger is 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 byte 1 –128 to +127 short 2 –32,768 to +32,767 int 4 –2 billion to +2 billion long 8 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
  • 11.
    Floating point types •Floating-point numbers 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 the double type whenever you need numbers with fractional values.
  • 12.
    Character type • chardata 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'
  • 13.
    Boolean Type • Booleandata 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 : boolean one = true