Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Study Note on Java - Operators and Expressions

Rating
-
Sold
-
Pages
6
Uploaded on
28-02-2022
Written in
2021/2022

Study Note on Java - Operators and Expressions

Institution
Course

Content preview

Chapter 5: Operators and Expressions
5.1 Operators
 Is a symbol that tells the computer to perform certain mathematical or logical manipulations.
 Are used in programs to manipulate data and variables.
 Operators can be classified into 8 categories:
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Increment and Decrement Operators
6. Conditional Operators
7. Bitwise Operators
8. Special Operators
5.1.1 Arithmetic Operators
Operator Meaning
+ Addition or unary plus
- Subtraction or unary minus
* Multiplication
/ Division
% Modulo division

5.1.1.1 Integer Arithmetic
 When both the operands in a single arithmetic expression are integers, the expression is
called an Integer Expression and the operation is called Integer Arithmetic.
5.1.1.2 Real Arithmetic
 An arithmetic operation involving only real operands is called Real Arithmetic.
 A real operand may assume values either in decimal or exponential notation.
5.1.1.3 Mixed – mode Arithmetic
 When one of the operands is real and the other is integer, the expression is called a
mixed-mode arithmetic expression.
 If either operand is of the real type, then the other operand is converted to real and the
real arithmetic is performed.
5.1.2 Relational Operators
 Contains only one relational operator
 The general form is:
Ae-1 relational operator ae-2
 Ae-1 and ae-2 are arithmetic expressions, which may be simple constants,
variables or combination of them.
 When arithmetic expressions are used on either side of a relational operator, the
arithmetic expressions will be evaluated first and then the results compared. That is,
arithmetic operations have a higher priority over relational operations.
Operator Meaning
< Is less than
<= Is less than or equal to
> Is greater than
>= Is greater than or equal to
== Is equal to

, != Is not equal to

5.1.3 Logical Operators
 The logical operators && and || are used when we want to form compound conditions
by combining two or more relations.
Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT

5.1.4 Assignment Operators
 Assignment operators are used to assign the value of an expression to a variable.
 General form is:
V op= exp;
 V is a variable
 Exp is an expression
 Op is a java binary operator
 Op= is the shorthand assignment operator
 Shorthand Assignment Operators
Statement with simple assignment operator Statement with shorthand operator
a=a+1 a += 1
a=a–1 a -= 1
a = a * (n+1) a *= n+1
a = a / (n-1) a /= n+1
a=a%b a %= b

5.1.5 Increment and Decrement Operators
 The increment and decrement operators are ++ and –
 The operator ++ adds 1 to the operand
 The operator - - subtracts 1
5.1.6 Conditional Operator
 The character pair ? : is a ternary operator available in Java. This operator is used to
construct conditional expressions of the form:
exp1 ? exp2 : exp3
Where exp1, exp2, and exp3 are expressions.
 The operator ? : works as follows:
 exp1 is evaluated first. If it is nonzero (true), then the exp2 is evaluated and
becomes the value of the conditional expression.
 If exp1 is false, exp3 is evaluated and becomes the value of the conditional
expression.
5.1.7 Bitwise Operators
Operator Meaning
& Bitwise AND
! Bitwise OR
^ Bitwise exclusive OR
~ One’s complement
<< Shift left

Connected book

Written for

Institution
Course

Document information

Uploaded on
February 28, 2022
Number of pages
6
Written in
2021/2022
Type
Class notes
Professor(s)
Mrs. prabitha
Contains
All classes

Subjects

$7.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sinithomas

Also available in package deal

Get to know the seller

Seller avatar
sinithomas Study Notes
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
4 year
Number of followers
0
Documents
10
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions