Results 1 to 5 of 5

Thread: Reference !

  1. #1
    Jack_Tauson_Sr is offline Senior Member
    Join Date
    Nov 2011
    Posts
    109
    Rep Power
    0

    Default Reference !

    In the following code:

    class Node
    {
    int iData; // data used as key value
    double fData; // other data
    node leftChild; // this node’s left child
    node rightChild; // this node’s right child

    }

    I understand that Node is a class and when we want to refer to a variable we can use the format "type name " format where type is the name of the class and name is the name of the variable.

    So,In the above code, node leftchild is used where leftchild is a variable of type node. Why the node is not written as "Node" as N is capital while defining the class name. Shouldn't it be "Node leftchild" or "Node rightchild". Please clarify and thanks in advance.

    PS: the above code is an excerpt from a book.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Reference !

    Yes you are right.
    Code Conventions for the Java Programming Language: 9. Naming Conventions
    "Class names should be nouns, in mixed case with the first letter of each internal word capitalized. "
    And if the same node is meant as the class itself, then more than ever.
    p.s.: Burn the book :)

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,360
    Blog Entries
    7
    Rep Power
    20

    Default Re: Reference !

    It probably should be a 'Node' type instead of 'node' (unless there's something going on, not shown in the code snippet). That's the trouble with a lot of those books nowadays: those authors are only in it for the money and those books are full of crappy code. Also the names 'iData' and 'fData' are lousy imho, better change them to 'key' and 'data' instead ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Jack_Tauson_Sr is offline Senior Member
    Join Date
    Nov 2011
    Posts
    109
    Rep Power
    0

    Default Re: Reference !

    Thanks a lot for your answer guys.

    Any good Java book recommended for algorithms?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Reference !

    Quote Originally Posted by Jack_Tauson_Sr View Post
    Thanks a lot for your answer guys.

    Any good Java book recommended for algorithms?
    You asked this question two minutes earlier in Constructor Not Used ?

    Please go through the Forum Rules, particularly the second paragraph.

    db

    THREAD CLOSED
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Reference object
    By clj89 in forum New To Java
    Replies: 5
    Last Post: 10-22-2011, 11:32 PM
  2. How to change value by reference?
    By chris83190@hotmail.com in forum New To Java
    Replies: 5
    Last Post: 05-08-2011, 07:52 AM
  3. Don't pass by reference
    By Lyven in forum Advanced Java
    Replies: 6
    Last Post: 11-16-2009, 06:06 PM
  4. Object and reference
    By katie in forum New To Java
    Replies: 2
    Last Post: 10-19-2009, 03:45 PM
  5. Pass-by-reference
    By popjava in forum New To Java
    Replies: 1
    Last Post: 10-19-2009, 03:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •