CBSE 2026 results are out, Mukul scored a perfect 100/100 in Computer ScienceSee all toppers →

KwickAcademy Java · 8 min · free

Java Operators, Precedence and Expressions

8 min5 KwickClipsFull text belowFree
Next lesson →Kajal Ma'am (MCA), teaching since 2004Remembered in this browser

Arithmetic, relational, logical, assignment, increment, ternary and bitwise operators, plus the precedence that decides what runs first.

Follows the syllabus of: CBSE Class 11 Information Technology (802), CBSE Class 12 Information Technology (802), ICSE Class 9 Computer Applications, ICSE Class 10 Computer Applications

On screen in this lesson

Three new words

Operator: a symbol that does a job, like + or ==
Operand: the value it works on
Expression: operators and operands that give one value

Arithmetic operators

OperatorMeaning17 and 5
+add22
-subtract12
*multiply85
/divide3
%remainder2

Comparing vs storing

OperatorAsksExample
==equal?5 == 5 is true
!=not equal?5 != 3 is true
> and <greater, less?7 < 3 is false
>= and <=or equal?5 >= 5 is true
=stores a valuemarks = 45

Logical operators

OperatorTrue whenExample
&& (AND)both are trueage>=18 && hasId
! (NOT)value is false!isHoliday
OR: two barseither is truerain OR holiday

Increment and decrement

++ adds 1 and -- takes away 1
Prefix ++a: change first, then use the new value
Postfix a++: use the old value, then change
Alone on a line, a++ and ++a do the same thing

Trace: b = a++ + ++a;

StepValue useda after
starta = 55
a++5 (old)6
++a7 (new)7
b = 5 + 7b = 127

Quick answers

What does 10 + 4 * 3 % 5 - 8 / 3 give?

10, because * / % run left to right before + and -.

What is the difference between = and ==?

A single = stores a value; == compares two values and gives true or false.

KwickClips from this lesson

Short clips, one idea each. Good for revision the night before.

The full lesson, in text

Hello students, welcome to Kwickprep. What does ten plus four times three mod five minus eight by three give in Java? By the end of this lesson, you will solve it in seconds. We learn arithmetic, relational, logical, assignment, increment, ternary and bitwise operators, and the order Java follows.

Start with three words used all through this lesson. An operator is a symbol that does a job, like adding or comparing. An operand is a value the operator works on. In marks plus five, marks and five are operands. An expression is a mix of operators and operands that gives one final value.

Arithmetic operators do maths, and we use seventeen and five as the operands. Plus adds them, giving twenty two. Minus subtracts, giving twelve. Star multiplies, giving eighty five. Slash divides, and with two ints the answer is three, because the decimal is dropped. Percent, called modulus, gives the remainder, which is two.

Relational operators compare two values, and the answer is always true or false. Double equals asks, are they equal? Not equals asks, are they different? Greater than and less than compare which is bigger. Greater than or equal to, and less than or equal to, also say true when both are equal. Do not mix these with a single equals, which stores a value instead of comparing.

Logical operators join or flip true and false values. AND, written as two ampersands, is true only when both sides are true, like age eighteen or more and has I D. NOT, written as an exclamation mark, flips true to false and false to true. OR, written as two vertical bars, is true when either side is true. AND and OR are short circuit, so they skip the right side when the left side decides the answer.

Here, m is seventeen and n is five. Seventeen by five is three, and the remainder is two. The last line checks whether m is more than ten and n is more than zero. Both sides are true, so AND gives true.

Now the operators that confuse students most, increment and decrement. Plus plus adds one to a variable, and minus minus takes away one. In prefix form, the operator comes first. The variable changes first, and then the new value is used. In postfix form, the operator comes after. The old value is used first, and then the variable changes. When plus plus stands alone as a statement, both forms give the same result.

Let us trace int b equals a plus plus plus plus plus a, step by step, with a starting at five. At the start, a is five. First comes a plus plus, which is postfix. It uses the old value five, then a becomes six. Next comes plus plus a, which is prefix. It makes a seven first, then uses seven. So b is five plus seven, which is twelve, and a ends at seven.

The first line is the trace we just did, so it prints seven and twelve. Now pause and predict the second one yourself. The variable x starts at three. Minus minus x is prefix, so x becomes two, and two is used. Then x plus plus is postfix, so two is used again, and x becomes three. So y is two times two, which is four, and x ends at three.

Compound assignment operators do a calculation and store the answer in one step. Take a wallet balance of one hundred rupees, and start from one hundred in every row. Plus equals forty nine adds a recharge cashback, giving one forty nine. Minus equals thirty takes away thirty, giving seventy. Star equals two doubles it, giving two hundred. Slash equals three gives thirty three, because int division drops the decimal. Percent equals seven stores the remainder, which is two.

The ternary operator is a short if else that gives a value. It is called ternary because it has three parts. First a condition, then a question mark and the value if true, then a colon and the value if false. A long ternary can continue on the next line. Here m, the marks, is sixty eight. Is m at least thirty three? Yes, so r, the result, becomes Pass.

Some syllabuses also include bitwise operators, which work on the binary digits of a number. Six is one one zero in binary, and three is zero one one. Bitwise AND keeps a one only where both have one, so the answer is two. XOR keeps a one where the bits are different, so the answer is five. Bitwise NOT flips every bit, and in Java, NOT six is minus seven. Left shift by one doubles the number, giving twelve. Right shift by one halves it, giving three. There is also bitwise OR, a single bar, and six OR three is seven.

Precedence decides which operator works first, and associativity decides the order when two have the same level. Postfix increment and decrement come first. Next come prefix increment, NOT and casts, which group from right to left. Then multiply, divide and remainder. Then add and subtract, both from left to right. Then comparisons, and after them equality checks. Shift and bitwise levels sit between these rows, so check your textbook if your syllabus needs them. Lowest are AND, then OR, then the ternary, then assignment. The ternary and assignment group from right to left.

Now the question from the start. Star, percent and slash have the same level, so they go left to right. Four times three is twelve, and twelve mod five is two. Eight by three is two. Now it is ten plus two minus two, which is ten. For y, minus is left to right, so twenty minus five is fifteen, then minus three is twelve.

Let us revise what we learned today. Slash with two ints drops the decimal, and percent gives the remainder. Double equals compares, while a single equals stores. Prefix changes first and then uses, while postfix uses first and then changes. The ternary operator picks one of two values. And star, slash and percent work before plus and minus, just as AND works before OR. Now trace the pause and predict program again without looking.

Courses that teach this

CourseUnit
CBSE Class 11 Information Technology (802)Part B, Unit 5: Fundamentals of Java Programming
CBSE Class 12 Information Technology (802)Fundamentals of Java Programming
ICSE Class 9 Computer ApplicationsOperators in Java
ICSE Class 10 Computer ApplicationsRevision of Class IX Syllabus
ISC Class 11 Computer Science (868)Object-Oriented Programming with Java
GSEB Std 12 Computer StudiesObject-Oriented Concepts and Java Basics
Programming All levels JavaJava Language Basics

Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.

Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

Want a plan that actually fits your board dates?

Ask Kajal Ma'am directly, 20+ years teaching computer science. Free demo class first, no payment.

Talk to Kajal Ma'am on WhatsApp

Or see the Class 12 Computer Science course →

Studying outside India?

We coach CBSE, IGCSE & international students across the globe, one-to-one, in your local time zone.

Visit International →