Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Does Java Operators precedence is working from C language perspective?

 
Greenhorn
Posts: 11
Java
  • Mark post as helpful
  • send pies
  • 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: 22014
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 10777
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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?
 
what if we put solar panels on top of the semi truck trailer? That could power this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic