0% found this document useful (0 votes)
2 views

1.2 Data Types, Operators and Control Statements

Uploaded by

chibunnajoe31
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

1.2 Data Types, Operators and Control Statements

Uploaded by

chibunnajoe31
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Subject Name

Data Types Operators & Control Statements

Dr. Anuprita Deshmukh

103 Java Programming (Dr Anuprita Deshmukh)


1.0 Java introduction
Subject Name

Learning Objectives

To know about

• To know the data types of the Java


• To know the use of various operators in java programs.
• To learn how to build expressions using operators in java
program.
• To know the functions of operators.
• To learn Control structure in java.

103 Java Programming(Dr Anuprita Deshmukh)


1.0 Java introduction
Subject Name

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

103 Java Programming(Dr Anuprita Deshmukh)


1.0 Java introduction
Subject Name

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.

103 Java Programming(Dr Anuprita Deshmukh)


1.0 Java introduction
Subject Name

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

float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7


decimal digits
double 8 bytes Stores fractional numbers. Sufficient for storing 15
decimal digits
boolean 1 bit Stores true or false values
char 2 bytes Stores a single character/letter or ASCII values

103 Java Programming(Dr Anuprita Deshmukh)


1.0 Java introduction
Subject Name

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

The switch Statement


The Java switch statement executes one statement from multiple conditions. It is
like if-else-if ladder statement. The switch statement works with byte, short, int,
long, enum types, String and some wrapper types like Byte, Short, Int, and Long.
The syntax for switch is:
switch(expression)
{
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}

103 Java Programming(Dr Anuprita Deshmukh)


1.0 Java introduction
Subject Name

Thank You

103 Java Programming(Dr Anuprita Deshmukh)


1.0 Java introduction

You might also like