Sunday, 15 July 2012
The 3 main Principles of Object Oriented Programming - How to Program with Java
Object Oriented Programming (or OOP) may be classified by three main principles.
1) Encapsulation
2) Inheritance
3) Polymorphism
All these seem like intimidating words but are really fairly simple concepts to comprehend. If you wish to learn how to program with java, you will need to know these concepts. So let's have a look at our first main principle of OOP, encapsulation. Encapsulation just means that we wish to limit the access that other pieces of code have to our particular object. So, for example, if you have a Person object, and this Person object has a first and last name as attributes. In the event that another piece of code tries to change your Person object's first name to be say "Frank3", you could have a look at what the first name is trying to be set to, and strip out any digits so we're just left with "Frank". Without having encapsulation, we wouldn't be able to stop "silly programmers" from changing the values of our variables to something that wouldn't make sense, or even worse, break the application. Make sense?
The second principle of OOP, and a very important concept if you wish to learn how to program with Java, is Inheritance. This principle refers to a super class (or parent class) and a sub-class (or child class) and the idea that a child class gains all the attributes of its parent. You can think of it in terms of a real world situation, just like a real parent and child. A child has a tendency to inherit certain characteristics from his or her parents, like say, eye colour or hair colour. Let's think about another example in terms of programming, say we have super class "Vehicle" and sub-classes "Car" and "Motorcycle". A "Vehicle" has wheels, and therefore through inheritence so would a "Car" and a "Motorcycle", but a "Car" has doors, and a "Motorcycle" does not. So it wouldn't be accurate to say that a "Vehicle" has doors, as that statement would be incorrect. So you can see how we could determine all the aspects that are common between a "Car" and a "Motorcycle" and define them inside of the "Vehicle" super class.
The 3rd principle of OOP is Polymorphism. This principle sounds the most intimidating, but I can explain it in simple terms. Polymorphism means that an object (i.e. Animal) can take on several forms while your program is running. Let's imagine you have created an Animal class and defined the method "Speak". You then asked three of your friends to make types of animals and have them implement the "Speak" method. You won't know what type of animals your friends create, nor how their Animals will speak, until you actually hear those animals speak. This is very much like how Java handles this problem. It's known as dynamic method binding, which simply means, Java won't know how the specific Animal speaks until runtime. So perhaps your friends have created a Dog, Cat and Snake. These are three kinds of Animals, and they each speak differently. When Java asks the Dog to speak, it says "woof". Whenever Java asks the Cat to speak, it says "meow". Whenever Java asks the snake to speak, it hisses. There's the advantage of polymorphism, all we did was define an Animal interface with a Speak method, and we can create a whole bunch of types of animals that speak in their own distinctive way.
For more information about how you can program with Java, there is a wealth of straightforward java tutorials presented on the howtoprogramwithjava.com web site.
Subscribe to:
Post Comments (Atom)
Nice explanation :)
ReplyDeleteThis comment has been removed by a blog administrator.
DeleteHow will you describe the steps or algorithm in making any general program in an OOP programming language???? And how will you do that for a non-OOP language????
ReplyDeleteHighlight the difference in the programming styles of the OOP and non-OOP languages.
very helpful :)
ReplyDeleteI have completely read your post and the content is crisp and clear. Thank you for posting such an informative article, I have decided to follow your blog so that I can myself updated.Android Training in Bangalore
ReplyDeletegreat
ReplyDeletethanks man
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThanks a lot very much for the high quality and results-oriented help.
ReplyDeleteI won’t think twice to endorse your blog post to anybody who wants
and needs support about this area.
java training in chennai
java training in bangalore
Ciitnoida provides Core and java training institute in
ReplyDeletenoida. We have a team of experienced Java professionals who help our students learn Java with the help of Live Base Projects. The object-
oriented, java training in noida , class-based build
of Java has made it one of most popular programming languages and the demand of professionals with certification in Advance Java training is at an
all-time high not just in India but foreign countries too.
By helping our students understand the fundamentals and Advance concepts of Java, we prepare them for a successful programming career. With over 13
years of sound experience, we have successfully trained hundreds of students in Noida and have been able to turn ourselves into an institute for best
Java training in Noida.
java training institute in noida
java training in noida
Thanks for sharing a worthy information. This is really helpful for learning. Keep doing more.
ReplyDeleteComputer Training Institute Franchise
Best Education Franchise In India
Training Franchise Opportunities In India
Education Franchise Opportunities In India
Top Education Franchises
Spoken English Franchise
Top Education Franchise In India
Thanks admin, I learned oops with the help of your blog. Continue sharing more like this.
ReplyDeleteUiPath Training in Chennai
UiPath Course
RPA Training in Chennai
AWS Training in Chennai
DevOps Training in Chennai
Angularjs Training in Chennai
Best Content ever!!! Keep doing more and update your blog regularly for the future reference.
ReplyDeleteSelenium Training in Chennai
selenium Classes in chennai
iOS Training in Chennai
Digital Marketing Training in Chennai
Software testing training in Adyar
Software testing training in Tambaram
Big Data Training in Chennai
Software testing Course in Velachery
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.
ReplyDeletesafety course in chennai
I really like your article. Keep sharing.
ReplyDeleteTally Course in Chennai
Tally Institute in Chennai
Learn Tally ERP 9
Unix Course in Chennai
LINUX Training in Chennai
C C++ Training in Chennai
Sap fico training institute in Noida
ReplyDeleteSap fico training institute in Noida - Webtrackker Technology is IT Company which is providing the web designing, development, mobile application, and sap installation, digital marketing service in Noida, India and out of India. Webtrackker is also providing the sap fico training in Noida with working trainers.
WEBTRACKKER TECHNOLOGY (P) LTD.
C - 67, sector- 63, Noida, India.
F -1 Sector 3 (Near Sector 16 metro station) Noida, India.
+91 - 8802820025
0120-433-0760
0120-4204716
EMAIL: info@webtrackker.com
Website: www.webtrackker.com
I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
ReplyDeleteData Science Training in Chennai
Robotic Process Automation Training in Chennai
Cloud Computing Training in Chennai
Data Warehousing Training in Chennai
Dev Ops Training in Chennai
Thanks For sharing Your information The information shared Is Very Valuable Please Keep Updating Us Time Just went On reading Thae article Python Online Training DataScience Online Training AWS Online Training Hadoop Online Training
ReplyDeleteThanks 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.
ReplyDeleteBest PHP Training Institute in Chennai|PHP Course in chennai
Best .Net Training Institute in Chennai
Powerbi Training in Chennai
R Programming Training in Chennai
Javascript Training in Chennai
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeleteAndroid Training Institute in Chennai | Android Training Institute in anna nagar | Android Training Institute in omr | Android Training Institute in porur | Android Training Institute in tambaram | Android Training Institute in velachery
Thanks for sharing article. The way you have stated everything above is quite awesome. Keep blogging like this. Thanks.
ReplyDeleteAWS training in chennai | AWS training in anna nagar | AWS training in omr | AWS training in porur | AWS training in tambaram | AWS training in velachery
The Contents are quite awesome...Gained lots of Informative Informations from it, Keep Updating...
ReplyDeleteJava training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery
"It's really good. Thank you for your information. Keep Blogging! .
ReplyDeleteDigital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery
"
It’s really a Great Post .Looking for Some More Stuff
ReplyDeleteDigital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery
Marketing is all about analytics. Talentedge offers Marketing Analytics program to sharpen your skills. To know more visit:-
ReplyDeleteMany companies are pivoting to virtual events and More than 90% of event marketers plan to make virtual a key part of their strategy going forward. biography format and team building invitation email
ReplyDeleteVisit Bharat Go Digital Academy to learn the digital marketing skills in India.
ReplyDeleteAre you looking for the best Azure training in Chennai here is the best suggestion for you, Infycle Technologies the best Software training institute to study to also other technical courses like Cyber Security, Graphic Design and Animation, Block Security, Java, Cyber Security, Oracle, Python, Big data, Azure, Python, Manual and Automation Testing, DevOps, Medical Coding etc., with technical trainers with amazing training with a peaceful environment. And we also provide 100+ Live Practical Sessions and Real-Time scenarios which helps you to easily get through the interviews in top MNC’s. for more queries approach us on 7504633633, 7502633633
ReplyDeleteThat's an superb post. Thanks for sharing.
ReplyDeletealso, visit Java course in Pune