0% found this document useful (0 votes)
522 views21 pages

Variables, Data Types, Operators, Keywords, Control Statements

The document discusses variables, data types, operators, and control statements in Java. It defines three types of variables (local, instance, static) and lists the primitive data types (boolean, byte, short, int, long, float, double, char). It also describes arithmetic, assignment, comparison, and logical operators. Finally, it provides an overview of control statements including if/else statements, loops (for, while, do-while), and jump statements (break, continue).

Uploaded by

Julfikar Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
522 views21 pages

Variables, Data Types, Operators, Keywords, Control Statements

The document discusses variables, data types, operators, and control statements in Java. It defines three types of variables (local, instance, static) and lists the primitive data types (boolean, byte, short, int, long, float, double, char). It also describes arithmetic, assignment, comparison, and logical operators. Finally, it provides an overview of control statements including if/else statements, loops (for, while, do-while), and jump statements (break, continue).

Uploaded by

Julfikar Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

VARIABLES, DATA TYPES, OPERATORS, KEYWORDS,

CONTROL STATEMENTS
Variables
Syntax

Data type variable_name ;

Example: int data;


char name = ‘x’;
• THERE ARE THREE TYPES OF VARIABLES IN JAVA :

• LOCAL VARIABLE,
• INSTANCE VARIABLE,
• STATIC VARIABLE.
public class A
{
static int m=100; Static variable
void method()
{
int n=90; Local variable
}
public static void main(String args[])
{
int data=50; Instance variable
}
}
Data Types
Data types are divided into two groups:

• Primitive data types - byte, short, int, long, float,


double, boolean and char

• Non-primitive data types - String, Arrays and Classes


Primitive Data Types :
Boolean Data Type:

Boolean x = false;
System.out.println(“Number is :” +x);

Byte Data Type:

byte Num = 100;


System.out.println(“Number is :” +Num);

Short Data Type:

short s = 10000;
System.out.println(“Number is :” +s);

Int Data Type:

int a = 100000;
System.out.println(“Number is :” +a);
Long Data Type:

long b = -200000L;
System.out.println(“Number is :” +b);

Float Data Type:

float p = 234.5f;
System.out.println(“Number is :” +p);

Double Data Type:

double d = 12.3;
System.out.println(“Number is :” +d);

Char Data Type:

char letter = ’A’;


System.out.println(“Number is :” +letter);
Operators

Operator in Java is a symbol that is used to


perform operations.
Arithmetic Operators:
Assignment Operators:
Comparison Operators
Logical Operators
KEYWORDS

Keywords are predefined words by Java so they cannot be


used as a variable or object name or class name.
Keywords:
Control
Java Control Statements: Statements

Decision Making Loop Statements Jump Statements


Statements

• if statements • for • break


• if else statements • while • continue
• if-else-if ladder • do while • return
• switch statements
DECISION MAKING STATEMENTS
• if • if else • if-else-if • switch

if (condition) if (condition) if (condition) switch (expression)


{ { case 1:
{ statement 1; statement 1; statement 1;
} } break
statement 1; else else if (condition 2) case 2;
{ { statement 2;
} statement 2; statement 2; break;
} } .
else .
{ default :
statement 3; statement;
}
LOOP STATEMENTS

• for • while • do while

for(initialization; initialization; initialization;


condition; while (condition) do
increment/decrement) { {

{ statement 1; statement 1;
increment/ increment/
statement 1; decrement; decrement;

} } }
while (condition);
JUMP STATEMENTS

• break • continue

break; continue;
THE END

You might also like