This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Brand new to Programming.  RSS feed

 
Bp Parker
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, glad to be with these forums as I take a dive
into programming. I've done days of research and have decided
to take in Java as my first language. So here is my question ..

I understand variables are used to store value.
So in the code below,



is 42, true, & A the values the variables are storing?
I also understand this question is most likely dumb
but i'm just trying to make sure i'm understanding it.
Thanks in advance

AddiTech89.




 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes they are values stored in the variables defined.
 
Steffe Wilson
Ranch Hand
Posts: 165
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bp, welcome to the forum.
Yes, as Tushar says, you are correct.
One way to think of it is that variables are like boxes or containers into which you put things, whether they be numbers, individual characters, strings of text or other objects.
And no question is dumb; we're all on the same path here, just at different places along it.
 
Campbell Ritchie
Marshal
Posts: 55799
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steffe Wilson wrote:. . . One way to think of it is that variables are like boxes or containers into which you put things, whether they be numbers, individual characters, strings of text or other objects.. . .
Since the OP's variables all point to primitives, then yes, the variables actually contain the values mentioned. When you write
int myNumber = 42;
… then somewhere there is a memory location containing this:-
0000_0000_0000_0000_0000_0000_0001_1010

But if you use a reference type (i.e. anything which isn't a primitive), then your memory location contains some information to find the object in memory. Probably a location where the true memory location of your object is to be found, but that is neither strictly defined nor the same for all implementations.

And welcome again
 
Steffe Wilson
Ranch Hand
Posts: 165
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:When you write
int myNumber = 42;
… then somewhere there is a memory location containing this:-
0000_0000_0000_0000_0000_0000_0001_1010

correction:
0000_0000_0000_0000_0000_0000_0010_1010
(this being the binary encoding of the decimal number 42)

Fair point about object refs Campbell, they are handled differently, maybe I should have excluded the word 'objects' from my analogy to avoid that particular issue.
 
Campbell Ritchie
Marshal
Posts: 55799
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steffe Wilson wrote:. . . correction:
0000_0000_0000_0000_0000_0000_0010_1010 . . .
Damn! You are right; I had written 26 in binary.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!