• 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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: 61690
192
  • 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: 5443
147
Chrome Eclipse IDE Java Postgres Database 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: 61690
192
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!