3- Object Oriented Programming Java(Lecture-3) 500 4
3- Object Oriented Programming Java(Lecture-3) 500 4
String - stores text, such as "Hello". String values are surrounded by double quotes
int - stores integers (whole numbers), without decimals, such as 123 or -123
float - stores floating point numbers, with decimals, such as 19.99 or -19.99
char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single
quotes
boolean - stores values with two states: true or false
4
Identifiers
• All Java variables must be identified with unique names.
• These unique names are called identifiers.
• Identifiers can be short names (like x and y) or more descriptive names
(age, sum, totalVolume).
• Note: It is recommended to use descriptive names in order to create
understandable and maintainable code.
5
// Good
int minutesPerHour = 60;
6
The general rules for naming variables are:
• Names can contain letters, digits, underscores, and dollar signs
• Names must begin with a letter
• Names should start with a lowercase letter, and cannot contain
whitespace
• Names can also begin with $ and
• Names are case-sensitive ("myVar" and "myvar" are different variables)
• Reserved words (like Java keywords, such as int or boolean) cannot be
used as names
7
Java Data Types
• As explained before, a variable in Java must be a specified data type:
Primitive data types - includes byte, short, int, long, float, double,
boolean and char
Non-primitive data types - such as String, Arrays and Classes (you will
learn more about these in a later chapter)
8
Primitive Data Types
• A primitive data type specifies the size and type of variable values, and it
has no additional methods.
• There are eight primitive data types in Java:
S.No Data Type Size Description
1. byte 1 byte Stores whole numbers from -128 to 127
2. short 2 bytes Stores whole numbers from -32,768 to 32,767
3. int 4 bytes Stores whole numbers from -2,147,483,648 to 2,147,483,647
4. long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
5. float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits
6. double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal digits
7. boolean 1 bit Stores true or false values
8. char 2 bytes Stores a single character/letter or ASCII values
9
Numbers
10
Thank You…!