![Page 1: ITFT-Constants, variables and data types in java](https://reader031.vdocuments.site/reader031/viewer/2022020110/555a5fccd8b42a47748b528d/html5/thumbnails/1.jpg)
CONSTANTS, VARIABLES AND DATA TYPES
![Page 2: ITFT-Constants, variables and data types in java](https://reader031.vdocuments.site/reader031/viewer/2022020110/555a5fccd8b42a47748b528d/html5/thumbnails/2.jpg)
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.
![Page 3: ITFT-Constants, variables and data types in java](https://reader031.vdocuments.site/reader031/viewer/2022020110/555a5fccd8b42a47748b528d/html5/thumbnails/3.jpg)
Constants
![Page 4: ITFT-Constants, variables and data types in java](https://reader031.vdocuments.site/reader031/viewer/2022020110/555a5fccd8b42a47748b528d/html5/thumbnails/4.jpg)
Integer constantAn 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.
![Page 5: ITFT-Constants, variables and data types in java](https://reader031.vdocuments.site/reader031/viewer/2022020110/555a5fccd8b42a47748b528d/html5/thumbnails/5.jpg)
Real ConstantsThe 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
![Page 6: ITFT-Constants, variables and data types in java](https://reader031.vdocuments.site/reader031/viewer/2022020110/555a5fccd8b42a47748b528d/html5/thumbnails/6.jpg)
Character Constants
A single character constant contains a single character enclosed with in a pair of single quote mark. Example: -
‘a’,’A’,’12’
![Page 7: ITFT-Constants, variables and data types in java](https://reader031.vdocuments.site/reader031/viewer/2022020110/555a5fccd8b42a47748b528d/html5/thumbnails/7.jpg)
String constant
A string constant is a sequence of character enclosed between double quote. Example:
“hello”, ”java”
![Page 8: ITFT-Constants, variables and data types in java](https://reader031.vdocuments.site/reader031/viewer/2022020110/555a5fccd8b42a47748b528d/html5/thumbnails/8.jpg)
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
![Page 9: ITFT-Constants, variables and data types in java](https://reader031.vdocuments.site/reader031/viewer/2022020110/555a5fccd8b42a47748b528d/html5/thumbnails/9.jpg)
Data Types
![Page 10: ITFT-Constants, variables and data types in java](https://reader031.vdocuments.site/reader031/viewer/2022020110/555a5fccd8b42a47748b528d/html5/thumbnails/10.jpg)
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
![Page 11: ITFT-Constants, variables and data types in java](https://reader031.vdocuments.site/reader031/viewer/2022020110/555a5fccd8b42a47748b528d/html5/thumbnails/11.jpg)
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.
![Page 12: ITFT-Constants, variables and data types in java](https://reader031.vdocuments.site/reader031/viewer/2022020110/555a5fccd8b42a47748b528d/html5/thumbnails/12.jpg)
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'
![Page 13: ITFT-Constants, variables and data types in java](https://reader031.vdocuments.site/reader031/viewer/2022020110/555a5fccd8b42a47748b528d/html5/thumbnails/13.jpg)
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
![Page 14: ITFT-Constants, variables and data types in java](https://reader031.vdocuments.site/reader031/viewer/2022020110/555a5fccd8b42a47748b528d/html5/thumbnails/14.jpg)