SlideShare a Scribd company logo
4
Most read
5
Most read
13
Most read
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

More Related Content

PPTX
Packages in java
PPTX
Java input
PPTX
Constants in java
PDF
Arrays in Java
PDF
Java variable types
PPT
Java static keyword
PPTX
Static Members-Java.pptx
PPTX
Pointers in c language
Packages in java
Java input
Constants in java
Arrays in Java
Java variable types
Java static keyword
Static Members-Java.pptx
Pointers in c language

What's hot (20)

PDF
Constants, Variables and Data Types in Java
PPTX
I/O Streams
PPTX
Classes objects in java
PPTX
Unit 5 java-awt (1)
PPTX
Ppt on this and super keyword
PPTX
Array in Java
PPTX
java interface and packages
PPTX
Java tokens
PPTX
Methods in java
PPS
String and string buffer
PPTX
Programming in c Arrays
PPTX
Storage class in c
PPT
Collection Framework in java
PPTX
Strings in Java
PPT
Java Collections Framework
PPSX
Java IO, Serialization
PPTX
ArrayList in JAVA
PPT
Data types
PPTX
Vectors in Java
Constants, Variables and Data Types in Java
I/O Streams
Classes objects in java
Unit 5 java-awt (1)
Ppt on this and super keyword
Array in Java
java interface and packages
Java tokens
Methods in java
String and string buffer
Programming in c Arrays
Storage class in c
Collection Framework in java
Strings in Java
Java Collections Framework
Java IO, Serialization
ArrayList in JAVA
Data types
Vectors in Java
Ad

Viewers also liked (11)

PDF
itft-Decision making and branching in java
PPSX
Data types, Variables, Expressions & Arithmetic Operators in java
PPT
Chapter1 c programming data types, variables and constants
PPT
Classes, objects and methods
PPT
constants, variables and datatypes in C
PPTX
02 data types in java
PPTX
Classes And Objects
PPT
Exception handling in java
PDF
Java exception handling ppt
PPTX
Classes, objects in JAVA
PPS
Java Exception handling
itft-Decision making and branching in java
Data types, Variables, Expressions & Arithmetic Operators in java
Chapter1 c programming data types, variables and constants
Classes, objects and methods
constants, variables and datatypes in C
02 data types in java
Classes And Objects
Exception handling in java
Java exception handling ppt
Classes, objects in JAVA
Java Exception handling
Ad

Similar to ITFT-Constants, variables and data types in java (20)

PPTX
Programming fundamental
PPT
2 1 data
PPTX
Computer Programming Java Data Types.pptx
PPTX
Topic-5_-Programming-Fundamentals-Part-2.pptx
PPTX
JAVA LESSON-01.pptx
PPT
JAVA PROGRAMMING : Data types
PPTX
Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.) I...
PPTX
Chapter i(introduction to java)
PPTX
03 and 04 .Operators, Expressions, working with the console and conditional s...
PPT
Chapter 2 java
PPTX
Java Foundations: Data Types and Type Conversion
PDF
03-Primitive-Datatypes.pdf
PPTX
Data types in java.pptx power point of java
PPT
Java: Primitive Data Types
PPTX
FUNDAMENTAL OF C
PDF
Lecture 2 java.pdf
PPTX
Java chapter 2
PPTX
Lecture no 1
PPSX
Java session3
PPTX
a variable in Java must be a specified data type
Programming fundamental
2 1 data
Computer Programming Java Data Types.pptx
Topic-5_-Programming-Fundamentals-Part-2.pptx
JAVA LESSON-01.pptx
JAVA PROGRAMMING : Data types
Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.) I...
Chapter i(introduction to java)
03 and 04 .Operators, Expressions, working with the console and conditional s...
Chapter 2 java
Java Foundations: Data Types and Type Conversion
03-Primitive-Datatypes.pdf
Data types in java.pptx power point of java
Java: Primitive Data Types
FUNDAMENTAL OF C
Lecture 2 java.pdf
Java chapter 2
Lecture no 1
Java session3
a variable in Java must be a specified data type

More from Atul Sehdev (8)

PDF
itft-Overview of java language
PDF
itft-Operators in java
PDF
itft-Java evolution
PDF
itft-Inheritance in java
PDF
itft-Fundamentals of object–oriented programming in java
PDF
ITFT-Classes and object in java
PDF
ITFT- C,c++,java and world wide web
PDF
ITFT- Applet in java
itft-Overview of java language
itft-Operators in java
itft-Java evolution
itft-Inheritance in java
itft-Fundamentals of object–oriented programming in java
ITFT-Classes and object in java
ITFT- C,c++,java and world wide web
ITFT- Applet in java

Recently uploaded (20)

PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Open Quiz Monsoon Mind Game Final Set.pptx
PPH.pptx obstetrics and gynecology in nursing
O5-L3 Freight Transport Ops (International) V1.pdf
Microbial disease of the cardiovascular and lymphatic systems
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Pharma ospi slides which help in ospi learning
Week 4 Term 3 Study Techniques revisited.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Renaissance Architecture: A Journey from Faith to Humanism
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
01-Introduction-to-Information-Management.pdf
Microbial diseases, their pathogenesis and prophylaxis
STATICS OF THE RIGID BODIES Hibbelers.pdf
Cardiovascular Pharmacology for pharmacy students.pptx
human mycosis Human fungal infections are called human mycosis..pptx

ITFT-Constants, variables and data types in java

  • 2. 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.
  • 4. 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.
  • 5. 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
  • 6. Character Constants A single character constant contains a single character enclosed with in a pair of single quote mark. Example: - ‘a’,’A’,’12’
  • 7. String constant A string constant is a sequence of character enclosed between double quote. Example: “hello”, ”java”
  • 8. 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
  • 10. 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
  • 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 • 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'
  • 13. 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