What is a component

I listen to the podcast java posse, on this there is often discussion about components (note components are not (clearly) objects). They lament the fact that Java does not have components, and contrast with .NET that does. Components apparently makes developing applications (not just GUI apps) easier.

I can figure from the discussion certain qualities that a component has, its something to-do with decoupling (substituting one component for another is just a matter of plumbing). It has something to-do with properties, it definitely has something to-do with events and delegates.

So to the questions:

./ can anyone explain to me what a component is. (and why java beans are not components).

./ can anyone explain how they help development.

./ can anyone explain why java does not have them if they are so useful.

Asked by: Miranda838 | Posted: 23-01-2022

Answer 1

Software Engineering Radio has an episode on exactly this topic: http://se-radio.net/podcast/2008-02/episode-87-software-components

The general idea is that a software component can describe what its own dependencies and services are, in the form of metadata. I don't know why you might have heard that Java does not have components, since you can certainly imagine an architecture in Java where components do describe themselves through metadata. I suppose it's just that the Java platform definition by itself doesn't really have a component architecture.

Update: Indeed, one need not imagine such an architecture because as others pointed out, Java Beans or Servlets could certainly be considered component-based architectures.

Answered by: First Name860 | Posted: 24-02-2022

Answer 2

The term component is one of the most ambiguous and overused ones in OO.

Most people would agree that a component is made up of a group of classes, which collaborate together to implement one or more interfaces. One of the classes takes on the role of the 'front-end' i.e. it implements the interface but delegates the work to the other classes within the group. As you say components should be replaceable without the rest of the system knowing.

A great example of a component based architecture was COM. Its a great example because it was so heavily used and rigidly specified. But note that the need for this architecture was based on the inflexibility of the C++ compilation and deployment model.

in Java you can do an awful lot to a class without breaking binary compatability with the rest of the system. So there is not as much need to build rigid, component based architectures. But it all depends on how you define the term, e.g any project built using dependency injection could count as 'component based'.

Answered by: Lenny132 | Posted: 24-02-2022

Answer 3

Although in Java beginnings the notion of component was many times related with Gui components, the generic sense of component in software engineering goes beyond that notion.

Simply put, a component is a piece of software, which is reusable. Like bricks, we combine and join them to build a whole application. The key insight of software components in modern environments is the Metadata, which describes the component’s content and enables reuse.

In 1996, the JDK 1.0 was the first managed runtime environment providing components with metadata. In this case, components are .class files containing bytecodes and metadata. Yet, and according to the Java Specification, a .class file only contains one type definition. So, to deploy a bundle of types as a component we may use a Jar archive containing several .class files.

On the other hand, in the .Net platform, which provides the same idea of reusable components, a component may contain more than one type definition. In this case a component (aka assembly in .Net) is a .dll or a .exe file.

Answered by: Melissa465 | Posted: 24-02-2022

Answer 4

It depends on what you mean by "component". The term can mean lots of different things in a lot of different contexts, so it can easily get confusing. With that said, here's my understanding of the subject:

A component is different from an object (although objects are often used to represent and build components). The difference being a couple of things:

  1. Objects tend to just be "things" whereas components are actors. The difference being that a component is a part of a process, while an object represents some kind of abstract idea.
  2. Components help ensure code re-use and pluggability because they are basically small "sub-programs" (or sometimes programs in their own right) that ideally can be adapted to work well with other components.
  3. You tend to see components more in "nothing shared" message-passing systems like Erlang or Kamaelia, mainly because those types of frameworks tend to be best suited for component-oriented design.

There are a lot of good examples of component-oriented design, but my first choice would be UNIX. The basic idea behind UNIX is that it is more a set of small programs designed to work together rather than being made up of several more monolithic programs.

Answered by: Connie632 | Posted: 24-02-2022

Answer 5

Software comes in several groupings. Here are the Java chunks.

  • Statements.
  • Method functions. Multiple statements.
  • Class. Multiple attributes and method functions.
  • File. One or more classes. One class is the public class in the file, other classes are hidden in the file.
  • Package. Multiple classes. These form a hierarchy.

"Component", "Layer", "Tier" and other philosophical groupings are -- generally -- notional. The VB COM environment had a formalism for components. Everyone else treats them as just ideas.

Beans are classes. Can be single class be a component? Maybe. A component is usually a bunch of classes. Sometimes as few as two - a formal interface and an implementation.

Components help you focus on a logical grouping of classes, packages, groupings, etc.

Since a component is notional, every language more-or-less has them. There are few language formalisms for components. They aren't really needed. It's an idea or a principle you use to structure your thinking.

You can, with some care, define an approach to "components" with an interface and metadata and numerous other features.

Answered by: Ted862 | Posted: 24-02-2022

Answer 6

I don't know .NET components particularly, but from the Java POV, I'd say that a component is some functional unit that should have a defined interface/usage principle. While Java does not have components as a language concept, there are IMHO components in Java. Technical components would be e.g.:

  • EJBs
  • Servlets

Functional components would be e.g.:

  • Automatic Update for an application
  • Formula mechanism that enables calculations on a data model

Architectural components could be JAR files or OSGi bundles.

Of course, there is always room for interpretation ;)

Answered by: Rebecca345 | Posted: 24-02-2022

Similar questions

java - Tree component in JSF

What is a good tree component in JSF. I also want the user to be able to select one (using radiobutton) or more than one node (using checkboxes) from that tree component. Is there any existing component that meets my need? thanks Vikas

java - Custom swing component - Turning a node into text

I'm writing a custom swing component (something completely new, but think JTree or JList). I'm trying to follow the general design of JTree, JTable, JList etc for consistency (I've also seen various poor 3rd party components abandon the separable model and/or renderer approach). So, I have a model full of nodes, the component itself and a renderer. At some point the node has to be turned into text and displayed by ...

java - Is there a free (LGPL< BSD, etc. ) RDF editor component for swing?

I look for a JComponenet based RDF editor which I could embed in my application? It does'n need to be fancy . Thanks in advance.

java - How to return actual cell component bounds in a JTable?

I have a custom renderer in a JTable to display JCheckboxes for booleans. However, this causes a slight issue because when the user clicks in the table cell, but not in the checkbox, the checkbox is still checked. Is there a way I can return the bounds of the actual JCheckbox that is rendered by the JTable at a particular point so I can determine if ...

java - Facelets custom component doesn't set attribute after submit

I am having a problem with custom components in facelets. The first time that the page is rendered, the attributes are set properly on the component class. When a form is submitted however, the attributes are not set. Here is the class that I am using to test this. public class TestEcho extends UIData { /** Logger. */ private static Log log = LogFactory.getLog(TestEcho.class); private...

class - Calling methods of "parent" component in Java

I have the following situation I think would be best to show in sample program code. I have a Java class that extends JPanel. In this class are two objects which are two more JPanels. In one of the JPanel objects is a JTable object. I added a listener to this JTable that detects a double click. When it detects a double click, I want to fire a method in t...

How to tell if my Java component is in an Applet?

I have a Component which I am using both in a standalone Java application as well as in a Java applet. How can I figure out from within the Component whether my component is in an applet? Also, once I figure out that I'm running in an Applet, how can I get access to the Applet?

java - Post a KeyEvent to the focused component

What is the best way to post a Button Press to a component? I tried using the Robot class and it works, normally. However, this class has some problems under some Linux platforms, so I wonder what is the best Java-only way to post an event to a component. In this particular case, I want to post backspace events to a JTextField when I press a button. EDIT: I've used the Robot class after all. I fi...

java - Making a component less sensitive to Dragging in Swing

A JComponent of mine is firing a mouseDragged event too vigorously. When the user is trying to click, it interprets is as a drag even if the mouse has only moved 1 pixel. How would I add a rule for a particular component that amounted to: Do not consider it a drag event unless the mouse has moved 10 pixels from the point at which is was pressed down.

java - What is the best way to unit test a EJB3 component without having to deploy the component

I would like to have a JUnit (or other) system where the enterprise beans can be tested in a mock environment so that all resources/beans and so on are injected locally. The enterprise beans should not have to accomplish this. All kinds of injection should be supported. I would like to have a maven plugin for this so that the tests can be run from a maven build. Transactions are not necessary during...

java - How do I use a base class or interface with a grid or loop component in Tapestry 5?

I have a concrete class A that extends BaseA and implements InterfaceA. I want to loop through a list of A using either the base class or interface as the looping variable. Trying something like this: &lt;t:loop source="listOfA" value="propertyOfTypeBaseA"&gt; ${propertyOfTypeBaseA.someField} &lt;/t:loop&gt; gives me an error "Could not find a coercion from type A to BaseA". The sam...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)