Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

core java

 
Hari Prasad M
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is encapsulation ? real time example ?

where we use reflection ? which situation ?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the index of any core Java book.
 
ak pillai
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is encapsulation ? real time example ?




Being able to encapsulate members of a class is important for security and integrity. We can protect variables from unacceptable values. The sample code below describes how encapsulation can be used to protect the MyMarks object from having negative values. Any modification to member variable �vmarks� can only be carried out through the setter method setMarks(int mark). This prevents the object �MyMarks� from having any negative values by throwing an exception.



Reflection is used when you have to introspect a class and its memebers to do stuff dynamically. This is used by lot of application frameworks like Hibernate etc, java based editors, etc. Code with intrspection can adversely affect performance proper caching strategy should be implemented.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic