• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Objects vs. Variables

 
Jacob Michaels
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please explain the difference between Objects and Variables? Are all Variables created in Java considered Objects?
Thanks for any responses!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read this. It's exactly what you need.
 
Jacob Michaels
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So would you agree or disagree that all variables created in Java are Objects?
Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No variables that you create in Java are objects. A variable is either a primitive type (such as int) or an object reference.
This is a tremendously important concept.
When you create a variable of a primitive type:

The variable contains an integer value (in this case uninitialized).
But when you declare an object variable:

no Integer object exists until you create one and assign it to the variable as in

The variable is merely a holder for the reference to the actual object.
hth,
bear
[ September 16, 2003: Message edited by: Bear Bibeault ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic