• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Variables hold the state of the program and methods operate on that state

 
Ranch Hand
Posts: 118
Android Objective C Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
variables like int,string etc hold values which change and we can also have types of those fields aka variables which can be given access modifiers and some types of variables have default values as well. But i am still failing to understand what exactly does the statement mean. Encountered this statement while going through JAVA SE 8 OCA I - 808.
 
Saloon Keeper
Posts: 9556
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have a link to the specific text you are referring to?

 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Objective C Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Carey,

The text i am referring to is on kindle edition of JAVA SE 8 OCAJP-I book in the first chapter. I have do not have any soft copy of that...
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

krishnadhar Mellacheruvu wrote:variables like int,string etc hold values which change and we can also have types of those fields aka variables which can be given access modifiers and some types of variables have default values as well. But i am still failing to understand what exactly does the statement mean.


Me too, because I doubt that it actually said what you wrote.

First of all, "int, string [which should actually be String] etc" are NOT variables, they're types.

Secondly, String values don't change, because String is immutable.

Now I don't want to swamp you with terminology here, but it is really important that you understand the ones that the book is using.

In the declaration: "private String firstName;":
  • 'String' is the type.
  • 'firstName' is the variable.           and
  • 'private' is the access modifier.
  • and 'firstName' is a variable not because you can change the contents of a String, but because you can change IT (ie, firstName) to hold a different String, viz:
      private String firstName = "a new first name";
      ...
      firstName = "a different first name";
    but if the declaration was:
      private final String firstName;
    you couldn't; and 'firstName' would then be a constant.

    Now, getting back to your question: What exactly is it about the statement that you don't understand?

    My advice would be to copy the statement (or paragraph) that's causing you problems, and and paste it here exactly as it appears in the book, and then ask your question again - maybe with a bit more detail about what it is you don't understand.

    HIH

    Winston
     
    krishnadhar Mellacheruvu
    Ranch Hand
    Posts: 118
    Android Objective C Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi

    Winston,

    This is what is written in the book...

    Java classes have two primary elements: methods, often called functions or procedures in other languages, and fields, or more generally known as variables. Together these are called members of the class. Variables hold the state of the program, and members operate on that state. If the change is important to remember, a variable stores that change.

    The last sentence is what i did not get properly..

    Does the STATE here means the values that the variables store... ?
     
    Marshal
    Posts: 76404
    364
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The state of an object means all the values of its fields combined. So if one field changes the state changes. I think you have misread what the book says; it probably says methods operate on that state. It is a bit inaccurate to say that fields are called variables; there are some variables which are not fields and some fields may be constant so they are not variables.

    Note that static fields do not actually form part of the object.
     
    Winston Gutkowski
    Bartender
    Posts: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    krishnadhar Mellacheruvu wrote:Does the STATE here means the values that the variables store... ?


    Basically, yes. But as Campbell says, it usually refers to the current values of ALL variables that a class has collectively.

    For example, the "state" of a ChessGame class would probably be the positions of all pieces currently on its 'board'.

    HIH

    Winston
     
    krishnadhar Mellacheruvu
    Ranch Hand
    Posts: 118
    Android Objective C Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi

    Ricthie,

    Yup, thats a type mistake from my side, it is indeed methods and not members,

    @Winston

    Thats an awesome example to make it understandable....
     
    Winston Gutkowski
    Bartender
    Posts: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    krishnadhar Mellacheruvu wrote:Thats an awesome example to make it understandable....


    Glad you liked it. And welcome to JavaRanch.

    Winston
     
    I'm full of tinier men! And a tiny ad:
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic