• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need of Setters/Getters

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 13
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic