• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

Some confused points in pass-by-value topic, chapter 4 (Java OCA 8 Programmer I Study Guide, Sybex)

 
Ranch Hand
Posts: 221
27
IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

“Pass-by-value” is one of the most confusing topic for me until I read this topic from OCA book. This topic is explained very well, I could understand some points which was unclear for me.
I have some confused notes about this topic and I would like to share it.

1. On page 188, the latest row
Don’t we pass num variable instead of 5 or I think wrong? As this

2. On page 191, line #5 of example
The note which is written after comment in line 5 ( // 1 ) is confused me. I understand such comment show output which the same line return. Line 5 returns 2 but we know that this code doesn’t change the value of number. Maybe authors write value of number variable in it so they want to show that value of number variable isn’t change in that line, so it is explained the last paragraph of section.

3. On page 191, the last paragraph of section, fifth sentence:
Maybe numbers should be number.

Sorry for my English, maybe I don’t say my opinion correctly.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's another excellent article about the pass-by-value concept.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mushfiq Mammadov wrote:1. On page 188, the latest row


The actual code in the book is correct, but newNumber(5); isn't an example of pass-by-value. Should indeed beto have a true illustrative pass-by-value example

Mushfiq Mammadov wrote:2. On page 191, line #5 of example


I agree with you on this one: the comment behind the statement could indeed be confusing, certainly for the method invocations because you have the value of the parameter and you have the return value (which might be ignored). But there is just one number. If you have a look at the code (and/or read the explanation in the section), it's obviously the value of the variable used in the statement. Once you know this, these comments are not confusing anymore, but at a 1st glance it probably could be. And because the code is well explained in the section directly below the code, these line comments could even be dropped. Or for more clarity could be a little bit extended toor even more verboseBoth indicate the value of the variable before and after this statement. Just a suggestion, don't know if it really improves the understanding of the comments in the code snippet

Mushfiq Mammadov wrote:3. On page 191, the last paragraph of section, fifth sentence:


Not maybe, but definitely

Mushfiq Mammadov wrote:Sorry for my English, maybe I don’t say my opinion correctly.


I think I understood everything correctly after a 1st read, so no problem here

Hope it helps!
Kind regards,
Roel
 
author & internet detective
Posts: 41763
885
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mushfiq Mammadov wrote:Don’t we pass num variable instead of 5 or I think wrong?



Mushfiq Mammadov wrote:3. On page 191, the last paragraph of section, fifth sentence:
Maybe numbers should be number.



Added these two the errata. I've noted your other comments in a private list I'm keeping of "things that could be clearer, but aren't wrong." Thanks!
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:...

Mushfiq Mammadov wrote:3. On page 191, the last paragraph of section, fifth sentence:
Maybe numbers should be number.



Added these two the errata.


An erratum to the errata: the errata says the 3rd paragraph, but it is the 4th.
 
Jeanne Boyarsky
author & internet detective
Posts: 41763
885
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bram Vonk wrote:An erratum to the errata: the errata says the 3rd paragraph, but it is the 4th.


Noted. Thank you. And welcome to CodeRanch!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic