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

JAVA Lecture 2

The document discusses variables in 3 key points: 1. Variables are memory locations used to store data and are referenced by name. They have a datatype and are declared, initialized, and utilized. 2. Variable initialization assigns a value to the variable. Variable utilization uses the variable value. 3. Common datatypes include boolean, char, byte, short, int, long, float, and double. Strings are a non-primitive datatype for character sequences.

Uploaded by

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

JAVA Lecture 2

The document discusses variables in 3 key points: 1. Variables are memory locations used to store data and are referenced by name. They have a datatype and are declared, initialized, and utilized. 2. Variable initialization assigns a value to the variable. Variable utilization uses the variable value. 3. Common datatypes include boolean, char, byte, short, int, long, float, and double. Strings are a non-primitive datatype for character sequences.

Uploaded by

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

Variables:-

• Variable is piece of memory location which is used to store the


information.
• Variables are reference to memory location in which data are stored.

• 3 steps of variable usage are:-


• Variable Declaration.
• Variable Initialization.
• Variable utilization.
• Declaration :-
Datatype + Reference Variable

Ex:- int a; char b ; float c;

Here datatype represents which type of data the reference variable can store in the memory
location, and the reference variable gives the identity to data, so as if we want to access the data
we have to call the reference variable.

• Variable Initialization:-
Variable initialization means giving values to a variable.
Ex :-
int a = 10;
So here a is a reference variable which represents a memory location in which we are storing a
value i.e 10.
• Variable utilization:-
Variable utilization means using the variable.

int a = 4;
Int b

int b = a;

Or
int a = 5;
int b = 6;
Int c;

Int c = a+b;
i.e c = 5+6;
So C=11
Data Types :- Datatypes are the keyword which represents a type of Data. It is predefined.
Data Type Description Defauult Values Size comments
Boolean True or False FALSE 1 bit
char character null 2 byte
byte numeric 0 1 byte
short numeric 0 2 byte
int numeric 0 4 byte
long numeric 0 8 byte
float decimal 0.000000 4 byte upto 7 decimal digits
0.000000000000
double decimal 000 8 byte upto 16 decimal digits
Non-Primitive Data Type or Reference Data Types:-

String: Strings are defined as an mulitple of characters. The difference between a character array and a string in Java is,
the string is designed to hold a sequence of characters in a single variable whereas, a character array is a collection of
separate char type entities.

Java Operators :-

Operators are symbols which are used to perform some operations.

Types Of Operators:-
• Arithmetic Operators:-This operation are used to perform any arithmetic operations in Java.
1. +
2. -
3. *
4. / = quotient
5. % = remainder
Relational Operators :- It check the relation between two entities and returns true or false.
These operators are used to check for relations like equality, greater than, less than. They return boolean result after the
comparison and are extensively used in looping statements as well as conditional if else statements.

1. == equal to
2. != not equal
3. > greater than
4. < less than
5. >= greater than or equal to
6. <= less than or equal to

Suraj = 20;
Dheeraj = 21;

Suraj > Dheeraj ---false


Suraj == Dheeraj--- false
Suraj<Dheeraj--- True
Suraj >= Dheeraj-- false
Suraj<= Dheeraj– true

Suraj != Dheeraj True


• Logical Operators :-
These operators are used
to perform “logical AND” and “logical OR” operation,
Returns Boolean value.
A B Result
• &&, Logical AND : returns true when both
conditions are true. TRUE TRUE TRUE
• ||, Logical OR : returns true if at least one
condition is true.
TRUE FALSE FALSE

• &&, Logical AND:-


FALSE TRUE FALSE
• (Condition one)&&(Condition two) :- Both
condition should be true FALSE FALSE FALSE
||, Logical OR:-

(condition one) OR
(condition two) {any one
condition should be true}
A B Result
TRUE TRUE TRUE
NOT is denoted by ! TRUE FALSE TRUE
FALSE TRUE TRUE
FALSE FALSE FALSE

You might also like