How do I learn OOP concepts of Java easily?
-
After reading I am forgetting the concepts easily. I want to become good developer and I want to know OOP concepts fully.Even if I learn with real time example also I am forgetting it.
-
Answer:
This is a problem I was facing some time back. I think I have found a solution to this problem to an extent so I'll share it with you. Here it goes- OOP concepts were laid down to so that HUGE projects could be made maintainable. When you write a program in Java, it's barely 200 lines of code. That's not huge. You could use C and write that big a program and it will be still considered good. OOP concepts come into use while writing programs that use tens of thousands of lines of code. The only way to master OOP is read code that use OOP concepts. You can learn all you want about OOP but without seeing it in practice, you won't be able to appreciate it's power. Right now, the best source for reading code would be the jdk installed on your machine. Just find the folders where jdk is installed, open the .class files you are interested in and read them. Pay attention to how they have been organised. The way they are organised is the best illustration you can find for OOP concepts. This would (not only) make you strong in OOP but also teach you the way classes are written in Java. Once you know way around these classes, you'll know why an IDE gives a warning the way it does and many other quirks of Java. Hope it helps. All the best.
Kunal Suri at Quora Visit the source
Other answers
Observe, study, analyse your own life from morning to evening.... all events carefully.... You would learn OOP concepts... easily...
Bhalchandra Gholkar
In the initial stages it takes a Hercules effort to master a concept. Your problem is being faced by millions of developers and first time practitioners across domains. It takes perseverance and hard work to become familiar with the concept. Coming to the core of your question, in the initial learning stages don't always go with the popular text books on java, they might be of a very good standards and might seem as Greek and Latin to amateur's. Browse the internet for the key topics and you will find tons of articles articulated in a perfect manner which fits your bill. Go through those concepts till you understand(Read 100 or 1000 times). And the problem with Java is that until you code it and make mistakes you never get to know your actual stand. So be positive, read, code and learn
Pramod Sripada
Lets see if we can compact the OOP concepts for Java (which generally requires whole chapters in a book). Always remember these three biggies of OOP: Encapsulation, Inheritance, Polymorphism Encapsulation is all about declaring class members (i.e. variables, methods and possibly inner classes inside a class) and assigning scope to them (i.e. you need to decide who (other classes) have access to your class' members). Java divide such access in four categories: within class access (mark with private keyword); from classes within a package (no keyword required); from classes in inheritance hierarchy (using protected keyword); and from everywhere (use public keyword). General rule is, data meant to be private, functionality meant to be public (to be used by other classes). Logic in public methods usually distribute over private methods. For protected, see next section. Inheritance is all about overriding method implementations and/or just method signatures from an existing parent (super) class while optionally coming up with new methods in child class. Java specifically allows the concept of interface to implement "method signature only" approach whereas a standard parent class can also enforce "method signature" approach by using abstract keyword. "Method implementation" approach is used by standard parent class, and methods are usually marked either as protected or public to be allowed to be inherited (specially if subclass belong to a different package). The idea is, you can use both parent class logic along with your own logic in the overridden method. To stop method overriding, use "final" keyword with method. To stop a class being a parent, use 'final' keyword with the class. Polymorphism, can be classified as static polymorphism (very easy: same method but different arguments aka method overloading) or dynamic polymorphism which is a very strong OOP concept and it happens because of inheritance. It allows an inherited (or overridden) method to be called from a parent class reference. Read that again, "it allows a parent class to call method which "will be" overridden by a future sub class method". This allows us to create powerful abstraction where as a designer we can govern general rules on how the interactions between methods will happen, but the actual logic is implemented by various subclass. A very simple (hypothetical) example of polymorphism in action: public double calculateInterest(AccountType accountType) { accountType.getInterstRate() * overdueAmount; } Depending on which subclass of AccountType is passed, the value of interest rate can be different. Come up with a new account type? no worries, inherit from AccountType (either using extends or implements depending upon whether its a class or an interface), override getInterstRate and provide new logic. That should cover it. Easy to remember? EIP. Shoot any questions in the comments.
Usman Saleem
Object oriented is extremely simple and easy to understand. But is helps to never use obscure acrynoms like OOP, or silly terms with no inherent meaning like Polymorphism.The reality is that programming at one time used almost entirely global variables that had no grouping or heirarchy, and libraries of functions that were equally unordered or grouped. C started to try to allow variables that were related, to be grouped together in a struct. Then C++ went further and allowed functions related to the data in a struct to be added as well, and then it was called a class. That really is about all there is too it. You can base one class of another, and they call it inheritance, but that is a poor use of the word. When you have the same function in different classes, that is called overloading and polymorphism, but again a poor choice of words. The real point is that in C we used to have to have long switch statements in order to determine which function we wanted to call for a particular type when traversing something like a display list. With different classes having their own version of a function with the same name, we can call that function knowing any object will have a function of that name, and the correct function will still be called, because the pointer to the correct function is stored by the compiler, into the object itself, in a hidden virtual function table.Hope that helps?
Kirk Augustin
To learn any concept, I would recommend solving some real problems. For OOP I would recommend developing programs like Paint/ATM or any else you think would be useful. First write down all the classes and then jot the the different commons methods/functions and variables, this way you would be able to clearly see the same variables/methods being used in different classes. Now after you have noted down the common things try to construct a structure from base to top. e.g you are creating a university management system, you would be using the variables name,id,age etc in both Student and employee classes. So create a super class that has these variables and extend both Student and Employee class from this super class. You can use methods the same told earlier. Hope this helps :) Feel free to contact.
Hamza Bodla
For implementing OOPS in JAVA first you need to be clear with OOPS concepts off-course and then you can do a requirement analysis to figure out what features of OOPS can possibly be implemented in the code. If you want to study oops concepts in detail, a book http://www.cvauni.edu.vn/imgupload_dinhkem/file/pttkht/object-oriented-analysis-and-design-with-applications-2nd-edition.pdf by Grady Booch will help.
Abhishek Jain
The best way to learn anything is by learning it with an real life example. check out this post, the OOP concepts are explained so well that you won't forgot. http://learn2geek.com/4-pillars-oop-java/
Ankit Nanglia
i believe OOP is like art, everybody can draw but only few can draw nice , OOP needs time and practice to learn and to know what is the right design pattern to solve specific problem if you didn't pick the right one you will find yourself using anti-pattern, its hard to say that you can't learn it from the first day or by easy way .. what i suggest as good reference for OOP is the "Design Patterns gang of four (GoF)"
Yosri Amarneh
Related Q & A:
- How do I make a window in Java?Best solution by Stack Overflow
- How do I retrieve a URL in Java?Best solution by Stack Overflow
- How can I learn how to do stick figures or animated stuff online free?Best solution by Yahoo! Answers
- How do I make my web browser java compatible?Best solution by answers.yahoo.com
- How can I make a fake fan sign easily online?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.