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

java-01

Uploaded by

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

java-01

Uploaded by

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

1

A way of viewing word with OOP


Execution Process of Java Program 2
Java Data Types 3
4
Primitive Data Types

 The primitive data types


are built-in data types and
they specify the type of
value stored in a variable
and the memory size. The
primitive data types do
not have any additional
methods.
 In java, primitive data
types
includes byte, short, int, l
ong, float, double, char,
and boolean.
5
6
Non-primitive Data Types

 In java, non-primitive data types are


the reference data types or user-
created data types. All non-primitive
data types are implemented using
object concepts. Every variable of the
non-primitive data type is an object.
The non-primitive data types may use
additional methods to perform certain
operations. The default value of non-
primitive data type variable is null.
 In java, examples of non-primitive data
types
are String, Array, List, Queue, Stack, C
lass, Interface, etc.
7
Primitive Vs Non-primitive Data Types
8
Java Variables

 A variable is a named memory location used to store a data value. A variable


can be defined as a container that holds a data value.
 In java, we use the following syntax to create variables.
9
In java programming language variables are
classified as follows.

➢ Local variables
➢ Instance variables or Member variables or Global variables
➢ Static variables or Class variables
➢ Final variables
10
Local variables

 The variables declared inside a


method or a block are known as
local variables. A local variable is
visible within the method in which
it is declared. The local variable is
created when execution control
enters into the method or block
and destroyed after the method
or block execution completed.
Instance variables or member variables or 11
global variables

 The variables declared inside a


class and outside any method,
constructor or block are known
as instance variables or
member variables. These
variables are visible to all the
methods of the class. The
changes made to these
variables by method affects all
the methods in the class. These
variables are created separate
copy for every object of that
class.
12
Static variables or Class variables

 A static variable is a variable that


declared using static keyword. The
instance variables can be static variables
but local variables can not. Static
variables are initialized only once, at the
start of the program execution. The
static variable only has one copy per
class irrespective of how many objects
we create.
 The static variable is access by using
class name.
13
Final variables

 A final variable is a variable that


declared using final keyword.
The final variable is initialized
only once, and does not allow
any method to change it's
value again. The variable
created using final keyword
acts as constant. All variables
like local, instance, and static
variables can be final variables.
14
Java Operators

 An operator is a symbol used to perform arithmetic and logical operations. Java


provides a rich set of operators.
 In java, operators are classified into the following four types.
• Arithmetic Operators
• Relational (or) Comparison Operators
• Logical Operators
• Assignment Operators
• Bitwise Operators
• Conditional Operators
Arithmetic Operators 15

🔔 The addition operator can be used with numerical data types and character or string data type. When it is used with numerical
values, it performs mathematical addition and when it is used with character or string data type values, it performs concatenation
(appending).

🔔 The modulus (remainder of the division) operator is used with integer data type only.

🔔 The increment and decrement operators are used as pre-increment or pre-decrement and post-increment or post-decrement.
🔔 When they are used as pre, the value is get modified before it is used in the actual expression and when it is used as post, the value
is get modified after the actual expression evaluation.
16
17
Relational Operators (<, >, <=, >=, ==, !=)

 The relational operators are the symbols that are used to compare two values. That means the
relational operators are used to check the relationship between two values. Every relational operator
has two possible results either TRUE or FALSE. In simple words, the relational operators are used to
define conditions in a program. The following table provides information about relational operators.
18
19
Logical Operators

 The logical operators are the symbols that are used to combine multiple conditions into
one condition. The following table provides information about logical operators.

🔔 The operators &, |, and ^ can be used with both Boolean and integer data type values. When they are used with
integers, performs bitwise operations and with Boolean, performs logical operations.

🔔 Logical operators and Short-circuit operators both are similar, but in case of short-circuit operators once the
decision is finalized it does not evaluate remaining expressions.
20
21
Assignment Operators

 The assignment operators are used to assign right-hand side value (R-value) to the left-hand side variable (Value). The
assignment operator is used in different variants along with arithmetic operators. The following table describes all the
assignment operators in the java programming language.
22
23
Bitwise Operators

 The bitwise operators are used to perform bit-level operations in the java programming language.
When we use the bitwise operators, the operations are performed based on binary values..
Let us consider two variables A and B as A = 25 (11001) and B = 20 (10100).
24
25
Conditional Operators

 The conditional operator is also called


a ternary operator because it requires
three operands. This operator is used for
decision making. In this operator, first, we
verify a condition, then we perform one
operation out of the two operations based
on the condition result. If the condition is
TRUE the first option is performed, if the
condition is FALSE the second option is
performed.

You might also like