Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need of Setters/Getters

 
Mallik kannan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48967
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12125
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And just because a member is private doesn't mean there will be a getter or a setter for it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic