• 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
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

What does the period do?  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beginner here,

This is from another thread:  https://coderanch.com/t/245950/certification/Exam-Prep-post-increment I read but I could not understand what the JMM125.i on the last line of code means. Especially that period between the JMM125 and i. What does it do to make it come out as a 3?

Explanation? Thank you!



Product:

1
2
1
2
0
1
3
 
Marshal
Posts: 64172
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the idea is to show that the three local variables called i are distinct from the static field called i. Note the scopes of the three local variables must not overlap.
 
Sheriff
Posts: 5931
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On line 3 you have an instance class variable called i.  That variable can be seen in all methods except when it is hidden by a local variable.  On line 12 you have a local variable also called i that hides the instance class variable.  Line 16 accesses the instance class variable directly.  It is 3 because you use it in line 6.

[Edit: missed that the first i is static.]
 
Campbell Ritchie
Marshal
Posts: 64172
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My mistake: there are only two local variables.
 
Ranch Hand
Posts: 531
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Peter Park wrote:Beginner here,

This is from another thread:  https://coderanch.com/t/245950/certification/Exam-Prep-post-increment I read but I could not understand what the JMM125.i on the last line of code means. Especially that period between the JMM125 and i. What does it do to make it come out as a 3?

Explanation? Thank you!



Product:

1
2
1
2
0
1
3



Hi, Peter,

When you loop within the static main method, you don't declare a new int variable in your loop, you assign a value to one that already exists, the static one. You don't have to qualify the static variable's name with class name if you don't want to. It's a tricky piece of code. I would always qualify for readability.

So basically, it increments the static i variable and then prints out its last value.

With best regards,

Anton.
 
Peter Park
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies! I think I understand it.
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!