File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Need of Setters/Getters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need of Setters/Getters" Watch "Need of Setters/Getters" New topic
Author

Need of Setters/Getters

Mallik kannan
Greenhorn

Joined: Sep 07, 2009
Posts: 4
Hi all,

I am new java beginner , i need of some clarification and they are as follows:

a. I want to know the need of JUnit?
b. While Using Private Variables, Setters/ Getters are came into play. My Query is Q) Is private variables are handled only by Setters/getters? or What are all the other usage of Setters and getters other than private variables?

Thanks in advance,

Kannan
jake dickens
Ranch Hand

Joined: Mar 23, 2011
Posts: 30
Mallik kannan wrote:Hi all,

I am new java beginner , i need of some clarification and they are as follows:

a. I want to know the need of JUnit?
b. While Using Private Variables, Setters/ Getters are came into play. My Query is Q) Is private variables are handled only by Setters/getters? or What are all the other usage of Setters and getters other than private variables?

Thanks in advance,

Kannan


From what I understand is setters set the variables and can't be changed it will test to see if the number you put in matches the number you have set so the program will not crash lol
getters are the fetchers meaning they get those numbers you have set one book you should get is head first java or at least look at it it will explain better then that.
KayCee Clark
Greenhorn

Joined: Jun 22, 2011
Posts: 13

JUnit is for testing. You write test cases in an assertions-like style. The idea is to test as you write, minimizing the need to place a load of assertions, print statements, and other contortions in your code. You end up with your test cases ( and expected results ) in a lot of small files that can be run individually or as a unit. They can later be used to regression test your code when you make changes later. ( without un-commenting print statements or compiling assertions in and out of your code )

The book Test Driven Development describes this process using JUnit.


*************************************

Setter and getter methods are considered better OO form than allowing others to access your data directly. If you decide to change the data structure or the range of valid values, the client is minimally impacted because they still call the getter and setter methods.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38756
    
  23
Welcome to the Ranch

Set and get methods can be used for non-private fields, too. You can include restrictions in a set method about ranges of values, for example.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11302
    
  16

And just because a member is private doesn't mean there will be a getter or a setter for it.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Need of Setters/Getters