• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Brand new to Programming.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.




 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes they are values stored in the variables defined.
 
Ranch Hand
Posts: 165
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76887
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76887
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You can't expect to wield supreme executive power just because
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic