2. Java abstraction or object-oriented
programming is a way of separating the
implementation of an interface and one of the
five motifs,
along with encapsulation, inheritance,
polymorphism, class, and object abstraction.
3. it is achieved using Java the interface and the
abstract class in Java. An interface or abstract
class is something that is not concrete,
something that is incomplete.
4. To use the interface or the abstract class, we
need to extend and implement an abstract
method with concrete behavior.
An example of abstraction is to create an
interface to denote common behavior without
specifying Details on how this example
behavior works.
5. An interface called Server is created that has
the start () and stop () method.
This is called the server abstraction because
each server must have a way to start and stop
and the details may be different.
As I said earlier, the Abstraction in Java is
implemented using abstract classes and
interfaces, as discussed in the next section.
6. In truth, which is an abstraction in Java, the
difference between abstraction and
encapsulation is also a very popular Java
interview because the strong capacity of
OOPS is one of the main requirements for
Java developers.
Abstraction is also one of the concepts
difficult to master. The programmer usually
mixes different levels of abstraction that
result in flexible code,
7. If you want to use it, you need to make it
complete or concrete, extending it. A class is
called concrete if it does not contain any
abstract method and implements the entire
abstract method inherited from the abstract
class or interface implemented.
By the way, Java has a concept of abstract
classes, abstract method, but a variable can not
be abstract in Java.
8. A popular example of an abstract class in Java
is the ActionListener, which has an abstract
method called actionPerformed (ActionEvent
ae).
This method is called when an ActionEvent is
activated as when the JButton is clicked.
9. It is common in java to attach ActionListener
with JButton by implementing the
actionPerformed abstract method
(ActionEvent a) using the anonymous class.
An abstract method in Java does not have the
body, it is just a statement. To use an
abstract method, it is necessary to replace
this method in the subclass.
When you know that something needs to be
there, you do not know exactly how it should
be. For example.
10. When I'm creating a class called Vehicle, I know
there must be methods like start () and stop (),
but I do not know how this start and stop
method should work,
since each vehicle can have different start and
stop mechanism and .. g some they can be
initiated by kicking or some can be by pressing
buttons.
11. If you know some behavior during the
creation of a class and this would remain
common to all subclasses, add it to an
abstract class.
An interface like the Runnable interface is a
good example of Java abstraction that is used
to abstract the tasks performed by multiple
threads.
Callable is another good summary of a task
that can return value.