Tuesday, September 3, 2013

Encapsulation | how to achieve encapsulation in Java


Encapsulation:


Before moving into the concept and definition, first of all i would like to ask you one thing. Do you know about capsule (medicine)? Have you seen capsule .?

Everyone has the same answer for the above questions. that is YES

If you know a capsule , definitely you knew about encapsulation.

How a capsule will look like?

As every one knows that the medicine which is wrapped is the capsule.

How Capsule related to Encapsulation: 


Just like a capsule(which wraps up medicine) , wrapping up  the data is called Encapsulation in OOPS. Encapsulation is a mechanism of hiding the data 
( variables/methods ) from the external world.

In java a class is the best example of Encapsulation

How to achieve Encapsulation in Java:


In java, Encapsulation can be achieved by using access specifiers (especially private modifier). 

As we know a private access specifier specifies access with in the class (local access), the data can't be exposed to the other classes (in same application or different application).


Let me elaborate this with an example.

CapsulateData is the class with some variables as given below.



As accountNumber, accountName are private variables they can't be accessed outside the class.

If we try to do so, following will be the result.





Here as accountName and accountNumber are private fileds, we can't access them in other classes(not only variables , even private methods also).

From this, we can clearly understood that the data
 (accountName , accountNumber ) is hidden by the class from the outside world, which we consider to be encapsulation.




63 comments:

  1. this post is very useful for everyone who learn java encapsulation in detail.
    thanks for this nice post.

    ReplyDelete
  2. Australia Best Tutor is one of the best Online Assignment Help providers at an affordable price. Here All Learners or Students are getting best quality assignment help with reference and styles formatting.

    Visit us for more Information

    Australia Best Tutor
    Sydney, NSW, Australia
    Call @ +61-730-407-305
    Live Chat @ https://www.australiabesttutor.com




    Our Services

    Online assignment help
    my assignment help Student
    Assignment help Student
    help with assignment Student
    Students instant assignment help
    Students Assignment help Services

    ReplyDelete
  3. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    Are you looking for the best Java training institute in Chennai?
    Come and learn with Aorta, the best java training institute in Chennai offering the best platform to learn and get the depth of Java
    java training in chennai
    java course in chennai

    ReplyDelete
  4. Cloud Computing Training In Noida
    Webtrackker is IT based company in many countries. Webtrackker will provide you a real time projects based training on Cloud Computing. If you are looking for the Cloud computing training in Noida then you can join the webtrackker technology.
    Cloud Computing Training In Noida , Cloud Computing Training center In Noida , Cloud Computing Training institute In Noida ,

    Company Address:
    Webtrackker Technology
    C- 67, Sector- 63, Noida
    Email: info@webtrackker.com
    Website: www.webtrackker.com
    http://webtrackker.com/Cloud-Computing-Training-Institutes-In-Noida.php

    ReplyDelete
  5. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
    Click here:
    angularjs6 Training in Chennai
    Click here:
    angularjs Training in online

    ReplyDelete
  6. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts
    Microsoft azure training in chennai
    Click here:
    Microsoft azure training in online
    Click here:
    Microsoft azure training in bangalore
    Click here:
    Microsoft azure training in pune

    ReplyDelete
  7. Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision. 
    Blueprism training in velachery

    Blueprism training in marathahalli


    AWS Training in chennai

    ReplyDelete
  8. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
    Devops Training in Chennai

    Devops Training in Bangalore

    ReplyDelete

  9. Like different elements of India, numerous oil and spices usually cross into making food. This effects in substances getting caught to the partitions of the filter out.
    Visit here
    http://kitchenware.ml
    Best kitchen chimney installation and service
    Auto clean chimney sevice in Faridabad

    ReplyDelete
  10. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging.
    Sap Basis Online Training
    Sap Abap Online Training
    Sap Pp Online Training

    ReplyDelete
  11. I really like the dear information you offer in your articles. I’m able to bookmark your site and show the kids check out up here generally. Im fairly positive theyre likely to be informed a great deal of new stuff here than anyone
    java training in annanagar | java training in chennai

    java training in chennai | java training in electronic city

    ReplyDelete
  12. You blog post is just completely quality and informative. Many new facts and information which I have not heard about before. Keep sharing more blog posts.
    Data Science training in Chennai | Data science training in bangalore
    Data science training in pune | Data science online training
    Data Science Interview questions and answers

    ReplyDelete
  13. Thanks for sharing. I really liked your post, keep sharing!!

    CEH Training In Hyderbad

    ReplyDelete

  14. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
    Matlab Training in Chennai | Best Matlab Training in Chennai
    AWS Training in Chennai | Best AWS Training in Chennai
    Devops Training in Chennai | Best Devops Training in Chennai

    ReplyDelete

  15. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
    Matlab Training in Chennai | Best Matlab Training in Chennai
    AWS Training in Chennai | Best AWS Training in Chennai
    Devops Training in Chennai | Best Devops Training in Chennai

    ReplyDelete
  16. You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us
    Microsoft Azure online training
    Selenium online training
    Java online training
    Python online training
    uipath online training

    ReplyDelete
  17. Mình đã tìm thấy các thông tin cần thiết ở đây, cảm ơn bạn. Mình cũng muốn giới thiệu về một Công ty dịch thuật uy tín - Công ty dịch thuật miền trung - MIDtrans có trụ sở chính chính tại địa chỉ 02 Hoàng Diệu, TP Đồng Hới, tỉnh Quảng Bình có Giấy phép kinh doanh số 3101023866 cấp ngày 9/12/2016 là đơn vị chuyên cung cấp dịch vụ dịch thuật, phiên dịch dành các cá nhân. Hệ thống thương hiệu và các Công ty dịch thuật con trực thuộc: công ty dịch thuật hcm - dịch thuật sài gòn 247 , địa chỉ 47 Điện Biên Phủ, Phường Đakao, Quận 1 TP HCM, dịch thuật buôn mê thuột, đăk lăk : địa chỉ 100 , Lê lợi, TP Buôn Mê Thuột là nhà cung ứng dịch vụ dịch thuật uy tín hàng đầu tại Đăk Lăk; vietnam translate : dịch vụ dịch thuật cho người nước ngoài có nhu cầu, giao diện tiếng Anh dễ sử dụng; dịch thuật công chứng gò vấp : nhà cung ứng dịch vụ dịch vụ dịch thuật phiên dịch hàng đầu tại Quận Bình Thạnh, TP HCM; dịch thuật đà nẵng : Địa chỉ 54 Đinh Tiên Hoàng, Quận Hải Châu, TP Đà Nẵng chuyên cung cấp dịch vụ dịch thuật công chứng, dịch thuật chuyên ngành tại Đà Nẵng; dịch thuật hà nội midtrans : địa chỉ 101 Láng Hạ, Đống Đa, Hà Nội là nhà cung ứng dịch vụ biên dịch, phiên dịch chuyên nghiệp tại địa bàn Hà Nội. Chúng tôi chuyên cung cấp các dịch vụ biên dịch và phiên dịch, dịch thuật công chứng chất lượng cao hơn 50 ngôn ngữ khác nhau như tiếng Anh, Nhật, Hàn, Trung, Pháp, Đức, Nga, Tây Ban Nha, Bồ Đào Nha, Ý, Ba Lan, Phần Lan, Thái Lan, Hà Lan, Rumani, Lào, Campuchia, Philippin, Indonesia, La Tinh, Thụy Điển, Malaysia, Thổ Nhĩ Kỳ..vv... Dịch thuật MIDtrans tự hào với đội ngũ lãnh đạo với niềm đam mê, khát khao vươn tầm cao trong lĩnh vực dịch thuật, đội ngũ nhân sự cống hiến và luôn sẵn sàng cháy hết mình. Chúng tôi phục vụ từ sự tậm tâm và cố gắng từ trái tim những người dịch giả.Tự hào là công ty cung cấp dịch thuật chuyên ngành hàng đầu với các đối tác lớn tại Việt nam trong các chuyên ngành hẹp như: y dược (bao gồm bệnh lý), xây dựng (kiến trúc), hóa chất, thủy nhiệt điện, ngân hàng, tài chính, kế toán. Các dự án đã triển khai của Công ty dịch thuật chuyên nghiệp MIDtrans đều được Khách hàng đánh giá cao và đạt được sự tín nhiệm về chất lượng biên phiên dịch đặc biệt đối với dịch hồ sơ thầu , dịch thuật tài liệu tài chính ngân hàng, dịch thuật tài liệu y khoa đa ngữ chuyên sâu. Đó là kết quả của một hệ thống quản lý chất lượng dịch thuật chuyên nghiệp, những tâm huyết và kinh nghiệm biên phiên dịch nhiều năm của đội ngũ dịch giả của chúng tôi. Hotline: 0947688883. email: info@dichthuatmientrung.com.vn . Các bạn ghé thăm site ủng hộ nhé. Cám ơn nhiều

    ReplyDelete
  18. Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
    python training in bangalore

    ReplyDelete
  19. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts.
    AI course malaysia

    ReplyDelete
  20. This comment has been removed by the author.

    ReplyDelete
  21. Excellent Blog! I would like to thank for the efforts you have made in writing this post. It is very informative. I wanted to thank you for sharing this information!! Artificial Intelligence Course

    ReplyDelete
  22. Your new valuable key points imply much a person like me and extremely more to my office workers. With thanks; from every one of us.
    Aws training chennai | AWS course in chennai
    Rpa training in chennai | RPA training course chennai
    oracle training chennai | oracle training in chennai

    ReplyDelete

  23. Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well I really get amazed to read this. It's really good.
    I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you!.
    mobile phone repair in Fredericksburg
    iphone repair in Fredericksburg
    cell phone repair in Fredericksburg
    phone repair in Fredericksburg
    tablet repair in Fredericksburg
    mobile phone repair in Fredericksburg
    mobile phone repair Fredericksburg
    iphone repair Fredericksburg
    cell phone repair Fredericksburg
    phone repair Fredericksburg


    ReplyDelete
  24. Really awesome blog!!! I finally found a great post here.I really enjoyed reading this article. Thanks for sharing valuable information.Data Science Course
    Data Science Course in Marathahalli
    Data Science Course Training in Bangalore

    ReplyDelete
  25. Very useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article..Thanks for sharing this info,it is very helpful.
    Salesforce Training in Chennai

    Salesforce Online Training in Chennai

    Salesforce Training in Bangalore

    Salesforce Training in Hyderabad

    Salesforce training in ameerpet

    Salesforce Training in Pune

    Salesforce Online Training

    Salesforce Training

    ReplyDelete
  26. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area. data science training in Hyderabad

    ReplyDelete
  27. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!
    Data science Training in hyderabad

    ReplyDelete
  28. this is really nice to read..informative post is very good to read..thanks a lot!
    data scientist training and placement in hyderabad

    ReplyDelete
  29. Thanks for such a great post and the review, I am totally impressed! Keep stuff like this coming.
    business analytics course in hyderabad

    ReplyDelete
  30. I want to express my heartfelt thanks for the valuable information you have provided regarding the degree colleges in Hyderabad offering B.Com programs.

    <a href="<a href=”https://www.cmsforca.in/b-com”a>Degree Colleges in Hyderabad For B.com</a>

    ReplyDelete
  31. This idea is a useful technique to increase knowledge.I appreciate you sharing. Please continue.
    Degree Colleges in Hyderabad For B.com

    ReplyDelete
  32. This concept is a practical method to increase knowledge.I value your sharing. Please go ahead.
    Degree Colleges in Hyderabad For B.com

    ReplyDelete
  33. This idea is an excellent approach to broaden your knowledge.thank you for revealing. kindly continue.
    Best Juniour Colleges In Hyderabad For CEC

    ReplyDelete