About Java Bean [duplicate] - java

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What is a Java Bean exactly?
This is a simple question about Java Bean, there is some restriction in the type of classe? For example, a bean can be a abstract class ?
Thanks

A JavaBean class is a class which respects a number of conventions. But depending on the usage of the class, some conventions are or aren't important. In the strict sense, a JavaBean class
must have a public no-arg constructor allowing to instantiate it
must have properties available through getters and setters
must be serializable
So, in the strict sense, a JavaBean class may not be abstract. But an abstract class can be the superclass of a JavaBean class.

Related

Can we call class with setter and getter as Java Bean? [duplicate]

This question already has answers here:
What is a JavaBean exactly?
(23 answers)
Closed 6 years ago.
In bean standards, it is mentioned that it must implement serializable.
But in general developers say to create beans which means simple setter/getter.
Is bean correct terminology or any other terminology for class with setter and getter methods?
I think it's just called a class that follows Object Oriented Programming (OOP) principles when you use getters and setters and make the fields private.
http://codebetter.com/raymondlewallen/2005/07/19/4-major-principles-of-object-oriented-programming/

when abstract class doesn't contain any abstract method [duplicate]

This question already has answers here:
Why use an abstract class without abstract methods?
(11 answers)
Closed 7 years ago.
I am still confused when abstract class doesn't contain any abstract method, what a purpose of it? why don't use regular class rather than abstract class if it doesn't contain any abstract method ? In fact, I was saw this situation is applied on java and libgdx library or perhaps for every library.
So, because this situation, I was thinking is it very important to know why use abstract class without abstract method rather than regular class.
When you make a class abstract (either with or without abstract methods), you are forcing the users of this class to create concrete sub-classes of it, since they can't instantiate it.
A user of an abstract class must create a concrete derived class.
This can be useful since it allows the author of an abstract class to introduce abstract functions at a later date. The amount of refactoring necessary at that time is then significantly reduced.

Why are nested interfaces declared implicitly static? [duplicate]

This question already has answers here:
Why are interfaces static?
(5 answers)
Closed 5 years ago.
as the title says, why nested interfaces are implicitly static.Why cant i use nested interfaces just like nested classes ie like with static and without static
From the oracle documentation:
an inner class is associated with an instance of its enclosing class
and has direct access to that object's methods and fields
i.e. it maintains a reference to its enclosing instance.
An interface on the other and is just a static definition of type. A contract, used to provide some polymorphism.
An interface cannot itself be instantiated, therefor it cannot have state, and thus it cannot "know" about an enclosing instance.
Java interface are interfaces. A interface rule is ACID. The I in ACID means:
To demonstrate isolation, we assume two transactions execute
at the same time, each attempting to modify the same data.
So fields are automatically public static final.

why we are declaring class as abstract even if it has no abstract methods [duplicate]

This question already has answers here:
Defining an abstract class without any abstract methods
(12 answers)
Use of an abstract class without any abstract methods
(7 answers)
Closed 9 years ago.
can any one please explain the scenario when A class may be declared abstract even if it has no abstract methods. i have tried in many websites but i did not found it.Thanks a lot.
Broadly, this would be because the class provides concrete implementations of functionality but should not itself be instantiated. For example, an AbstractWidget in a price calculator may not be suitable to directly instantiate, but it has concrete implementations of certain widget functionality like being rearranged. The expectation is that the subclass adds new methods altogether, or overrides the ones already declared.

Why define a abstract interface in Java [duplicate]

This question already has answers here:
Java abstract interface
(9 answers)
Closed 9 years ago.
As we know, interface is to define some method, but some interface defined as a abstract interface, but why ?
for example:
public abstract interface Test{
}
what is the advantage for using abstract to define a interface?
There is no need to add that abstract key word. It's redundant there.
Interfaces are implicitly abstract.
Language Spec JLS# 9.1.1.1 abstract Interfaces
Every interface is implicitly abstract.
This modifier is obsolete and should not be used in new programs.
refer to http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html for the same.
Also see https://stackoverflow.com/a/18778307/805378 to get the difference between abstract and interface.
to make a class 100% abstract without using 'abstract'.

Categories