File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Isn't this contradictory ?

 
Netty poestel
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 1 of section[4.5] Marcus Green tutorial states:-

"Essentially a class level variable will always be assigned a default value and a member variable (one contained within a method) will not be assigned any default value. "

but

"Certified Programmer & Developer for Java 2 Study Guide...by Kathy Sierra and Bates " states on page 33[1st chapter- Language fundamentals]:-
Instance variables[ also called as member variables] are variables defined at the class level.

Isn't this contradictory ?
 
Jay Pawar
Ranch Hand
Posts: 411
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Netty,

Here are my views...


"Essentially a class level variable will always be assigned a default value and a member variable (one contained within a method) will not be assigned any default value. "


I wouldn't call member variable which is within a method. Variables within a method are called local variables and they need to be initialized before you use them.
I perfectly agree with Kathy & Bert's terminology for member variables
 
Jay Pawar
Ranch Hand
Posts: 411
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Typo...
I meant to say I wouldn't call a variable which is within a method as MEMBER variable. I believe it's a local variable
 
Colin Fletcher
Ranch Hand
Posts: 200
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a difference in termanology here.

Instance Variables = member variables = class level variable
local variable = METHOD variables = are defined within a method.



From the code snippet above, you can see the userName variable is an instance variable or a member variable. The aVariable variable in doSomething is a method variable.

Hope this helps
 
Jay Pawar
Ranch Hand
Posts: 411
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Netty,
I would appreciate if you could give me a link to Marcus Green tutorial ?
Thanks in advance
 
Corey McGlone
Ranch Hand
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just as my own nitpick, be careful when you refer to "class-level" variables. When someone says "class-level" to me, I immediately think static variable. The terminology I use is like this, and usually seems to be appropriate:

Local Variable - A variable defined within a method
Instance Variable / Member Variable - A non-static variable declared within a class
Class Variable / Static variable - A static variable declared within a class
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jay Pawar:
Netty,
I would appreciate if you could give me a link to Marcus Green tutorial ?
Thanks in advance



Marcus' Java Certification HeadQuarters (JCHQ)

I started out there before I came over to JavaRanch. Marcus has helped a lot towards my SCJP 1.4 - especially the Question Of The Day
 
Netty poestel
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcus tutorial page URL [Objective 5, Unassigned variables]:-

http://www.jchq.net/certkey/0405certkey.htm

and thx. all for all the feedbacks.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic