This question already has answers here:
When should one use interfaces?
(19 answers)
Closed 5 years ago.
I'm having trouble understanding why I should use interfaces, and how I should integrate them into my current project. I use a lot of polymorphism already, and I usually see polymorphism and interfaces side by side in other projects of my peers.
Why do you use interfaces? What are the real benefits?
This question has already been answered in:
When should one use interfaces?
What is an interface in Java?
Java Interfaces?
To get more information about OOP design you can also refer to books like Head First: Object oriented analysis and design. There are also some on-line courses on platforms like Coursera and Edx that you can use.
Related
This question already has answers here:
How to achieve method chaining in Java?
(4 answers)
Closed 3 years ago.
For example how do I do this?
getServer().getManager().registerNewUser(arguments);
and
getServer().getStats().user(arguments);
Stuff like this, I've tried searching the web but I cant find any tutorials on this,so I'm asking here.
In OOP, in general, this concept is called class composition more on this you can find it here https://en.wikipedia.org/wiki/Object_composition
Also for java and the difference between Composition and inheritance https://www.baeldung.com/java-inheritance-composition
This question already has answers here:
Is java Purely Object Oriented?
(12 answers)
Closed 6 years ago.
What does the term Purely Object Oriented mean in case of Programming Languages? Is Java a purely Object Oriented and which languages come under this category? I've often read that Purely Object Oriented languages are one in which everything comes in form of objects and so can anyone clarify the confusion.
Java still has the primitives like short , int , long , float and double
these are not considered objects. However, in ruby for example everything,
including the numbers are objects.
This question already has answers here:
What does it mean to "program to an interface"?
(33 answers)
Closed 7 years ago.
we always use this code
List mylist=new ArrayList();
I look this statement into deep and i found that mylist is an interface reference which is referring to the ArrayList which is a class.I found(on internet) that there is some benefits of it like Loose coupling ,memory management etc.But How ?what are the benefits of using interface refernce?
There is no memory management benefits.
However, using the interface Type allows you to make use of polymorphism.
Here, it means you can use any class inheriting List as a working implementation replacement.
This is allowing loose coupling because you are not tied with ONE and ONLY list implementation.
https://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html
https://docs.oracle.com/javase/tutorial/java/concepts/interface.html
This question already has answers here:
Why is using a wild card with a Java import statement bad?
(18 answers)
Closed 9 years ago.
I am a student, and a couple of the books I have been reading (Java for Dummies, for one) has said using the wildcard import statement is bad programming practice and encourage the reader to avoid using it. Whereas, in class, we are encouraged to use it. Can somebody please explain why it is poor programming practice?
If so, what adverse affects does it have on the program performance? For example, slow it down.
The more you insert, the higher the change that you will get a naming collision where two classes have the same class name:
http://en.wikipedia.org/wiki/Name_collision
The first example i can find within the java API are:
http://docs.oracle.com/javase/6/docs/api/javax/naming/Binding.html
http://docs.oracle.com/javase/6/docs/api/org/omg/CosNaming/Binding.html
This question already has answers here:
How to most elegantly iterate through parallel collections?
(8 answers)
Closed 6 years ago.
I've got two List objects and I want to pair them up, just like the zip() function in Python. I'm pretty sure this isn't available in the JDK, but is there something like this in a fairly widespread library, similar to Apache Commons Collections? Thanks.
Functional Java has zip, zipWith and zipIndex the way you would expect from Haskell or Scala. (Indeed, the authors are pretty much all Haskell programmers.)