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

Core Java Durga

Uploaded by

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

Core Java Durga

Uploaded by

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

the next topic—no, not the next topic.

I am going to talk about operators and


assignment. The subtopics are operators and assignment operators.

Operators are the most important topic in SCJP. Do you know the value of 2 * 3?
Don't think too much; its value is 6. Okay, from our learning of addition,
subtraction, multiplication, and so on, there is nothing new in the concept of
operators, right? However, do you know the best book for SCJP is by Kathi Sierra?
If you open this book and read the section on operators, she mentions an important
point in the introduction: most exam takers score the least in the operator
concept. Like, I remember when I prepared for my exam, I didn't face any difficulty
in mathematics, so I ignored the topic. But then, in the exam, I struggled. Later,
students started coming to me saying, "Sir, this is my score," with many students
barely passing the SCJP exam due to low scores in the operator concept.

I remember one student who scored 87% overall in SCJP, scoring 100% in language
fundamentals, exception handling, and collections concepts, 95% in multithreading
concepts, but only 36% in operators and assignment concepts. The score distribution
in the old version of the exam showed this clearly. When I opened the book again, I
underlined the statement: "most exam takers score the least in the operator
concept." That shows the power of this concept. Do not underestimate this topic,
even though it is very basic. There are several loopholes that you need to remember
very carefully.

Now, let's discuss the agenda related to operators. Our agenda includes:

Increment and Decrement Operators


Arithmetic Operators
String Concatenation Operators
Relational Operators
Equality Operators
Instanceof Operator
Bitwise Operators
Short Circuit Operators
Type Cast Operator
Assignment Operator
Conditional Operator
New Operator
We will cover these topics comprehensively in four sessions, focusing on increment
and decrement operators first.

There are two types of increment operators in Java:

Pre-increment (++x)
Post-increment (x++)
For example, if int x = 10; int y = ++x;, y will be 11 because it is pre-increment.
If int x = 10; int y = x++;, y will be 10 because it is post-increment.

Similarly, there are decrement operators:

Pre-decrement (--x)
Post-decrement (x--)
For example, if int x = 10; int y = --x;, y will be 9 because it is pre-decrement.
If int x = 10; int y = x--;, y will be 10 because it is post-decrement.

We can apply increment and decrement operators only to variables, not to constant
values. For example, 10++ is invalid and will cause a compile-time error.

Next, nesting of increment and decrement operators is not allowed. For example, ++
(++x) is invalid.
Let’s conclude this section with an example:

csharp
Copy code
int x = 10;
int y = ++x + x++;
System.out.println(y); // Output will be 22 because ++x is 11 and x++ is also 11
before incrementing to 12.
In summary, the key points for increment and decrement operators are:

Applicable only to variables, not constants.


Nesting is not allowed.
Be cautious with pre and post behavior.
We'll continue with other operators in the next sessions.

You might also like