I can not find the meaning of Bind, let me explain what this is. I would like an example of Bind with the same java language.
I can not find the meaning of Bind, let me explain what this is. I would like an example of Bind with the same java language.
Defines how data in different formats are mapped to and from objects. There are numerous possibilities, where the most common are:
Consists of mapping attributes in HTTP requests to objects or maps. The way 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
.
<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) { ... }
}
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);
The best-known examples are JPA frameworks such as Hibernate and Eclipselink, where you can set up a class so that field data in a table is linked to the attributes of a class, so you can send and retrieve data without writing SQL clauses or retrieve field by field.
Mapping example of a JPA entity:
@Entity
public class Pessoa {
@Id
long id;
String nome;
String endereco;
...
}
Another example is method binding or method binding , which means how the language does to determine which is the correct method to call according to several factors :
In some cases, you can determine the correct method at compile time, for example if it is static or final
. In other vessels, the correct method is determined at runtime, which in theory is slower since it includes more processing during program execution. In fact, the JVM includes a series of optimizations that make the performance impact practically negligible in most cases.
Other examples of binding include:
Dynamic Bind and Staind Bind.
In static bind, you have methods inside your main class and call them directly in main
(methods have to be static), eg:
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 parent methods.
Dynamic bind, an instance of the main class is created to use its methods, eg
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: link