What is to bind?

Asked

Viewed 7,033 times

5

I can’t find the meaning of Bind to explain to me what this is. I would like an example of Bind with the same java language.

  • 3

    Where did you see this? It’s too generic to answer without knowing where you got the java bind from.

  • Is there bind in java? My teacher mentioned this bind business with dotnet and Asp.net. The problem is that I don’t know how to ask a nice question, but programmers already talk about bind.

  • http://imasters.com.br/linguagens/asp/asp-net-model-binding-com-web-forms-retornando-e-exibindo-dados-parte-01/

  • If it helps to improve your question, it seems you want to know the equivalent of c# in java.

  • Caraca the guys want to close my question... Nor helped me. This community leaves to wish.

  • 3

    Your question is not clear enough, try to make the problem clearer, see my previous comment, apparently you want to know something equivalent to the c# Binding model in java. And have patience, a question being closed or voted for does not mean that it is "lost". just try to make your doubt clearer that it won’t be closed.

  • That’s what I wanted to know...but never mind. Forget it, I lost the taste.. I want to learn...never mind.

  • 2

    How about editing the question, making that clear? We don’t know your doubt if you don’t explain it. People are trying hard to help, but you can’t guess. Edit the question with the tips I gave, paste the link in it, this way, will be very explicit your doubt.

  • 4

    @gonz if you ask a question that can not understand is your duty to improve it. We want to help, but without understanding the question we can not. Comments like "Forget can close, I lost the taste" tell me you think we’re against the question. On the contrary, we’re curious to know what you want, and until then we closed because they are the rules of the site. You can [Edit] the question to clarify that I then help clear the comments here. Ping @Sergio when you’ve done Edit.

  • That is I do not know how to improve it, also because it is something new to me the term bind. I was watching João Batista Neto’s Angout and the guys already talked about bind, "bindada". I wanted to learn what this is. I don’t know how to improve the question...

  • I wish I could ask a clearer question, but I can’t. I tried. I’m going to read this article: http://imasters.com.br/linguagens/asp/asp-net-model-binding-com-web-forms-returning-displaysData/

  • 5

    @The suspension of the question doesn’t mean we don’t want to help or anything like that. It turns out that we have no crystal ball and there was no way to help without giving a kick by passing away, as can be seen in the answers we have here. Think on the other side, how annoying it is who answered the wrong question you had asked. The guy goes to work researching, writing and then you say "but that’s not what I wanted to know". This is why we need the question to be clear. A tip to prevent this from happening is to include all possible details in the question. Hug.

  • 4

    Okay @utluiz. Now I get it I was just thinking about my side. I didn’t picture it that way you said it. Sorry, I’m trying to improve every day. rs :D

Show 8 more comments

2 answers

9


Bind or Binding are terms used in different applications, but in general refer to how Java or any language links certain things.

Data Binding

Define how data in different formats are mapped to and from objects. There are numerous possibilities, where the most common ones are:

Binding HTTP request

It consists of mapping attributes in HTTP requests for objects or maps. How this is done depends on the framework.

JSF for example uses special tags like <h:inputText/>:

<h:inputText value="#{userController.username}" />

The above example would map the field in HTML with an attribute String username in class UserController.

Frameworks such as Spring MVC or JAX-RS compatible usually map each request parameter directly to an attribute. For example:

<input type="text" name="nome" />

It would be connected as follows:

class Usuario { 
    String nome;
    public void setNome(String nome) { ... }
}

class UsuarioController {
    @GET
    @Path("/usuario/incluir)
    public String incluir(Usuario usuario) { ... } 
}

Binding of JSON and XML

Data represented in JSON and XML can also be linked with objects using libraries such as Jackson (JSON) and JAXB (XML).

Example with Jackson:

ObjectMapper mapper = new ObjectMapper();
String json = "{'nome' : 'Maria'}";
Pessoa pessoa = mapper.readValue(json, Pessoa.class);

Binding of databases

The best known examples are JPA frameworks such as Hibernate and Eclipselink, where you can configure a class so that the data of the fields in a table is linked to the attributes of a class, it is possible to send and recover data without writing SQL clauses or recovering field by field.

Example of mapping a JPA entity:

@Entity
public class Pessoa {
    @Id
    long id;
    String nome;
    String endereco;
    ...
}

Method Binding

Another example is the method Binding or linking of methods, which means how language does to determine which is the correct method that should be called according to several factors:

  • Class hierarchy, for example when a subclass overrides a method or when a class implements the interface method.
  • Method overload, for example when methods of the same name receive parameters of different types one has a different number of parameters

In some cases it is possible to determine the correct method at compile time, for example if it is static or final. In the other vessels the correct method is determined at runtime, which in theory is slower since it includes further processing during the execution of the program. In fact, the JVM includes a series of optimizations that make the impact of performance virtually negligible in most cases.

Other

Other examples of Binding include:

  • How MVC web frameworks decide which method to call according to the request parameters and settings.
  • How Dependency Injection frameworks decide which class to inject based on criteria such as class hierarchy, annotations, and settings.

3

There is Dynamic Bind and Static Bind.

In the static bind, you have methods within your main class and call them straight into the main (the methods have to be static), e.g.:

public class Main{
    public static void varType(float var){
        System.out.println("Is an float!");
    }

    public static void varType(int var){
        System.out.println("Is an int!");
    }

    public static void varType(String var){
        System.out.println("Is an string!");
    }

    public static void main(String args[]){
        int x = 0;
        float y = 0;
        String z = "0";
        varType(x);
        varType(y);
        varType(z);
    }
}

In short, calls are made in the static method in the main methods.

The dynamic bind is created an instance of the main class to use its methods, e.g.:

public class Main{
    public void varType(float var){
        System.out.println("Is an float!");
    }

    public void varType(int var){
        System.out.println("Is an int!");
    }

    public void varType(String var){
        System.out.println("Is an string!");
    }

    public static void main(String args[]){
        int x = 0;
        float y = 0;
        String z = "0";
        Main m = new Main();
        m.varType(x);
        m.varType(y);
        m.varType(z);
    }
}

Reference: http://beginnersbook.com/2013/04/java-static-dynamic-binding/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.