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

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: 62806
203
  • 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: 5667
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: 62806
203
  • 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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!