1

I was wondering what the difference is between attributes and properties in Java and what their relationship is.

Do either of them refer to specifically class or instance variables?

On some websites, I'm understanding that properties refer to the variables that change over instances of the class, which can be set using the set-get methods. Attributes, on the other hand, I found were class variables, or fields. But this makes me confused because then why do Static methods in a class need to have a parameter that is a reference to the class in order to access class attributes.

Why can't they just access them directly since class attributes are just static variables which can be accessed directly?

rarora25
  • 99
  • 9
  • Perhaps, this link provides the answer https://stackoverflow.com/questions/10115588/what-is-the-difference-between-field-variable-attribute-and-property-in-java – Andres Sacco Dec 28 '20 at 20:43
  • 3
    Does this answer your question? [What is the difference between field, variable, attribute, and property in Java POJOs?](https://stackoverflow.com/questions/10115588/what-is-the-difference-between-field-variable-attribute-and-property-in-java) – Strahinja Dec 28 '20 at 20:45
  • attribute/property - same thing. – OldProgrammer Dec 28 '20 at 20:45
  • can you guys give example of each of these in Java – rarora25 Dec 28 '20 at 20:52

1 Answers1

1

Here you will find the Java Language Specification. You'll find that the words attribute and property basically aren't in it.

These are english terms. Terms used by people to convey an idea. Any argument that uses such terms is (over)simplifying. They should have stated somewhere in the argument, tutorial, book, or explanation what, precisely, they mean with these words, because the more or less implied 'I mean what the java lang spec says it means' cannot work for these terms - they aren't in there.

I've read many tutorials and arguments in my day. The sheer number of completely different things that the words 'attribute' and 'property' were supposed to mean is as long as my leg.

Thus, the answer to your question is as simple as it may be disappointing: There is no difference. You'd have to define what you mean.

On some websites I'm understanding that properties refer to the variables that change over instances of the class, which can be set using the set-get methods.

That's one of a billion specifications, and not particularly clearly specified either.

But this makes me confused because then why do Static methods in a class need to have a parameter that is a reference to the class in order to access class attributes.

But, it doesn't. You can refer to a static field without any context or parameter, and you can access them directly.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
rzwitserloot
  • 85,357
  • 5
  • 51
  • 72
  • There's an old (but still relevant) [JavaBean specification](https://download.oracle.com/otn-pub/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/beans.101.pdf?AuthParam=1609189193_54c57a93cee2a253f66bd2c8a9c3b0fc) where properties are defined. This is the base for most frameworks in Java. – Luiggi Mendoza Dec 28 '20 at 21:01
  • Sure, within various frameworks and specs the word has a specific meaning. But javabeans is not the only book that uses this word in a more official context, and I'm not so sure it's what OP has read or what OP's book/tutorial/article/etc is talking about. Without being sure, any question about precise meanings of words is completely pointless without first defining. – rzwitserloot Dec 28 '20 at 21:36
  • Answer is here: https://www.geeksforgeeks.org/what-is-the-difference-between-field-variable-attribute-and-property-in-java/ – rarora25 Dec 29 '20 at 15:26