1.2 Data Types, Operators and Control Statements
1.2 Data Types, Operators and Control Statements
Learning Objectives
To know about
Class Vs Structure
Sr. No Class Structure
1 defined using ‘class’ defined using ‘struct’
2 stored in memory as a Every member is provided with a
reference. unique memory location.
3 Variables can be initialized Variables cannot be initialized during
during the declaration, the declaration,
4 all the members are private all the members are public
5 Reference type value type
Class Vs Structure
Sr. No Class Structure
6 variable can have null values no null values in any structure member
7 The reference type (before creating an values allocated to structures are stored in
object) is allocated on heap memory. stack memory.
8 have constructors and destructors. doesn’t have a constructor or destructor.
9 It can use inheritance to inherit doesn’t support inheritance
properties from base class.
10 The ‘protected’ access modifier can be doesn’t support protected access modifier.
used with the data members defined
inside the class.
Data Types
Data Type Size Description
byte 1 byte Stores whole numbers from -128 to 127
short 2 bytes Stores whole numbers from -32,768 to 32,767
int 4 bytes Stores whole numbers from -2,147,483,648 to
2,147,483,647
long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808
to 9,223,372,036,854,775,807
The if Statement
Syntax for if statement is :
if (condition1) {
// Statements to be executed if condition1 is true
} else if (condition2) {
// Statements to be executed if the condition1 is false and
condition2 is true
}
else {
// Statements to be executed if the condition1 is false and
condition2 is false
}
103 Java Programming(Dr Anuprita Deshmukh)
1.0 Java introduction
Subject Name
Operator
Type of Operator Operator
Arithmetic Operators +, - , *, /, %
Assignment Operators =, +=, -=, *=, /=, %=, ^=
Relational Operators <, >, ==, !=, <=, >=
Ternary Operators ?:
Increment and Decrement ++, --
Operators
Logical Operators &&, ||, !
Bitwise Operators &, |, ^, ~
Shift Operators <<, >>
103 Java Programming(Dr Anuprita Deshmukh)
1.0 Java introduction
Subject Name
Thank You