Please view the following link - the tutorial is a tutorial labelled "The Jvava Tutorial" which has a section catered to annotations:
You have to protect variables, because you depend in them.
Limiting the access to the getter and setter, you can depend on the variables to be used in the context you expect to have them.
Also, you can validate the value on the setter, which gives you the chance to to reject the value in case it is not ok (throw Exception). This protects your code from failing.
As a 3. argument: The same variable can be part of different methods/classes. but each name of a variable has to be unique, otherwise the code will fail.
So one limits down the range, where the variable exists as much as possible. therefor, one can use the same name again - not that one does it constantly, but one has the chance to.
And last but not least: it's simply good design/style to do so.
The usage of static should also be limited as much as possible.
There are some occasions where it is needed - but that should be used as less as possible.
Please read about the "encapsulation" - the link, that Richard posted. And please do some more research.
This is a basic of java development. One can't go without this, so you need to understand it.
in the ProductConsumer class, but Netbeans gave me the same error message, "cannot find symbol: method messageList(), location: class ProductConsumer," so I need to create a method messageList() in ProductConsumer. Thanks.
Firstly you need to understand the product you are using: Netbeans does not produce these error messages, they come from the Java compiler; this is a Java program error. Secondly you need to look at your use of the package keyword, as I mentioned in my earlier message. And thirdly, go back to the responses that Torsten.H has given you about your use of messageList().
One of these days I'm going to think of a really clever signature.
Last Visit: 31-Dec-99 19:00 Last Update: 14-Dec-17 7:31