aspose file tools*
The moose likes Beginning Java and the fly likes Objects vs. Variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Objects vs. Variables" Watch "Objects vs. Variables" New topic
Author

Objects vs. Variables

Jacob Michaels
Ranch Hand

Joined: Mar 23, 2003
Posts: 35
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

Read this. It's exactly what you need.


[Jess in Action][AskingGoodQuestions]
Jacob Michaels
Ranch Hand

Joined: Mar 23, 2003
Posts: 35
So would you agree or disagree that all variables created in Java are Objects?
Thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61421
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Objects vs. Variables