• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Does Java Operators precedence is working from C language perspective?

 
Greenhorn
Posts: 11
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello every one!
Actually i am a kickbhut in C.
I just started to learn Java., And directly preparing for OCJP6 Certification.
In Kathy-Sierra book, and as well as in exam syllabus also, there's no Operator's precedence matter.
But i was in fully confused when i saw the Java Operators precedence table from Documentation.

From my C-Language: Operators(44) precedence table

1) () [] .(dot)
2)Unary: ++pre/--pre, -, +, (cast)
3)Arithmetic
4)bitshift
5)relational
6)bitwise
7)logical
8)ternary Operator
9)Assignment operators
10) unary post++/post--





Java Operators precedence table

Operators Precedence
1)postfix expr++ expr--
2)unary ++expr --expr +expr -expr ~ !
3) arithmetic
4)shift << >> >>>
5)relational < > <= >= instanceof
equality == !=
6)bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
7)logical AND &&
logical OR ||
8)ternary ? :
9)assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=





Please some one clarify me!
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "magic" here is in how i++ and ++i work. Both increment i, and both work before the assignment. The difference is that i++ returns the old value of i and ++i returns the new value.

They work a bit like this:
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:The "magic" here is in how i++ and ++i work. Both increment i, and both work before the assignment. The difference is that i++ returns the old value of i and ++i returns the new value.


Exactly the same as in C.
 
Omkar chary
Greenhorn
Posts: 11
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am talking about operators precedence! According to Java operators precedence rule!
post increment and decrement operators having higher precedence then assignment operator.
incrementation has to be done first then assignment has to be done as from my C language operators perspective!
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Omkar onky wrote: I am talking about operators precedence! According to Java operators precedence rule!
post increment and decrement operators having higher precedence then assignment operator.
incrementation has to be done first then assignment has to be done as from my C language operators perspective!


OK, but what does the post-increment operator do? (I presume this is the one you're having problems with)

I suggest you read up on what it was designed to do - in BOTH languages - before you start using exclamation marks on us.

Winston
 
Omkar chary
Greenhorn
Posts: 11
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apology, Mr.Winston, I am requesting you to, see this link Here!
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, do you still have a question about this? It works the same in Java as in C. Did you expect something different? Why?
 
The harder I work, the luckier I get. -Sam Goldwyn So tiny. - this ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic