<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1406353607070992173</id><updated>2026-10-13T04:38:49.755-05:00</updated><category term="programacion"/><category term="redes"/><category term="java"/><category term="cisco"/><category term="poo"/><category term="configuracion router"/><category term="configuracion switch"/><category term="enrutamiento dinamico"/><category term="rails"/><category term="ror"/><category term="ruby on rails"/><category term="web"/><category term="c#"/><category term="configuracion vlan"/><category term="eclipselink"/><category term="enrutamiento estatico"/><category term="java ee"/><category term="jpa"/><category term="jsf"/><category term="netbeans"/><category term="primefaces"/><category term="ruby"/><category term="herramientas"/><category term="ospf"/><category term="prolog"/><category term="rip"/><category term="windows"/><category term="c"/><category term="c++"/><category term="cableado"/><category term="compilacion"/><category term="devkit"/><category term="encapsulamiento"/><category term="fibra optica"/><category term="gliffy"/><category term="modelado"/><category term="mvc"/><category term="mysql"/><category term="prezi"/><category term="railsinstaller"/><category term="rest"/><category term="scheme"/><category term="visual studio"/><category term="vtp"/><title type='text'>Notas en Ing. Sistemas</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>32</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-5933067567506258908</id><published>2015-07-08T22:12:00.004-05:00</published><updated>2015-07-09T08:44:39.215-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="eclipselink"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java ee"/><category scheme="http://www.blogger.com/atom/ns#" term="jpa"/><category scheme="http://www.blogger.com/atom/ns#" term="jsf"/><category scheme="http://www.blogger.com/atom/ns#" term="netbeans"/><category scheme="http://www.blogger.com/atom/ns#" term="primefaces"/><category scheme="http://www.blogger.com/atom/ns#" term="programacion"/><category scheme="http://www.blogger.com/atom/ns#" term="web"/><title type='text'>Desarrollo de una aplicación web con Java EE (JSF + JPA) - Parte 3</title><content type='html'>&lt;div style=&quot;text-align: justify&quot;&gt;
En esta tercera parte terminaremos con las pruebas a la base de datos que empezamos en la &lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_7.html&quot;&gt;parte anterior&lt;/a&gt; y crearemos el primer formulario de la aplicación.
&lt;br/&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;
&lt;br/&gt;
En este serie vamos a desarrollar una aplicación web usando Java EE, integrando las siguientes tecnologías EclipseLink (JPA 2.1), PrimeFaces 5.0
JSF 2.0.
&lt;br/&gt; &lt;br/&gt;
Para ello usaremos NetBeans IDE 8.0.2, y de base de datos MySQL 5.6.25, usando MySQL JDBC Driver 5.1.23 para conectar nuestra aplicación Java con MySQL, y MySQL Workbench 6.3 para gestionar y visualizar la base de datos.
&lt;br/&gt;&lt;br/&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;b&gt;Contenido&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ol class=&quot;indice&quot;&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_8.html#section1&quot;&gt;Terminando las pruebas a entidades&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_8.html#section2&quot;&gt;El primer controlador&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_8.html#section3&quot;&gt;Programando una vista&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_8.html#section4&quot;&gt;Conclusión - Link de Descarga del Proyecto&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br/&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section1&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Terminando las pruebas a entidades&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
En la &lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_7.html&quot;&gt;parte anterior&lt;/a&gt; hicimos una prueba de registro de información, y aprendimos cómo usar las entidades para persistir información de nuestra aplicación a la base de datos. Ahora, haremos una segunda prueba, pero ésta vez será de lectura, y veremos como obtener la información de la base de datos y usarla en nuestra aplicación.
&lt;br/&gt;&lt;br/&gt;
Como vimos en la parte anterior, todo el acceso a datos se hace a través de una clase EntityManager, que se instancia a través de un EntityManagerFactory. Para recuperar información de la base de datos, usaremos una instancia de EntityManager que tiene métodos para crear objetos de tipo Query; la cual se utiliza para realizar consultas a la base de datos. Entonces, la secuencia de pasos que tenemos que implementar en el código es la siguiente:
&lt;ol&gt;
&lt;li&gt;Obtener una instancia del EntityManagerFactory&lt;/li&gt;
&lt;li&gt;Obtener una instancia de EntityManager usando la instancia del EntityManagerFactory&lt;/li&gt;
&lt;li&gt;Obtener una instancia de Query usando el método .createQuery() de la instancia de EntityManager&lt;/li&gt;
&lt;li&gt;Instruir a la instancia de Query que ejecute la consulta, y procesar los datos devueltos por la misma&lt;/li&gt;
&lt;li&gt;Una vez terminada el procesamiento de datos, cerrar el objeto EntityManager usando su método .close()&lt;/li&gt;
&lt;li&gt;Cerrar el objecto EntityManagerFactory usando su método .close()&lt;/li&gt;
&lt;/ol&gt;
En NetBeans, hacemos click derecho en el nombre de nuestro proyecto y elegimos &quot;New&quot; &gt; &quot;Other&quot; del menú contextual.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnuelFA2VbCO8pm2NU76vrHmEPBGEgKVv76Yje9t346jMeLT7khXDFidYlsoe2lS_RMCNagKkWAi1RtTHaSUtegPihm9kV5decaQbQ0MqpX9BcGAkawKzrcpIDf6YIKdQtfUAeVlxAmnE/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnuelFA2VbCO8pm2NU76vrHmEPBGEgKVv76Yje9t346jMeLT7khXDFidYlsoe2lS_RMCNagKkWAi1RtTHaSUtegPihm9kV5decaQbQ0MqpX9BcGAkawKzrcpIDf6YIKdQtfUAeVlxAmnE/s320/1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
En la sección de &quot;Categories&quot; elegimos la carpeta &quot;Java&quot;, y en la sección de &quot;File Types&quot;, elegimos &quot;Java Main Class&quot;, y damos click en &quot;Next&quot;.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjppGr733xolAe5s6C8WrQGyg2-zsmQwjcvpp67n8MWcLHJA1CkpaBUIEwwLQuookbAI-3E1Av4mCs_-NMC7ugtGF5E4Qc-QtNIpG-0mJmMjeUW_edxAOptgTP-a9BLFtvsymizd2T72E8/s1600/2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjppGr733xolAe5s6C8WrQGyg2-zsmQwjcvpp67n8MWcLHJA1CkpaBUIEwwLQuookbAI-3E1Av4mCs_-NMC7ugtGF5E4Qc-QtNIpG-0mJmMjeUW_edxAOptgTP-a9BLFtvsymizd2T72E8/s320/2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Proporcionamos un nombre al archivo, y utilizaremos el mismo paquete donde guardamos el archivo PruebaRegistro.java. (En mi caso, lo llamaré PruebaLectura que será guardada en el paquete com.nes.test). Damos click en &quot;Finish&quot;.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwkz7WfjdynSjJqG2lt8LAEq5YBqcgX4MyqZ7dRFVatFF7jguZgJjFD_9sBQ6qjexgZUl_awfSiQSGUMOdpCuT4i4Sa_zdBNzkj_zyNkqZSNnQY9b2CBb5bZPkSiW_xSG0Jnbl0TNQRZ0/s1600/3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwkz7WfjdynSjJqG2lt8LAEq5YBqcgX4MyqZ7dRFVatFF7jguZgJjFD_9sBQ6qjexgZUl_awfSiQSGUMOdpCuT4i4Sa_zdBNzkj_zyNkqZSNnQY9b2CBb5bZPkSiW_xSG0Jnbl0TNQRZ0/s320/3.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Codificamos el archivo PruebaLectura usando los pasos descritos anteriormente.
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;PruebaLectura.java&lt;/b&gt;
&lt;pre class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.test;

import com.nes.entidades.DetallePedido;
import com.nes.entidades.Pedido;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

public class PruebaLectura {
  
  public static void main(String[] args) {
    //Obtener una instancia de EntityManagerFactory
    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(&quot;WebAppPU&quot;);
    //Obtener una instancia de EntityManager
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    
    //Obtener una instancia de Query
    Query query = entityManager.createQuery(&quot;SELECT p FROM Pedido p where p.id = 1&quot;);
    //Instruir a la instancia de Query que ejecute la consulta
    Pedido pedido = (Pedido) query.getSingleResult();
    //Procesar los datos devueltos
    System.out.println(&quot;Información de Pedido: &quot;);
    System.out.println(&quot;ID: &quot; + pedido.getId());
    System.out.println(&quot;Tienda: &quot; + pedido.getTienda().getNombre());
    System.out.println(&quot;Usuario: &quot; + pedido.getUsuario().getNombre());
    System.out.println(&quot;Detalle del pedido&quot;);
    for(DetallePedido detalle : pedido.getDetalle()){
      System.out.println(&quot;- Libro: &quot; + detalle.getLibro().getNombre() +
        &quot; Cantidad: &quot; + detalle.getCantidad() +
        &quot; Precio Unitario: &quot; + detalle.getPrecioUnitario());
    }
    
    //Cerrar la instancia de EntityManager
    entityManager.clear();
    //Cerrar la instancia de EntityManagerFactory
    entityManagerFactory.close();
  }
  
}&lt;/code&gt;&lt;/pre&gt;
Nótese que al momento de obtener la instancia de Query, es necesario pasarle un parámetro String al método .createQuery(). Este parámetro es la consulta a ejecutar en la base de datos, que debe estar escrita en JPQL. JPQL es un lenguaje de consulta definido por JPA. JQPL es similar a SQL, pero en vez de operar en tablas y columnas en la base de datos como lo hace SQL; JQPL opera en atributos y relaciones de nuestras entidades.
Puedes leer más sobre el lenguaje JPQL en &lt;a href=&quot;https://en.wikibooks.org/wiki/Java_Persistence/JPQL&quot;&gt;este link.&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
El método .getSingleResult() devuelve un objeto de tipo Object, pero como sabemos que nuestra Query retornará un pedido, es que le hacemos una conversión de tipo cast a tipo Pedido, y almacenamos su valor en una variable de trabajo. Finalmente, hacemos uso de los métodos getter y setter que codificamos en nuestras entidades para mostrar en consola la información traída de nuestra base de datos. Nótese lo fácil que es pasar de una entidad a otra: empezamos mostrando la información de la entidad Pedido, almacenada en la tabla &quot;pedido&quot; en la base de datos; y terminamos mostrando la información del detalle del pedido, que se encuentra almacenada en la tabla &quot;detallepedido&quot; en la base datos. Ésta es una de los beneficios de usar JPA; si no usáramos JPA tendríamos que haber realizado una consulta SQL a la base de datos para obtener los datos del pedido, y luego otra consulta SQL para obtener los datos del detalle del pedido. JPA hace esto por nosotros de manera automática.
&lt;br/&gt;
&lt;br/&gt;
Procedemos a ejecutar el archivo PruebaLectura.java. Para ello hacemos click derecho cualquier lugar del código del archivo y elegimos la opción &quot;Run File&quot; del menú contextual.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizpIlnPsFlcDpPbZVfv4FjNNnAutexqirwAXa82G-ZSRmLl0rWe6t3ek2zgut5cIKQHeKHMNWT3pYJd4s3pPGU67_Lw1DASk_ahyHzpO4JAuYDd_2PHkIgyI-kq5UF3DM8hxkSg1Du1mU/s1600/3.5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizpIlnPsFlcDpPbZVfv4FjNNnAutexqirwAXa82G-ZSRmLl0rWe6t3ek2zgut5cIKQHeKHMNWT3pYJd4s3pPGU67_Lw1DASk_ahyHzpO4JAuYDd_2PHkIgyI-kq5UF3DM8hxkSg1Du1mU/s320/3.5.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Se ejecuta nuestro código, y en la ventana de &quot;Output&quot; podemos ver el resultado de la ejecución: la consola muestra la información del pedido con ID igual a 1 y su detalle correspondiente.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSDpAe1vvWjeJzSVa0qBFpOWNJX48cX9NJPaqHfd7WRlts22W9q5QGW6QfQ653kLQO-8tHFCCBGC1Bbk0eM4GO6MtcW_uHOu3MbfP4Itk2ARGUit5-GuiamgoZepk_gYd4zPSJe5VpAvk/s1600/4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSDpAe1vvWjeJzSVa0qBFpOWNJX48cX9NJPaqHfd7WRlts22W9q5QGW6QfQ653kLQO-8tHFCCBGC1Bbk0eM4GO6MtcW_uHOu3MbfP4Itk2ARGUit5-GuiamgoZepk_gYd4zPSJe5VpAvk/s320/4.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
En el ejemplo anterior, utilizamos JPA para buscar un pedido en particular. Ahora utilizaremos JPA para buscar una colección: mostraremos en consola todos los géneros de la base de datos. En el mismo archivo PruebaLectura.java, agregamos un poco más de código al final del archivo:
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;PruebaLectura.java&lt;/b&gt;
&lt;pre class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.test;

import com.nes.entidades.DetallePedido;
import com.nes.entidades.Genero;
import com.nes.entidades.Pedido;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

public class PruebaLectura {
  
  public static void main(String[] args) {
    //Obtener una instancia de EntityManagerFactory
    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(&quot;WebAppPU&quot;);
    //Obtener una instancia de EntityManager
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    
    //Obtener una instancia de Query
    Query query = entityManager.createQuery(&quot;SELECT p FROM Pedido p where p.id = 1&quot;);
    //Instruir a la instancia de Query que ejecute la consulta
    Pedido pedido = (Pedido) query.getSingleResult();
    //Procesar los datos devueltos
    System.out.println(&quot;Información de Pedido: &quot;);
    System.out.println(&quot;ID: &quot; + pedido.getId());
    System.out.println(&quot;Tienda: &quot; + pedido.getTienda().getNombre());
    System.out.println(&quot;Usuario: &quot; + pedido.getUsuario().getNombre());
    System.out.println(&quot;Detalle del pedido&quot;);
    for(DetallePedido detalle : pedido.getDetalle()){
      System.out.println(&quot;- Libro: &quot; + detalle.getLibro().getNombre() +
        &quot; Cantidad: &quot; + detalle.getCantidad() +
        &quot; Precio Unitario: &quot; + detalle.getPrecioUnitario());
    }
    
    //Cerrar la instancia de EntityManager
    entityManager.clear();
    //Cerrar la instancia de EntityManagerFactory
    entityManagerFactory.close();
    
    //Obtener una instancia de EntityManagerFactory
    EntityManagerFactory entityManagerFactory1 = Persistence.createEntityManagerFactory(&quot;WebAppPU&quot;);
    //Obtener una instancia de EntityManager
    EntityManager entityManager1 = entityManagerFactory1.createEntityManager();
    
    //Obtener una instancia de Query
    Query query1 = entityManager1.createQuery(&quot;SELECT g FROM Genero g&quot;);
    //Instruir a la instancia de Query que ejecute la consulta
    List&lt;Genero&gt; listaGeneros = (List&lt;Genero&gt;) query1.getResultList();
    //Procesar los datos devueltos
    System.out.println();
    System.out.println(&quot;Lista de Generos&quot;);
    for(Genero g : listaGeneros) {
      System.out.println(&quot;ID: &quot; + g.getId() + &quot; Nombre: &quot; + g.getNombre());
    }
    
    //Cerrar la instancia de EntityManager
    entityManager1.clear();
    //Cerrar la instancia de EntityManagerFactory
    entityManagerFactory1.close();
  }
  
}
&lt;/code&gt;&lt;/pre&gt;
Para procesar colecciones, hacemos uso del método .getResultList() de la clase Query. Y como sabemos que retornará información sobre genero, podemos hacer una conversión de tipo cast a List&lt;Genero&gt; que almacenamos en una variable de trabajo. Finalmente, iteramos sobre la lista de Generos y mostramos el resultado en consola.
&lt;br/&gt;&lt;br/&gt;
Volvemos a ejecutar el archivo PruebaLectura.java y ahora vemos que en la pestaña de &quot;Output&quot;, además de la información del pedido mostrada anteriormente, también se muestra la información de los géneros registrados en la base de datos. (Me tomé la libertad de agregar más registros en la tabla Género de la base de datos para evidenciar este ejemplo)
&lt;br/&gt;&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgafvHxpcO8gSnQyoiK0cx3CrsMoJWEJo8i6YFLniJfYltWQM1oHke2m_lafTDlBK8CQcDpcza2AMicyCOq15nBKZ8qHECXe3eNuUFU-mOtLuEiMw8qvjl5Qx6IFKYh-_GYwMAX2TbrkLQ/s1600/5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgafvHxpcO8gSnQyoiK0cx3CrsMoJWEJo8i6YFLniJfYltWQM1oHke2m_lafTDlBK8CQcDpcza2AMicyCOq15nBKZ8qHECXe3eNuUFU-mOtLuEiMw8qvjl5Qx6IFKYh-_GYwMAX2TbrkLQ/s320/5.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Hasta este punto, hemos creado las entidades y hemos registrar y obtener información de nuestra base de datos; pero la idea es que los usuarios de la aplicación sean los que puedan registrar y consultar la información, y no estarla codificando nosotros mismos. En la siguiente parte, crearemos el primero formulario de la aplicación.

&lt;br/&gt;&lt;br/&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section2&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;El primer controlador&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
Java Server Faces (JSF) utiliza el modelo de vista-controlador conocido como MVC. Según &lt;a href=&quot;https://es.wikipedia.org/wiki/Modelo%E2%80%93vista%E2%80%93controlador&quot;&gt;Wikipedia&lt;/a&gt;: 
&lt;blockquote&gt;El modelo–vista–controlador (MVC) es un patrón de arquitectura de software que separa los datos y la lógica de negocio de una aplicación de la interfaz de usuario y el módulo encargado de gestionar los eventos y las comunicaciones. Para ello MVC propone la construcción de tres componentes distintos que son el modelo, la vista y el controlador. 
&lt;br/&gt;&lt;br/&gt;
El Modelo es la representación de la información con la cual el sistema opera; [..] el Controlador responde a eventos (usualmente acciones del usuario) e invoca peticiones al &#39;modelo&#39; cuando se hace alguna solicitud sobre la información [..] y la Vista presenta el Modelo [..] en un formato adecuado para interactuar (usualmente la interfaz de usuario).&lt;/blockquote&gt;
&lt;br/&gt;&lt;br/&gt;
En nuestra aplicación, ya tenemos la parte del modelo: son nuestras entidades. En JSF, un controlador es implementado mediante una clase java con la anotación @ManagedBean. Y las vista es implementada mediante un archivo XHTML.
&lt;br/&gt;&lt;br/&gt;
Vamos a crear un formulario para que los usuarios puedan registrar géneros en la base de datos. Para ello procederemos a crear el primer controlador. En la pestaña de &quot;Projects&quot;, damos click derecho a nuestro proyecto y elegimos &quot;New&quot; &gt; &quot;Java Class&quot; del menú contextual.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMDeTJYLNG2CZiCmN19JXY1VKjEgWVguc6FvpaXvLhvowUts3XcgXSFxxV0BtMxFWLF5F_ihLba6x5eQdhlxFkJ91uWwI8zKexSV9giR5tdo0GI_fkIwFBV6GAbj341jWINT51Dmyyc5I/s1600/6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMDeTJYLNG2CZiCmN19JXY1VKjEgWVguc6FvpaXvLhvowUts3XcgXSFxxV0BtMxFWLF5F_ihLba6x5eQdhlxFkJ91uWwI8zKexSV9giR5tdo0GI_fkIwFBV6GAbj341jWINT51Dmyyc5I/s320/6.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Proporcionamos un nombre para nuestro controlador, lo llamaremos &quot;ControladorGenero&quot; y será guardado en un nuevo paquete llamado &quot;com.nes.controladores&quot;, y damos click en &quot;Finish&quot;.
&lt;br/&gt;&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1e8kImYqPbXyJOPLeTK6h1A31K809suxi5hI9G15Yt-wokIqTlTD2f4I0CFMw7A36p8WqZ1kp44KYOm7uLEV73bq0otgWam4KN8aimvu2ue-tX-Gi4_RkdqjddU-MN2ramaeUumuyY3A/s1600/7.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1e8kImYqPbXyJOPLeTK6h1A31K809suxi5hI9G15Yt-wokIqTlTD2f4I0CFMw7A36p8WqZ1kp44KYOm7uLEV73bq0otgWam4KN8aimvu2ue-tX-Gi4_RkdqjddU-MN2ramaeUumuyY3A/s320/7.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;&lt;br/&gt;
Codificamos el archivo ControladorGenero:
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;ControladorGenero.java&lt;/b&gt;
&lt;pre class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.controladores;

import com.nes.entidades.Genero;
import javax.faces.bean.ManagedBean;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

@ManagedBean
public class ControladorGenero {
  private Genero genero = new Genero();
  
  public void registrarGenero() {
    //Obtener una instancia de EntityManagerFactory
    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(&quot;WebAppPU&quot;);
    //Obtener una instancia de EntityManager
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    //Como vamos a persistir datos, abrimos una transacción
    entityManager.getTransaction().begin();
    //Persistimos la información
    entityManager.persist(genero);
    //Ejecutamos la transacción
    entityManager.getTransaction().commit();
    //Cerramos la instancia de EntityManager
    entityManager.close();
    //Cerramos la instancia de EntityManagerFactory
    entityManagerFactory.close();
  }
  
  public Genero getGenero() {
    return genero;
  }

  public void setGenero(Genero genero) {
    this.genero = genero;
  }
}
&lt;/code&gt;&lt;/pre&gt;

El controlador tiene un solo atributo de tipo Genero con sus respectivos métodos getter y setter. Y también tiene un método registrarGenero() que persiste la información del atributo de tipo Genero.

&lt;br/&gt;&lt;br/&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section3&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Programando una vista&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
Ahora procederemos a crear la primera vista que usará el controlador programado anteriormente. En la pestaña &quot;Projects&quot;, expandimos el proyecto y le damos click derecho en &quot;Web Pages&quot;, elegimos &quot;New&quot; &gt; &quot;Folder&quot; del menú contextual.
&lt;br/&gt;&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNPeH2ngEeNms8GpBsqT658YpijSpCHGgs5hEwVsrZdaXDtg3wy2grIXsKasJfbUmaT0TPc-t9wM_cnt8w3o8WXh8HOPGOyLt7bA7j4izeaPwwZJojnLACgRnc9cMSB8JtuCUfcDOfwjg/s1600/8.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNPeH2ngEeNms8GpBsqT658YpijSpCHGgs5hEwVsrZdaXDtg3wy2grIXsKasJfbUmaT0TPc-t9wM_cnt8w3o8WXh8HOPGOyLt7bA7j4izeaPwwZJojnLACgRnc9cMSB8JtuCUfcDOfwjg/s320/8.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Proporcionamos un nombre a la carpeta, la llamaremos &quot;app&quot;, y damos click en &quot;Finish&quot;.
&lt;br/&gt;&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1A3HlIiTaXQZMP8A4CvBzBVO-x2JCellFRM7MFiMe2x1lywMeLspZkwQ9OWiy7L3Y29FV-m5h1KAvBARVQ2oOhDil9IpYVH4kuZxTefolA-mZm3hyphenhyphenqCPnBz9Q9b94ml-3ymXUVibgw0U/s1600/9.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1A3HlIiTaXQZMP8A4CvBzBVO-x2JCellFRM7MFiMe2x1lywMeLspZkwQ9OWiy7L3Y29FV-m5h1KAvBARVQ2oOhDil9IpYVH4kuZxTefolA-mZm3hyphenhyphenqCPnBz9Q9b94ml-3ymXUVibgw0U/s320/9.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;&lt;br/&gt;
Damos click derecho en la carpeta &quot;app&quot; y elegimos &quot;New&quot; &gt; &quot;Other&quot; del menú contextual.
&lt;br/&gt;&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXazCFiFhYt4KtxVx9LkDkEvJjQ-33-2ZcooJHgtGbQa7kp86o8DJAO082HikLY3km7e9bVgnValwutnsyjmp_aZC4lI1-hck3PB8on3iprnK2HaDeuVK4I1c5jSUwm0OIbkMVwH09cY4/s1600/10.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXazCFiFhYt4KtxVx9LkDkEvJjQ-33-2ZcooJHgtGbQa7kp86o8DJAO082HikLY3km7e9bVgnValwutnsyjmp_aZC4lI1-hck3PB8on3iprnK2HaDeuVK4I1c5jSUwm0OIbkMVwH09cY4/s320/10.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Proporcionamos un nombre, el cual llamaremos &quot;registroGenero&quot;, y damos click en &quot;Finish&quot;.
&lt;br/&gt;&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmFhJAnvw11BXt8_TYnmBQrPXpqxcKsow3VabYOlVpM_Rf7KgVqTPgNZxPar6O3RszLjMVEhfWZ9iUWSbbCHxGlSr60aotuT5adhteazfmgLiOQup0bdaJ5_goOZjpw5HH_VZvcFIgDmQ/s1600/11.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmFhJAnvw11BXt8_TYnmBQrPXpqxcKsow3VabYOlVpM_Rf7KgVqTPgNZxPar6O3RszLjMVEhfWZ9iUWSbbCHxGlSr60aotuT5adhteazfmgLiOQup0bdaJ5_goOZjpw5HH_VZvcFIgDmQ/s320/11.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Editamos el contenido del archivo registroGenero.xhtml para que quede de la siguiente manera:
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;ControladorGenero.java&lt;/b&gt;
&lt;pre class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&amp;lt;?xml version=&#39;1.0&#39; encoding=&#39;UTF-8&#39; ?&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&amp;gt;
&amp;lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
      xmlns:h=&quot;http://xmlns.jcp.org/jsf/html&quot;
      xmlns:p=&quot;http://primefaces.org/ui&quot;&amp;gt;
  &amp;lt;h:head&amp;gt;
    &amp;lt;title&amp;gt;Registro de Género&amp;lt;/title&amp;gt;
  &amp;lt;/h:head&amp;gt;
  &amp;lt;h:body&amp;gt;
    &amp;lt;h:form&amp;gt;
      &amp;lt;h:outputLabel for=&quot;txtNombre&quot; value=&quot;Nombre: &quot; /&amp;gt;
      &amp;lt;p:inputText id=&quot;txtNombre&quot; value=&quot;#{controladorGenero.genero.nombre}&quot; /&amp;gt;
      &amp;lt;p:commandButton action=&quot;#{controladorGenero.registrarGenero}&quot;
                       value=&quot;Guardar&quot; /&amp;gt;
    &amp;lt;/h:form&amp;gt;
  &amp;lt;/h:body&amp;gt;
&amp;lt;/html&amp;gt;

&lt;/code/&gt;&lt;/pre&gt;

Como podemos ver, la vista se compone de un formulario, el cual contiene una label con el valor de &quot;Nombre: &quot;, un input text (caja de texto), y un botón con el valor de &quot;Guardar&quot; para enviar el formulario. Nótese que para el input le asignamos el valor del atributo de tipo Genero del ControladorGenero, y que para el botón de envío de formulario le asignamos el método .registrarGenero() del ControladorGenero. Para hacer esta asignación, hacemos un binding con nuestro controlador, utilizando Expression Language. Para saber más sobre Expression Language puede &lt;a href=&quot;http://docs.oracle.com/javaee/7/tutorial/jsf-develop001.htm#BNAQP&quot;&gt;revisar la documentación de Oracle&lt;/a&gt;.
&lt;br/&gt; &lt;br/&gt;
Finalmente ejecutamos la aplicación, para eso damos click derecho en el archivo &quot;registrarGenero.xhtml&quot; de nuestra aplicación y elegimos &quot;Run File&quot; del menú contextual. La aplicación se despliega y se abre la ventana del browser mostrando el formulario:
&lt;br/&gt;&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsdu60DJseR6CHXJjQi163KAORLPI96E-vIP3Y9R8Zbez_1kQ7LKmT5dvtfWqbj2ZYjAwMF6mJrrXF4gr707X7Nz0-MrR9ToILvzGxIKpgT4fzIMuVLIlSgcQb6qKGQG083VWCu-Uztas/s1600/12.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsdu60DJseR6CHXJjQi163KAORLPI96E-vIP3Y9R8Zbez_1kQ7LKmT5dvtfWqbj2ZYjAwMF6mJrrXF4gr707X7Nz0-MrR9ToILvzGxIKpgT4fzIMuVLIlSgcQb6qKGQG083VWCu-Uztas/s320/12.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Proporcionamos un nombre, y damos click en el botón de Guardar.
&lt;br/&gt;&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv_hCGYc7UAZ_nh8wEwz_BHCzc8J5sQFk1Z2omaCv5_NxAxFFeUwj82rBg7QMbEZXxQsWzq0vGzA7h8GrpIDabfEhknATMahTYX4vU66fh8IiaA0nlfcb0hAaRiU51cuk35K3HDpdH16M/s1600/13.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv_hCGYc7UAZ_nh8wEwz_BHCzc8J5sQFk1Z2omaCv5_NxAxFFeUwj82rBg7QMbEZXxQsWzq0vGzA7h8GrpIDabfEhknATMahTYX4vU66fh8IiaA0nlfcb0hAaRiU51cuk35K3HDpdH16M/s320/13.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Revisamos la base de datos, y podemos observar que en la tabla Genero se ha insertado un nuevo registro.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoTL0cXNrbd9slbkdA1EGpN9FfloKfviHE_Aqd2aIeP-OtwcH1rWNXLoK_S_YpHig_-gk3eCj4gVUpSVYb0W91rXITdTEjf4frcoWDVy9dh3w6cKA0y0Mx1AFf9d2P7yo0RNcPvUpAlB4/s1600/14.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoTL0cXNrbd9slbkdA1EGpN9FfloKfviHE_Aqd2aIeP-OtwcH1rWNXLoK_S_YpHig_-gk3eCj4gVUpSVYb0W91rXITdTEjf4frcoWDVy9dh3w6cKA0y0Mx1AFf9d2P7yo0RNcPvUpAlB4/s320/14.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section4&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Conclusión - Link de Descarga del Proyecto&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
Recapitulando, en esta parte terminamos con las pruebas de las entidades: realizando una pequeña prueba de lectura de información de la base de datos, demostrando que nuestra aplicación Java se conecta adecuadamente con la base de datos MySQL. También creamos el primer controlador y creamos la primera vista de la aplicación, la cual contiene un formulario que permite a los usuarios registrar géneros en la base de datos. &lt;b&gt;Puedes descargar el código del proyecto de NetBeans hasta este punto &lt;a href=&quot;https://github.com/JBAndreu/nes-java-ee/archive/parte3.zip&quot;&gt;haciendo click en este link.&lt;/a&gt;&lt;/b&gt;
&lt;br/&gt;&lt;br/&gt;
La aplicación hasta ahora permite a los usuarios registrar géneros exitosamente, pero no se muestra algún mensaje notificando a los usuarios que el registro se hizo adecuadamente o no. En la siguiente parte, mejoraremos la interfaz de usuario y continuaremos con el desarrollo de la aplicación.
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;Referencias:&lt;/b&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://en.wikibooks.org/wiki/Java_Persistence/JPQL&quot;&gt;JPQL, Java Persistence WikiBook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://es.wikipedia.org/wiki/Modelo%E2%80%93vista%E2%80%93controlador&quot;&gt;Modelo Vista Controlador, Wikipedia&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/javaee/7/tutorial/jsf-develop001.htm#BNAQP&quot;&gt;Utilizando Expression Language para referencia Beans Administrados&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/5933067567506258908/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_8.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/5933067567506258908'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/5933067567506258908'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_8.html' title='Desarrollo de una aplicación web con Java EE (JSF + JPA) - Parte 3'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnuelFA2VbCO8pm2NU76vrHmEPBGEgKVv76Yje9t346jMeLT7khXDFidYlsoe2lS_RMCNagKkWAi1RtTHaSUtegPihm9kV5decaQbQ0MqpX9BcGAkawKzrcpIDf6YIKdQtfUAeVlxAmnE/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-5974265518660058517</id><published>2015-07-07T22:55:00.000-05:00</published><updated>2015-07-09T08:44:34.824-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="eclipselink"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java ee"/><category scheme="http://www.blogger.com/atom/ns#" term="jpa"/><category scheme="http://www.blogger.com/atom/ns#" term="jsf"/><category scheme="http://www.blogger.com/atom/ns#" term="netbeans"/><category scheme="http://www.blogger.com/atom/ns#" term="primefaces"/><category scheme="http://www.blogger.com/atom/ns#" term="programacion"/><category scheme="http://www.blogger.com/atom/ns#" term="web"/><title type='text'>Desarrollo de una aplicación web con Java EE (JSF + JPA) - Parte 2</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
En esta segunda parte procederemos a crear las entidades de la aplicación, utilizando EclipseLink que implementa la especificación JPA que nos ayudará a manejar nuestra base de datos MySQL.
&lt;br/&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;
&lt;br/&gt;
En este serie vamos a desarrollar una aplicación web usando Java EE, integrando las siguientes tecnologías EclipseLink (JPA 2.1), PrimeFaces 5.0
JSF 2.0.
&lt;br/&gt;&lt;br/&gt;
Para ello usaremos NetBeans IDE 8.0.2, y de base de datos MySQL 5.6.25, usando MySQL JDBC Driver 5.1.23 para conectar nuestra aplicación Java con MySQL, y MySQL Workbench 6.3 para gestionar y visualizar la base de datos.
&lt;br /&gt; &lt;br/&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;b&gt;Contenido&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ol class=&quot;indice&quot;&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_7.html#section1&quot;&gt;Creación de clases&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_7.html#section2&quot;&gt;Creación de entidades&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_7.html#section3&quot;&gt;Agregando una unidad de persistencia&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_7.html#section4&quot;&gt;Probando las entidades&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_7.html#section5&quot;&gt;Conclusión - Link de Descarga del Proyecto&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br/&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section1&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Creación de clases&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
Las clases que procederemos a crear en nuestro proyecto son las que se muestran en el siguiente diagrama de clases:
&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI0Y_UuuWMhu7xeh64xIT6oSs9idWYBYmoHiy41Y1LeVgBs0lPdyrmIQ3V1mMkPA4aEp_NsQZjyhqC23APcExhByxQxwjA8YzHroUVRwuRu9kEJ6itZXJk3PdXOoKT1O6BxpJiH1b2ifU/s1600/Diagrama+de+Clases.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI0Y_UuuWMhu7xeh64xIT6oSs9idWYBYmoHiy41Y1LeVgBs0lPdyrmIQ3V1mMkPA4aEp_NsQZjyhqC23APcExhByxQxwjA8YzHroUVRwuRu9kEJ6itZXJk3PdXOoKT1O6BxpJiH1b2ifU/s400/Diagrama+de+Clases.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
En la pestaña de &quot;Projects&quot; expandimos nuestro proyectos, y damos click derecho en &quot;Source Packages&quot;, elegimos New &gt; Java Class del menú contextual.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKbRVrWOAPZkZn0XBnjNQY7pDdIKXQPgNfQM4DnV4KdqTFe4d43EuYZIQ2ogTJCnsBcUv4hw1jtMd15Fht2TKWPwnRUK_YQIgPs7RdF9-4QQzs0_jBHtqGEvqjmLNqrgk4fntt8JJdrqY/s1600/1+new+java+class.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKbRVrWOAPZkZn0XBnjNQY7pDdIKXQPgNfQM4DnV4KdqTFe4d43EuYZIQ2ogTJCnsBcUv4hw1jtMd15Fht2TKWPwnRUK_YQIgPs7RdF9-4QQzs0_jBHtqGEvqjmLNqrgk4fntt8JJdrqY/s320/1+new+java+class.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
En el cuadro de diálogo que aparece brindamos un nombre a nuestra clase en &quot;Class Name&quot;, y en &quot;Package&quot; proporcionamos el nombre del paquete donde se guardarán las clases. Procedemos a crear la clase Genero, que estará dentro del paquete com.nes.entidades.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-pyFF_CRuUxlYeLveaQ8LychHP14u9kL7ZcNHvq_2d7ISUEROoYBCezxQbcKKzcsLn5wY4uS6NFxehNDhGQ_eh1fiodfyA4O3gTg66YUiAWYV-MEN-XMN-pQUaXV1oXYKxVDSNYIZH8/s1600/2+new+class+dialog.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ-pyFF_CRuUxlYeLveaQ8LychHP14u9kL7ZcNHvq_2d7ISUEROoYBCezxQbcKKzcsLn5wY4uS6NFxehNDhGQ_eh1fiodfyA4O3gTg66YUiAWYV-MEN-XMN-pQUaXV1oXYKxVDSNYIZH8/s320/2+new+class+dialog.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
En nuestra nueva clase Genero, procedemos a codificar los atributos respectivos de la clase.
&lt;pre class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

public class Genero {
  private int id;
  private String nombre;
}&lt;/code&gt;&lt;/pre&gt;

A continuación, procedemos a generar los getter y setters de la clase, para eso hacemos click derecho en cualquier lugar del código del archivo Género.java, elegimos &quot;Refactor&quot; &gt; &quot;Encapsulate fields&quot; del menú.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuMkaa1e2Uwv60Z5BXdU-QUP5JXbkkqL4MTBEhp5ii7fUrMxfSTnAYDlbLk_KAIr78TD9bB8iGENYEbo9lA3DRP8KqTTyAF4wyq75BnK79F4RYci_EVeRnT7icIJCXEAs0Nx_PZJrgsxo/s1600/1+new+java+class.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuMkaa1e2Uwv60Z5BXdU-QUP5JXbkkqL4MTBEhp5ii7fUrMxfSTnAYDlbLk_KAIr78TD9bB8iGENYEbo9lA3DRP8KqTTyAF4wyq75BnK79F4RYci_EVeRnT7icIJCXEAs0Nx_PZJrgsxo/s320/1+new+java+class.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Elegimos cuales atributos deseamos generar los getters/setters (en este caso todos los atributos), y damos click en &quot;Refactor&quot;.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfIij6jS2ev5b3w30TuwKKZy7Pk_OgVEV5lo86Yq0OgNXR4faoldXgdzY5yRCNrKwIcO_lzHoR9VMbqGJHO-DyFEwqPBCkUtlFtDPUHY-9tNv7SDYB8r52jAwpHpBxQNcnFd0tziF-8gA/s1600/4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfIij6jS2ev5b3w30TuwKKZy7Pk_OgVEV5lo86Yq0OgNXR4faoldXgdzY5yRCNrKwIcO_lzHoR9VMbqGJHO-DyFEwqPBCkUtlFtDPUHY-9tNv7SDYB8r52jAwpHpBxQNcnFd0tziF-8gA/s320/4.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Ahora nuestra clase Genero, tiene los métodos Get y Set respectivos para poder acceder a los atributos de la clase que están marcados como privados. El archivo Genero.java debe quedar de la siguiente manera:
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;Genero.java&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

public class Genero {
  private int id;
  private String nombre;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getNombre() {
    return nombre;
  }

  public void setNombre(String nombre) {
    this.nombre = nombre;
  }
}
&lt;/code&gt;&lt;/pre&gt;
Repetimos la misma secuencia de pasos para crear las demás clases de la aplicación: Usuario, Libro, Tienda, DetallePedido, Pedido y Stock. Procederemos a codificar las clases y sus respectivos métodos getters y setters para cada atributo. Las clases resultantes deben quedar de esta manera:
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;Usuario.java&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

import java.util.ArrayList;
import java.util.List;

public class Usuario {
  private int id;
  private String nombre;
  private String usuario;
  private String clave;
  private boolean administrador;
  private List&lt;Pedido&gt; pedidos = new ArrayList&lt;&gt;();

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getNombre() {
    return nombre;
  }

  public void setNombre(String nombre) {
    this.nombre = nombre;
  }

  public String getUsuario() {
    return usuario;
  }

  public void setUsuario(String usuario) {
    this.usuario = usuario;
  }

  public String getClave() {
    return clave;
  }

  public void setClave(String clave) {
    this.clave = clave;
  }

  public boolean isAdministrador() {
    return administrador;
  }

  public void setAdministrador(boolean administrador) {
    this.administrador = administrador;
  }

  public List&lt;Pedido&gt; getPedidos() {
    return pedidos;
  }

  public void setPedidos(List&lt;Pedido&gt; pedidos) {
    this.pedidos = pedidos;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;b&gt;Libro.java&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

public class Libro {
  private int id;
  private String nombre;
  private float precio;
  private Genero genero;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getNombre() {
    return nombre;
  }

  public void setNombre(String nombre) {
    this.nombre = nombre;
  }

  public float getPrecio() {
    return precio;
  }

  public void setPrecio(float precio) {
    this.precio = precio;
  }

  public Genero getGenero() {
    return genero;
  }

  public void setGenero(Genero genero) {
    this.genero = genero;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;b&gt;Tienda.java&lt;/b&gt;
&lt;pre   class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

public class Tienda {
  private int id;
  private String nombre;
  private String direccion;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getNombre() {
    return nombre;
  }

  public void setNombre(String nombre) {
    this.nombre = nombre;
  }

  public String getDireccion() {
    return direccion;
  }

  public void setDireccion(String direccion) {
    this.direccion = direccion;
  }
  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;b&gt;DetallePedido.java&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

public class DetallePedido {
  private int id;
  private Pedido pedido;
  private Libro libro;
  private float precioUnitario;
  private int cantidad;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public Pedido getPedido() {
    return pedido;
  }

  public void setPedido(Pedido pedido) {
    this.pedido = pedido;
  }

  public Libro getLibro() {
    return libro;
  }

  public void setLibro(Libro libro) {
    this.libro = libro;
  }

  public float getPrecioUnitario() {
    return precioUnitario;
  }

  public void setPrecioUnitario(float precioUnitario) {
    this.precioUnitario = precioUnitario;
  }

  public int getCantidad() {
    return cantidad;
  }

  public void setCantidad(int cantidad) {
    this.cantidad = cantidad;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;b&gt;Pedido.java&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

import java.util.ArrayList;
import java.util.List;

public class Pedido {
  private int id;
  private Usuario usuario;
  private Tienda tienda;
  private List&lt;DetallePedido&gt; detalle = new ArrayList&lt;&gt;();

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public Usuario getUsuario() {
    return usuario;
  }

  public void setUsuario(Usuario usuario) {
    this.usuario = usuario;
  }

  public Tienda getTienda() {
    return tienda;
  }

  public void setTienda(Tienda tienda) {
    this.tienda = tienda;
  }

  public List&lt;DetallePedido&gt; getDetalle() {
    return detalle;
  }

  public void setDetalle(List&lt;DetallePedido&gt; detalle) {
    this.detalle = detalle;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;b&gt;Stock.java&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

public class Stock {
  private int id;
  private Libro libro;
  private Tienda tienda;
  private int cantidad;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public Libro getLibro() {
    return libro;
  }

  public void setLibro(Libro libro) {
    this.libro = libro;
  }

  public Tienda getTienda() {
    return tienda;
  }

  public void setTienda(Tienda tienda) {
    this.tienda = tienda;
  }

  public int getCantidad() {
    return cantidad;
  }

  public void setCantidad(int cantidad) {
    this.cantidad = cantidad;
  }
}
&lt;/code&gt;&lt;/pre&gt;
Hasta este punto tenemos las clases que utilizaremos en nuestra aplicación. A continuación procederemos a convertir estas clases en Entidades de EclipseLink que representarán las tablas en nuestra base de datos.
&lt;br /&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section2&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Creación de entidades&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;
&lt;br /&gt;&lt;br /&gt;
Para que nuestras clases de Java se vuelvan entidades de EclipseLink, se hace uso de la anotación @Entity. Esto indica a EclipseLink que la clase representa una tabla en nuestra base de datos. La anotación @Entity necesita que las clases que la utilicen implementen la interfaz Serializable del paquete java.io.Serializable. Por lo que también haremos que las clases implementen dicha interfaz.
&lt;br/&gt;&lt;br/&gt;
También es necesario especificar cuál atributo de la clase será usado como llave primaria en la base de datos. Como todas nuestras clases tienen un atributo id de tipo entero usaremos ese atributo para que sea la llave primaria de las tablas en nuestra base de datos. Para eso, se usa la anotación @Id.
&lt;br/&gt;&lt;br/&gt;
Además, para no preocuparnos por cómo generar la llave primaria con cada nuevo registro en nuestra aplicación, usaremos la anotación @GeneratedValue para indicar a EclipseLink que la llave primaria se generará automáticamente. También especificamos que la estrategia para generar las llaves primarias será mediante el uso del Identity en MySQL (también conocido como AUTO_INCREMENT), y esto lo hacemos con la propiedad GenerationType.IDENTITY dentro de la anotación @GeneratedValue.
&lt;br/&gt;&lt;br/&gt;
En una base de datos, las tablas no se encuentran aisladas. Las tablas se encuentran asociadas con otras mediante llaves foráneas, y dependiendo de la cardinalidad, se tienen asociaciones uno a uno, uno a muchos, o muchos a muchos.
&lt;br/&gt;&lt;br/&gt;
En nuestra aplicación, podemos observar que tenemos muchas asociaciones entre diferentes entidades, por citar algunas:
&lt;ul&gt;
&lt;li&gt;Un libro tiene un género y a su vez; un género puede estar presente en muchos libros. Esto es una relación de uno a muchos entre Libro y Genero&lt;/li&gt;
&lt;li&gt;Un usuario puede realizar muchos pedidos y a su vez; un pedido es realizado por un usuario. Esto es una relación de uno a muchos entre Usuario y Pedido&lt;/li&gt;
&lt;li&gt;Un usuario puede realizar muchos pedidos y a su vez; un pedido es realizado por un usuario. Esto es una relación de uno a muchos entre Usuario y Pedido&lt;/li&gt;
&lt;li&gt;Una tienda tiene una colección de existencias (stocks), y a su vez una existencia (stock) tiene está asignado a una tienda. Esto es una relación de uno a muchos entre Tienda y Stock.&lt;/li&gt;
&lt;/ul&gt;
Para especificar dichas relaciones entre tablas, se usan las anotaciones @ManyToOne y @OneToMany para representar asociaciones muchos-a-uno y de uno-a-muchos respectivamente. Mas información sobre relaciones en JPA en el &lt;a href=&quot;https://en.wikibooks.org/wiki/Java_Persistence/Relationships&quot;&gt;WikiBook de Java Persistence.&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Haciendo uso de éstas anotaciones, nuestras clases quedan de la siguiente manera:
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;Genero.java&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Genero implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int id;
  private String nombre;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getNombre() {
    return nombre;
  }

  public void setNombre(String nombre) {
    this.nombre = nombre;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;b&gt;Libro.java&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

@Entity
public class Libro implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int id;
  private String nombre;
  private float precio;
  @ManyToOne
  private Genero genero;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getNombre() {
    return nombre;
  }

  public void setNombre(String nombre) {
    this.nombre = nombre;
  }

  public float getPrecio() {
    return precio;
  }

  public void setPrecio(float precio) {
    this.precio = precio;
  }

  public Genero getGenero() {
    return genero;
  }

  public void setGenero(Genero genero) {
    this.genero = genero;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;b&gt;Stock.java&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

@Entity
public class Stock implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int id;
  @ManyToOne
  private Libro libro;
  @ManyToOne
  private Tienda tienda;
  private int cantidad;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public Libro getLibro() {
    return libro;
  }

  public void setLibro(Libro libro) {
    this.libro = libro;
  }

  public Tienda getTienda() {
    return tienda;
  }

  public void setTienda(Tienda tienda) {
    this.tienda = tienda;
  }

  public int getCantidad() {
    return cantidad;
  }

  public void setCantidad(int cantidad) {
    this.cantidad = cantidad;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;b&gt;Tienda.java&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Tienda implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int id;
  private String nombre;
  private String direccion;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getNombre() {
    return nombre;
  }

  public void setNombre(String nombre) {
    this.nombre = nombre;
  }

  public String getDireccion() {
    return direccion;
  }

  public void setDireccion(String direccion) {
    this.direccion = direccion;
  }
  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;b&gt;Usuario.java&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

@Entity
public class Usuario implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int id;
  private String nombre;
  private String usuario;
  private String clave;
  private boolean administrador;
  @OneToMany(mappedBy = &quot;usuario&quot;)
  private List&lt;Pedido&gt; pedidos = new ArrayList&lt;&gt;();

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getNombre() {
    return nombre;
  }

  public void setNombre(String nombre) {
    this.nombre = nombre;
  }

  public String getUsuario() {
    return usuario;
  }

  public void setUsuario(String usuario) {
    this.usuario = usuario;
  }

  public String getClave() {
    return clave;
  }

  public void setClave(String clave) {
    this.clave = clave;
  }

  public boolean isAdministrador() {
    return administrador;
  }

  public void setAdministrador(boolean administrador) {
    this.administrador = administrador;
  }

  public List&lt;Pedido&gt; getPedidos() {
    return pedidos;
  }

  public void setPedidos(List&lt;Pedido&gt; pedidos) {
    this.pedidos = pedidos;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;b&gt;Pedido.java&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

@Entity
public class Pedido implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int id;
  @ManyToOne
  private Usuario usuario;
  @ManyToOne
  private Tienda tienda;
  @OneToMany(mappedBy = &quot;pedido&quot;)
  private List&lt;DetallePedido&gt; detalle = new ArrayList&lt;&gt;();

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public Usuario getUsuario() {
    return usuario;
  }

  public void setUsuario(Usuario usuario) {
    this.usuario = usuario;
  }

  public Tienda getTienda() {
    return tienda;
  }

  public void setTienda(Tienda tienda) {
    this.tienda = tienda;
  }

  public List&lt;DetallePedido&gt; getDetalle() {
    return detalle;
  }

  public void setDetalle(List&lt;DetallePedido&gt; detalle) {
    this.detalle = detalle;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;b&gt;DetallePedido.java&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.entidades;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

@Entity
public class DetallePedido implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int id;
  @ManyToOne
  private Pedido pedido;
  @ManyToOne
  private Libro libro;
  private float precioUnitario;
  private int cantidad;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public Pedido getPedido() {
    return pedido;
  }

  public void setPedido(Pedido pedido) {
    this.pedido = pedido;
  }

  public Libro getLibro() {
    return libro;
  }

  public void setLibro(Libro libro) {
    this.libro = libro;
  }

  public float getPrecioUnitario() {
    return precioUnitario;
  }

  public void setPrecioUnitario(float precioUnitario) {
    this.precioUnitario = precioUnitario;
  }

  public int getCantidad() {
    return cantidad;
  }

  public void setCantidad(int cantidad) {
    this.cantidad = cantidad;
  }
}
&lt;/code&gt;&lt;/pre&gt;

Cabe resaltar que en la entidad Pedido usamos la anotación @OneToMany(mappedBy = &quot;pedido&quot;) para especificar la relación de uno-a-muchos con la entidad DetallePedido. La propiedad mappedBy indica que la llave foránea se encuentra en el otro lado de la relación con el atributo proporcionado. En este caso particular, quiere decir en la entidad Pedido, se le indica que la llave foránea que la asocia con la entidad DetallePedido se encuentra dentro de la entidad DetallePedido en el atributo pedido. Este mismo escenario sucede entre la entidad Usuario y la entidad Pedido.
&lt;br/&gt; &lt;br/&gt;
Si revisamos el código, podemos observar que la entidad DetallePedido, sí cuenta con una atributo llamado pedido, que es de tipo Pedido.
&lt;br /&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section3&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Agregando una unidad de persistencia&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;
&lt;br /&gt;&lt;br /&gt;
Si estuviste atento mientras implementabas las anotaciones en nuestras entidades, NetBeans muestra una advertencia: &quot;The project doest not contain a persistence unit&quot; o &quot;El proyecto no contiene una unidad de persistencia&quot;. &lt;br/&gt; &lt;br/&gt;
Según la &lt;a href=&quot;http://docs.oracle.com/cd/E19798-01/821-1841/bnbrj/index.html&quot;&gt;documentación de Oracle:&lt;/a&gt; &quot;Una unidad de persistencia define un conjunto de entidades que son manejados por instancias de EntityManager en una aplicación. Este conjunto de entidades representan los datos contenidos en una única fuente de datos.&quot;
&lt;br /&gt; &lt;br /&gt;
En este proyecto vamos a usar una única fuente de datos, la cual es nuestra base de datos MySQL, por lo cual es necesario crear una sola unidad de persistencia. Para crear la unidad de persistencias, en nuestro proyecto, damos click derecho, &quot;New&quot; &gt; &quot;Other&quot;.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi57tWJkP4IhXYdzBJlM4YiivYDJ21KYVxqAj1L66yMmQuBdhxNY7aBl5wt8kZhE4RfeOigURklEPxamdUj2yXxUzyVQ4UxBT6CgxyjE6XexExEXFJqGjXaPoQC-UwcgpbeI3hijpKQTJU/s1600/5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi57tWJkP4IhXYdzBJlM4YiivYDJ21KYVxqAj1L66yMmQuBdhxNY7aBl5wt8kZhE4RfeOigURklEPxamdUj2yXxUzyVQ4UxBT6CgxyjE6XexExEXFJqGjXaPoQC-UwcgpbeI3hijpKQTJU/s320/5.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Elegimos la carpeta &quot;Persistence&quot; en la sección de &quot;Categories&quot;, y luego elegimos &quot;Persistence Unit&quot; de la sección &quot;File Types&quot;, y damos click en Next.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYm7ficpKW34mI96NyFZr4IaphWNsaKki5V0oexIs1WhkWclqN8QnJ8n4SWIjlY0RuDlNcyqehiuKpovd8W8YAdExyPWxhvAujHyYPvbqRgoswzNaF1-JJUOPzFOxHw4rHxeM852LEn9A/s1600/6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYm7ficpKW34mI96NyFZr4IaphWNsaKki5V0oexIs1WhkWclqN8QnJ8n4SWIjlY0RuDlNcyqehiuKpovd8W8YAdExyPWxhvAujHyYPvbqRgoswzNaF1-JJUOPzFOxHw4rHxeM852LEn9A/s320/6.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Proveemos de un nombre a nuestra unidad de persistencia en &quot;Persistence Unit Name&quot; (en mi caso lo llamaré &quot;WebAppPU&quot;), elegimos como proveedor de persistencia (&quot;Persistence Provider&quot;), a EclipseLink, y en &quot;Data Source&quot;, elegimos &quot;New Data Source&quot;, nos aparecerá una ventana, y elegimos nuestra conexión a la base de datos &lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee.html#section4&quot;&gt;creada anteriormente en la parte 1&lt;/a&gt;., y le proporcionamos un nombre (en mi caso lo llamaré &quot;nes_java_db&quot;). &lt;b&gt;Toma nota del nombre de la unidad de persistencia que lo usaremos luego en esta parte.&lt;/b&gt;
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKjipBO9Fs0_s3BaDpoGnjJGu6XRd_Q7IwmHMXKr3TlmrZJszIgCy2lPiT4dcTIAUweUUEyv7jPhSWlcIVFzZq9CsI6SRCANUyHmrJqaBhoZLeinsDMuEMeJ7cONzM_VjBnyFiTrl34Po/s1600/7.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKjipBO9Fs0_s3BaDpoGnjJGu6XRd_Q7IwmHMXKr3TlmrZJszIgCy2lPiT4dcTIAUweUUEyv7jPhSWlcIVFzZq9CsI6SRCANUyHmrJqaBhoZLeinsDMuEMeJ7cONzM_VjBnyFiTrl34Po/s320/7.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Damos click en &quot;Ok&quot; para cerrar el cuadro de diálogo del Data Source, y en &quot;Finish&quot; para terminar de crear nuestra unidad de persistencia. NetBeans crea la unidad de persistencia en un archivo llamado &quot;persistence.xml&quot;, bajo la carpeta &quot;Configuration Files&quot; en la pestaña de Projects. Damos doble click en persistence.xml para abrir el archivo.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiICcip0gk_m88FZcGYyLVbyqAFySBovhtjjjLnnq3xsbO1xCmrEEEumsnFLtfvVEURgIWEZHeB10lgRf5HWI5GZjoJlmDK8ZMvVDrRMGaM5uBBT5nHW7ZewoVoSG2jv2GzLFvUnj1ON1g/s1600/8.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiICcip0gk_m88FZcGYyLVbyqAFySBovhtjjjLnnq3xsbO1xCmrEEEumsnFLtfvVEURgIWEZHeB10lgRf5HWI5GZjoJlmDK8ZMvVDrRMGaM5uBBT5nHW7ZewoVoSG2jv2GzLFvUnj1ON1g/s320/8.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Nos aseguramos que la opción &quot;Use Java Transaction APIs&quot; se encuentra deseleccionada, y que &quot;Table Generation Strategy&quot; se encuentre en &quot;Create&quot;. La primera opción indica que no vamos a usar tecnología Java Transaction API (conocida como JTA), sino que nosotros mismos manejaremos las transacciones a nuestra base de datos. La segunda opción indica que las tablas se crearán en caso que no existan en la base de datos. (Si seguiste este tutorial paso a paso, recuerda que actualmente nuestra base de datos se encuentra vacía).
&lt;br/&gt; &lt;br/&gt;
Nos aseguramos que la opción &quot;Include All Entity Classes in &quot;WebApp&quot; Module&quot; se encuentre deseccionada, y damos click en el botón &quot;Add Class&quot;, elegimos todas nuestras entidades de la lista y damos click en &quot;Ok&quot; para agregarlas.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuKidrKcoWH8QfAWGiACX1sD_xUmoyBOo7XSEtqRCe4aFdjg5SCgvxOWVs39Y8SRuCfkDpET46Y0l9IfSCMgdMeM4KgZcr837sgv76_IRIwefywLca5XdKPEzBMLe9kjLHPYerrAX5TWg/s1600/9.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuKidrKcoWH8QfAWGiACX1sD_xUmoyBOo7XSEtqRCe4aFdjg5SCgvxOWVs39Y8SRuCfkDpET46Y0l9IfSCMgdMeM4KgZcr837sgv76_IRIwefywLca5XdKPEzBMLe9kjLHPYerrAX5TWg/s320/9.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;&lt;br/&gt;
En el archivo persistence.xml hacemos click en el botón &quot;Source&quot; para visualizar el contenido del archivo, y debemos tener el contenido similar a este:
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;persistence.xml&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;
&amp;lt;persistence version=&quot;2.1&quot; xmlns=&quot;http://xmlns.jcp.org/xml/ns/persistence&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd&quot;&amp;gt;
  &amp;lt;persistence-unit name=&quot;WebAppPU&quot; transaction-type=&quot;RESOURCE_LOCAL&quot;&amp;gt;
    &amp;lt;non-jta-data-source&amp;gt;nes_java_db&amp;lt;/non-jta-data-source&amp;gt;
    &amp;lt;class&amp;gt;com.nes.entidades.DetallePedido&amp;lt;/class&amp;gt;
    &amp;lt;class&amp;gt;com.nes.entidades.Genero&amp;lt;/class&amp;gt;
    &amp;lt;class&amp;gt;com.nes.entidades.Libro&amp;lt;/class&amp;gt;
    &amp;lt;class&amp;gt;com.nes.entidades.Pedido&amp;lt;/class&amp;gt;
    &amp;lt;class&amp;gt;com.nes.entidades.Stock&amp;lt;/class&amp;gt;
    &amp;lt;class&amp;gt;com.nes.entidades.Tienda&amp;lt;/class&amp;gt;
    &amp;lt;class&amp;gt;com.nes.entidades.Usuario&amp;lt;/class&amp;gt;
    &amp;lt;exclude-unlisted-classes&amp;gt;true&amp;lt;/exclude-unlisted-classes&amp;gt;
    &amp;lt;properties&amp;gt;
      &amp;lt;property name=&quot;javax.persistence.schema-generation.database.action&quot; value=&quot;create&quot;/&amp;gt;
    &amp;lt;/properties&amp;gt;
  &amp;lt;/persistence-unit&amp;gt;
&amp;lt;/persistence&amp;gt;&lt;/code&gt;&lt;/pre&gt;

Procedemos a editar el archivo haciendo los siguientes cambios:
&lt;ul&gt;
&lt;li&gt;Cambiamos la línea &quot;&amp;lt;non-jta-data-source&amp;gt;nes_java_db&amp;lt;/non-jta-data-source&amp;gt;&quot; por &quot;&amp;lt;provider&amp;gt;org.eclipse.persistence.jpa.PersistenceProvider&amp;lt;/provider&amp;gt;&quot;&lt;/li&gt;
&lt;li&gt;Bajo el nodo &amp;lt;properties&amp;gt; agregamos lo siguiente&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Agregamos la cadena de conexión: &lt;br/&gt;&amp;lt;property name=&quot;javax.persistence.jdbc.url&quot; value=&quot;jdbc:mysql://localhost:3306/nes_java_db?zeroDateTimeBehavior=convertToNull&quot;/&amp;gt;&lt;/li&gt;
&lt;li&gt;Agregamos el driver de MySQL: &lt;br/&gt;&amp;lt;property name=&quot;javax.persistence.jdbc.driver&quot; value=&quot;com.mysql.jdbc.Driver&quot;/&amp;gt;&lt;/li&gt;
&lt;li&gt;Agregamos el nombre de usuario de las credenciales de MySQL (en este caso, usaré el usuario root, tú puedes usar otro) &lt;br/&gt; &amp;lt;property name=&quot;javax.persistence.jdbc.user&quot; value=&quot;root&quot;/&amp;gt;&lt;br/&gt;&lt;/li&gt;
&lt;li&gt;Agregamos la clave del usuario de MySQL (mi clave es mysql, la tuya puede cambiar)&lt;br/&gt;&amp;lt;property name=&quot;javax.persistence.jdbc.password&quot; value=&quot;mysql&quot;/&amp;gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
El archivo final debe ser de la siguiente manera:
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;persistence.xml&lt;/b&gt;
&lt;pre  class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;
&amp;lt;persistence version=&quot;2.1&quot; xmlns=&quot;http://xmlns.jcp.org/xml/ns/persistence&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd&quot;&amp;gt;
  &amp;lt;persistence-unit name=&quot;WebAppPU&quot; transaction-type=&quot;RESOURCE_LOCAL&quot;&amp;gt;
    &amp;lt;provider&amp;gt;org.eclipse.persistence.jpa.PersistenceProvider&amp;lt;/provider&amp;gt;
    &amp;lt;class&amp;gt;com.nes.entidades.DetallePedido&amp;lt;/class&amp;gt;
    &amp;lt;class&amp;gt;com.nes.entidades.Genero&amp;lt;/class&amp;gt;
    &amp;lt;class&amp;gt;com.nes.entidades.Libro&amp;lt;/class&amp;gt;
    &amp;lt;class&amp;gt;com.nes.entidades.Pedido&amp;lt;/class&amp;gt;
    &amp;lt;class&amp;gt;com.nes.entidades.Stock&amp;lt;/class&amp;gt;
    &amp;lt;class&amp;gt;com.nes.entidades.Tienda&amp;lt;/class&amp;gt;
    &amp;lt;class&amp;gt;com.nes.entidades.Usuario&amp;lt;/class&amp;gt;
    &amp;lt;exclude-unlisted-classes&amp;gt;true&amp;lt;/exclude-unlisted-classes&amp;gt;
    &amp;lt;properties&amp;gt;
      &amp;lt;property name=&quot;javax.persistence.jdbc.url&quot; value=&quot;jdbc:mysql://localhost:3306/nes_java_db?zeroDateTimeBehavior=convertToNull&quot;/&amp;gt;
      &amp;lt;property name=&quot;javax.persistence.jdbc.driver&quot; value=&quot;com.mysql.jdbc.Driver&quot;/&amp;gt;
      &amp;lt;property name=&quot;javax.persistence.jdbc.user&quot; value=&quot;root&quot;/&amp;gt;
      &amp;lt;property name=&quot;javax.persistence.jdbc.password&quot; value=&quot;mysql&quot;/&amp;gt;
      &amp;lt;property name=&quot;javax.persistence.schema-generation.database.action&quot; value=&quot;create&quot;/&amp;gt;
    &amp;lt;/properties&amp;gt;
  &amp;lt;/persistence-unit&amp;gt;
&amp;lt;/persistence&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
Con esto, ya tenemos nuestras entidades mapeadas, y nuestro proyecto configurado para que pueda conectarse con nuestra base de datos. En la siguiente parte, probaremos que las entidades se hayan programado correctamente.
&lt;br /&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section4&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Probando las entidades&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;
&lt;br /&gt;&lt;br /&gt;
En esta parte crearemos un par de archivos de prueba, para probar que las entidades hayan sido programadas correctamente, y demostrar que nuestra aplicación realmente se conecta con la base de datos.
&lt;br/&gt;&lt;br/&gt;
Damos click derecho a nuestro proyecto desde la pestaña de &quot;Projects&quot;, y vamos a &quot;New&quot; &gt; &quot;Other&quot;.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNYfivvOdlGTz1E2TKot9eeuRiYemp43qg-Kc_J6sq0Kz2siviU6ni_wsIWsDQH1DVRs1SQT6jCG6zPXb6fLkkgpKdOYBFwYyRjLIJelPCcjfVFZ0oJ7ZUK5aO66fDk0pJcHQKe4wjyX4/s1600/5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNYfivvOdlGTz1E2TKot9eeuRiYemp43qg-Kc_J6sq0Kz2siviU6ni_wsIWsDQH1DVRs1SQT6jCG6zPXb6fLkkgpKdOYBFwYyRjLIJelPCcjfVFZ0oJ7ZUK5aO66fDk0pJcHQKe4wjyX4/s320/5.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
En la sección de &quot;Categories&quot; elegimos la carpeta &quot;Java&quot;, y en la sección de &quot;File Types&quot;, elegimos la opción &quot;Java Main Class&quot;, y damos click en &quot;Next&quot;.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjMCNe7oSDgVT07Abj7HiZqKI9ruIP_R1RHayDl8WR44qS6jn80RJt5WFCOFCDSqebHNp2tIYwSkmcR1FluWSyYsWE9Q-duWo1fMoQX3ctVnawyHUDrbnx55bcqCEAn_wpamDX9zp7IXU/s1600/11.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjMCNe7oSDgVT07Abj7HiZqKI9ruIP_R1RHayDl8WR44qS6jn80RJt5WFCOFCDSqebHNp2tIYwSkmcR1FluWSyYsWE9Q-duWo1fMoQX3ctVnawyHUDrbnx55bcqCEAn_wpamDX9zp7IXU/s320/11.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Damos un nombre a nuestro archivo y especificamos el paquete donde se guardará. En mi caso, lo llamaré &quot;PruebaRegistro&quot; dentro del paquete &quot;com.nes.test&quot;, y damos click en &quot;Finish&quot; para crear nuestro archivo.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoBcth0EPqHoEwBPMsfGNmOE4Zz1Gcy46rimIqhNwKPAvWwo8VPTOsbzBBv1bEsfnOVwjgNM1llTPgN-m318rseBCTISuyG1C75w63l2AVp-qYGIKnSIL3jYo23iXh9rr0rBihQz9v-WU/s1600/12.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoBcth0EPqHoEwBPMsfGNmOE4Zz1Gcy46rimIqhNwKPAvWwo8VPTOsbzBBv1bEsfnOVwjgNM1llTPgN-m318rseBCTISuyG1C75w63l2AVp-qYGIKnSIL3jYo23iXh9rr0rBihQz9v-WU/s320/12.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Para registrar la información de las entidades a la base de datos en JPA, se realiza a través del EntityManager (Gestor de entidades). Para ello, se tiene un EntityManagerFactory que se encarga de crear una instancia de EntityManager que podremos usar para registrar información a la base de datos. También como especificamos anteriormente que no usaremos Java Transaction API (JTA) para la gestión de las transacciones, lo haremos nosotros mismos en el código. Entonces, la secuencia de pasos que debe seguir el código para la prueba de registro queda de la siguiente manera:
&lt;ol&gt;
&lt;li&gt;Obtener una instancia del EntityManagerFactory&lt;/li&gt;
&lt;li&gt;Obtener una instancia de EntityManager usando la instancia del EntityManagerFactory&lt;/li&gt;
&lt;li&gt;Como vamos a registrar datos, es necesario abrir e iniciar una transacción en el EntityManager&lt;/li&gt;
&lt;li&gt;Instanciaremos nuestras entidades, y luego usaremos el método .persist() del EntityManager para registrarlas en la base de datos&lt;/li&gt;
&lt;li&gt;Finalizar la transacción haciendo un commit, para que se registre la información en la base de datos&lt;/li&gt;
&lt;li&gt;Cerrar el objeto EntityManager usando su método .close()&lt;/li&gt;
&lt;li&gt;Cerrar el objecto EntityManagerFactory usando su método .close()&lt;/li&gt;
&lt;/ol&gt;
Registraremos en la base de datos una instancia de cada entidad que tenemos en nuestro proyecto, el archivo PruebaRegistro queda de la siguiente manera:
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;PruebaRegistro.java&lt;/b&gt;
&lt;pre class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;package com.nes.test;

import com.nes.entidades.DetallePedido;
import com.nes.entidades.Genero;
import com.nes.entidades.Libro;
import com.nes.entidades.Pedido;
import com.nes.entidades.Stock;
import com.nes.entidades.Tienda;
import com.nes.entidades.Usuario;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class PruebaRegistro {

  public static void main(String[] args) {
    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(&quot;WebAppPU&quot;);
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    entityManager.getTransaction().begin();
  
    //Registrar un género
    Genero genero = new Genero();
    genero.setNombre(&quot;Drama&quot;);
    entityManager.persist(genero);
    
    //Registrar un Libro
    Libro libro = new Libro();
    libro.setNombre(&quot;Hamlet&quot;);
    libro.setPrecio(22.99f);
    libro.setGenero(genero);
    entityManager.persist(libro);
    
    //Registrar un Usuario
    Usuario usuario = new Usuario();
    usuario.setNombre(&quot;Fulano de Tal&quot;);
    usuario.setUsuario(&quot;usuario&quot;);
    usuario.setClave(&quot;1234&quot;);
    usuario.setAdministrador(false);
    entityManager.persist(usuario);
    
    //Registrar una tienda
    Tienda tienda = new Tienda();
    tienda.setNombre(&quot;Tienda #1&quot;);
    tienda.setDireccion(&quot;Av. Siempreviva 742&quot;);
    entityManager.persist(tienda);
    
    //Registrar Stock
    Stock stock = new Stock();
    stock.setLibro(libro);
    stock.setTienda(tienda);
    stock.setCantidad(12);
    entityManager.persist(stock);
    
    //Registrar un Pedido
    Pedido pedido = new Pedido();
    pedido.setTienda(tienda);
    pedido.setUsuario(usuario);
    entityManager.persist(pedido);
    
    //Registrar DetallePedido
    DetallePedido detallePedido = new DetallePedido();
    detallePedido.setPedido(pedido);
    detallePedido.setLibro(libro);
    detallePedido.setPrecioUnitario(libro.getPrecio());
    detallePedido.setCantidad(1);
    entityManager.persist(detallePedido);
    
    entityManager.getTransaction().commit();
    entityManager.close();
    entityManagerFactory.close();
  }
  
}
&lt;/code&gt;&lt;/pre&gt;
Finalmente, ejecutamos el archivo PruebaRegistro dando doble click en cualquier lugar del código y seleccionando la opción &quot;Run File&quot;, también podemos usar el atajo Shift+F6 desde el archivo para ejecutarlo.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIOzM8F_SOfTWYzq-U2XmAx9DiLOa5I6R7BrPUjDsK_lUsao6fQaU8YTAeKNsxdO0cbz_IN0G-0sdNkucT8mbC2EKYj68fMVzHXTa6KFYTFlgvyLsxFUszPuA7OtCIPQuaikDh4E3uaU0/s1600/x13.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIOzM8F_SOfTWYzq-U2XmAx9DiLOa5I6R7BrPUjDsK_lUsao6fQaU8YTAeKNsxdO0cbz_IN0G-0sdNkucT8mbC2EKYj68fMVzHXTa6KFYTFlgvyLsxFUszPuA7OtCIPQuaikDh4E3uaU0/s320/x13.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
El archivo se ejecuta correctamente y se evidencia en la ventana de Output con el mensaje &quot;BUILD SUCCESFUL&quot;
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPZ-5G1jOd5DtmvUgLyPsLW78z5RObQ8GMfWnI27RwDNc6-M-1deiJbV2E-sZVf0Px-I3vaeYUKY9oaHLIV5XSQgVbvljgUEEk_Cy3pqJ-aLcvQVFYmc8GVa90iWpPkLe1BslZAonKk-w/s1600/13.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPZ-5G1jOd5DtmvUgLyPsLW78z5RObQ8GMfWnI27RwDNc6-M-1deiJbV2E-sZVf0Px-I3vaeYUKY9oaHLIV5XSQgVbvljgUEEk_Cy3pqJ-aLcvQVFYmc8GVa90iWpPkLe1BslZAonKk-w/s320/13.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Si revisamos nuestra base de datos, podemos observar que las tablas han sido creadas automáticamente, y que además han sido pobladas con los datos de nuestra prueba de registro.
&lt;br/&gt;&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNGisMvEdG0J6HYPJiNZyh2PVx8_sU_SA_YBv-nx7oIL26B0eflyBZC8eB9Vjv6Oct_s2nvWlvKnPYDtNZdUnsgph885eFbKNu3I1RLR-EhDVvaRZLSSxSjGY-eqyXbScTGJKI8CeF_D8/s1600/14.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNGisMvEdG0J6HYPJiNZyh2PVx8_sU_SA_YBv-nx7oIL26B0eflyBZC8eB9Vjv6Oct_s2nvWlvKnPYDtNZdUnsgph885eFbKNu3I1RLR-EhDVvaRZLSSxSjGY-eqyXbScTGJKI8CeF_D8/s320/14.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
De esta manera, nuestra base de datos queda como se muestra en el siguiente diagrama:
&lt;br/&gt;&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbQqSvSrEKkN_u76fXxxbnrOifaX0Iv4Va7KykjNH-92tZbRyqPXDK-Ht29kQOZdk4-qx2838738RVdGTzK0bF7K36l2YhfTA8vHb77CteHoO5RhYiMw69IVlcHR4iV30UJgNvQfW8NeE/s1600/diagrama+BD.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbQqSvSrEKkN_u76fXxxbnrOifaX0Iv4Va7KykjNH-92tZbRyqPXDK-Ht29kQOZdk4-qx2838738RVdGTzK0bF7K36l2YhfTA8vHb77CteHoO5RhYiMw69IVlcHR4iV30UJgNvQfW8NeE/s400/diagrama+BD.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Cabe resaltar que en el código del archivo PruebaRegistro, en ninguna entidad usamos el método setId() para establecer el Id de nuestras entidades. Pero en la base de datos nos damos cuenta que el Id se ha creado automáticamente, esto es debido a la notación @GeneratedValue que pusimos en nuestras entidades, que hace que se generen de manera automática.
&lt;br/&gt;&lt;br/&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section5&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Conclusión - Link de Descarga del Proyecto&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;
&lt;br /&gt;&lt;br /&gt;
Recapitulando, en esta parte creamos las clases de entidades, encapsulamos sus atributos mediante los métodos getter y setter, y usamos las anotaciones de JPA para indicar que dichas clases son las que representaran a las tablas en la base de datos, y definimos las relaciones existentes entre ellas. &lt;b&gt;Puedes descargar el código del proyecto de NetBeans hasta este punto &lt;a href=&quot;https://github.com/JBAndreu/nes-java-ee/archive/entidades.zip&quot;&gt;haciendo click en este link.&lt;/a&gt;&lt;/b&gt;
&lt;br/&gt;
&lt;br/&gt;
En la siguiente parte, haremos una pequeña prueba de lectura de información en nuestra base de datos.
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;b&gt;Referencias:&lt;/b&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://en.wikibooks.org/wiki/Java_Persistence/Relationships&quot;&gt;WikiBook de Java Persistence&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.oracle.com/cd/E19798-01/821-1841/bnbpz/index.html&quot;&gt;Chapter 20 Introduction to the Java Persistence API&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/5974265518660058517/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_7.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/5974265518660058517'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/5974265518660058517'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee_7.html' title='Desarrollo de una aplicación web con Java EE (JSF + JPA) - Parte 2'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI0Y_UuuWMhu7xeh64xIT6oSs9idWYBYmoHiy41Y1LeVgBs0lPdyrmIQ3V1mMkPA4aEp_NsQZjyhqC23APcExhByxQxwjA8YzHroUVRwuRu9kEJ6itZXJk3PdXOoKT1O6BxpJiH1b2ifU/s72-c/Diagrama+de+Clases.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-1707242770834954071</id><published>2015-07-06T23:28:00.000-05:00</published><updated>2015-07-09T08:44:29.563-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="eclipselink"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java ee"/><category scheme="http://www.blogger.com/atom/ns#" term="jpa"/><category scheme="http://www.blogger.com/atom/ns#" term="jsf"/><category scheme="http://www.blogger.com/atom/ns#" term="netbeans"/><category scheme="http://www.blogger.com/atom/ns#" term="primefaces"/><category scheme="http://www.blogger.com/atom/ns#" term="programacion"/><category scheme="http://www.blogger.com/atom/ns#" term="web"/><title type='text'>Desarrollo de una applicación web con Java EE (JSF + JPA) - Parte 1</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
En este serie vamos a desarrollar una aplicación web usando Java EE, integrando las siguientes tecnologías EclipseLink (JPA 2.1), PrimeFaces 5.0
JSF 2.0. En esta primera parte crearemos la base de datos en MySQL, el proyecto en NetBeans, y comenzaremos la codificación de las entidades de nuestra aplicación en Java usando la especificación JPA con EclipseLink.
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Para ello usaremos NetBeans IDE 8.0.2, y de base de datos MySQL 5.6.25, usando MySQL JDBC Driver 5.1.23 para conectar nuestra aplicación Java con MySQL, y MySQL Workbench 6.3 para gestionar y visualizar la base de datos.
&lt;br /&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;b&gt;Contenido&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ol class=&quot;indice&quot;&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee.html#section1&quot;&gt;Introducción a la aplicación&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee.html#section2&quot;&gt;Creación del schema en MySQL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee.html#section3&quot;&gt;Creación del proyecto en NetBeans&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee.html#section4&quot;&gt;Conectando la base de datos al proyecto de NetBeans&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee.html#section5&quot;&gt;Agregando más librerías al proyecto NetBeans&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee.html#section6&quot;&gt;Conclusión&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;

&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section1&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Introducción a la aplicación&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
La aplicación de ejemplo que desarrollaremos será un gestor de libros para una cadena de librerías. Con esta aplicación, el administrador de la aplicación podrá gestionar las tiendas, y asignar qué libros se encuentran disponibles en cada tienda. Además, los clientes a través de la aplicación podrán consultar el catálogo de libros de cada tienda, y realizar pedidos. 
&lt;br /&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section2&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Creación del schema en MySQL&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
En MySQL workbench elegimos File &gt; New Query Tab del menú.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgv4xcROhU63_0Py9DBBKmufYKnIxsXx-jx3zhHu7wDE2ZqMw23xGq1ytbX0ka1djVWq5IHfq5JBKV5YVB0IiemOSahOkK7W6yr2b5_IOLGBCsS50uNXBQGTHiKo61Rcs69ezqJDEOSFCg/s1600/workbench+new+query+tab.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgv4xcROhU63_0Py9DBBKmufYKnIxsXx-jx3zhHu7wDE2ZqMw23xGq1ytbX0ka1djVWq5IHfq5JBKV5YVB0IiemOSahOkK7W6yr2b5_IOLGBCsS50uNXBQGTHiKo61Rcs69ezqJDEOSFCg/s320/workbench+new+query+tab.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Creamos una base de datos, a la cual llamaremos nes_java_db, lo cual se hace con este comando:

&lt;pre class=&quot;prettyprint&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB2Egb_SZxZaFR8Qi1u7LoCpDKZHb7EhZGGzz236N5gENFVb4-R6DPzdrA86rnaB9cZLvVbkc-BrxMqoAwi-2d3lvMDW2IFqWUAsMd0W7d-K5KlzUokxJRooHYQtcUpEXqEJJRrdFQXxz5/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;CREATE SCHEMA nes_java_db;&lt;/code&gt;&lt;/pre&gt;

Para ejecutar los comandos SQL en MySQL se puede usar el botón Execute Script, el cuál tiene un ícono de un rayo (ver imagen). Adicionalmente, se puede presionar Control+Shift+Enter si no se desea usar el botón.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpYjdVAJQZzKFvVcbms9P-04UWO0eON75vYegsgmBcW0QtYj4ajkbVnAR-zEpmMcwxebSsrsBGzvaE8atWPs3Z2a7usGbcAPWLlnGuB0xzz090anwEOjP_8eHWyBkNo5Xqu-0It9SvrPw/s1600/workbench+execute+script.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpYjdVAJQZzKFvVcbms9P-04UWO0eON75vYegsgmBcW0QtYj4ajkbVnAR-zEpmMcwxebSsrsBGzvaE8atWPs3Z2a7usGbcAPWLlnGuB0xzz090anwEOjP_8eHWyBkNo5Xqu-0It9SvrPw/s320/workbench+execute+script.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Ejecutamos el comando, y una vez ejecutado en la ventana de Output nos debe salir un mensaje de confirmación. (Si no tienes la ventana de Output puedes mostrarla seleccionando View &gt; Output desde el menú)
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvqQDTyVrGguvbOahb0vxvjvu2xqe4YD5e2IDtmDXYxbzXwouLubNyRa_vAAHQ5PGHa1Zf6H3NdhEw0CZ3HQF53qFNnSqPMmRbHsj5SfmHhzuXbtVzPxS1Ns5VXZnqIrX6l-pufMXRj_0/s1600/workbench+create+schema+succesfull.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvqQDTyVrGguvbOahb0vxvjvu2xqe4YD5e2IDtmDXYxbzXwouLubNyRa_vAAHQ5PGHa1Zf6H3NdhEw0CZ3HQF53qFNnSqPMmRbHsj5SfmHhzuXbtVzPxS1Ns5VXZnqIrX6l-pufMXRj_0/s320/workbench+create+schema+succesfull.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;
Si el nombre fue usado anteriormente, nos saldrá un error similar a éste: Error Code: 1007. Can&#39;t create database &#39;nes_java_db&#39;; database exists
&lt;br/&gt;Para solucionarlo, deberás cambiarle el nombre a la BD de nes_java_db a otro de tu elección. Toma nota del nombre de la BD que lo usaremos luego.
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlU8oD0D3mbU72HUqFLE4UTbJnT6Z0XM-H24P7YV-96lEHChcuY8m-_frQ91fz0iVcl89paqiQXz-kgQ6vZm6Tub5Tn_hXdEOotwh4tXyc5oxxIbAVi97NVCB5EsGzJlHCkpGm_bmB85M/s1600/workbench+create+schema+fail.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlU8oD0D3mbU72HUqFLE4UTbJnT6Z0XM-H24P7YV-96lEHChcuY8m-_frQ91fz0iVcl89paqiQXz-kgQ6vZm6Tub5Tn_hXdEOotwh4tXyc5oxxIbAVi97NVCB5EsGzJlHCkpGm_bmB85M/s320/workbench+create+schema+fail.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;



&lt;br /&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section3&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Creación del proyecto en NetBeans&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Abrimos NetBeans, y vamos a File &gt; New Project para crear el proyecto.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMnSWtKlXJ3y9fCysaFm9cxRXncfPbnLQmUQW2TlTRuAP-twjsdWyqcTPnWU_anmDmC6e82hrbAPWNvKYicZlsEFJp5WkUsj_ZltePqlV-nf0x-ZlhuNRAcjdyct2XBua4gSByouDU7RY/s1600/NB+new+project.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMnSWtKlXJ3y9fCysaFm9cxRXncfPbnLQmUQW2TlTRuAP-twjsdWyqcTPnWU_anmDmC6e82hrbAPWNvKYicZlsEFJp5WkUsj_ZltePqlV-nf0x-ZlhuNRAcjdyct2XBua4gSByouDU7RY/s320/NB+new+project.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
En &quot;Categories&quot; elegimos la opción Java Web, y luego bajo &quot;Projects&quot; elegimos &quot;Web Application&quot;.
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj03Z00HkOyc85034qb93_d8XvWVrx6LY39Imt4IfFT6qRef53kzr2adGMlsEA-eIKxbZHAHyuY3aNM2idELQ-Mnb9J-enDW-j_s4hvhFORmhuxcrJO4KSwZC6vpuT9BCAzhlnKBtMxz_I/s1600/NB+new+project+dialog+1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj03Z00HkOyc85034qb93_d8XvWVrx6LY39Imt4IfFT6qRef53kzr2adGMlsEA-eIKxbZHAHyuY3aNM2idELQ-Mnb9J-enDW-j_s4hvhFORmhuxcrJO4KSwZC6vpuT9BCAzhlnKBtMxz_I/s320/NB+new+project+dialog+1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Damos click en &quot;Next&quot;, y ahora nos pide darle un nombre a nuestro proyecto, y elegir la ubicación. En mi caso lo llamaré &quot;WebApp&quot;. Para cambiar la ruta del proyecto, se usa el botón &quot;Browse&quot; y se abre un cuadro de diálogo para elegir la nueva ubicación del proyecto. Cuando terminamos le damos siguiente.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisgqdwxiGfO_jpVX1WvyRlBol7_rTwHJSI99XQ3HBy1pZSNDzV7YCxOHQQ0TO_PhBk942BTiZEYrIyzwUkS2EwpjJqsw57kxU63nK29ErQ17fBJO-6xlsZI26n9Ounf_u7pTC5ZTAEsqE/s1600/NB+new+project+dialog+2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisgqdwxiGfO_jpVX1WvyRlBol7_rTwHJSI99XQ3HBy1pZSNDzV7YCxOHQQ0TO_PhBk942BTiZEYrIyzwUkS2EwpjJqsw57kxU63nK29ErQ17fBJO-6xlsZI26n9Ounf_u7pTC5ZTAEsqE/s320/NB+new+project+dialog+2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
A continuación se pide elegir el servidor a utilizar para nuestra aplicación, en mi caso usaré GlassFish Server 4.1 que vino con la instalación de NetBeans 8.0.2. Damos click en &quot;Next&quot;.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpQp9wqCetJ6v5pQLv_IrUYKKYZLk44KWg8223hISV9PeYKMipaNTPVUsXnTb7sAl1_c3wOCOumvTiOeJALdelHm-RK2tx4j09h4korPt-KYOEoeANBG7Bmj1dAjq01-pyXf868exbz9Q/s1600/NB+new+project+dialog+3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpQp9wqCetJ6v5pQLv_IrUYKKYZLk44KWg8223hISV9PeYKMipaNTPVUsXnTb7sAl1_c3wOCOumvTiOeJALdelHm-RK2tx4j09h4korPt-KYOEoeANBG7Bmj1dAjq01-pyXf868exbz9Q/s320/NB+new+project+dialog+3.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Finalmente, se pide especificar si se va a utilizar algún framework en en el proyecto. En nuestro caso elegiremos Java Server Faces, con la librería JSF 2.2.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRcBbxIsZgJWHMeICxNneuFsIHtAaBpQz5yWHT03ea245y-rhNzJX1iEizK9_WOIvYNlmENlDgycoHEy5Evbok8gZhvF76Q85AGZ_fBOtgCmQbtWFELTL4YbW_f7VmD0JEWnr63mnurmU/s1600/NB+new+project+dialog+4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRcBbxIsZgJWHMeICxNneuFsIHtAaBpQz5yWHT03ea245y-rhNzJX1iEizK9_WOIvYNlmENlDgycoHEy5Evbok8gZhvF76Q85AGZ_fBOtgCmQbtWFELTL4YbW_f7VmD0JEWnr63mnurmU/s320/NB+new+project+dialog+4.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Vamos a la pestaña de &quot;Components&quot; y seleccionamos Primefaces, si tenemos varias versiones de Primefaces instaladas, podemos elegir la versión a usar haciendo click en el botón &quot;More&quot;, yo utilizaré Primefaces 5.0 que vino instalada junto con NetBeans 8.0.2.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg37k7WvuE-nVwQub8PMxdcUxObceg4seOD0fCfjAUjYLNeGNGqlGkXcZqGKRx1Zws6E5t5cNuIsTKkbsI2ZjhOJj4xYqUTbA3clnctbUdAyCNP4TKebEVFWdMA6fCJZ_zgox6n4JMRRaU/s1600/NB+new+project+dialog+5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg37k7WvuE-nVwQub8PMxdcUxObceg4seOD0fCfjAUjYLNeGNGqlGkXcZqGKRx1Zws6E5t5cNuIsTKkbsI2ZjhOJj4xYqUTbA3clnctbUdAyCNP4TKebEVFWdMA6fCJZ_zgox6n4JMRRaU/s320/NB+new+project+dialog+5.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Damos click en &quot;Finish&quot; y NetBeans procede a crear nuestro proyecto. En este momento podemos probar que nuestra aplicación se haya creado correctamente. Para ello, damos click derecho en el nombre del proyecto y elegimos la opción &quot;Run&quot;. (Adicionalmente, se puede ir Run &gt; Run Project del menú)
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1BXbOHX2sZden7JC_IEJP-Vf3tH6rEbvMedmtsjpmj-nXQCzIrM0cS0YVPVCJ8ufg0hn79E0cEqDS9pleFQvhk1BZ1qqRZeRfxQJEvdl8gLHi9SLpQ5q2ypFlCK1QN5glHgWUYoeAUJs/s1600/NB+Run+Project.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1BXbOHX2sZden7JC_IEJP-Vf3tH6rEbvMedmtsjpmj-nXQCzIrM0cS0YVPVCJ8ufg0hn79E0cEqDS9pleFQvhk1BZ1qqRZeRfxQJEvdl8gLHi9SLpQ5q2ypFlCK1QN5glHgWUYoeAUJs/s320/NB+Run+Project.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Luego de unos momentos, se abre el explorador y muestra nuestro proyecto, con el mensaje &quot;Hello from Facelets&quot;.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaCK_vrMgvrr-cGUwl6zqr53xF73NdpMuO5s1blYNXQ2NEAXI2kUy8CFVmtGXQWNFIQyGl_38TvHXaLh-y1DTHm36lavDHjXFQ6mDVAMod-xOzb-R3gQSUqtwgP3s4wgheAuelTyygA68/s1600/first+run.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaCK_vrMgvrr-cGUwl6zqr53xF73NdpMuO5s1blYNXQ2NEAXI2kUy8CFVmtGXQWNFIQyGl_38TvHXaLh-y1DTHm36lavDHjXFQ6mDVAMod-xOzb-R3gQSUqtwgP3s4wgheAuelTyygA68/s320/first+run.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;




&lt;br /&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section4&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Conectando la base de datos al proyecto de NetBeans&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;



Crearemos una nueva conexión de base de datos, para ello nos vamos a la pestaña de &quot;Services&quot;, hacemos click derecho en &quot;Database&quot; y elegimos &quot;New Connection&quot; del menú. (Si no se tiene la pestaña de Services abierta, se puede mostrarla seleccionando &quot;Window&quot; &gt; &quot;Services&quot; del menú principal)
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh91FKnzGzU6_ht48_2-dCIv7e2iOxu12PSceCXXATl4SYbvb_1Rautcb1HZVkyraZOjmiwXCnYoMkP-vFPgl-iFutiZiqy8f55cao3FKhRVyOPw-MBObVGl8u8ZvL701EJvoaSbut_VUE/s1600/NB+new+connection.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh91FKnzGzU6_ht48_2-dCIv7e2iOxu12PSceCXXATl4SYbvb_1Rautcb1HZVkyraZOjmiwXCnYoMkP-vFPgl-iFutiZiqy8f55cao3FKhRVyOPw-MBObVGl8u8ZvL701EJvoaSbut_VUE/s320/NB+new+connection.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Elegimos el driver adecuado, que en nuestro caso es MySQL y damos click en &quot;Next&quot;.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDKc3bK9mFY2cgXVIs87d_tShnDuVQaKLjS_VatGiICKOzVJiKcjkTvXOszkXW2lJ0AvLlMsxkGYHYfWbzhWxNIj5jy2veJ6TYfwONDlFIJAaYV9mgGIGFHjSaqbh6ALqJDxUNBgVBxIw/s1600/new+connection+wizard+1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDKc3bK9mFY2cgXVIs87d_tShnDuVQaKLjS_VatGiICKOzVJiKcjkTvXOszkXW2lJ0AvLlMsxkGYHYfWbzhWxNIj5jy2veJ6TYfwONDlFIJAaYV9mgGIGFHjSaqbh6ALqJDxUNBgVBxIw/s320/new+connection+wizard+1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Completamos la información requerida para conectarse a la base de datos, en &quot;Database&quot; ponemos el nombre que le proporcionamos a la base de datos de MySQL, en &quot;User Name&quot; y &quot;Password&quot; llenamos las credenciales de acceso para conectarse a MySQL. En &quot;Host&quot; y &quot;Port&quot; colocamos la información del host y el puerto de conexión para la base de datos. Como tengo MySQL instalado localmente y corriendo en el puerto por defecto, mi Host es localhost, y mi puerto es 3306. Si se desea probar si la conexión es válida, se da click en el botón &quot;Test Connection&quot; y de ser válido nos saldrá un mensaje &quot;Connection Succedeed&quot;. 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBTHGwse6QFKWzNXFoQi2i6i6obD8FRkFrJB9ps66i3Cb8G1cnsDv7yzc_nhyl4ELY-7JwDxTBaKaUklTKgfdsM416SMZaGQhRPAGRGh3Su0awm2hd5Uzb0OxBfNHd0kNvC4olTO9nKfE/s1600/new+connection+wizard+2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBTHGwse6QFKWzNXFoQi2i6i6obD8FRkFrJB9ps66i3Cb8G1cnsDv7yzc_nhyl4ELY-7JwDxTBaKaUklTKgfdsM416SMZaGQhRPAGRGh3Su0awm2hd5Uzb0OxBfNHd0kNvC4olTO9nKfE/s320/new+connection+wizard+2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Finalmente damos click en &quot;Finish&quot; y nuestra conexión ya debería estar listada bajo &quot;Databases&quot;.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCtdqcUjK_msPHzrRHD6dJ_ZPF5RdSCUpE9tBOOfPX2fCCiJxFWaONbQpqQ1-hbIEapkensmgpSo9i7DtdkEIhbUUbiE6nkP83RSbW9mCJSvjbdo2hGuok3lHniho4Am-WVvsej9asS8I/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCtdqcUjK_msPHzrRHD6dJ_ZPF5RdSCUpE9tBOOfPX2fCCiJxFWaONbQpqQ1-hbIEapkensmgpSo9i7DtdkEIhbUUbiE6nkP83RSbW9mCJSvjbdo2hGuok3lHniho4Am-WVvsej9asS8I/s320/1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;


&lt;br /&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section5&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Agregando más librerías al proyecto NetBeans&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Si vamos la pestaña de &quot;Projects&quot; y expandimos la carpeta &quot;Libraries&quot; de nuestro proyecto, podemos ver que NetBeans agregó algunas librerías, pero éstas no son suficientes para el desarrollo de nuestra aplicación.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidpE106oZD_TRXqoW7P5qGzQ3GrTu4Qm96sRTpTzl8XtVaxeWG0SqkDoSXW3muLS8ufigqJUD2l0cF6zg7T75TK_0C9JqJJUln80vU3f-vhR0JtTFU23lp4-B30F4gDR6IpMpnlkKgNes/s1600/2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidpE106oZD_TRXqoW7P5qGzQ3GrTu4Qm96sRTpTzl8XtVaxeWG0SqkDoSXW3muLS8ufigqJUD2l0cF6zg7T75TK_0C9JqJJUln80vU3f-vhR0JtTFU23lp4-B30F4gDR6IpMpnlkKgNes/s320/2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Para agregar una librería, hacemos click derecho en la carpeta de &quot;Libraries&quot; de nuestro proyecto y elegimos &quot;Add Library&quot;.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1LVr02FNaI5Ssdb6fHf63dBWENY8z3-VmvzEpOxmkoLV0qFOgkqbfv3OMJ4Ligf4FRYF4CdLTlvV1drPzctWYC8hbDn_fSvgr-6Vu-f6QIWzyE5JlF7M3ffds8T9xbwebUKa6IfrrmRU/s1600/add+library.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1LVr02FNaI5Ssdb6fHf63dBWENY8z3-VmvzEpOxmkoLV0qFOgkqbfv3OMJ4Ligf4FRYF4CdLTlvV1drPzctWYC8hbDn_fSvgr-6Vu-f6QIWzyE5JlF7M3ffds8T9xbwebUKa6IfrrmRU/s320/add+library.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Elegimos EclipseLink (JPA 2.1) que viene instalada con NetBeans 8.0.2, y también agregamos la librería del driver JDBC de MySQL que viene instalada con NetBeans 8.0.2, si no elegiste la opción de instalar el conector de MySQL a la hora de instalar NetBeans, la puedes descargar de la &lt;a href=&quot;http://dev.mysql.com/&quot;&gt;página de desarrolladores de MySQL&lt;/a&gt;. Finalmente, nuestro proyecto debe quedar con esas librerías agregadas.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjipgjhf2jliTpsjkDNUwRyTrqg7YJCCC36LzskdIQW5_08c6EcpPf8cpmNnYCTde8UeUCGJqLSmFF1agPNghpqHhDRSSjRZe_wB8xiDa5G3aDDZBr8WrZcd3nERU-dF_vDfaStdDrmADE/s1600/fin.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjipgjhf2jliTpsjkDNUwRyTrqg7YJCCC36LzskdIQW5_08c6EcpPf8cpmNnYCTde8UeUCGJqLSmFF1agPNghpqHhDRSSjRZe_wB8xiDa5G3aDDZBr8WrZcd3nERU-dF_vDfaStdDrmADE/s320/fin.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section6&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Conclusión&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Con esto, terminamos la configuración inicial de nuestro proyecto. Recapitulando lo que hicimos en esta parte: creamos la base de datos en MySQL, creamos el proyecto en NetBeans, agregamos una conexión de base de datos en NetBeans, y finalmente agregamos las librerías faltantes nuestro proyecto en NetBeans.
&lt;br /&gt;&lt;br /&gt;
En la siguiente parte, entraremos de lleno a la codificación del proyecto. Empezaremos con la codifiación de clases Java que serán nuestras entidades, las cuales representan a las tablas de nuestra base de datos. Con ayuda de la tecnología EclipseLink, usaremos la especificación JPA para crear las tablas de la base de datos automáticamente junto con la creación de nuestras entidades.
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/1707242770834954071/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/1707242770834954071'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/1707242770834954071'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2015/07/desarrollo-de-una-app-web-con-java-ee.html' title='Desarrollo de una applicación web con Java EE (JSF + JPA) - Parte 1'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgv4xcROhU63_0Py9DBBKmufYKnIxsXx-jx3zhHu7wDE2ZqMw23xGq1ytbX0ka1djVWq5IHfq5JBKV5YVB0IiemOSahOkK7W6yr2b5_IOLGBCsS50uNXBQGTHiKo61Rcs69ezqJDEOSFCg/s72-c/workbench+new+query+tab.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-8183961234941559637</id><published>2013-06-17T01:00:00.000-05:00</published><updated>2013-06-17T01:00:07.249-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programacion"/><category scheme="http://www.blogger.com/atom/ns#" term="rails"/><category scheme="http://www.blogger.com/atom/ns#" term="ror"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby on rails"/><category scheme="http://www.blogger.com/atom/ns#" term="web"/><title type='text'>Primera aplicación en Ruby on Rails - Primera Parte</title><content type='html'>&lt;div class=&quot;estilogeneral&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9YjNYcUSSLzEZyEO0-R32Zo494ZCML_zVcumccCOSz5hLe3Wl6riEMaU7tFhOkI7i0Z5qd3DSYSfUKxfna_YOqFMxyS0SxXAMNeohSN_cw5Zz2ZZA_wv0vRpUCd2yUjeB5yeRd4vGoXI/s1600/rails.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9YjNYcUSSLzEZyEO0-R32Zo494ZCML_zVcumccCOSz5hLe3Wl6riEMaU7tFhOkI7i0Z5qd3DSYSfUKxfna_YOqFMxyS0SxXAMNeohSN_cw5Zz2ZZA_wv0vRpUCd2yUjeB5yeRd4vGoXI/s1600/rails.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
En esta entrada explicaremos paso a paso el desarrollo de una aplicación en Ruby on Rails. Nuestra primera aplicación consistirá en un blog muy simple que tendrá posts (publicaciones). En esta primera parte, crearemos una nueva aplicación en Rails y la configuraremos para que nos muestre un mensaje de Hola Mundo.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
Antes de empezar, sugiero revisar un poco la teoría detrás de Rails, en mi entrada&amp;nbsp;&lt;a href=&quot;http://notasensistemas.blogspot.com/2013/06/introduccion-teorica-ruby-on-rails-ror.html&quot; target=&quot;_blank&quot;&gt;Introducción teórica a Ruby on Rails&lt;/a&gt;. Si no tienes instalado Rails en tu computadora puedes revisar mi entrada &lt;a href=&quot;http://notasensistemas.blogspot.com/2013/06/ruby-on-rails-instalacion-en-windows.html&quot; target=&quot;_blank&quot;&gt;Instalación de Ruby on Rails en Windows&lt;/a&gt;&amp;nbsp;y seguir los pasos descritos para instalar Rails.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
Este proyecto será desarrollado en el siguiente entorno de configuración.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Ruby 1.9.3&lt;/li&gt;
&lt;li&gt;Rails 3.2.13&lt;/li&gt;
&lt;li&gt;Windows 7&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
Creando un nuevo proyecto: Blog&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Empezaremos creando nuestro nuevo proyecto que llamaremos Blog. En Rails, para crear un nuevo proyecto, desde la consola escribimos el comando rails new seguido del nombre de nuestro proyecto. En esta caso, vamos a crear un proyecto llamado Blog, por lo que el comando es&amp;nbsp;&lt;b&gt;rails new Blog.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9pZdRhuHEKOGkSTr8oQVWz_tTMkrceWnYuPkCx6aRc-FgxNtWbBZ4uxh60LKEL3CNh8kDi-ThPbhtdHQUECnARxyl3ELgMM-MBfbTf-sCs8_7k1BEnTyxWiO4acks1jkI2c5eHeGijzk/s1600/01+new+app+command.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9pZdRhuHEKOGkSTr8oQVWz_tTMkrceWnYuPkCx6aRc-FgxNtWbBZ4uxh60LKEL3CNh8kDi-ThPbhtdHQUECnARxyl3ELgMM-MBfbTf-sCs8_7k1BEnTyxWiO4acks1jkI2c5eHeGijzk/s320/01+new+app+command.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
Rails automáticamente crea una carpeta con el nombre de nuestro proyecto y crea una serie de archivos y carpetas que es la estructura de todo proyecto en Rails. Si abrimos el directorio donde creamos nuestro proyecto en Rails podemos ver que se ha creado una carpeta Blog con el siguiente contenido.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXUY6s8TKF2PnvLzL8Umjnzm2JZPStZlJBiMaV3162SyJcP0SwMbMLE8C2F8wx8d7e0feeHAZ-nRiqsEDvYH0O7mtkpM-VoBf86NzayLFZE5GE4MNRtrWpT52MW4-0mAyF1d5bkgGSZNg/s1600/02+folder+structure.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;172&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXUY6s8TKF2PnvLzL8Umjnzm2JZPStZlJBiMaV3162SyJcP0SwMbMLE8C2F8wx8d7e0feeHAZ-nRiqsEDvYH0O7mtkpM-VoBf86NzayLFZE5GE4MNRtrWpT52MW4-0mAyF1d5bkgGSZNg/s320/02+folder+structure.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Rails crea una serie de carpetas para nuestro proyecto, entre éstas se incluyen:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;app, carpeta principal donde se guardan los archivos importantes para nuestro aplicativo. Dentro se encuentran:&lt;/li&gt;
&lt;ul&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;controllers: carpeta donde se almacenan todos nuestros controladores&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;views: carpeta donde se almacenan todas nuestras vistas&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;models: carpeta donde se guardan todos nuestros modelos&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;assets: carpeta donde se almacenan los recursos de nuestro aplicativo web, dentro se encuentran las carpetas images, javascripts and stylesheets donde se deben guardar nuestras imágenes, archivos javascript y hojas de estilo respectivamente.&lt;/li&gt;
&lt;/ul&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;config, carpeta donde se almacenan las configuraciones de la aplicación. Dentro se encuentran:&lt;/li&gt;
&lt;ul&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;database.yml: archivo de conexión a nuestra base de datos&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;routes.rb: archivo donde se configuran las rutas de nuestro aplicativo&lt;/li&gt;
&lt;/ul&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;public: archivo donde se guardan los recursos públicos de la aplicación (accesible por todos los usuarios a través de URLs)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
&lt;/h3&gt;
&lt;h3&gt;
&lt;br /&gt;&lt;/h3&gt;
&lt;h3&gt;
Probando la aplicación&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
Podemos probar nuestra aplicación, ejecutando desde consola el comando &lt;b&gt;rails server&lt;/b&gt; desde el directorio de nuestra aplicación (carpeta Blog). Si deseamos detener el servidor se hace con el comando Ctrl+C desde la consola de Windows (símbolo del sistema).&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcFtwSimvAKPekeUgxH0EEUir1_RMyrsLKAxjubLF4VzidKP6MpQEK_LK8-xhC-_YvTZFly4NrJJs8pmnK8Sae0Pwe4f0fuFdMR_DMoPzMvS5-sN98M6Rby8fOgHGDjqWwYy2dvr7LEJo/s1600/03+testing+the+app.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;73&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcFtwSimvAKPekeUgxH0EEUir1_RMyrsLKAxjubLF4VzidKP6MpQEK_LK8-xhC-_YvTZFly4NrJJs8pmnK8Sae0Pwe4f0fuFdMR_DMoPzMvS5-sN98M6Rby8fOgHGDjqWwYy2dvr7LEJo/s320/03+testing+the+app.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
Rails por defecto utiliza el puerto 3000, a menos que se haya configurado de otra manera o el puerto se encuentre actualmente en uso, podemos ver nuestra aplicación desde la ruta &lt;b&gt;http://localhost:3000&lt;/b&gt; desde cualquier navegador web.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMyLVb1g9VTfATWSlecoGsUOJQQ2K3BOGeVJsOLBjrKt_z7QPoVUAb-SYbIAeiNC1RmOudVJoXO4VgJu_40gTxflqkBm9V2EP1lU91LfGirBfUyZi7_wEmSZG77M5cCE8eUbWyWlIZfRM/s1600/04+new+app.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;188&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMyLVb1g9VTfATWSlecoGsUOJQQ2K3BOGeVJsOLBjrKt_z7QPoVUAb-SYbIAeiNC1RmOudVJoXO4VgJu_40gTxflqkBm9V2EP1lU91LfGirBfUyZi7_wEmSZG77M5cCE8eUbWyWlIZfRM/s320/04+new+app.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
Como podemos observar, se muestra una página inicial de Rails, esta es la página de inicio por defecto de Ruby on Rails, que muestra la página web index.html ubicada en la carpeta public.&lt;/div&gt;
&lt;h3&gt;
&lt;/h3&gt;
&lt;h3&gt;
&lt;br /&gt;&lt;/h3&gt;
&lt;h3&gt;
Creando la base de datos&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Ahora que sabemos que nuestra aplicación funciona correctamente, es momento de crear nuestra base de datos. La gran mayoría de las aplicaciones en Rails trabaja con una base de datos. La base de datos que usaremos en nuestro proyecto debe ser especificada en un archivo de configuración llamado database.yml ubicado dentro de la carpeta config. &amp;nbsp;Utilizando nuestro editor de texto favorito abrimos el archivo config/database.yml. (Yo voy a utilizar Sublime Text 2 como editor de texto, puedes usar el de tu preferencia).&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY4wHtNxNrShmtATmxo4uYDcTS-La2a80yP4AZbmRJa0Ack_16KjI3wOMLbR2eboX3c2BgfNhyphenhyphenOHPYRJZiEMxlY4oBsw5n4zMkUR0tFisGWTKGpH_HB2yQQbu2heLFEk-GuRSN61dUSd8/s1600/05+database.yml.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;281&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY4wHtNxNrShmtATmxo4uYDcTS-La2a80yP4AZbmRJa0Ack_16KjI3wOMLbR2eboX3c2BgfNhyphenhyphenOHPYRJZiEMxlY4oBsw5n4zMkUR0tFisGWTKGpH_HB2yQQbu2heLFEk-GuRSN61dUSd8/s320/05+database.yml.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
Rails automáticamente configura nuestro archivo de configuración de la base de datos para usar la base de datos SQLite, esta es la base de datos por defecto para Rails 3.2.13. En este archivos especificamos la base de datos que deseamos utilizar, por ejemplo, si queremos utilizar MySQL o PostgreSQL. Sin embargo, para esta aplicación utilizaremos la base de datos por defecto, por lo que no modificaremos el archivo. Este archivo contiene tres secciones para los 3 diferentes ambientes en que Rails se ejecuta por defecto:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;El ambiente de development (desarrollo) es usado para trabajar en los equipos locales o de desarrollo mientras se programa y se trabaja manualmente con la aplicación.&lt;/li&gt;
&lt;li&gt;El ambiente de test (prueba) es usado cuando se ejecutan pruebas automatizadas.&lt;/li&gt;
&lt;li&gt;El ambiente de production (producción) es usado para desplegar la aplicación.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
Para crear la base de datos, desde la consola escribimos el comando rake db:create.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYmb9Acn905DAHIh37AD3-exsJf984JBIzk04Eo7-CdHlBzmFdcY6MOexZUduMhxsBFDLOgoFLHouwhNUKO18Atn-_1kmCCVCoUUTfFaBjS3Jc6Tl4o9oQdVB2_BXaJ9FgW1hY7VnV0W0/s1600/06+rake+db+create.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYmb9Acn905DAHIh37AD3-exsJf984JBIzk04Eo7-CdHlBzmFdcY6MOexZUduMhxsBFDLOgoFLHouwhNUKO18Atn-_1kmCCVCoUUTfFaBjS3Jc6Tl4o9oQdVB2_BXaJ9FgW1hY7VnV0W0/s320/06+rake+db+create.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
Este comando crea nuestra base de datos en blanco dentro de la carpeta db.&lt;/div&gt;
&lt;h3&gt;
&lt;/h3&gt;
&lt;h3&gt;
&lt;br /&gt;&lt;/h3&gt;
&lt;h3&gt;
&quot;Hola Mundo&quot; en Rails&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
En esta parte cambiaremos la página de inicio de la aplicación por una página programad por nosotros que muestre un mensaje de &quot;Hola Mundo&quot;. (¿Por qué un &quot;Hola Mundo&quot;? &lt;a href=&quot;http://es.wikipedia.org/wiki/Hola_mundo&quot; target=&quot;_blank&quot;&gt;Revisa este enlace&lt;/a&gt;) Para hacer que Rails muestre un mensaje de &quot;Hola Mundo&quot; se necesitan crear al menos una vista y un controlador. Afortunadamente, Rails nos da las facilidades para crear una vista y un controlador con un solo comando. Crearemos un controlador llamado home con una vista llamada inicio. Desde la consola, escribimos el comando &lt;b&gt;rails generate controller home index&lt;/b&gt;.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTWGDQ8WXmqhcq-5Eg-rBjSHMeBThp5Od8BJFnHxlz-b3hnYhSXi_rgbN1ZJxaU8ec_iR0UBwBIBHUYda_4sSvzLmpXmmLlL0hvEf4mu67tgRaUnCsg1wvHL_ukF3NBU_w-nLq5-N0SGk/s1600/07+rails+generate+controller.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;123&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTWGDQ8WXmqhcq-5Eg-rBjSHMeBThp5Od8BJFnHxlz-b3hnYhSXi_rgbN1ZJxaU8ec_iR0UBwBIBHUYda_4sSvzLmpXmmLlL0hvEf4mu67tgRaUnCsg1wvHL_ukF3NBU_w-nLq5-N0SGk/s320/07+rails+generate+controller.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
Rails create una serie de archivos por nosotros, incluyendo app/views/home/index.html.erb. Este archivo es &amp;nbsp;una de las vistas de nuestra aplicación y es la plantilla que se usa para mostrar los resultados de la acción index de nuestro controlador home. A continuación, abrimos la vista app/views/home/index.html.erb borramos el contenido y agregamos el siguiente código HTML: &amp;lt;h1&amp;gt;Hola Mundo&amp;lt;/h1&amp;gt;.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg83Ng33s2CgndJ2ErVBtdI2Y3dpFeKKVvbLUFqMeZP3DqNhMEGSFzzVmEEult8JYWmvNkusll5e5XVyU9Apdf0LShOMWjBfWcI0lIYWTh1cAuLZSqcc-VAQq-id4ubbDSF45rFUcC_D4Y/s1600/08+changing+the+view.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;181&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg83Ng33s2CgndJ2ErVBtdI2Y3dpFeKKVvbLUFqMeZP3DqNhMEGSFzzVmEEult8JYWmvNkusll5e5XVyU9Apdf0LShOMWjBfWcI0lIYWTh1cAuLZSqcc-VAQq-id4ubbDSF45rFUcC_D4Y/s320/08+changing+the+view.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Ahora que tenemos nuestro controlador y vista generadas, debemos de configurar Rails para que nos muestre el mensaje de Hola Mundo. En este caso, queremos mostrar el mensaje cuando vayamos a la página de inicio de nuestra aplicación en vez de la página por defecto de Rails (es decir, mostrar Hola Mundo cuando vayamos a la dirección http://localhost:3000). Para ello tenemos que eliminar el archivo public/index.html y luego procedemos a indicarle a Rails dónde se encuentra nuestra página de inicio. Entonces, tenemos que editar el archivo config/routes.rb. Este archivo contiene todas las rutas de nuestra aplicación que almacena entradas en un DSL (Domain-Specific languague o Lenguaje de dominio específico) que le dice a Rails cómo conectar las peticiones de los navegadores a un controlador y una acción en particular.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Abrimos el archivo config/routes.rb y encontramos la línea que comienza con root :to y la descomentamos (eliminamos el símbolo #) y escribimos &lt;b&gt;root :to =&amp;gt; &#39;home#index&#39;&lt;/b&gt;. Debe verse de la siguiente manera.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMdmoca3rtCtkGwMMdgCzXZElJxy78ZTQSolO0v3ttoNTdFHYTtq0dvS6kQIYu46_V3Va9_fOl-9VsFxiIZfYaPdorwzDFcMiUHarKHx3BmdpvJ5HqN6KnsRA7dp_OtpGcnI_X9JMRkdQ/s1600/09+changing+the+route+file.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;97&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMdmoca3rtCtkGwMMdgCzXZElJxy78ZTQSolO0v3ttoNTdFHYTtq0dvS6kQIYu46_V3Va9_fOl-9VsFxiIZfYaPdorwzDFcMiUHarKHx3BmdpvJ5HqN6KnsRA7dp_OtpGcnI_X9JMRkdQ/s320/09+changing+the+route+file.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Ahora cuando navegamos a la URL de nuestra aplicación en http://localhost:3000 podemos ver que nos muestra el mensaje de Hola Mundo. Recuerda que si detuviste el servidor debes de volver a iniciarlo ejecutando el comando &lt;b&gt;rails server &lt;/b&gt;desde la consola de Windows.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjy1v-rsOjPo0gTEmjvXNPQrlwtdFFT0H40-n6XePEoS048jaZCUbBWoG_dc7NKqKFvnrwz6lbU-u-nqKnMv3SV1Heno-8SAiHcYNmSexi4osDwHTyx8WQUPSZxQy1AGixagvwjKKzEsQY/s1600/10+hello+world.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;147&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjy1v-rsOjPo0gTEmjvXNPQrlwtdFFT0H40-n6XePEoS048jaZCUbBWoG_dc7NKqKFvnrwz6lbU-u-nqKnMv3SV1Heno-8SAiHcYNmSexi4osDwHTyx8WQUPSZxQy1AGixagvwjKKzEsQY/s320/10+hello+world.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
Y finalmente ahora Rails nos muestra nuestro mensaje de Hola Mundo. Con esto concluyo esta primera parte de nuestra primera aplicación con Ruby. Recapitulando, en esta primera parte aprendimos a:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Crear un nuevo proyecto en Rails&lt;/li&gt;
&lt;li&gt;Explorar la estructura base de un proyecto Rails&lt;/li&gt;
&lt;li&gt;Crear una base de datos en blanco&lt;/li&gt;
&lt;li&gt;Crear un controlador y una vista&lt;/li&gt;
&lt;li&gt;Cambiar la ruta de inicio de nuestra aplicación&lt;/li&gt;
&lt;li&gt;Ejecutar y detener el servidor de Rails&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
Fuente:&amp;nbsp;&lt;a href=&quot;http://guides.rubyonrails.org/getting_started.html&quot; target=&quot;_blank&quot;&gt;Ruby on Rails Guides: Getting started&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/8183961234941559637/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2013/06/primera-aplicacion-en-ruby-on-rails.html#comment-form' title='1 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/8183961234941559637'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/8183961234941559637'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2013/06/primera-aplicacion-en-ruby-on-rails.html' title='Primera aplicación en Ruby on Rails - Primera Parte'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9YjNYcUSSLzEZyEO0-R32Zo494ZCML_zVcumccCOSz5hLe3Wl6riEMaU7tFhOkI7i0Z5qd3DSYSfUKxfna_YOqFMxyS0SxXAMNeohSN_cw5Zz2ZZA_wv0vRpUCd2yUjeB5yeRd4vGoXI/s72-c/rails.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-4122150585452521312</id><published>2013-06-14T09:51:00.000-05:00</published><updated>2013-06-14T09:51:00.198-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="devkit"/><category scheme="http://www.blogger.com/atom/ns#" term="mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="rails"/><category scheme="http://www.blogger.com/atom/ns#" term="ror"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby on rails"/><category scheme="http://www.blogger.com/atom/ns#" term="windows"/><title type='text'>Instalación de la gema mysql2 en Windows</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9YjNYcUSSLzEZyEO0-R32Zo494ZCML_zVcumccCOSz5hLe3Wl6riEMaU7tFhOkI7i0Z5qd3DSYSfUKxfna_YOqFMxyS0SxXAMNeohSN_cw5Zz2ZZA_wv0vRpUCd2yUjeB5yeRd4vGoXI/s1600/rails.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9YjNYcUSSLzEZyEO0-R32Zo494ZCML_zVcumccCOSz5hLe3Wl6riEMaU7tFhOkI7i0Z5qd3DSYSfUKxfna_YOqFMxyS0SxXAMNeohSN_cw5Zz2ZZA_wv0vRpUCd2yUjeB5yeRd4vGoXI/s1600/rails.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
En esta entrada veremos como instalar correctamente la gema mysql2 en Windows para poder usar la base de datos MySQL en nuestras aplicaciones de Ruby on Rails.&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Se va a realizar la instalación para el siguiente entorno de configuración:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Windows 7 o XP&lt;/li&gt;
&lt;li&gt;Ruby 1.9.3&lt;/li&gt;
&lt;li&gt;Rails 3.2.13&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
Antes de empezar, ten en cuenta que es necesario haber instalado previamente Ruby y Ruby on Rails. Si deseas saber cómo instalar Ruby y Rails en Windows puedes revisar la entrada &lt;a href=&quot;http://notasensistemas.blogspot.com/2013/06/ruby-on-rails-instalacion-en-windows.html&quot; target=&quot;_blank&quot;&gt;Instalación de Ruby on Rails en Windows&lt;/a&gt;.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
En primer lugar, debemos de descargar el Devkit desde la web oficial de&amp;nbsp;&lt;a href=&quot;http://rubyinstaller.org/downloads/&quot; target=&quot;_blank&quot;&gt;Ruby Installer&lt;/a&gt;, como estamos usando Ruby 1.9.3 debemos de descargar el archivo &quot;DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe&quot;. Una vez descargado, lo ejecutamos y especificamos la ruta donde se desea que se extraigan los archivos. En mi caso voy a extraerlos en la ruta: C:/Devkit.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Desde la consola de Windows, nos desplazamos hacia la ruta donde se han extraído los archivos y ejecutamos el comando &lt;b&gt;ruby dk.rb init&lt;/b&gt;.&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjm1fDWaYIJWhHy2bDBPcoJPdnxqtC8_XJbqdB2B3mFAyPKajLRUy94mZeBdpwzrosip2EiTlqYynFqgIKEFEba2y2qnGAiEWruQ00pGnjnBR02GrilB8fgqDAlgswmilqI35FwbVGGZ8/s1600/a.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;69&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjm1fDWaYIJWhHy2bDBPcoJPdnxqtC8_XJbqdB2B3mFAyPKajLRUy94mZeBdpwzrosip2EiTlqYynFqgIKEFEba2y2qnGAiEWruQ00pGnjnBR02GrilB8fgqDAlgswmilqI35FwbVGGZ8/s320/a.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Este comando va a generar un archivo llamado config.yml, el cual debemos de editar agregando al final la ruta de donde se ha instalado Ruby en nuestra computadora. En mi caso, como tengo instalado Rails en la ruta&amp;nbsp;G:\Programas\Rails\Ruby1.9.3 el archivo config.yml queda de la siguiente manera.&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNCjjqPa-P4VgrAILP0C8G3FXpAIG1YXzPWM08eNbd2BSdXxzx_fKL-clB-hKlBNSw3oTCAXZf_Gn2b4dP3HI3-6l1SyAQ5Khvc4kUHluvF3zps-qmHB5yJXyVZ-LqSq_8j4gWJKXIeVc/s1600/b.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;123&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNCjjqPa-P4VgrAILP0C8G3FXpAIG1YXzPWM08eNbd2BSdXxzx_fKL-clB-hKlBNSw3oTCAXZf_Gn2b4dP3HI3-6l1SyAQ5Khvc4kUHluvF3zps-qmHB5yJXyVZ-LqSq_8j4gWJKXIeVc/s320/b.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Guardamos el archivo y desde la ruta donde extrajimos los archivos del Devkit ejecutamos el comando &lt;b&gt;ruby dk.rb install&lt;/b&gt; para instalar el Devkit.&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPeOX_zl3AExw-Cw2QH1pTTx7ieZ-WNASHFnZBmCWtdecFn9JPSe4DJtReFKjqDUJq52sQIt9ROof0C2qEPphNz09bLAQELwxDlK4pLFhgW4OYBfwhpYOhNU4CYJx1r5mf9HMuo-_C3gY/s1600/c.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;30&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPeOX_zl3AExw-Cw2QH1pTTx7ieZ-WNASHFnZBmCWtdecFn9JPSe4DJtReFKjqDUJq52sQIt9ROof0C2qEPphNz09bLAQELwxDlK4pLFhgW4OYBfwhpYOhNU4CYJx1r5mf9HMuo-_C3gY/s320/c.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Una vez instalado el Devkit, procedemos a descargar el conector MySQL desde&amp;nbsp;&lt;a href=&quot;http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick&quot; target=&quot;_blank&quot;&gt;la web oficial de desarrolladores de MySQL&lt;/a&gt;, y extraemos el contenido del .zip en nuestro directorio de preferencia. Yo lo voy a extraer en la ruta C:/MySQL.&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCQQE0-uwuMeg_GqXau1uBYjp-OF56FGvDlSh_hUz1t0YElwQbYFXoMtAub2AucqEgzbE6zKXRrAx3yL4a4PCxXEuuBVm2NYNHM4PcrwC1pAnEXtX6z1JD5vAaFiA1dZGlNNteVtK9Djc/s1600/d.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;115&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCQQE0-uwuMeg_GqXau1uBYjp-OF56FGvDlSh_hUz1t0YElwQbYFXoMtAub2AucqEgzbE6zKXRrAx3yL4a4PCxXEuuBVm2NYNHM4PcrwC1pAnEXtX6z1JD5vAaFiA1dZGlNNteVtK9Djc/s320/d.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Ahora, procedemos a instalar la gema mysql2 en nuestra computadora, ejecutando el comando&amp;nbsp;&lt;b&gt;gem install mysql2 -- &#39;--with-mysql-lib=&quot;c:/MySQL/bin&quot; --with-mysql-include=&quot;c:/MySQL/include&quot;&#39;&lt;/b&gt;. Debes especificar la ruta donde extrajistes el .zip que descargamos en el paso anterior en las opciones with-mysql-lib y with-mysql-include. (Cambia el comando es si no extrajistes el .zip en la ruta C:/MySQL).&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-Zmf5JmTmCrUHozBGqzuAfEe1OBx0V9iSM-VSoZmVqTPO6cFBuEABLU0udJZNPcOFQ9Ykkwf4CwJ9kQJV3J_bbyDr-6ZoUDrEZxZZUnEQTbmyZskukxBsKK48z4zBFTfBl4xQvFzWZ9s/s1600/e.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;84&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-Zmf5JmTmCrUHozBGqzuAfEe1OBx0V9iSM-VSoZmVqTPO6cFBuEABLU0udJZNPcOFQ9Ykkwf4CwJ9kQJV3J_bbyDr-6ZoUDrEZxZZUnEQTbmyZskukxBsKK48z4zBFTfBl4xQvFzWZ9s/s320/e.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
Finalmente, copiamos la DLL libmysql.dll desde la carpeta lib de donde guardamos el conector a la carpeta bin en donde tenemos instalado Rails en nuestra computadora. Como yo guarde el conector en C:/MySQL y Rails en mi computadora se encuentra instalado en G:/Programas/Rails/Ruby1.9.3, tengo que copiar el archivo C:/MySQL/lib/libmysql.dll a la ruta G:/Programas/Rails/Ruby1.9.3/bin. Finalmente, ya tenemos instalada la gema mysql2 en Windows. Ahora podemos crear un proyecto en Rails y configurarlo para que utilice MySQL como base de datos usando la gema mysql2.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: arial;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 20px;&quot;&gt;Fuente:&amp;nbsp;&lt;a href=&quot;http://maxivak.com/installing-mysql2-gem-on-ruby-1-9-2-and-rails-3-0-5-on-windows/&quot; target=&quot;_blank&quot;&gt;Maxivak.com&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/4122150585452521312/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2013/06/instalacion-de-la-gema-mysql2-en-windows.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/4122150585452521312'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/4122150585452521312'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2013/06/instalacion-de-la-gema-mysql2-en-windows.html' title='Instalación de la gema mysql2 en Windows'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9YjNYcUSSLzEZyEO0-R32Zo494ZCML_zVcumccCOSz5hLe3Wl6riEMaU7tFhOkI7i0Z5qd3DSYSfUKxfna_YOqFMxyS0SxXAMNeohSN_cw5Zz2ZZA_wv0vRpUCd2yUjeB5yeRd4vGoXI/s72-c/rails.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-7046400950666939645</id><published>2013-06-11T03:00:00.000-05:00</published><updated>2013-06-11T09:42:46.246-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="rails"/><category scheme="http://www.blogger.com/atom/ns#" term="railsinstaller"/><category scheme="http://www.blogger.com/atom/ns#" term="ror"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby on rails"/><category scheme="http://www.blogger.com/atom/ns#" term="windows"/><title type='text'>Ruby on Rails: Instalación en Windows</title><content type='html'>&lt;div class=&quot;estilogeneral&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8PZc71bBX6Ec_wruo0ZFpFD-g5b3D09SQeHyVr9iHEGDuZUgCXdTtbuAmWJExBmDC1Xmgy3e09FCydX_DQvj02XbuuWGJaVsExoGnNEbAn-CnGC5QNSahGy9zNJJbkld_sJOLTnsHcKw/s1600/rails.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8PZc71bBX6Ec_wruo0ZFpFD-g5b3D09SQeHyVr9iHEGDuZUgCXdTtbuAmWJExBmDC1Xmgy3e09FCydX_DQvj02XbuuWGJaVsExoGnNEbAn-CnGC5QNSahGy9zNJJbkld_sJOLTnsHcKw/s1600/rails.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Uno de los grandes problemas cuando quise aprender hace mucho tiempo atrás era como hacer para instalar Rails en Windows. En esta entrada voy a demostrar lo fácil que es actualmente instalar Rails en entornos Windows usando Rails Installer.&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;Procederemos a instalar Ruby on Rails en Windows la siguiente configuración:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Windows 7&lt;/li&gt;
&lt;li&gt;Ruby 1.9.3&lt;/li&gt;
&lt;li&gt;Rails 3.2.13&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Visitamos la pagina de&amp;nbsp;&lt;a href=&quot;http://railsinstaller.org/&quot; target=&quot;_blank&quot;&gt;Rails Installer&lt;/a&gt;&amp;nbsp;y nos desplazamos hacia abajo y elegimos la opción de Windows Downloads: &quot;Windows Ruby 1.9&quot;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjT7OYFembid8ihLQIrvj3gXCrua05vDQun_NLDzWWf2Qee__fIVQLFbIDNoy5-spvhH4GYj_QBuEID31Q9mvCSbr6qlEdhDiV7GELzLhRG6l3TcsFbDT1kw8vDNmHkVF9YJvynekCtTSY/s1600/installer+1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;196&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjT7OYFembid8ihLQIrvj3gXCrua05vDQun_NLDzWWf2Qee__fIVQLFbIDNoy5-spvhH4GYj_QBuEID31Q9mvCSbr6qlEdhDiV7GELzLhRG6l3TcsFbDT1kw8vDNmHkVF9YJvynekCtTSY/s400/installer+1.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
Una vez descargado el instalador (aproximadamente 60 MB), lo ejecutamos y seguimos los pasos del instalador para instalar Ruby y Rails en nuestra computadora. No olvidar marcar la opción &quot;Add executables for Ruby, DevKit and Git (if checked above) to the PATH.&quot; Si eliges la opción de Instalar Git, al finalizar la instalación debes ingresar tus datos para registrar una cuenta en Github.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlq5alUTQAJay5vKqfbX512kMsYXLKSo8oLNoN5zlSPj8lEGjdIVhCcvBrbttY1Xwk3J9E-Hv7jFPW1wX910us7wAxdw5EOhf3VW-1OsYZK6JzwJDjBqMcMQL0QMObYE2ThW9LgbnjhCc/s1600/installer+2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;248&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlq5alUTQAJay5vKqfbX512kMsYXLKSo8oLNoN5zlSPj8lEGjdIVhCcvBrbttY1Xwk3J9E-Hv7jFPW1wX910us7wAxdw5EOhf3VW-1OsYZK6JzwJDjBqMcMQL0QMObYE2ThW9LgbnjhCc/s320/installer+2.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
Y ya tenemos instalado Rails, para confirmar que se ha instalado correctamente podemos usar los comandos ruby -v y rails -v para verificar la version que se ha instalado en nuestra computadora.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6v7Y_mwocV2XYfe5NnyaO_LYxkBWm-3ITq2eLBe-K5x0GlR6_mYMPgWoEOiM52a0SIi5PJy_PeQvWKjEecks6PTMTePJfBYqaHOTdkq7cqJjALkCgyxkmpjg0WgP44yfhwlz3vDS_XgU/s1600/installer+3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;161&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6v7Y_mwocV2XYfe5NnyaO_LYxkBWm-3ITq2eLBe-K5x0GlR6_mYMPgWoEOiM52a0SIi5PJy_PeQvWKjEecks6PTMTePJfBYqaHOTdkq7cqJjALkCgyxkmpjg0WgP44yfhwlz3vDS_XgU/s320/installer+3.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/7046400950666939645/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2013/06/ruby-on-rails-instalacion-en-windows.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/7046400950666939645'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/7046400950666939645'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2013/06/ruby-on-rails-instalacion-en-windows.html' title='Ruby on Rails: Instalación en Windows'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8PZc71bBX6Ec_wruo0ZFpFD-g5b3D09SQeHyVr9iHEGDuZUgCXdTtbuAmWJExBmDC1Xmgy3e09FCydX_DQvj02XbuuWGJaVsExoGnNEbAn-CnGC5QNSahGy9zNJJbkld_sJOLTnsHcKw/s72-c/rails.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-8067369960325551582</id><published>2013-06-08T23:10:00.000-05:00</published><updated>2013-06-08T23:18:07.303-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="mvc"/><category scheme="http://www.blogger.com/atom/ns#" term="rails"/><category scheme="http://www.blogger.com/atom/ns#" term="rest"/><category scheme="http://www.blogger.com/atom/ns#" term="ror"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby on rails"/><title type='text'>Introducción teórica a Ruby on Rails (RoR)</title><content type='html'>&lt;div class=&quot;estilogeneral&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_mUpYTU_E-_l8umVlpYxbJu_tttIObZW2Q9rRKFWLwu9zYxYO64xm482I-KoatbnyZAHDjMK6RzOJYjRTZ3zTPg09ieMMAptrZ2OgQru5FVgO76yikqN9jmm4XaKIEeHuJNHPr9aU3Bc/s1600/Untitled.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;75&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_mUpYTU_E-_l8umVlpYxbJu_tttIObZW2Q9rRKFWLwu9zYxYO64xm482I-KoatbnyZAHDjMK6RzOJYjRTZ3zTPg09ieMMAptrZ2OgQru5FVgO76yikqN9jmm4XaKIEeHuJNHPr9aU3Bc/s400/Untitled.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Ruby on Rails (RoR o simplemente Rails) es un framework para desarrollar aplicaciones web basado en el lenguaje de programación Ruby. Rails esta diseñado para facilitar la programación de aplicaciones web haciendo suposiciones acerca de lo que un programador necesita para empezar a programar. Te permite escribir menos código y llegar mas lejos que muchos otros lenguajes y/o frameworks. Incluso, hasta algunos programadores expertos en Rails dicen que hace el desarrollo de aplicaciones web mas divertida.&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span class=&quot;titulo&quot;&gt;Rails es un software obstinado. Rails asume que hay una &quot;mejor manera&quot; de hacer las cosas, y esta diseñado para hacerlo de esa manera - y en algunos casos, desalentarte a usar alternativas. Si uno aprende &quot;de la forma Rails&quot; (The Rails Way) es probable que descubras un gran aumento de la productividad. Si persistes en llevar las viejas costumbres de otros lenguajes de programación para el desarrollo de aplicaciones Rails, o tratas de utilizar patrones que has aprendido en otros lugares, es probable que tengas una experiencia menos feliz al usar Rails.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span class=&quot;titulo&quot;&gt;La filosofía de Rails incluye muchos principios, aqui cito algunos:&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;DRY (Don&#39;t repeat yourself - No te repitas) - Este principio sugiere que escribir el mismo código una y otra vez no es bueno.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Convention over configuration (Convención sobre configuración) - Significa que Rails asume cosas acerca de lo que quieres hacer y como lo vas a hacer, en vez de requerir que especifiques cada minúsculo detalle de lo que quieres o vas a hacer en una infinidad de archivos de configuración.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;REST es el mejor patrón para las aplicaciones web - organizar tu aplicación en torno a recursos y verbos HTTP es la manera mas rápida de desarrollar.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 style=&quot;text-align: justify;&quot;&gt;
1. La arquitectura MVC&lt;/h1&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Rails se encuentra basado en el patrón MVC - Model, View, Controller, (Modelo, Vista y Controlador), usualmente llamado simplemente MVC. Algunos beneficios de usar MVC incluyen:&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Aislamiento de la lógica del negocio de la interfaz de usuario&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Facilita mantener el&amp;nbsp;código&amp;nbsp;bajo el principio de DRY&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Hace mas claro donde pertenece cada bloque de código para facilitar el mantenimiento&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
&lt;/h3&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
1.1 Modelo&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Un modelo representa la información (datos) de la aplicación y las reglas para manipular estos datos. En el caso de Rails, los modelos son usados generalmente para manejar la interacción con su correspondiente tabla en la base de datos. En la mayoría de los casos, cada table en la base de datos corresponde a un modelo en la aplicación. La mayor parte de la lógica de negocio de la aplicación se concentra en los modelos.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
1.2 Vistas&lt;/h3&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Las vistas representan la interfaz de usuario de la aplicación. En Rails, las vistas usualmente son archivos HTML con código Ruby embebido que realiza tareas asociadas solamente a la presentación de datos. Las vistas tienen a cargo la tarea de proveer de datos al navegador web u otra herramienta que se utilice para hacer peticiones a la aplicación.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
1.3 Controlador&lt;/h3&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Los controladores son el pegamento que une los modelos y las vistas. En Rails, los controladores son responsables de procesar las peticiones de los navegadores web, interrogar a los modelos para obtener información y pasar esta información a las vistas para su presentación.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h1 style=&quot;text-align: justify;&quot;&gt;
2. El Modelo REST&lt;/h1&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
REST (Representational State of Transfer - Estado representativo de la transferencia) es la base de la arquitectura REST. En Rails, REST se usa en dos principios:&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Usar identificadores de recursos como URLs para representar recursos&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Transferir representaciones de estado del recurso entre componentes del sistema&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Por ejemplo, si tenemos la siguiente petición HTTP:&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
DELETE /photos/17&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
se entiende que se refiere a un recurso llamado photos (fotos) con el identificador (ID) 17, e indica que la acción que se quiere realizar al recurso photos es un un DELETE - (ELIMINAR).&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h1 style=&quot;text-align: justify;&quot;&gt;
3. Links de Interés&lt;/h1&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Si quieres saber mas sobre Rails, o la teoría que se ha tocado en esta entrada, aquí te dejo algunos links:&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;&lt;a href=&quot;http://www.ruby-lang.org/es/&quot; target=&quot;_blank&quot;&gt;Lenguaje Ruby&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;&lt;a href=&quot;http://www.ruby-doc.org/docs/ProgrammingRuby/&quot; target=&quot;_blank&quot;&gt;Programando en Ruby&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;&lt;a href=&quot;http://es.wikipedia.org/wiki/Modelo_Vista_Controlador&quot; target=&quot;_blank&quot;&gt;Modelo Vista Controlador&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;&lt;a href=&quot;http://es.wikipedia.org/wiki/Representational_State_Transfer&quot; target=&quot;_blank&quot;&gt;Modelo REST&lt;/a&gt;&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;&lt;a href=&quot;http://www.infoq.com/articles/rest-introduction&quot; target=&quot;_blank&quot;&gt;Introducción a REST&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Fuente:&amp;nbsp;&lt;a href=&quot;http://guides.rubyonrails.org/getting_started.html&quot; target=&quot;_blank&quot;&gt;Ruby on Rails Guides&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/8067369960325551582/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2013/06/introduccion-teorica-ruby-on-rails-ror.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/8067369960325551582'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/8067369960325551582'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2013/06/introduccion-teorica-ruby-on-rails-ror.html' title='Introducción teórica a Ruby on Rails (RoR)'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_mUpYTU_E-_l8umVlpYxbJu_tttIObZW2Q9rRKFWLwu9zYxYO64xm482I-KoatbnyZAHDjMK6RzOJYjRTZ3zTPg09ieMMAptrZ2OgQru5FVgO76yikqN9jmm4XaKIEeHuJNHPr9aU3Bc/s72-c/Untitled.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-8528120352917196857</id><published>2012-04-22T11:24:00.001-05:00</published><updated>2013-06-10T12:22:06.517-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="programacion"/><title type='text'>POO: El problema de los alumnos</title><content type='html'>&lt;div class=&quot;estilogeneral&quot; style=&quot;text-align: justify;&quot;&gt;
En esta entrada trataremos sobre la resolución de un problema de programación orientado a objetos: &quot;Defina una clase Alumnos con atributos nrocarnet, nombre y promedio. Luego muestre el mejor y peor alumno y el promedio de todos los alumnos.&quot;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;La clase Alumno&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
En primer lugar, creamos una clase Alumno en donde programaremos los atributos de los alumnos que nos pide el problema: numero de carnet, nombre y promedio. No hay que confundirse con la clase &lt;b&gt;Alumnos&lt;/b&gt; que nos dice el problema. Esta clase &lt;b&gt;Alumnos&lt;/b&gt; se va a encargar de mostrar el mejor alumno, el peor alumno y el promedio de todos los alumnos. Para que la clase Alumnos pueda realizar estas operaciones, debe tener una colección de objetos de tipo alumno que es lo que vamos a definir en el código siguiente. &lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package Principal;

public class Alumno {
    private int nroCarnet;
    private String nombre;
    private double promedio;
    
    public int getNroCarnet() {
        return nroCarnet;
    }

    public void setNroCarnet(int nroCarnet) {
        this.nroCarnet = nroCarnet;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public double getPromedio() {
        return promedio;
    }

    public void setPromedio(double promedio) {
        this.promedio = promedio;
    }
}
&lt;/pre&gt;
Como podemos observar, definimos los atributos de la clase Alumno y sus métodos get y set respectivamente.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;La clase Alumnos&lt;/b&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package Main;

import java.util.ArrayList;

public class Alumnos {
    private ArrayList&amp;lt;Alumno&amp;gt; lista;
    
    public Alumnos(){
        this.lista = new ArrayList&amp;lt;Alumno&amp;gt;();
    }
    
    public ArrayList&amp;lt;Alumno&amp;gt; getLista(){
        return this.lista;
    }
    
    public void AgregarAlumno(Alumno alumno){
        this.lista.add(alumno);
    }    
        
    public double getPromedio(){
        double contador = 0.0;
        for (int i = 0; i &amp;lt; this.lista.size(); i++) {
            contador += this.lista.get(i).getPromedio();
        }
        return contador / this.lista.size();
    }
    public Alumno MejorAlumno(){
        Alumno alumno = new Alumno();
        alumno.setPromedio(-1.0);
        for (int i = 0; i &amp;lt; this.lista.size(); i++) {
            if(this.lista.get(i).getPromedio() &amp;gt; alumno.getPromedio()){
                alumno = this.lista.get(i);
            }
        }
        return alumno;
    }
    
    public Alumno PeorAlumno(){
        Alumno alumno = new Alumno();
        alumno.setPromedio(10000.0);
        for (int i = 0; i &amp;lt; this.lista.size(); i++) {
            if(this.lista.get(i).getPromedio() &amp;lt; alumno.getPromedio()){
                alumno = this.lista.get(i);
            }
        }
        return alumno;
    }
}&lt;/pre&gt;
&lt;br /&gt;
Como podemos observar, nuestra clase Alumnos contiene una colección de la clase Alumnos. Esta colección se encuentra implementada como un objeto ArrayList (Linea 6) y se inicializa dentro del constructor de la clase (Linea 9). Ademas, si queremos mostrar al usuario todos los alumnos de la clase debemos de implementar su método get para que pueda ser llamado desde Main (Lineas 12-14). Para poder agregar objetos a nuestra colección implementamos el método AgregarAlumno(Lineas 16-18). Finalmente, las operaciones del mejor alumno, el peor alumno y el promedio de los alumnos se implementan en las lineas siguientes (Lineas 20-47)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;La clase Main&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
En nuestra clase principal Main declaramos e inicializamos un objeto Alumnos (Linea 4) y un objeto Alumno (Linea 5), luego creamos nuevos alumnos y los agregamos a la lista de alumnos (Lineas 6-23), luego mostramos todos los alumnos de la lista de alumnos (Lineas 25-32) y finalmente mostramos el resultado de las operaciones de mejor alumno, peor alumno y promedio de los alumnos que nos pide el problema (Lineas 33-39).
&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package Main;
public class Main {
   public static void main(String[] args) {
        Alumnos listaAlumnos = new Alumnos();
        Alumno alumno = new Alumno();
        alumno.setNombre(&quot;Juan Perez&quot;);
        alumno.setNroCarnet(001);
        alumno.setPromedio(15.00);
        listaAlumnos.AgregarAlumno(alumno);
        alumno = new Alumno();
        alumno.setNombre(&quot;Julio Paz&quot;);
        alumno.setNroCarnet(002);
        alumno.setPromedio(09.00);
        listaAlumnos.AgregarAlumno(alumno);
        alumno = new Alumno();
        alumno.setNombre(&quot;Maria Ramirez&quot;);
        alumno.setNroCarnet(003);
        alumno.setPromedio(13.00);
        listaAlumnos.AgregarAlumno(alumno);
        alumno = new Alumno();
        alumno.setNombre(&quot;Diana Martinez&quot;);
        alumno.setNroCarnet(004);
        alumno.setPromedio(16.00);
        listaAlumnos.AgregarAlumno(alumno);
        for (int i = 0; i &amp;lt; listaAlumnos.getLista().size(); i++) {
            alumno = listaAlumnos.getLista().get(i);
            System.out.println(&quot;Alumno &quot; + (i+1));
            System.out.println(&quot;NroCarnet: &quot; + alumno.getNroCarnet());
            System.out.println(&quot;Nombre: &quot; + alumno.getNombre());
            System.out.println(&quot;Promedio: &quot; + alumno.getPromedio());
            System.out.println(&quot;-----------------------------&quot;);
        }
        alumno = listaAlumnos.MejorAlumno();
        System.out.println(&quot;El mejor alumno es &quot; + alumno.getNombre() + &quot; con promedio &quot; 
                + alumno.getPromedio());
        alumno = listaAlumnos.PeorAlumno();
        System.out.println(&quot;El peor alumno es &quot; + alumno.getNombre() + &quot; con promedio &quot; 
                + alumno.getPromedio());
        System.out.println(&quot;El promedio de todos los alumnos es de &quot; + listaAlumnos.getPromedio()); 
   }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script language=&#39;javascript&#39;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/8528120352917196857/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2012/04/poo-el-problema-de-los-alumnos.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/8528120352917196857'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/8528120352917196857'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2012/04/poo-el-problema-de-los-alumnos.html' title='POO: El problema de los alumnos'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-7063728623453840020</id><published>2012-04-18T12:30:00.002-05:00</published><updated>2013-06-10T12:22:38.645-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="programacion"/><title type='text'>POO: El problema del empleado</title><content type='html'>&lt;div class=&quot;estilogeneral&quot; style=&quot;text-align: justify&quot;&gt;En esta entrada trataremos sobre la resolución de un problema de programación orientado a objetos: &quot;Defina una clase empleado con todos sus atributos y un arreglo con los puestos que ocupa en la empresa. Use get y set.&quot; La razón de ser de este problema es darnos cuenta del uso de arreglos cuando programamos la clase Empleado.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;La clase Empleado&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package Principal;

public final class Empleado {

    private String nombre;
    private String apPaterno;
    private String apMaterno;
    private double sueldo;
    private String[] puestos;
    private int indice;

    public Empleado(String nombre, String apPaterno, String apMaterno, double sueldo, String[] puestos) {
        this.setNombre(nombre);
        this.setApMaterno(apMaterno);
        this.setApPaterno(apPaterno);
        this.setSueldo(sueldo);
        this.puestos = new String[5];
        indice = 0;
        if(puestos.length&amp;lt;= this.getPuestos().length)//Arreglo de menor tamaño del esperado
        {
            for (int i = 0; i &amp;lt; puestos.length; i++) {
                this.setPuesto(puestos[i]);
            }
        }else{//Arreglo de mayor tamaño del esperado
            for (int i = 0; i &amp;lt; this.getPuestos().length; i++) {
                this.setPuesto(puestos[i]);
            }
        }
    }

    public void setPuesto(String puesto) {
        if (indice &amp;lt; this.getPuestos().length) {
            this.puestos[indice] = puesto;
            indice++;
        }
    }
    public String[] getPuestos() {
        return puestos;
    }
    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getApPaterno() {
        return apPaterno;
    }

    public void setApPaterno(String apPaterno) {
        this.apPaterno = apPaterno;
    }

    public String getApMaterno() {
        return apMaterno;
    }

    public void setApMaterno(String apMaterno) {
        this.apMaterno = apMaterno;
    }

    public double getSueldo() {
        return sueldo;
    }

    public void setSueldo(double Sueldo) {
        this.sueldo = Sueldo;
    }
}
&lt;/pre&gt;&lt;br /&gt;
Lo más resaltante de la clase es la línea 9 en la que declaramos el arreglo puestos y la línea 17 en la que inicializamos el arreglo dentro del constructor. Las líneas 19 a 28 y las líneas 31 a 36 muestran la forma de realizar operaciones con nuestro arreglo dentro de la clase empleado.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Programación en la clase Main&lt;/b&gt; &lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package Principal;

import java.util.Random;
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        
        String[] puestos = new String[3];
        puestos[0] = &quot;Administrador&quot;;
        puestos[1] = &quot;Jefe de Area&quot;;
        puestos[2] = &quot;Subgerente&quot;;
        
        Empleado emp = new Empleado(&quot;Juan&quot;, &quot;Perez&quot;, &quot;Perez&quot;, 1500, puestos);
        System.out.println(&quot;Datos del empleado&quot;);
        System.out.println(&quot;Nombre: &quot; + emp.getNombre());
        System.out.println(&quot;Apellidos: &quot; + emp.getApPaterno() + &quot; &quot; + emp.getApMaterno());
        System.out.println(&quot;Sueldo: &quot; + emp.getSueldo());
        System.out.println(&quot;Puestos: &quot;);
        for (int i = 0; i &amp;lt; emp.getPuestos().length; i++) {
            if (emp.getPuestos()[i] != null) {
                System.out.println((i+1) + &quot;) &quot; + emp.getPuestos()[i]);
            }
        }
        
        emp.setPuesto(&quot;Jefe Comercial&quot;);
        
        System.out.println(&quot;\n&quot; + &quot;Nuevos Puestos: &quot;);
        for (int i = 0; i &amp;lt; emp.getPuestos().length; i++) {
            if (emp.getPuestos()[i] != null) {
                System.out.println((i+1) + &quot;) &quot; + emp.getPuestos()[i]);
            }
        }         
    }
}
&lt;/pre&gt;&lt;br /&gt;
De manera análoga, en nuestro Main definimos un arreglo en la línea 11 y le asignamos valores en las líneas 12 a 14. Luego, manipulamos arreglos en las líneas 22 a 26 y en las líneas 31 a 35.&lt;br /&gt;
&lt;br /&gt;
Si bien es cierto que el ejercicio está orientado a familiarizarnos con el uso de arreglos, también pudimos haber implementado una lista en vez de usar un arreglo. Para usar listas en Java, podemos programar nuestra propia clase Lista o podemos hacer uso de la clase ArrayList de Java que se encuentra en java.util.&lt;br /&gt;
&lt;br /&gt;
Además, cabe resaltar que nuestra clase empleado tiene un campo Sueldo, que representa el sueldo fijo que gana el empleado en su organización. En la vida real, tenemos este tipo de empleados que ganan un sueldo fijo y se les denomina &quot;empleados a tiempo completo&quot;. Pero también tenemos &quot;empleados a tiempo parcial&quot; los cuales se les paga por el número de horas que trabajan. Si quisiéramos modelar estos dos tipos de empleado, deberíamos crear una clase para empleados a tiempo completo y otra para empleados a tiempo parcial.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Resultado de la ejecución&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGGwz-QjGkzmWzN2dPBNOzWaEkcaMzQlqlLBA1iVUN-9BeaxJoJ_kVizQtW0gRnTZ0eofPPBMyXEwc7clxERE9O-AzjPkbdPYmjufMPBaecM3Lwsl0CypDQvQGPvY3uo5g6FEVC1IV_y0/s1600/Imagen1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;125&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGGwz-QjGkzmWzN2dPBNOzWaEkcaMzQlqlLBA1iVUN-9BeaxJoJ_kVizQtW0gRnTZ0eofPPBMyXEwc7clxERE9O-AzjPkbdPYmjufMPBaecM3Lwsl0CypDQvQGPvY3uo5g6FEVC1IV_y0/s320/Imagen1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script language=&#39;javascript&#39;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/7063728623453840020/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2012/04/poo-el-problema-del-empleado.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/7063728623453840020'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/7063728623453840020'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2012/04/poo-el-problema-del-empleado.html' title='POO: El problema del empleado'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGGwz-QjGkzmWzN2dPBNOzWaEkcaMzQlqlLBA1iVUN-9BeaxJoJ_kVizQtW0gRnTZ0eofPPBMyXEwc7clxERE9O-AzjPkbdPYmjufMPBaecM3Lwsl0CypDQvQGPvY3uo5g6FEVC1IV_y0/s72-c/Imagen1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-9100353647752708507</id><published>2012-04-15T20:13:00.001-05:00</published><updated>2013-06-10T12:22:54.606-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="encapsulamiento"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><title type='text'>POO: Principio de encapsulamiento</title><content type='html'>&lt;div class=&quot;estilogeneral&quot; style=&quot;text-align: justify;&quot;&gt;En la programación orientada a objetos se denomina encapsulamiento al ocultamiento de los &quot;datos&quot; (en realidad, su estado) de un objeto, de tal manera que sólo se puedan cambiar dichos estados mediante las operaciones (métodos) definidas en dicho objeto.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;Contenido&lt;/span&gt;  &lt;br /&gt;
&lt;ol class=&quot;indice&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2012/04/poo-principio-de-encapsulamiento.html#section1&quot;&gt;&lt;b&gt;Introducción&lt;/b&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2012/04/poo-principio-de-encapsulamiento.html#section2&quot;&gt;&lt;b&gt;Encapsulamiento en Java&lt;/b&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2012/04/poo-principio-de-encapsulamiento.html#section3&quot;&gt;&lt;b&gt;Encapsulamiento de objetos en Netbeans&lt;/b&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section1&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Introducción&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
El encapsulamiento es una simple idea poderosa que provee dos principales beneficios a los desarrolladores de software: la modularidad y el ocultamiento de la información. La modularidad hace que el código fuente (y también el mantenimiento) de un objeto pueda ser escrito independientemente del código fuente de otros objetos. De esta manera, un objeto puede ser transferido alrededor del sistema sin alterar su estado y conducta.&lt;br /&gt;
&lt;br /&gt;
Por otro lado, el ocultamiento de la información hace que un objeto tenga una &quot;interfaz pública&quot; que otros objetos pueden utilizar para comunicarse con él. Esta &quot;interfaz pública&quot; en realidad son los métodos que se programan para cambiar los estados de los &quot;datos&quot; (llamados atributos) de un objeto. Estos métodos también son conocidos como accesores, y dependiendo de su función (establecer u obtener el valor de un atributo de un objeto) se le conocen también como &quot;getters&quot; y &quot;setters&quot; o como &quot;get&quot; y &quot;set&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section2&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Encapsulamiento en java&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Para ilustrar la programación del principio de encapsulamiento en Java, programaremos una clase Persona con sus atributos: nombre, apellido paterno y apellido paterno. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package Principal;
public class Persona{
    String nombre;
    String apellidoPaterno;
    String apellidoMaterno;
}
&lt;/pre&gt;&lt;br /&gt;
Hasta este punto, la clase Persona se encuentra programada, si queremos usar la clase podemos declarar e inicializar un objeto Persona y asignarle valores a sus atributos. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package Principal;

public class Main {

    public static void main(String[] args) {
        Persona persona = new Persona();
        persona.nombre = &quot;Juan&quot;;
        persona.apellidoPaterno = &quot;Perez&quot;;
        persona.apellidoMaterno = &quot;Perez&quot;;
        System.out.println(&quot;Hola soy un empleado y mi nombre es &quot; + persona.nombre + &quot; &quot; + persona.apellidoPaterno + &quot; &quot; + persona.apellidoMaterno);
    }
}
&lt;/pre&gt;&lt;br /&gt;
Sin embargo, no estamos aplicando el concepto de encapsulamiento. Con el encapsulamiento no se debería tener el acceso directo a los atributos de la clase persona. Nótese que estamos accediendo directamente a los atributos de nuesto objeto persona: persona.nombre, persona.apellidoPaterno y persona.apellidoMaterno.&lt;br /&gt;
&lt;br /&gt;
Ahora, mejoraremos nuestra pequeña clase persona aplicando el encapsulamiento en todos sus atributos implementando métodos para establecer el valor de un atributo, a los cuales nombraremos con el prefijo set; e implementando métodos para devolver el valor de un atributo, a los cuales nombraremos con el prefijo get.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package Principal;
public class Persona{
    private String nombre;
    private String apellidoPaterno;
    private String apellidoMaterno;

    public String getNombre(){
        return this.nombre;
    }

    public String getApellidoPaterno(){
        return this.apellidoPaterno;
    }

    public String getApellidoMaterno(){
        return this.apellidoMaterno;
    }

    public void setNombre(String nombre){
        this.nombre = nombre;
    }

    public void setApellidoPaterno(String apellidoPaterno){
        this.apellidoPaterno = apellidoPaterno;
    }

    public void setApellidoMaterno(String apellidoMaterno){
        this.apellidoMaterno = apellidoMaterno;
    }
}
&lt;/pre&gt;&lt;br /&gt;
Aplicando el encapsulamiento, los atributos de la clase Persona se han convertido en inaccesibles para otros objetos (ya que los hemos marcado como privados usando la palabra reservada private). Ahora para poder acceder a dichos atributos deberemos de usar los métodos get y set que programamos anteriormente.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package Principal;

public class Main {

    public static void main(String[] args) {
        Persona persona = new Persona();
        persona.setNombre(&quot;Juan&quot;);
        persona.setApellidoPaterno(&quot;Perez&quot;);
        persona.setapellidoMaterno(&quot;Perez&quot;);
        System.out.println(&quot;Hola soy un empleado y mi nombre es &quot; + persona.getNombre() + &quot; &quot; + persona.getApellidoPaterno() + &quot; &quot; + persona.getApellidoMaterno());
    }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section3&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Encapsulamiento de objetos en Netbeans&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
El IDE (Entorno integrado de desarrollo) Netbeans ofrece una funcionalidad para realizar el encapsulamiento de objetos de manera automática. Para encapsular los atributos de una clase, abrimos el archivo de la clase a encapsular y damos clic en el menú Refactor/Reestructurar.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjftbwJPiQTnXLD1pifDOyGvi2Aqm-1KaaZg5NgkgGrNU6rr4DWKNiKaHABQbITAhaY1lNSvYdW7WY95foeNjYaoABVV_Kj_FCA7afJ_pgSSwjWlSAmOWEKyUAH5ANygymNeYnyV7IzTms/s1600/Menu+Refactor.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjftbwJPiQTnXLD1pifDOyGvi2Aqm-1KaaZg5NgkgGrNU6rr4DWKNiKaHABQbITAhaY1lNSvYdW7WY95foeNjYaoABVV_Kj_FCA7afJ_pgSSwjWlSAmOWEKyUAH5ANygymNeYnyV7IzTms/s320/Menu+Refactor.png&quot; width=&quot;196&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
En el menú elegimos la opción Encapsulate Fields/Encapsular campos. A continuación nos muestra un cuadro de diálogo con los atributos de la clase, elegimos que atributos deseamos encapsular, especificamos si queremos métodos get o métodos set o ambos, entre otras opciones. Para finalizar damos clic en el botón Refactor/Reestucturar.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBU5zpUe6FFLA3qIxRH8l4OROyhv6D7IEDgEWYYuC67PqzKyva3t519RUPXTppDfTjUFGpnTsUUIATtwpIr2z8ZBuHyCYAhk32S5UVBJyv0pugn-0M7AKPdFvJh3SWqbRvz2Y6rWFF0Ws/s1600/Cuadro+Dialogo+Refactor.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;196&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBU5zpUe6FFLA3qIxRH8l4OROyhv6D7IEDgEWYYuC67PqzKyva3t519RUPXTppDfTjUFGpnTsUUIATtwpIr2z8ZBuHyCYAhk32S5UVBJyv0pugn-0M7AKPdFvJh3SWqbRvz2Y6rWFF0Ws/s320/Cuadro+Dialogo+Refactor.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Fuente: &lt;a href=&quot;http://profesores.fi-b.unam.mx/carlos/java/java_basico3_3.html&quot;&gt; Conceptos de la Programación Orientada a Objetos (OOP) &lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://es.wikipedia.org/wiki/Encapsulamiento_%28inform%C3%A1tica%29&quot;&gt; Encapsulamiento (informática) &lt;/a&gt;&lt;/div&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script language=&#39;javascript&#39;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/9100353647752708507/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2012/04/poo-principio-de-encapsulamiento.html#comment-form' title='1 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/9100353647752708507'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/9100353647752708507'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2012/04/poo-principio-de-encapsulamiento.html' title='POO: Principio de encapsulamiento'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjftbwJPiQTnXLD1pifDOyGvi2Aqm-1KaaZg5NgkgGrNU6rr4DWKNiKaHABQbITAhaY1lNSvYdW7WY95foeNjYaoABVV_Kj_FCA7afJ_pgSSwjWlSAmOWEKyUAH5ANygymNeYnyV7IzTms/s72-c/Menu+Refactor.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-3031303124709521355</id><published>2012-04-08T20:01:00.000-05:00</published><updated>2012-04-08T20:01:00.991-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c"/><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="programacion"/><title type='text'>Diferencias entre C++ y Java</title><content type='html'>&lt;div class=&quot;estilogeneral&quot;&gt;En esta entrada trataremos sobre las diferencias existen entre los lenguajes de&amp;nbsp;programación&amp;nbsp;C/C++ y Java bajo los criterios de orientado a objetos,&amp;nbsp;código&amp;nbsp;de maquina generado, punteros, sobrecarga de funciones y operadores, entre otros.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;Orientado a objetos&lt;/span&gt; &lt;br /&gt;
C++: Se pueden escribir programas orientados a objetos, no orientados a objetos, o una mezcla de ambos.&lt;br /&gt;
Java: Puramente orientado a objetos: cualquier función debe pertenecer a alguna clase. La función main es un método estático de la clase principal.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;Código de máquina generado&lt;/span&gt;&lt;br /&gt;
C++: El compilador genera código de máquina para una plataforma concreta.&lt;br /&gt;
Java: El compilador genera código de máquina (bytecode) para el procesador JVM. Dicho código debe ser interpretado posteriormente para su ejecucion.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;Punteros&lt;/span&gt;&lt;br /&gt;
C++: Existen punteros con una aritmética bien definida, y entre otras cosas, permiten programador explorar la memoria del computador físico.&lt;br /&gt;
Java: No existe el concepto de puntero; los objetos son accedidos mediante referencias (una referencia se puede considerar como el propio identificador del objeto). No existe aritmética de referencias.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;Sobrecarga de funciones y operadores&lt;/span&gt;&lt;br /&gt;
C++: Existen ambos tipos de sobrecarga.&lt;br /&gt;
Java: Sólo existe la sobrecarga de funciones (métodos). Los operadores que existen ya vienen sobrecargados por el compilador como por el ejemplo el operador &quot;+&quot; para sumar números o concatenar cadenas.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;Objetos&lt;/span&gt;&lt;br /&gt;
C++: Ningún ancestro común.&lt;br /&gt;
Java: Todos los objetos heredan automáticamente de la clase Object.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/3031303124709521355/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2012/04/diferencias-entre-c-y-java.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/3031303124709521355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/3031303124709521355'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2012/04/diferencias-entre-c-y-java.html' title='Diferencias entre C++ y Java'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-149823888894923717</id><published>2012-04-04T08:01:00.000-05:00</published><updated>2012-04-04T08:01:22.763-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="compilacion"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="programacion"/><title type='text'>El Proceso de compilación en Java</title><content type='html'>&lt;div class=&quot;estilogeneral&quot; style=&quot;text-align: justify;&quot;&gt;Los programas Java no son ejecutables, es decir que no se compilan como los programas en C o C++. En su lugar, son interpretados por una aplicación conocida como la máquina virtual de Java (JVM). Gracias a ello no tienen porque incluir todo el código y librerías propias de cada sistema.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Previamente el código fuente en Java se tiene que precompilar generando un código (que no es directamente ejecutable) previo conocido como bytecode o J-code. Ese código (generado normalmente en archivos con extensión .class) es el que es ejecutado por la máquina virtual de Java que interpreta las instrucciones de los bytecodes, ejecutando el código de la aplicación. Por esta razón, podemos decir que Java es híbrido, porque es compilado e interpretado a la vez.&lt;br /&gt;
&lt;br /&gt;
El bytecode se puede ejecutar en cualquier plataforma, lo único que se requiere es que esa plataforma posea un intérprete adecuado (la máquina virtual específica para esa plataforma). La máquina virtual de Java, además es un programa muy pequeño y que se distribuye gratuitamente para prácticamente todos los sistemas operativos como Windows, Mac OS y Unix/Linux. Si deseamos poder ejecutar aplicaciones Java en nuestra computadora podemos descargar el Java Runtime Enviroment (JRE), en cambio si deseamos también programar y compilar nuestros propios archivos escritos en Java debemos de descargar el Java Developer Kit (JDK). En el JDK viene incluido el JRE.&lt;br /&gt;
&lt;br /&gt;
En Java la unidad fundamental del código es la clase. Son las clases las que se distribuyen en el formato bytecode de Java y éstas se cargan dinámicamente durante la ejecución del programa Java.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinlosWFsPtOUwWkJHmb2MBMToEguXUjgGj7ox-7xu4vLdkFvSoPp6RB8BRqNO3GoB9Ci2ld01ttFMEPTOT7K2VtqJidUcUfWa5tG0haLIeD2osOPjn2suUtubpQ4Cl4Lfi3qic2ziWOR0/s400/proceso.bmp&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;117&quot; width=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinlosWFsPtOUwWkJHmb2MBMToEguXUjgGj7ox-7xu4vLdkFvSoPp6RB8BRqNO3GoB9Ci2ld01ttFMEPTOT7K2VtqJidUcUfWa5tG0haLIeD2osOPjn2suUtubpQ4Cl4Lfi3qic2ziWOR0/s400/proceso.bmp&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Fuente: &lt;a href=&quot;http://prograbasicajava.blogspot.com/2009/04/proceso-compilacion-programa-java.html&quot;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/149823888894923717/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2012/04/el-proceso-de-compilacion-en-java.html#comment-form' title='1 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/149823888894923717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/149823888894923717'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2012/04/el-proceso-de-compilacion-en-java.html' title='El Proceso de compilación en Java'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinlosWFsPtOUwWkJHmb2MBMToEguXUjgGj7ox-7xu4vLdkFvSoPp6RB8BRqNO3GoB9Ci2ld01ttFMEPTOT7K2VtqJidUcUfWa5tG0haLIeD2osOPjn2suUtubpQ4Cl4Lfi3qic2ziWOR0/s72-c/proceso.bmp" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-6239675760286568787</id><published>2012-04-02T13:22:00.000-05:00</published><updated>2012-04-02T13:22:45.696-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><title type='text'>POO: Características de Java</title><content type='html'>&lt;div class=&quot;estilogeneral&quot;&gt;En esta entrada dejo una presentación sobre las características de Java como lenguaje de programación.  &lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;prezi-player&quot;&gt;&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;.prezi-player { width: 550px; } .prezi-player-links { text-align: center; }&lt;/style&gt;&lt;object id=&quot;prezi_suue0qlnwxtp&quot; name=&quot;prezi_suue0qlnwxtp&quot; classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; width=&quot;550&quot; height=&quot;400&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://prezi.com/bin/preziloader.swf&quot;/&gt;&lt;param name=&quot;allowfullscreen&quot; value=&quot;true&quot;/&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;/&gt;&lt;param name=&quot;bgcolor&quot; value=&quot;#ffffff&quot;/&gt;&lt;param name=&quot;flashvars&quot; value=&quot;prezi_id=suue0qlnwxtp&amp;amp;lock_to_path=0&amp;amp;color=ffffff&amp;amp;autoplay=no&amp;amp;autohide_ctrls=0&quot;/&gt;&lt;embed id=&quot;preziEmbed_suue0qlnwxtp&quot; name=&quot;preziEmbed_suue0qlnwxtp&quot; src=&quot;http://prezi.com/bin/preziloader.swf&quot; type=&quot;application/x-shockwave-flash&quot; allowfullscreen=&quot;true&quot; allowscriptaccess=&quot;always&quot; width=&quot;550&quot; height=&quot;400&quot; bgcolor=&quot;#ffffff&quot; flashvars=&quot;prezi_id=suue0qlnwxtp&amp;amp;lock_to_path=0&amp;amp;color=ffffff&amp;amp;autoplay=no&amp;amp;autohide_ctrls=0&quot;&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div class=&quot;prezi-player-links&quot;&gt;&lt;p&gt;&lt;a title=&quot;Características de Java&quot; href=&quot;http://prezi.com/suue0qlnwxtp/caracteristicas-de-java/&quot;&gt;Características de Java&lt;/a&gt; on &lt;a href=&quot;http://prezi.com&quot;&gt;Prezi&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/6239675760286568787/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2012/04/poo-caracteristicas-de-java.html#comment-form' title='1 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/6239675760286568787'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/6239675760286568787'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2012/04/poo-caracteristicas-de-java.html' title='POO: Características de Java'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-3686433876537455730</id><published>2011-12-26T16:42:00.000-05:00</published><updated>2011-12-26T16:42:13.993-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="herramientas"/><category scheme="http://www.blogger.com/atom/ns#" term="prezi"/><title type='text'>Prezi: Una nueva forma de hacer presentaciones</title><content type='html'>&lt;div class=&quot;estilogeneral&quot;&gt;&lt;div style=&quot;text-align: justify&quot;&gt;En esta entrada trataremos sobre Prezi, una herramienta que permite crear presentaciones en Flash de manera rápida e innovadora.&lt;br /&gt;
&lt;br /&gt;
Sobre el licenciamiento, Prezi cuenta 3 tipos de licencia: una gratis y dos pagadas. La versión gratis permite crear presentaciones en Prezi a través de Internet almacenando hasta 100 MB y permite descargar tus presentaciones para reproducirlas sin necesidad de tener una conexión a Internet. Todas tus presentaciones en Prezi creadas con una licencia gratuita son de acceso publico a toda la comunidad Prezi y si lo deseas, puedes hacer que los usuarios puedan guardar una copia de tus presentaciones para ellos mismos. Las versiones pagadas ofrecen almacenamiento a partir de 500 MB y nuevas características como crear Prezis privados, cambiar el logo de Prezi en las presentaciones por el logo de tu elección y crear Prezis sin necesidad de Internet a través de una aplicación de escritorio. Puedes encontrar licencias pagadas desde $59.00 anual.&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
Les dejo un ejemplo de una presentación en Prezi.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div class=&quot;prezi-player&quot;&gt;&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;.prezi-player { width: 550px; } .prezi-player-links { text-align: center; }&lt;/style&gt;&lt;object id=&quot;prezi_ftv9hvziwqi2&quot; name=&quot;prezi_ftv9hvziwqi2&quot; classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; width=&quot;550&quot; height=&quot;400&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://prezi.com/bin/preziloader.swf&quot;/&gt;&lt;param name=&quot;allowfullscreen&quot; value=&quot;true&quot;/&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;/&gt;&lt;param name=&quot;bgcolor&quot; value=&quot;#ffffff&quot;/&gt;&lt;param name=&quot;flashvars&quot; value=&quot;prezi_id=ftv9hvziwqi2&amp;amp;lock_to_path=1&amp;amp;color=ffffff&amp;amp;autoplay=no&amp;amp;autohide_ctrls=0&quot;/&gt;&lt;embed id=&quot;preziEmbed_ftv9hvziwqi2&quot; name=&quot;preziEmbed_ftv9hvziwqi2&quot; src=&quot;http://prezi.com/bin/preziloader.swf&quot; type=&quot;application/x-shockwave-flash&quot; allowfullscreen=&quot;true&quot; allowscriptaccess=&quot;always&quot; width=&quot;550&quot; height=&quot;400&quot; bgcolor=&quot;#ffffff&quot; flashvars=&quot;prezi_id=ftv9hvziwqi2&amp;amp;lock_to_path=1&amp;amp;color=ffffff&amp;amp;autoplay=no&amp;amp;autohide_ctrls=0&quot;&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div class=&quot;prezi-player-links&quot;&gt;&lt;p&gt;&lt;a title=&quot;Coca Cola Company&quot; href=&quot;http://prezi.com/ftv9hvziwqi2/coca-cola-company/&quot;&gt;Coca Cola Company&lt;/a&gt; on &lt;a href=&quot;http://prezi.com&quot;&gt;Prezi&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
Fuente: &lt;a href=&quot;http://prezi.com&quot;&gt;Prezi&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/3686433876537455730/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2011/12/prezi-una-nueva-forma-de-hacer.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/3686433876537455730'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/3686433876537455730'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2011/12/prezi-una-nueva-forma-de-hacer.html' title='Prezi: Una nueva forma de hacer presentaciones'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-68304940987244803</id><published>2011-12-18T13:01:00.001-05:00</published><updated>2013-06-10T12:23:31.331-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programacion"/><category scheme="http://www.blogger.com/atom/ns#" term="prolog"/><title type='text'>Árbol Genealógico en Prolog</title><content type='html'>&lt;div class=&quot;estilogeneral&quot; style=&quot;text-align: justify;&quot;&gt;En esta entrada trataremos sobre la representación de un árbol genealógico en prolog mediante un ejemplo del árbol de la familia Gonzales. Luego, codificaremos los hechos en Prolog, especificando quien es padre de quien y quien es madre de quien, según se representa en el árbol genealógico y a partir de estas relaciones podremos codificar functores que expresen las demás relaciones de parentesco en la familia.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;La familia Gonzales&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
A continuación, presentamos el árbol genealógico de la familia Gonzales &lt;b&gt;(clic en la imagen para agrandar).&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3KCmBZ-ptwI8zoD1ANnRNQYyjC1gTZrDmNooC7gUTNacvdxqymubF0Lzuj0WpOYbkRCfffk-PyUuToamsvrAbKbPD0oaE-RM6DRNnYR1p4ND9OjdH0zBSeIY77Kw_LOXUFkB9iLW_SZY/s1600/Familia+Gonzales.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;111&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3KCmBZ-ptwI8zoD1ANnRNQYyjC1gTZrDmNooC7gUTNacvdxqymubF0Lzuj0WpOYbkRCfffk-PyUuToamsvrAbKbPD0oaE-RM6DRNnYR1p4ND9OjdH0zBSeIY77Kw_LOXUFkB9iLW_SZY/s320/Familia+Gonzales.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt; Codificación en Prolog&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;% Hechos
esMadreDe(sara, jorge).
esMadreDe(sara, gonzalo).
esMadreDe(sara, lucia).
esMadreDe(lucia, jose).
esMadreDe(lucha, martin).
esMadreDe(daniela, ana).
esMadreDe(daniela, miguel).
esMadreDe(carmen, dora).
esMadreDe(carmen, enrique).
esPadreDe(manuel, gonzalo).
esPadreDe(manuel, lucia).
esPadreDe(manuel, fernando).
esPadreDe(jorge, martin).
esPadreDe(jorge, francisco).
esPadreDe(gonzalo, ana).
esPadreDe(gonzalo, miguel).
esPadreDe(fernando, dora).
esPadreDe(fernando, enrique).

% Reglas
esAbuelaDe(A,B) :-
 esMadreDe(A, N),
 esMadreDe(N, B).
esAbuelaDe(A,B) :-
 esPadreDe(A, N),
 esPadreDe(N, B).
esAbuelaDe(A,B) :-
 esPadreDe(A, N),
 esMadreDe(N, B).
esAbuelaDe(A,B) :-
 esMadreDe(A, N),
 esPadreDe(N, B).
esNietoDe(A, B) :-
 esAbuelaDe(B, A).
esHermanoDe(A, B) :-
 esMadreDe(N, A),
 esMadreDe(N, B),
 not(A=B).
esHermanoDe(A, B) :-
 esPadreDe(N, A),
 esPadreDe(N, B),
 not(A=B).
esSobrinoDe(A, B) :-
 esHermanoDe(N, A),
 esMadreDe(N, B).
esSobrinoDe(A, B) :-
 esHermanoDe(N, A),
 esPadreDe(N, B).
esTioDe(A, B) :-
 esSobrinoDe(B, A).
esPrimoDe(A, B) :-
 esTioDe(A, N),
 esMadreDe(N, B),
 not(A=B).
esPrimoDe(A, B) :-
 esTioDe(A, N),
 esPadreDe(N, B),
 not(A=B).
&lt;/pre&gt;&lt;br /&gt;
Como podemos observar, a partir de los hechos obtenidos del árbol genealógico (relaciones de paternidad &quot;EsPadreDe&quot; y &quot;EsMadreDe&quot;, podemos inferir todas las demás relaciones de parentesco como abuelo, primo, tío, nieto, hermano entre otros.&lt;br /&gt;
&lt;/div&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script language=&#39;javascript&#39;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/68304940987244803/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2011/12/arbol-genealogico-en-prolog.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/68304940987244803'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/68304940987244803'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2011/12/arbol-genealogico-en-prolog.html' title='Árbol Genealógico en Prolog'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3KCmBZ-ptwI8zoD1ANnRNQYyjC1gTZrDmNooC7gUTNacvdxqymubF0Lzuj0WpOYbkRCfffk-PyUuToamsvrAbKbPD0oaE-RM6DRNnYR1p4ND9OjdH0zBSeIY77Kw_LOXUFkB9iLW_SZY/s72-c/Familia+Gonzales.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-5075554281762001767</id><published>2011-12-15T11:42:00.003-05:00</published><updated>2013-06-10T12:24:05.033-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programacion"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Ejercicios con listas en Scheme</title><content type='html'>&lt;div class=&quot;estilogeneral&quot;&gt;En esta entrada resolveremos algunos ejercicios con listas en Scheme.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;Contenido&lt;/span&gt;  &lt;br /&gt;
&lt;ol class=&quot;indice&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/12/ejercicios-con-listas-en-scheme.html#section1&quot;&gt;Concatenar dos listas&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/12/ejercicios-con-listas-en-scheme.html#section2&quot;&gt;Invertir una lista&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/12/ejercicios-con-listas-en-scheme.html#section3&quot;&gt;Elementos comunes de dos listas&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/12/ejercicios-con-listas-en-scheme.html#section4&quot;&gt;Eliminar un numero de una lista&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/12/ejercicios-con-listas-en-scheme.html#section5&quot;&gt;Diferencia de dos listas&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/12/ejercicios-con-listas-en-scheme.html#section6&quot;&gt;Intercalar elementos de dos listas&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/12/ejercicios-con-listas-en-scheme.html#section7&quot;&gt;Reemplazar elementos en una lista&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/12/ejercicios-con-listas-en-scheme.html#section8&quot;&gt;Colocar un elemento al final de una lista&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section1&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Concatenar dos listas&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Implemente una funcion que dadas dos listas, devuelva su concatenacion. No utilice la funcion append.&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;(define concatena (lambda (X Y)
                    (if (null? X)
                        Y
                        (cons (car X) (concatena (cdr X) Y))
                    )
                    ))
&lt;/pre&gt;&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section2&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Invertir una lista&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Hacer una funcion que invierta una lista&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;(define invierte (lambda (L1 L2)
  (if (null? L1)
   L2
   (invierte (cdr L1) (cons (car L1) L2)
  )
))
&lt;/pre&gt;&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section3&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Elementos comunes de dos listas&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Dada dos listas, devolver una lista con sus elementos comunes.&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;(define comunes (lambda (L1 L2)
                  (if (null? L1)
                      &#39;()
                      (if (null? (busca (car L1) L2))
                          (comunes (cdr L1) L2)
                          (cons (car L1) (comunes (cdr L1) (cdr L2)))
                      )
                  )
                  ))

(define busca (lambda (x L)
                (if (null? L)
                    &#39;()
                    (if (= (car L) x)
                        (cons x (busca x (cdr L)))
                        (busca x (cdr L))
                    )
                )
                ))
&lt;/pre&gt;&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section4&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Eliminar un numero de una lista&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Elimine un numero de una lista&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;(define elimina (lambda (L x)
                  (if (null? L)
                      &#39;()
                      (if (= (car L) x)
                          (elimina (cdr L) x)
                          (cons (car L) (elimina (cdr L) x))
                      )
                  )
              ))
&lt;/pre&gt;&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section5&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Diferencia de dos listas&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Hacer un programa que dada dos listas A y B devuelve la diferencia en el sentido de conjuntos (A-B).(A-B) son todos los elementos de A que no tiene B&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;(define diferencia (lambda (A B)
                     (if (null? A)
                         &#39;()
                         (if (null? (busca (car A) B))
                             (cons (car A) (diferencia (cdr A) B))
                             (diferencia (cdr A) B)
                         )
                     )
                 ))
&lt;/pre&gt;&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section6&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Intercalar elementos de dos listas&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Hacer un programa que dadas dos listas intercale sus elementos.&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;(define intercala (lambda (A B)
                    (if (AND (null? A) (null? B))
                        &#39;()
                        (if (null? A)
                            (cons (car B) (intercala A (cdr B)))
                            (cons (car A) (intercala B (cdr A)))
                        )
                    )
                ))
&lt;/pre&gt;&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section7&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Reemplazar elementos en una lista&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Dada una lista y dos numeros x e y, Reemplace todos las ocurrencias de x en la lista por y.&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;(define reemplaza (lambda (L x y)
                    (if (null? L)
                        &#39;()
                        (if(= (car L) x)
                           (cons y (reemplaza (cdr L) x y))
                           (cons (car L) (reemplaza (cdr L) x y))
                        )
                    )
                    ))
&lt;/pre&gt;&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section8&quot; style=&quot;text-decoration: none;&quot;&gt;&lt;b&gt;Colocar un elemento al final de una lista&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Dada una lista y un numero x, colocar x al final de la lista.&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;(define poninicio (lambda (L y)
                    (if (null? L)
                        (cons y L)
                        (cons (car L) (poninicio (cdr L) y))
                    )
                    ))
&lt;/pre&gt;&lt;/div&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script language=&#39;javascript&#39;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/5075554281762001767/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2011/12/ejercicios-con-listas-en-scheme.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/5075554281762001767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/5075554281762001767'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2011/12/ejercicios-con-listas-en-scheme.html' title='Ejercicios con listas en Scheme'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-3893013416867140654</id><published>2011-11-09T10:17:00.003-05:00</published><updated>2013-06-10T12:24:11.737-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c#"/><category scheme="http://www.blogger.com/atom/ns#" term="poo"/><category scheme="http://www.blogger.com/atom/ns#" term="programacion"/><title type='text'>Ejemplos de polimorfismo en C#</title><content type='html'>&lt;div class=&quot;estilogeneral&quot; style=&quot;text-align: justify&quot;&gt;En esta entrada trataremos sobre el concepto del polimorfismo y daremos unos ejemplos.  &lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;Contenido&lt;/span&gt;  &lt;br /&gt;
&lt;ol class=&quot;indice&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/ejemplos-de-polimorfismo.html#section1&quot;&gt;Polimorfismo usando clases&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/ejemplos-de-polimorfismo.html#section2&quot;&gt;Polimorfismo usando interfaces&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;El polimorfismo se refiere a la posibilidad de definir múltiples clases con funcionalidad diferente, pero con métodos o propiedades denominados de forma idéntica.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section1&quot; style=&quot;text-decoration: none;&quot;&gt;Polimorfismo usando clases&lt;/a&gt;&lt;/span&gt;  &lt;br /&gt;
&lt;br /&gt;
Por ejemplo, tenemos una clase Empleado y otra clase Alumno, las cuales heredan de una clase abstracta Persona que tiene el metodo Saludar. En las clases hijas sobreescribiremos el metodo Saludar devolviendo el nombre de la persona y si es un empleado o un alumno.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;namespace notasensistemas.blogspot.com
{
    public abstract class Persona
    {
        public string Nombre { get; set; }

        public abstract string Saludar();
    }
    public class Alumno : Persona
    {
        public Alumno(string nombre)
        {
            this.Nombre = nombre;
        }
        public override string Saludar()
        {
            string saludo = &quot;Hola, mi nombre es &quot; + this.Nombre + &quot; y soy un alumno&quot;;
            return saludo;
        }
    }
    public class Empleado : Persona
    {
        public Empleado(string nombre)
        {
            this.Nombre = nombre;
        }
        public override string Saludar()
        {
            string saludo = &quot;Hola, mi nombre es &quot; + this.Nombre + &quot; y soy un empleado&quot;;
            return saludo;
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
En vez de tener un arreglo de empleados y otro de alumnos por separado, usaremos el polimorfismo con un solo arreglo de personas, al cual agregaremos un alumno y un empleado para luego iterar y llamar al metodo saludar.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;Persona[] personas = new Persona[2];
personas[0] = new Alumno(&quot;Jaime Correa&quot;);
personas[1] = new Empleado(&quot;Juan Perez&quot;);
for (int i = 0; i &amp;lt; personas.Length; i++)
{
     Console.WriteLine(personas[i].Saludar());
}
&lt;/pre&gt;El resultado es el siguiente:  &lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;Hola, mi nombre es Jaime Correa y soy un alumno
Hola, mi nombre es Juan Perez y soy un alumno
&lt;/pre&gt;Como podemos observar, a pesar de que tengamos un unico arreglo de objetos de tipo persona, cuando llamamos al metodo saludar, los objetos se comportan como un objeto de tipo alumno o un objeto de tipo empleado.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;&lt;a name=&quot;section2&quot; style=&quot;text-decoration: none;&quot;&gt;Polimorfismo usando interfaces&lt;/a&gt;&lt;/span&gt;   &lt;br /&gt;
&lt;br /&gt;
De la misma manera que en el ejemplo anterior, en vez de usar una clase padre Persona de la cual heredan las clases hijas Empleado y Alumno podemos definir una interfaz IPersona que defina el metodo Despedirse, y que las clases Empleado y Alumno implementen la interfaz IPersona.  &lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;public interface IPersona
    {
        String Despedirse();
    }
    public class Alumno : IPersona
    {
        public Alumno(string nombre)
        {
            this.Nombre = nombre;
        }
        public string Despedirse()
        {
            string adios = &quot;El alumno &quot; + this.Nombre + &quot; se despide cordialmente&quot;;
            return adios;
        }
    }
    public class Empleado : IPersona
    {
        public Empleado(string nombre)
        {
            this.Nombre = nombre;
        }
        public string Despedirse()
        {
            string adios = &quot;El empleado &quot; + this.Nombre + &quot; se despide cordialmente&quot;;
            return adios;
        }
    }
&lt;/pre&gt;De la misma manera que en el ejemplo anterior, podemos instanciar un arreglo de tipo IPersona, agregar objetos que implementen la interfaz IPersona: un objeto alumno o un objeto empleado, para luego iterar y llamar al metodo Despedirse.  &lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;IPersona[] personas = new IPersona[2];
personas[0] = new Alumno(&quot;Jaime Correa&quot;);
personas[1] = new Empleado(&quot;Juan Perez&quot;);
for (int i = 0; i &amp;lt; personas.Length; i++)
{
    Console.WriteLine(personas[i].Despedirse());
}
&lt;/pre&gt;El resultado es el siguiente:  &lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;El alumno Jaime Correa se despide cordialmente
El empleado Juan Perez se despide cordialmente
&lt;/pre&gt;&lt;br /&gt;
Fuente: &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/z165t2xk%28v=vs.80%29.aspx&quot; target=&quot;_blank&quot;&gt;Polymorphism&lt;/a&gt;&lt;/div&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script language=&#39;javascript&#39;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/3893013416867140654/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2011/10/ejemplos-de-polimorfismo.html#comment-form' title='6 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/3893013416867140654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/3893013416867140654'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2011/10/ejemplos-de-polimorfismo.html' title='Ejemplos de polimorfismo en C#'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-1447221994892075846</id><published>2011-11-03T11:49:00.002-05:00</published><updated>2011-12-15T12:15:56.570-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="gliffy"/><category scheme="http://www.blogger.com/atom/ns#" term="herramientas"/><category scheme="http://www.blogger.com/atom/ns#" term="modelado"/><title type='text'>Gliffy: Modela Diagramas en la Web</title><content type='html'>&lt;div class=&quot;estilogeneral&quot;&gt;&lt;div style=&quot;text-align:justify&quot;&gt;Navegando por Internet me encontré con &lt;a href=&quot;http://www.gliffy.com/&quot; target=&quot;_blank&quot;&gt;Gliffy&lt;/a&gt;, el cual es una herramienta para crear diagramas en Internet. Gliffy ofrece una variedad de diagramas para sus usuarios como diagramas de Venn, diagramas de red, diagramas FODA, organigramas, diagramas de clase, diagramas de procesos, diagramas para esquematizar sitios web entre otros.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
No es necesario registrarse o comprar el producto para empezar a modelar y probar el producto, basta con entrar al sitio y puedes empezar a usarlo. Gliffy ofrece diferentes planes y productos. La solución online permite diseñar tus modelos desde la web, eliminando la necesidad de instalar software en tu computadora para diseñar tus modelos.&lt;br /&gt;
&lt;br /&gt;
Gliffy cuenta con planes pagados desde $4.95 al mes ofreciendo 200 MB de espacio para que guardes hasta 200 diagramas en Internet. Alternativamente, ofrece también un plan gratis con 2 MB de espacio y puedes tener hasta 5 diagramas con la restricción de que los diagramas que guardes son de acceso público a todos los usuarios de Gliffy.&lt;br /&gt;
&lt;br /&gt;
Para terminar, les dejo un video en inglés introductorio sobre Gliffy:&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;object class=&quot;BLOGGER-youtube-video&quot; classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; codebase=&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0&quot; data-thumbnail-src=&quot;http://1.gvt0.com/vi/4FKMu2vT_PU/0.jpg&quot; height=&quot;266&quot; width=&quot;320&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/4FKMu2vT_PU&amp;fs=1&amp;source=uds&quot; /&gt;&lt;param name=&quot;bgcolor&quot; value=&quot;#FFFFFF&quot; /&gt;&lt;embed width=&quot;320&quot; height=&quot;266&quot;  src=&quot;http://www.youtube.com/v/4FKMu2vT_PU&amp;fs=1&amp;source=uds&quot; type=&quot;application/x-shockwave-flash&quot;&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;br /&gt;
Fuente: &lt;a href=&quot;http://www.gliffy.com/&quot;&gt;Gliffy&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/1447221994892075846/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2011/11/gliffy-modela-diagramas-en-la-web.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/1447221994892075846'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/1447221994892075846'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2011/11/gliffy-modela-diagramas-en-la-web.html' title='Gliffy: Modela Diagramas en la Web'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-6203799854848832584</id><published>2011-10-19T23:29:00.006-05:00</published><updated>2013-06-10T12:24:34.628-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c#"/><category scheme="http://www.blogger.com/atom/ns#" term="programacion"/><title type='text'>Tecnicas de caché en C#</title><content type='html'>&lt;div class=&quot;estilogeneral&quot;&gt;En esta entrada hablaremos sobre como implementar tecnicas de caché en C#.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Segun &lt;a href=&quot;http://es.wikipedia.org/wiki/Cach%C3%A9_%28inform%C3%A1tica%29&quot;&gt;Wikipedia&lt;/a&gt;&lt;br /&gt;
&lt;blockquote&gt;&quot;La caché es una memoria más pequeña y rápida, la cual almacena copias de datos ubicados en la memoria principal que se utilizan con más frecuencia.&lt;br /&gt;
&lt;br /&gt;
[...]Cuando se necesita leer o escribir en una ubicación en memoria principal, primero verifica si una copia de los datos está en la caché. Si es así, de inmediato lee o escribe en la memoria caché, que es mucho más rápido que de la lectura o la escritura a la memoria principal&quot;&lt;/blockquote&gt;&lt;br /&gt;
De este extracto queda claro que la caché es una memoria secundaria cuyo acceso es mas rapido que el de la memoria principal.&amp;nbsp;Sin embargo, hay que tener&amp;nbsp;en cuenta que &lt;b&gt;si bien es cierto que la implementacion del caché trae las ventajas mencionadas anteriormente, tambien trae riesgos a la hora de implementarlo en un ambiente de produccion&lt;/b&gt;. Esto es debido a que el caché tambien gasta recursos de memoria y tiempo de procesamiento, y si se hace un  abuso del mismo se reduce la performance de nuestras aplicaciones.&lt;br /&gt;
&lt;br /&gt;
Hablando en codigo, una implementacion de caché puede ser tan sencillo como implementar una tabla hash o un diccionario, hasta tan complicado como nuestro ingenio e imaginacion nos puedan llevar. En este ejemplo, presentaremos una clase Persona, y una clase CachePersona la cual se encargara de agregar, actualizar, listar, eliminar y comprobar la existencia de registros de la clase Persona.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Nota: La tecnica de caché presentada es un ejemplo basico de caracter ilustrativo. El proposito de este ejemplo es dar una introduccion acerca de las tecnicas de caché y como se implementan en el desarrollo de aplicativos.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;La Clase Persona&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;public class Persona
    {
        public int Codigo { get; set; }
        public String Nombre { get; set; }
        public String Apellidos { get; set; }
    }
&lt;/pre&gt;&lt;br /&gt;
&lt;span class=&quot;titulo&quot;&gt;La Clase CachePersona&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;public class CachePersona
    {
        Dictionary&amp;lt;int, Persona&gt; diccionario;
        public CachePersona()
        {
            diccionario = new Dictionary&amp;lt;int, Persona&gt;();
        }
        public Boolean ExisteEnCache(int Codigo)
        {
            return diccionario.ContainsKey(Codigo);
        }
        public void AgregarAlCache(Persona persona)
        {
            if (!ExisteEnCache(persona.Codigo))
            {
                diccionario.Add(persona.Codigo, persona);
            }
        }
        public Persona[] ListarCache()
        {
            Persona[] personas = new Persona[diccionario.Count];
            int[] codigos = diccionario.Keys.ToArray&amp;lt;int&gt;();
            for (int i = 0; i &amp;lt; codigos.Length; i++)
            {
                Int32 x = codigos[i];
                personas[i] = diccionario[x];
            }
            return personas;
        }
        public void EliminarDelCache(int codigo)
        {
            if (ExisteEnCache(codigo))
                diccionario.Remove(codigo);
        }
        public void VaciarCache()
        {
            diccionario.Clear();
        }
    }
&lt;/pre&gt;Como podemos observar tenemos la clase Persona que tiene los atributos Codigo, Nombre y Apellidos. Y tenemos la clase CachePersona que maneja el caché de los objetos de tipo Persona. Esta clase internamente contiene un diccionario y expone las operaciones: ExisteEnCache para verificar si un objeto de tipo persona existe en el caché, AgregarAlCache para agregar un nuevo objeto de tipo persona al caché, ListarCache que devuelve todos los objetos de tipo persona que se encuentran en caché, EliminarDelCache que elimina un objeto de tipo persona del caché segun su codigo y VaciarCache para limpiar el caché.  Para hacer uso del caché simplemente instanciamos un objeto de tipo CachePersona y hacemos uso de las operaciones de la clase.  &lt;br /&gt;
&lt;br /&gt;
Fuentes: &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa478965.aspx&quot; target=&quot;_blank&quot;&gt;Caching: Techniques and Best Practices&lt;/a&gt; &lt;br /&gt;
&lt;a href=&quot;http://es.wikipedia.org/wiki/Cach%C3%A9_%28inform%C3%A1tica%29&quot; target=&quot;_blank&quot;&gt;Caché (informatica)&lt;/a&gt; &lt;/div&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;
&lt;script language=&#39;javascript&#39;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/6203799854848832584/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2011/10/tecnicas-de-cache-en-c.html#comment-form' title='1 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/6203799854848832584'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/6203799854848832584'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2011/10/tecnicas-de-cache-en-c.html' title='Tecnicas de caché en C#'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-5109326896370607749</id><published>2011-10-11T16:37:00.005-05:00</published><updated>2011-10-12T15:03:11.146-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="cisco"/><category scheme="http://www.blogger.com/atom/ns#" term="configuracion switch"/><category scheme="http://www.blogger.com/atom/ns#" term="configuracion vlan"/><category scheme="http://www.blogger.com/atom/ns#" term="redes"/><category scheme="http://www.blogger.com/atom/ns#" term="vtp"/><title type='text'>Configuracion de VLANs con VTP</title><content type='html'>&lt;div style=&quot;font-family: Verdana,sans-serif; font-style: small; text-align: justify;&quot;&gt;&lt;br /&gt;
En esta entrada trataremos sobre cómo configurar VLANs en switches Cisco usando el protocolo VTP. Como vimos en la entrada&amp;nbsp;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/09/creacion-de-vlans-en-switches-cisco.html&quot;&gt;Creacion de VLANs en Switches Cisco&lt;/a&gt; podemos implementar muchas VLANs en un switch Cisco, pero ¿qué sucede cuando queremos implementar VLANs pero tenemos más de un switch en nuestra red? La respuesta es que debemos crear las VLANs una por una en cada Switch Cisco de nuestra red. Ahora imagine si tenemos una red con 20 switches: nuestro trabajo sería demasiado extenso y tedioso. Una solución a este problema es usar VTP.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
VTP (VLAN Trunk Protocol) es un protocolo propietario de Cisco que reduce la carga administrativa en la configuración de switches Cisco porque solamente configuramos las VLANs en un switch servidor (llamado VTP server) el cual se encargara de distribuir dicha configuracion a todos los demás switches clientes (llamados VTP client) que se encuentren en un mismo dominio administrativo (VTP domain).&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQswJg4J537Dq6wIpo2cv41Dqyzbz1oEhI-PM0mquqVwTel6NpFHFgJ38dUpdwhf71LAsxIvzx2tBdslZtLS_MSVsnLD-7XtF2hEW9l7J9ASVvpBQW7B-6RfNyYH7Hm8q4xALFswcHTqs/s1600/Configuracion+VTP.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;156&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQswJg4J537Dq6wIpo2cv41Dqyzbz1oEhI-PM0mquqVwTel6NpFHFgJ38dUpdwhf71LAsxIvzx2tBdslZtLS_MSVsnLD-7XtF2hEW9l7J9ASVvpBQW7B-6RfNyYH7Hm8q4xALFswcHTqs/s320/Configuracion+VTP.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
En este ejemplo, vamos a configurar 3 switches Cisco usando el protocolo VTP, los cuales se encontrarán en el dominio administrativo &quot;apuntes&quot;. El switch S1 va a ser el servidor VTP en el cual configuraremos las VLANs. Este switch servidor se encargará de replicar la configuración de las VLANs a nuestros switches S2 y S3 que son los clientes VTP.&lt;br /&gt;
&lt;br /&gt;
El comando para establecer el dominio administrativo es &lt;b&gt;vtp domain [nombre_dominio]&lt;/b&gt; donde [nombre_dominio] es el nombre del dominio administrativo. Para nuestro ejemplo nuestro dominio se llamará &quot;apuntes&quot;. El comando para asignar el modo VTP es &lt;b&gt;vtp [modo]&lt;/b&gt; donde [modo] es el modo que le vamos a asignar al equipo el cual puede ser &lt;b&gt;server &lt;/b&gt;para servidor o &lt;b&gt;client &lt;/b&gt;para cliente. Además existe un tercer modo llamado &lt;b&gt;transparent &lt;/b&gt;el cual sirve cuando deseamos que algún equipo no implemente el protocolo VTP.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Nota: En otras versiones de switches Cisco el comando para asignar el modo es vtp mode [modo], donde [modo] es el modo que le vamos a asignar al equipo (server, client o transparent).&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large; font-weight: bold;&quot;&gt;Contenido&lt;/span&gt;&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/configuracion-de-vlans-con-vtp.html#section1&quot;&gt;Configuracion de S2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/configuracion-de-vlans-con-vtp.html#section2&quot;&gt;Configuracion de S3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/configuracion-de-vlans-con-vtp.html#section3&quot;&gt;Configuracion de S1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/configuracion-de-vlans-con-vtp.html#section4&quot;&gt;Configurar las VLANs en el servidor VTP&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large; font-weight: bold;&quot;&gt;&lt;a name=&quot;section1&quot; style=&quot;text-decoration: none;&quot;&gt;Configuracion de S2&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Para el switch S2, configuraremos sus interfaces Fast Ethernet Fa0/1 y Fa0/2 en modo troncal como se ve en el diagrama de red presentado anteriormente y lo configuramos en modo cliente VTP.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Switch&amp;gt;enable&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Switch#configure terminal&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Switch(config)#hostname S2&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S2(config)#interface fa 0/1&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S2(config-if)#switchport mode trunk&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S2(config-if)#no shutdown&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S2(config-if)#exit&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S2(config)#interface fa 0/2&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S2(config-if)#switchport mode trunk&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S2(config-if)#no shutdown&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S2(config-if)#exit&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S2(config)#exit&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S2#vlan database&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S2(vlan)#vtp domain apuntes&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S2(vlan)#vtp client&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S2(vlan)#exit&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S2#exit&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large; font-weight: bold;&quot;&gt;&lt;a name=&quot;section2&quot; style=&quot;text-decoration: none;&quot;&gt;Configuracion de S3&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
De manera similar a S2, procedemos a configurar la interfaz Fa0/2 de S3 y a configurarlo en modo cliente VTP.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Switch&amp;gt;enable&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Switch#configure terminal&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Switch(config)#hostname S3&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S3(config)#interface fa 0/2&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S3(config-if)#switchport mode trunk&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S3(config-if)#no shutdown&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S3(config-if)#exit&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S3(config)#exit&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S3#vlan database&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S3(vlan)#vtp domain apuntes&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S3(vlan)#vtp client&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S3(vlan)#exit&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S3#exit&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large; font-weight: bold;&quot;&gt;&lt;a name=&quot;section3&quot; style=&quot;text-decoration: none;&quot;&gt;Configuracion de S1&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Para S1, configuramos sus interfaz Fa0/1 y lo configuramos en modo servidor VTP.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Switch&amp;gt;enable&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Switch#configure terminal&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Switch(config)#hostname S1&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1(config)#interface fa 0/1&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1(config-if)#switchport mode trunk&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1(config-if)#no shutdown&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1(config-if)#exit&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1(config)#exit&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1#vlan database&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1(vlan)#vtp domain apuntes&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1(vlan)#vtp server&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1(vlan)#exit&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1#exit&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large; font-weight: bold;&quot;&gt;&lt;a name=&quot;section4&quot; style=&quot;text-decoration: none;&quot;&gt;Configurar las VLANs en el servidor VTP&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Ahora que tenemos los equipos configurados, procedemos a crear las VLANs en nuestro servidor VTP.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;S1&amp;gt;enable&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1#vlan database&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1(vlan)#vlan 10 name ADMINISTRACION&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1(vlan)#vlan 20 name PRODUCCION&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1(vlan)#vlan 30 name APUNTES&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1(vlan)#exit&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;S1#exit&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Y listo, ya tenemos las VLANs creadas en todos nuestros equipos. Para comprobar que las VLANs han sido creadas usamos el comando &lt;b&gt;show vlan&lt;/b&gt; en S2 y S3 y podemos observar que se han creado las VLANs que hemos configurado en nuestro servidor VTP S1.&lt;br /&gt;
&lt;br /&gt;
Fuente:&amp;nbsp;&lt;a href=&quot;http://www.cisco.com/en/US/tech/tk389/tk689/technologies_configuration_example09186a0080890607.shtml&quot; target=&quot;_blank&quot;&gt;Configuring VLAN Trunk Protocol (VTP)&lt;/a&gt; &lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/5109326896370607749/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2011/10/configuracion-de-vlans-con-vtp.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/5109326896370607749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/5109326896370607749'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2011/10/configuracion-de-vlans-con-vtp.html' title='Configuracion de VLANs con VTP'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQswJg4J537Dq6wIpo2cv41Dqyzbz1oEhI-PM0mquqVwTel6NpFHFgJ38dUpdwhf71LAsxIvzx2tBdslZtLS_MSVsnLD-7XtF2hEW9l7J9ASVvpBQW7B-6RfNyYH7Hm8q4xALFswcHTqs/s72-c/Configuracion+VTP.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-6473552324601298234</id><published>2011-10-06T11:17:00.005-05:00</published><updated>2011-10-07T00:23:55.123-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c#"/><category scheme="http://www.blogger.com/atom/ns#" term="programacion"/><category scheme="http://www.blogger.com/atom/ns#" term="visual studio"/><title type='text'>Manejo de los recursos de una aplicacion en Visual Studio</title><content type='html'>&lt;div style=&quot;font-family: Verdana,sans-serif; font-size: small; text-align: justify;&quot;&gt;En esta entrada trataremos sobre como manejar los recursos que necesita una aplicación para su funcionamiento en Visual Studio. Cuando desarrollamos aplicaciones, a veces necesitamos datos que no son código fuente. En Visual Studio se les llama Recursos de Proyecto y pueden ser archivos de texto, audio, video, imágenes, íconos, archivos XML u otros tipos de datos que necesitamos para el funcionamiento de la aplicación que estamos desarrollando.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;div style=&quot;font-family: Verdana,sans-serif; font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Verdana,sans-serif; font-size: large; font-weight: bold;&quot;&gt;Contenido&lt;/span&gt;&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/manejo-de-los-recursos-de-una.html#section1&quot;&gt;Agregar un recurso al Proyecto&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/manejo-de-los-recursos-de-una.html#section2&quot;&gt;Acceder a un recurso del proyecto en código&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;a name=&quot;section1&quot; style=&quot;text-decoration: none;&quot;&gt;Agregar un recurso al Proyecto&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Para agregar un recurso a un proyecto hacemos clic con el botón secundario del mouse en el nodo Propiedades de nuestro proyecto en el Explorador de Soluciones y damos clic en la Opcion Abrir.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhv2D9k8VdOAxRjY1P4kePm8GOxLa3WZYPp-OJe6HcethGk5rv4H5x-W0dsW7iuoriQS2-7fNO7nr3PMdFHYTrM794az8HsE9kqDezD7SYtdLA8RuLLcCsurIiCE9edFdrrF9HL_NGAc3g/s1600/Solution+Explorer.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhv2D9k8VdOAxRjY1P4kePm8GOxLa3WZYPp-OJe6HcethGk5rv4H5x-W0dsW7iuoriQS2-7fNO7nr3PMdFHYTrM794az8HsE9kqDezD7SYtdLA8RuLLcCsurIiCE9edFdrrF9HL_NGAc3g/s1600/Solution+Explorer.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Luego, vamos a la pestaña Resources (Recursos) y damos clic en la opción Add Resource (Añadir Recurso), nos aparece un cuadro de diálogo y elegimos el recurso que deseamos añadir.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIAiHdON3o8-em2hIslTyCHbuS-86v3hRKJxDXkIZjbsXr5jcJMEItUOnSxo11_-YhWHUM7U0jctVB63I8R9iiAJrECahUVk5CEHu7xoZvzRiP1KbIsbbkXlE_giN6MemKNSK7Vx63Q3g/s1600/Pesta%25C3%25B1a+Recursos.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;142&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIAiHdON3o8-em2hIslTyCHbuS-86v3hRKJxDXkIZjbsXr5jcJMEItUOnSxo11_-YhWHUM7U0jctVB63I8R9iiAJrECahUVk5CEHu7xoZvzRiP1KbIsbbkXlE_giN6MemKNSK7Vx63Q3g/s320/Pesta%25C3%25B1a+Recursos.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
En este ejemplo, agregaré una imagen en formato GIF llamada blue.gif. Una vez agregado el recurso, se visualiza en la pestaña de recursos.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_qixoZh5GaKzg9rDbVI9ESsT58aTGlzq8CVBJLsqYEwEBDYp67M0yjSiyXVTHWpuBl5IKMSQG1wOzrtz2box_aw1ni8SN63AMzbCEJE4JSC8tUxtVbyUk8-k8geZ9jW6bdsHg344AKu0/s1600/Recurso+Agregado.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;177&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_qixoZh5GaKzg9rDbVI9ESsT58aTGlzq8CVBJLsqYEwEBDYp67M0yjSiyXVTHWpuBl5IKMSQG1wOzrtz2box_aw1ni8SN63AMzbCEJE4JSC8tUxtVbyUk8-k8geZ9jW6bdsHg344AKu0/s320/Recurso+Agregado.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;a name=&quot;section2&quot; style=&quot;text-decoration: none;&quot;&gt;Acceder a un recurso del proyecto en código&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Para acceder a un recurso desde el código simplemente llamamos a Properties.Resources y elegimos el recurso que deseamos usar.&lt;br /&gt;
&lt;br /&gt;
Por ejemplo, diseñamos un formulario el cual contiene un Picture Box.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJVRJSgIM3c7zC5E6Nw3VKE_OWlswDwxdBXD-cZ79HJCvU5JybyrbhQ8xsyhtdC4UyLusL5o37e8cup6jO9alvfIYmlIFNHGfMxnDN8wCAThyphenhyphenACIFQyeB_nuS-qUYAVPWt7qFRv8dHdJ8/s1600/Ejemplo.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJVRJSgIM3c7zC5E6Nw3VKE_OWlswDwxdBXD-cZ79HJCvU5JybyrbhQ8xsyhtdC4UyLusL5o37e8cup6jO9alvfIYmlIFNHGfMxnDN8wCAThyphenhyphenACIFQyeB_nuS-qUYAVPWt7qFRv8dHdJ8/s1600/Ejemplo.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Y en el código del formulario, asigno la imagen del PictureBox a una imagen de los recursos de mi aplicación. Para este ejemplo, usamos la imagen blue.gif de la sección &quot;Agregar un recurso a un proyecto&quot; de esta entrada.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhny7YrsR3KrDztaqebG73okCOjjh76ghstWgAjaPoh9EfIhvQTsP7N4a1wwzGSlyDUdZSFebmH4SSHRUidizAVWv_9N2Vvm02JlINzDUobtiouSfcQKDcRMHwSCw0ZGfntUE6nSRv6Bhs/s1600/Ejemplo2.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;138&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhny7YrsR3KrDztaqebG73okCOjjh76ghstWgAjaPoh9EfIhvQTsP7N4a1wwzGSlyDUdZSFebmH4SSHRUidizAVWv_9N2Vvm02JlINzDUobtiouSfcQKDcRMHwSCw0ZGfntUE6nSRv6Bhs/s320/Ejemplo2.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Si ejecutamos el formulario, podemos ver que el PictureBox muestra la imagen deseada.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdlfn7upkmyGcklbzv5qKtoJjWMCC2kcNDQK9KZT62pvOHkeOgfgFjiF0bCfanJQyTvP_AH7Nn-m6iFpwDoBuWoX1NEv6ZDpVGNxT5_qNtOzcI-N-nEMXKE6KqE8lm87WQVfHoPpRlnS4/s1600/Ejemplo3.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdlfn7upkmyGcklbzv5qKtoJjWMCC2kcNDQK9KZT62pvOHkeOgfgFjiF0bCfanJQyTvP_AH7Nn-m6iFpwDoBuWoX1NEv6ZDpVGNxT5_qNtOzcI-N-nEMXKE6KqE8lm87WQVfHoPpRlnS4/s1600/Ejemplo3.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
Advertencia: Este ejemplo se ha desarrollado usando Visual Studio 2010 Professional. Los pasos presentados en esta entrada pueden variar para otras versiones de Visual Studio &lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
Fuente: &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/7k989cfy%28v=vs.80%29.aspx&quot;&gt;Adding and Editing Resources (Visual C#)&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/6473552324601298234/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2011/10/manejo-de-los-recursos-de-una.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/6473552324601298234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/6473552324601298234'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2011/10/manejo-de-los-recursos-de-una.html' title='Manejo de los recursos de una aplicacion en Visual Studio'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhv2D9k8VdOAxRjY1P4kePm8GOxLa3WZYPp-OJe6HcethGk5rv4H5x-W0dsW7iuoriQS2-7fNO7nr3PMdFHYTrM794az8HsE9kqDezD7SYtdLA8RuLLcCsurIiCE9edFdrrF9HL_NGAc3g/s72-c/Solution+Explorer.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-3181115392431647516</id><published>2011-10-04T08:38:00.001-05:00</published><updated>2011-10-05T08:58:48.207-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programacion"/><category scheme="http://www.blogger.com/atom/ns#" term="prolog"/><title type='text'>Ejercicios en Prolog</title><content type='html'>&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;En esta entrada resolveremos algunos ejercicios en Prolog.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Contenido&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ol&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/ejercicios-en-prolog_04.html#section1&quot;&gt;&lt;li&gt;Dados dos numeros, indique el menor de ellos&lt;/li&gt;&lt;/a&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/ejercicios-en-prolog_04.html#section2&quot;&gt;&lt;li&gt;Dados dos numeros, devolver su residuo&lt;/li&gt;&lt;/a&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/ejercicios-en-prolog_04.html#section3&quot;&gt;&lt;li&gt;Dada la funcion residuo y un numero, mostrar los divisores de un numero&lt;/li&gt;&lt;/a&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/ejercicios-en-prolog_04.html#section4&quot;&gt;&lt;li&gt;Buscar un elemento en una lista&lt;/li&gt;&lt;/a&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/ejercicios-en-prolog_04.html#section5&quot;&gt;&lt;li&gt;Insertar un elemento al inicio de una lista&lt;br /&gt;
&lt;/li&gt;&lt;/a&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/ejercicios-en-prolog_04.html#section6&quot;&gt;&lt;li&gt;Insertar un elemento al final de una lista&lt;/li&gt;&lt;/a&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/ejercicios-en-prolog_04.html#section7&quot;&gt;&lt;li&gt;Sumar todos los elementos de una lista&lt;/li&gt;&lt;/a&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/ejercicios-en-prolog_04.html#section8&quot;&gt;&lt;li&gt;Dadas dos listas, determinar si estas son iguales&lt;/li&gt;&lt;/a&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/ejercicios-en-prolog_04.html#section9&quot;&gt;&lt;li&gt;Dado un numero, devuelva su factorial&lt;/li&gt;&lt;/a&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/ejercicios-en-prolog_04.html#section10&quot;&gt;&lt;li&gt;Hacer un programa para el calculo del numero fibonacci&lt;/li&gt;&lt;/a&gt;
&lt;/ol&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a name=&quot;section1&quot; style=&quot;text-decoration:none;&quot;&gt;Dados dos numeros, indique el menor de ellos&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;menor(X,Y,Z) :- X&amp;gt;Y, Z is Y.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;menor(X,Y,Z) :- Y&amp;gt;X, Z is X.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;Z contiene el numero menor entre X e Y.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a name=&quot;section2&quot; style=&quot;text-decoration:none;&quot;&gt;Dados dos numeros (x e y), devolver el residuo de X/Y&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;residuo(X,Y,Z) :- X&amp;lt;Y, Z is X.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;residuo(X,Y,Z) :- X1 is X-Y, residuo(X1,Y,Z1), Z is Z1.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;Z es la variable que contiene el residuo de dividir X/Y.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a name=&quot;section3&quot; style=&quot;text-decoration:none;&quot;&gt;Dada la funcion residuo y un numero, mostrar los divisores de un numero&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;divisores(X,Y) :- Y=1.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;divisores(X,Y) :- residuo(X,Y,Z), Z=0, writeln(Y,&#39;es divisor de&#39;,X), divisores(X,Y-1).&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;divisores(X,Y) :- divisores(X,Y-1).&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;residuo(X,Y,Z) :- X&amp;lt;Y, Z is X.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;residuo(X,Y,Z) :- X1 is X-Y, residuo(X1,Y,Z1), Z is Z1.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;muestraDivisores(X) :- divisores(X,X).&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;En este ejercicio reutilizamos la funcion residuo del ejercicio anterior, para mostrar todos los divisores de&amp;nbsp;X solo llamamos a la funcion muestraDivisores.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a name=&quot;section4&quot; style=&quot;text-decoration:none;&quot;&gt;Buscar un elemento en una lista&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;pertenece(X,[M|N]) :- X=M.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;pertenece(X,[M|N]) :- (X,N).&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;Esta funcion devuelve true o false si la variable X pertenece a la lista.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a name=&quot;section5&quot; style=&quot;text-decoration:none;&quot;&gt;Insertar un elemento al inicio de una lista&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;insertaInicio(X,L,Z) :- Z is [X|L].&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;X es el elemento a insertar, L es la lista y Z es la nueva lista con el elemento X al inicio.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a name=&quot;section6&quot; style=&quot;text-decoration:none;&quot;&gt;Insertar un elemento al final de una lista&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;insertaFinal(X,L,Z) :- L=[], Z is [X].&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;insertaFinal(X,[L|Lr],Z) :- insertaFinal(X,Lr,Z1), Z is [L|Z1].&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;X es el elemento a insertar al final, L es la lista y Z es la nueva lista con el elemento X al final.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a name=&quot;section7&quot; style=&quot;text-decoration:none;&quot;&gt;Sumar todos los elementos de una lista&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;suma([H|T],Y) :- T=[], Y is H.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;suma([H|T],Y) :- suma(T,Y1), Y is H+Y1.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;[H|T] es la lista,&amp;nbsp;Y devuelve la suma de todos sus elementos.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a name=&quot;section8&quot; style=&quot;text-decoration:none;&quot;&gt;Dadas dos listas, determinar si estas son iguales&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;soniguales([M|N],[P|Q]) :- M=P, soniguales(N,Q).&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;i&gt;soniguales(M,N) :- M=[], N=[].&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;Esta funcion devuelve true o false si las listas son iguales o no.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: large;&quot;&gt;&lt;b&gt;&lt;a name=&quot;section9&quot; style=&quot;text-decoration:none;&quot;&gt;Dado un numero, devuelva su factorial&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana;&quot;&gt;&lt;i&gt;factorial(N,F) :- N&amp;gt;1, N1 is N-1, factorial(N1,F1), F is N*F1.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana;&quot;&gt;&lt;i&gt;factorial(N,F) :- N=1, F is 1.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana;&quot;&gt;N es el numero a calcular su factoria y F es el factorial de N.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: large;&quot;&gt;&lt;b&gt;&lt;a name=&quot;section10&quot; style=&quot;text-decoration:none;&quot;&gt;Hacer un programa para el calculo del numero fibonacci&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana;&quot;&gt;&lt;i&gt;fibo(X,N) :- X=0, N is 1.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana;&quot;&gt;&lt;i&gt;fibo(X,N) :- X=1, N is 1.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana;&quot;&gt;&lt;i&gt;fibo(X,N) :- X&amp;gt;1, fibo(X-1,N1), fibo(X-2,N2), N is N1+N2.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana;&quot;&gt;N devuelve el numero fibonacci de X.&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/3181115392431647516/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2011/10/ejercicios-en-prolog_04.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/3181115392431647516'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/3181115392431647516'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2011/10/ejercicios-en-prolog_04.html' title='Ejercicios en Prolog'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-6831637864702184715</id><published>2011-10-01T11:06:00.003-05:00</published><updated>2011-10-04T01:24:59.241-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="cisco"/><category scheme="http://www.blogger.com/atom/ns#" term="enrutamiento dinamico"/><category scheme="http://www.blogger.com/atom/ns#" term="enrutamiento estatico"/><category scheme="http://www.blogger.com/atom/ns#" term="ospf"/><category scheme="http://www.blogger.com/atom/ns#" term="redes"/><category scheme="http://www.blogger.com/atom/ns#" term="rip"/><title type='text'>Recopilacion sobre Enrutamiento en Routers Cisco</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;En esta entrada haremos un repaso sobre&amp;nbsp;la implementacion de&amp;nbsp;enrutamiento estatico y el enrutamiento dinamico con RIP y con OSPF.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFqCdhICuX7UsE9UFQckyt2Lw43n2u4Yof9RXsn4xs1pqgtfQIsvgQJJY-tPVZlLqx8alSkveNGwgFEJWF7lBUuQl5dEhM4lHTuzFBHWKUEywQ8Tujnqa4e5E7byfQ4ZD4zm35QLf31Wg/s1600/Recopilacion+Enrutamiento.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;159&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFqCdhICuX7UsE9UFQckyt2Lw43n2u4Yof9RXsn4xs1pqgtfQIsvgQJJY-tPVZlLqx8alSkveNGwgFEJWF7lBUuQl5dEhM4lHTuzFBHWKUEywQ8Tujnqa4e5E7byfQ4ZD4zm35QLf31Wg/s320/Recopilacion+Enrutamiento.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Como podemos ver en el diagrama, tenemos tres hosts PC1, PC2 y PC3 los cuales se encuentran en redes diferentes. Estos&amp;nbsp;hosts&amp;nbsp;se conectan a los routers R1, R2 y R3. Tambien vemos que&amp;nbsp;R1 y R2 estan conectados mediante la red 1.1.1.0/30 a traves de sus interfaces seriales Se1/0 y que&amp;nbsp;R2 y R3 estan conectados mediante la red 2.2.2.0/30 a traves de sus interfaces seriales Se1/1 y Se1/0 respectivamente. Los detalles de la conexion serial se detallan en la siguiente tabla.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;table align=&quot;center&quot; border=&quot;1&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Router&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Interfaz&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Tipo de Interfaz&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Direccion IP&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Se1/0&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;DCE&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;1.1.1.1/30&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R2&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Se1/0&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;DTE&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;1.1.1.2/30&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R2&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Se1/1&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;DCE&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;2.2.2.1/30&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R3&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Se1/0&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;DTE&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;2.2.2.2/30&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;En este ejemplo, vamos&amp;nbsp;a configurar los equipos R1, R2 y R3 mediante las tres formas de enrutamiento que hemos visto en las entradas &lt;/span&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/09/enrutamiento-estatico-en-routers-cisco.html&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Enrutamiento Estatico en Routers Cisco&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;, &lt;/span&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/09/enrutamiento-dinamico-rip-con-routers.html&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Enrutamiento Dinamico con RIP en Routers Cisco&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; y&lt;/span&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/09/enrutamiento-dinamico-ospf-en-routers.html&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; Enrutamiento Dinamico con OSPF en Routers Cisco&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; para que PC1, PC2 y PC3 tengan conectividad entre si.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;&lt;strong&gt;Contenido&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/recopilacion-sobre-enrutamiento-en.html#section1&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;1. Configuracion del enrutamiento estatico en R1, R2 y R3&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/recopilacion-sobre-enrutamiento-en.html#section2&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;2. Configuracion del enrutamiento dinamico con RIP en R1, R2 y R3&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/recopilacion-sobre-enrutamiento-en.html#section3&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;3. Configuracion del enrutamiento dinamico con OSPF en R1, R2 y R3&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Antes de pasar a configurar el enrutamiento en los routers, tenemos que configurar las interfaces fastEthernet y seriales de cada router en la red. Tenga en cuenta que tenemos que usar el comando &lt;strong&gt;clock rate&lt;/strong&gt; en las interfaces de los router que son DCE. A continuacion procederemos a configurar las interfaces de cada router.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Configuracion para R1&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Router&amp;gt;enable&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Router#configure terminal&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Router(config)#hostname R1&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config)#interface fastEthernet0/0&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#ip address 192.168.20.1 255.255.255.0&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#no shutdown&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config)#interface serial 1/0&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#ip address 1.1.1.1 255.255.255.252&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#clock rate 64000&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#no shutdown&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config)#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Configuracion para R2&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;Router&amp;gt;enable&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;Router#configure terminal&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;Router(config)#hostname R2&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config)#interface fastEthernet 0/0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config-if)#ip address 192.168.50.1 255.255.255.0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config-if)#no shutdown&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config-if)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config)#interface serial 1/0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config-if)#ip address 1.1.1.2 255.255.255.252&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config-if)#no shutdown&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config-if)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config)#interface serial 1/1&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config-if)#ip address 2.2.2.1 255.255.255.252&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config-if)#clock rate 64000&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config-if)#no shutdown&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config-if)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Configuracion para R3&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;Router&amp;gt;enable&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;Router#configure terminal&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;Router(config)#hostname R3&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config)#interface fastEthernet0/0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config-if)#ip address 192.168.80.1 255.255.255.0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config-if)#no shutdown&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config-if)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config)#interface serial 1/0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config-if)#ip address 2.2.2.2 255.255.255.252&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config-if)#no shutdown&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config-if)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Hasta este punto hemos configurado los nombres de los equipos, sus interfaces fastEthernet y sus interfaces seriales. Entonces, podemos probar la conectividad entre los routers. En R1, probamos la conectividad con R2 mediante el comando &lt;strong&gt;ping 1.1.1.2&lt;/strong&gt;. En R2, probamos la conectividad con R3 mediante el comando ping &lt;strong&gt;2.2.2.2&lt;/strong&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Luego procedemos a la configuracion de la direccion IP, mascara de la red y direccion IP de la puerta de enlace para PC1, PC2 y PC3 como se muestra en el diagrama. Para PC1 su puerta de enlace es 192.168.20.1, para PC2 su puerta de enlace es 192.168.50.1 y para PC3 es 192.168.80.1. Luego, probamos la conectividad de cada host a su puerta de su enlace mediante el comando &lt;strong&gt;ping&lt;/strong&gt;. Por ejemplo, para probar la conectividad de PC1 a su puerta de enlace el comando es &lt;strong&gt;ping 192.168.20.1&lt;/strong&gt;.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;http://www.blogger.com/&quot; name=&quot;section1&quot; style=&quot;text-decoration: none;&quot;&gt;Configuracion del enrutamiento estatico en R1, R2 y R3&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Una vez que tenemos las interfaces configuradas en R1, R2 y R3 procedemos a configurar el enrutamiento estatico en cada equipo.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Configuracion del enrutamiento estatico para R1&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1&amp;gt;enable&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1#configure terminal&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config)#ip route 192.168.50.0 255.255.255.0 1.1.1.2&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config)#ip route 192.168.80.0 255.255.255.0 1.1.1.2&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config)#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Configuracion del enrutamiento estatico para R2&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2&amp;gt;enable&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2#configure terminal&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config)#ip route 192.168.20.0 255.255.255.0 1.1.1.1&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config)#ip route 192.168.80.0 255.255.255.0 2.2.2.2&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Configuracion del enrutamiento estatico para R3&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3&amp;gt;enable&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3#configure terminal&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config)#ip route 192.168.50.0 255.255.255.0 2.2.2.1&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config)#ip route 192.168.20.0 255.255.255.0 2.2.2.1&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Y listo, ya tenemos los routers configurados mediante enrutamiento estatico. Ahora podemos probar la conectividad entre los hosts haciendo &lt;b&gt;ping &lt;/b&gt;a sus direcciones IP. Por ejemplo, en PC1 para probar la conectividad con PC3 el comando es &lt;b&gt;ping 192.168.80.3&lt;/b&gt;.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Para ver la configuracion del enrutamiento estatico en el equipo usamos el comando &lt;b&gt;show ip route&lt;/b&gt;.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;http://www.blogger.com/&quot; name=&quot;section2&quot; style=&quot;text-decoration: none;&quot;&gt;Configuracion del enrutamiento dinamico con RIP en R1, R2 y R3&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Una vez que tenemos las interfaces configuradas en R1, R2 y R3 procedemos a configurar el enrutamiento dinamico con el protocolo RIP en cada equipo.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Configuracion del enrutamiento dinamico RIP para R1&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1&amp;gt;enable&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1#configure terminal&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1(config)#router rip&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1(config-router)#network 192.168.20.0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1(config-router)#network 1.0.0.0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1(config-router)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1(config)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong&gt;Configuracion del enrutamiento dinamico RIP para R2&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R2&amp;gt;enable&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R2#configure terminal&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R2(config)#router rip&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R2(config-router)#network 192.168.50.0&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R2(config-router)#network 1.0.0.0&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R2(config-router)#network 2.0.0.0&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R2(config-router)#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R2(config)#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R2#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Configuracion del enrutamiento dinamico RIP para R3&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R3&amp;gt;enable&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R3#configure terminal&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R3(config)#router rip&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R3(config-router)#network 192.168.80.0&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R3(config-router)#network 2.0.0.0&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R3(config-router)#exit&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R3(config)#exit&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R3#exit&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Y listo, ya tenemos los routers configurados mediante enrutamiento dinamico con el protocolo RIP. Ahora podemos probar la conectividad entre los hosts haciendo &lt;b&gt;ping &lt;/b&gt;a sus direcciones IP. Por ejemplo, en PC1 para probar la conectividad con PC2 el comando es &lt;b&gt;ping 192.168.50.5&lt;/b&gt;.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Para ver la configuracion del enrutamiento dinamico en el equipo usamos el comando &lt;b&gt;show ip protocols&lt;/b&gt;.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;http://www.blogger.com/&quot; name=&quot;section3&quot; style=&quot;text-decoration: none;&quot;&gt;Configuracion del enrutamiento dinamico con OSPF en R1, R2 y R3&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Una vez que tenemos las interfaces configuradas en R1, R2 y R3 procedemos a configurar el enrutamiento dinamico con el protocolo OSPF en cada equipo.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Configuracion del enrutamiento dinamico OSPF para R1&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1&amp;gt;enable&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1#configure terminal&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1(config)#router ospf 2&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1(config-router)#network 192.168.20.2 0.0.0.255 area 0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1(config-router)#network 1.1.1.0 0.0.0.3 area 0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1(config-router)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1(config)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R1#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Configuracion del enrutamiento dinamico OSPF para R2&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2&amp;gt;enable&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2#configure terminal&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config)#router ospf 2&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config-router)#network 192.168.50.0 0.0.0.255 area 0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config-router)#network 1.1.1.0 0.0.0.3 area 0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config-router)#network 2.2.2.0 0.0.0.3 area 0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config-router)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2(config)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R2#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong&gt;Configuracion del enrutamiento dinamico OSPF para R3&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3&amp;gt;enable&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3#configure terminal&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config)#router ospf 2&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config-router)#network 192.168.80.0 0.0.0.255 area 0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config-router)#network 2.2.2.0 0.0.0.3 area 0&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config-router)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3(config)#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;em&gt;R3#exit&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Y listo, ya tenemos los routers configurados mediante enrutamiento dinamico con el protocolo OSPF. Ahora podemos probar la conectividad entre los hosts haciendo &lt;b&gt;ping &lt;/b&gt;a sus direcciones IP. Por ejemplo, en PC2 para probar la conectividad con PC3 el comando es &lt;b&gt;ping 192.168.80.8&lt;/b&gt;.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Para ver la configuracion del enrutamiento dinamico en el equipo usamos el comando &lt;b&gt;show ip protocols&lt;/b&gt;.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Fuentes: &lt;/span&gt;&lt;a href=&quot;http://docwiki.cisco.com/wiki/Internetworking_Technology_Handbook&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Internetworking Technology Handbook&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.cisco.com/en/US/tech/tk365/technologies_tech_note09186a00800ef7b2.shtml&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Specifying a Next Hop IP Address for Static Routers&lt;/span&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/6831637864702184715/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2011/10/recopilacion-sobre-enrutamiento-en.html#comment-form' title='2 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/6831637864702184715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/6831637864702184715'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2011/10/recopilacion-sobre-enrutamiento-en.html' title='Recopilacion sobre Enrutamiento en Routers Cisco'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFqCdhICuX7UsE9UFQckyt2Lw43n2u4Yof9RXsn4xs1pqgtfQIsvgQJJY-tPVZlLqx8alSkveNGwgFEJWF7lBUuQl5dEhM4lHTuzFBHWKUEywQ8Tujnqa4e5E7byfQ4ZD4zm35QLf31Wg/s72-c/Recopilacion+Enrutamiento.png" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-1832162663518903234</id><published>2011-10-01T02:54:00.007-05:00</published><updated>2011-10-01T13:30:52.812-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="cisco"/><category scheme="http://www.blogger.com/atom/ns#" term="configuracion switch"/><category scheme="http://www.blogger.com/atom/ns#" term="configuracion vlan"/><category scheme="http://www.blogger.com/atom/ns#" term="redes"/><title type='text'>Conectividad en VLANs con Switches Cisco</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;En esta entrada hablaremos sobre como&amp;nbsp;poder&amp;nbsp;comunicar hosts que pertenecen en diferentes VLANs. En la entrada &lt;/span&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/09/creacion-de-vlans-en-switches-cisco.html&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Creacion de VLANs en Switches Cisco&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; vimos como se crea una VLAN y se asignan las interfaces del equipo a una VLAN en particular. Ahora veremos como podemos interconectar diferentes VLANs para poder tener conectividad en hosts que perteneces a diferentes VLANs.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw0fsf172tgSGMiUf8iS1-1oWE8gF8f4pnlFY3Rvp-SnvyTRsuIuv7DlNfNUC3SgZcUb-GIK5udgc_D2RQaJ9JSe0UEZRyldn5_-y6jbZSBJfO7aN1o7hd7LA2tz-OzZ1FN6N2v5JgJ14/s1600/Diagrama+Conexion+VLAN.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw0fsf172tgSGMiUf8iS1-1oWE8gF8f4pnlFY3Rvp-SnvyTRsuIuv7DlNfNUC3SgZcUb-GIK5udgc_D2RQaJ9JSe0UEZRyldn5_-y6jbZSBJfO7aN1o7hd7LA2tz-OzZ1FN6N2v5JgJ14/s320/Diagrama+Conexion+VLAN.png&quot; width=&quot;194&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Como podemos ver en el diagrama, tenemos dos hosts PC1 y PC2 que pertenecen a la VLAN20 y VLAN30 respectivamente y que se conectan al switch S1. El switch S1 se conecta al router R1 y tanto S1 como R1 pertenecen&amp;nbsp;a la VLAN10.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;En este ejemplo, vamos a configurar los equipos S1 y R1 para que los hosts PC1 y PC2 que se encuentran en VLANs separadas puedan tener conectividad entre si. Las puertas de enlace&amp;nbsp;para los hosts que pertenezcan a la VLAN10 y&amp;nbsp;VLAN20 se detallan en la siguiente tabla:&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;table align=&quot;center&quot; border=&quot;1&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;VLAN&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Puerta de Enlace&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;VLAN10&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;192.168.10.1&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;VLAN20&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;192.168.20.1&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;VLAN30&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;192.168.30.1&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;tbody&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;&lt;strong&gt;Contenido&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/conectividad-en-vlans-con-switches.html#section1&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;1. Configuracion del Switch S1&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/10/conectividad-en-vlans-con-switches.html#section2&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;2. Configuracion del Router R1&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;a href=&quot;http://www.blogger.com/&quot; name=&quot;section1&quot; style=&quot;text-decoration: none;&quot;&gt;Configuracion del Switch S1&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Como vimos en la entrada &lt;/span&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/09/configuracion-basica-de-switches-y.html&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Configuracion Basica de Switches y Routers Cisco&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; cambiamos el nombre del host a S1 y le asignamos sus claves de acceso correspondientes (Para este ejemplo no le asignaremos claves de acceso al equipo). Luego, como vimos en la entrada &lt;/span&gt;&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/09/creacion-de-vlans-en-switches-cisco.html&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Creacion de VLANs en Switches Cisco&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; procedemos a crear las VLANs de nuestra red: VLAN10, VLAN20 y VLAN30 para despues asignar las interfaces Fa0/2 y Fa0/3 a las VLANs VLAN20 y VLAN30 respectivamente. Finalmente, configuramos la interfaz Fa0/1 la cual es una conexion troncal con R1 y le asignamos la direccion IP a S1 como se muestra en el diagrama. Para asignar la direccion IP a un switch Cisco se usa el comando &lt;strong&gt;configure interface vlan [vlan_id]&lt;/strong&gt;&amp;nbsp;donde [vlan_id] es el ID de la VLAN a la cual queremos que pertenezca la direccion IP que vamos a asignarle al equipo, y&amp;nbsp;seguidamente usamos el comando &lt;strong&gt;ip address [direccion] [mascara]&lt;/strong&gt; donde [direccion] es la direccion IP y [mascara] es la mascara de la red. En nuestro ejemplo asignaremos la direccion IP 192.168.10.2/24 a S1 en la VLAN10.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Switch&amp;gt;enable&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Switch#configure terminal&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Switch(config)#hostname S1&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config)#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1#vlan database&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(vlan)#vlan 10 name VLAN10&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(vlan)#vlan 20 name VLAN20&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(vlan)#vlan 30 name VLAN30&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(vlan)#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1#configure terminal&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config)#interface fastEthernet0/2&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config-if)#switchport mode access&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config-if)#switchport access vlan 20&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config-if)#no shutdown&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config-if)#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config)#interface fastEthernet0/3&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config-if)#switchport mode access&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config-if)#switchport access vlan 30&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config-if)#no shutdown&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config-if)#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config)#interface fastEthernet0/1&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config-if)#switchport mode trunk&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config-if)#no shutdown&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config-if)#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config)#interface vlan 10&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config-if)#ip address 192.168.10.2 255.255.255.0&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config-if)#no shutdown&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config-if)#exit&lt;/span&gt;&lt;/em&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1(config)#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;S1#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Para verificar&amp;nbsp;que las VLANs fueron creadas correctamente y&amp;nbsp;comprobar&amp;nbsp;que las interfaces se asignaron correctamente a las VLANs se usa el comando &lt;strong&gt;show vlan&lt;/strong&gt;, para ver las interfaces troncales&amp;nbsp;del equipo se usa el comando &lt;strong&gt;show interface trunk&lt;/strong&gt;. Debemos de verificar que la interfaz troncal Fa0/1 de S1 permita el acceso de todas nuestras VLANs creadas anteriormente las cuales son 10, 20 y 30.&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;&lt;strong&gt;&lt;a href=&quot;http://www.blogger.com/&quot; name=&quot;section2&quot; style=&quot;text-decoration: none;&quot;&gt;Configuracion del Router R1&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Procedemos a cambiar el nombre del equipo a R1 y&amp;nbsp;procederemos a configurar&amp;nbsp;subinterfaces en&amp;nbsp;el equipo,&amp;nbsp;asignando la&amp;nbsp;direccion IP de la&amp;nbsp;puerta de enlace respectiva para cada VLAN. Estas subinterfaces son las que proporcionan el enrutamiento entre las VLANs. En el diagrama de red de este ejemplo podemos ver que todos los paquetes de las VLANs VLAN10, VLAN20 y VLAN30 llegan a R1 mediante su interfaz Fa0/0. Por tanto crearemos las subinterfaces en la interfaz Fa0/0. Para configurar&amp;nbsp;una subinterfaz simplemente agregamos un punto (.) seguido del ID de la VLAN al comando de configuracion de interfaz que conocemos. Tambien debemos especificar el protocolo de trunking que vamos a usar, ya sea ISL (InterSwitchLink, protocolo propietario de Cisco) o 802.11q (Estandar de la IEEE) mediante el comando&lt;strong&gt; encapsulation [protocol] [vlan_id]&lt;/strong&gt; donde [protocol] es el protocolo de trunking&amp;nbsp;y [vlan_id] es el&amp;nbsp;ID de la VLAN.&amp;nbsp;Por ejemplo, para crear la subinterfaz para la VLAN10 en la interfaz Fa0/0 con el protocolo&amp;nbsp;802.1q&amp;nbsp;los comandos son&amp;nbsp;&lt;strong&gt;configure fastEthernet 0/0.10&lt;/strong&gt; y&lt;strong&gt; encapsulation dot1q 10&lt;/strong&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Router&amp;gt;enable&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Router#configure terminal&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Router(config)#hostname R1&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config)#interface fastEthernet0/0.10&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#encapsulation dot1q 10&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#ip address 192.168.10.1 255.255.255.0&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#no shutdown&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#exit&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config)#interface fastEthernet0/0.20&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#encapsulation dot1q 20&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#ip address 192.168.20.1 255.255.255.0&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#no shutdown&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#exit&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config)#interface fastEthernet0/0.30&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#encapsulation dot1q 30&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#ip address 192.168.30.1 255.255.255.0&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#no shutdown&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#exit&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config)#interface fastEthernet0/0&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;/em&gt;&lt;/div&gt;&lt;em&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config-if)#no shutdown&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;&lt;/em&gt;&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1(config)#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;R1#exit&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Y listo, ya contamos con la conectividad entre VLANs. Para probar la conectividad entre los hosts PC1 y PC2 solo es necesario configurar la direccion IP del host, la mascara de la red y la direccion IP de la puerta de enlace. Para PC1 que pertenece a la VLAN20 su puerta de enlace es 192.168.20.1 y para PC2 que pertenece a la VLAN30 su puerta de enlace es 192.168.30.1. Y solo queda probar la conectividad realizando el comando &lt;strong&gt;ping&lt;/strong&gt;. Desde PC1 verificamos la conectividad con PC2 mediante el comando &lt;strong&gt;ping 192.168.30.3&lt;/strong&gt; y desde PC2 verificamos la conectividad con PC1 mediante el comando &lt;strong&gt;ping 192.168.20.2&lt;/strong&gt;.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Fuente: &lt;/span&gt;&lt;a href=&quot;http://www.cisco.com/en/US/tech/tk389/tk815/technologies_configuration_example09186a00800949fd.shtml&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Configuring InterVLAN Routing&lt;/span&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/1832162663518903234/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2011/10/conectividad-en-vlans-con-switches.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/1832162663518903234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/1832162663518903234'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2011/10/conectividad-en-vlans-con-switches.html' title='Conectividad en VLANs con Switches Cisco'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw0fsf172tgSGMiUf8iS1-1oWE8gF8f4pnlFY3Rvp-SnvyTRsuIuv7DlNfNUC3SgZcUb-GIK5udgc_D2RQaJ9JSe0UEZRyldn5_-y6jbZSBJfO7aN1o7hd7LA2tz-OzZ1FN6N2v5JgJ14/s72-c/Diagrama+Conexion+VLAN.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1406353607070992173.post-4758760937054929407</id><published>2011-09-30T09:49:00.006-05:00</published><updated>2011-10-03T09:09:42.119-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="enrutamiento dinamico"/><category scheme="http://www.blogger.com/atom/ns#" term="enrutamiento estatico"/><category scheme="http://www.blogger.com/atom/ns#" term="redes"/><title type='text'>Diferencias entre Enrutamiento Estático y Dinámico, Protocolo Vector-Distancia y Estado de Enlace</title><content type='html'>&lt;div style=&quot;font-family: Verdana,sans-serif; text-align: justify;&quot;&gt;En esta entrada tratermos sobre las diferencias existentes entre el enrutamiento estático y el enrutamiento dinámico, y también hablaremos sobre las diferencias entre el protoco vector-distancia y estado de enlace.&lt;/div&gt;&lt;div style=&quot;font-family: Verdana,sans-serif; text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;div style=&quot;font-family: Verdana,sans-serif; text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Verdana,sans-serif; text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Contenido&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/09/diferencias-entre-enrutamiendo-estatico.html#section1&quot;&gt;1. Diferencias entre Enrutamiento Estático y Dinámico&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://notasensistemas.blogspot.com/2011/09/diferencias-entre-enrutamiendo-estatico.html#section2&quot;&gt;2. Diferencias entre Protocolo Vector-Distancia y Protocolo Estado de Enlace&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Para dar una visión general, sabemos que en el tema de enrutamiento tenemos el enrutamiento estático y el enrutamiento dinámico. En el enrutamiento dinámico tenemos dos protocolos: el protocolo vector-distancia y el protocolo estado de enlace. En la práctica, una implementación del protocolo vector-distancia es RIP (Routing Information Protocol) y una implementación del protocolo estado de enlace es OSPF (Open Shortest Path First).&lt;/div&gt;&lt;div style=&quot;font-family: Verdana,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Verdana,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;http://www.blogger.com/&quot; name=&quot;section1&quot; style=&quot;text-decoration: none;&quot;&gt;Diferencias entre Enrutamiento Estático y Dinámico&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Verdana,sans-serif; text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table border=&quot;1&quot; style=&quot;font-family: Verdana,sans-serif; margin-left: 0px; margin-right: 0px; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;Enrutamiento Estático&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;Enrutamiento Dinámico&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td style=&quot;text-align: center;&quot;&gt;Genera carga administrativa y consume tiempo del administrador de red en redes grandes. El administrador debe configurar el enrutamiento en cada router de la red.&lt;/td&gt;  &lt;td style=&quot;text-align: center;&quot;&gt;No genera mucha carga administrativa porque los routers aprenden a enrutarse de los demás routers de la red.&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td style=&quot;text-align: center;&quot;&gt;El router no comparte su tabla de enrutamiento con los routers vecinos.&lt;/td&gt;  &lt;td style=&quot;text-align: center;&quot;&gt;El router comparte su tabla de enrutamiento con los routers vecinos.&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td style=&quot;text-align: center;&quot;&gt;Los routers no tienen capacidad de reacción ante un fallo en la red.&lt;/td&gt;  &lt;td style=&quot;text-align: center;&quot;&gt;Los routers tienen capacidad de reacción ante un fallo en la red.&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: Verdana,sans-serif; text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Verdana,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;http://www.blogger.com/&quot; name=&quot;section2&quot; style=&quot;text-decoration: none;&quot;&gt;Diferencias entre Protocolo Vector-Distancia y Protocolo Estado de Enlace&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Verdana,sans-serif; text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table border=&quot;1&quot; style=&quot;font-family: Verdana,sans-serif; margin-left: 0px; margin-right: 0px; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;Protocolo Vector-Distancia&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;Protocolo Estado de Enlace&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td style=&quot;text-align: center;&quot;&gt;Consume menos memoria y capacidad de procesamiento del router que el protocolo estado de enlace.&lt;/td&gt;  &lt;td style=&quot;text-align: center;&quot;&gt;Consume más memoria y capacidad de procesamiento del router que el protocolo vector-distancia.&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td style=&quot;text-align: center;&quot;&gt;Las actualizaciones de las tablas de enrutamiento se hacen periódicamente, o cuando cambia la topología de la red.&lt;/td&gt;  &lt;td style=&quot;text-align: center;&quot;&gt;Las actualizaciones de las tablas de enrutamiento son desencadenadas por eventos.&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td style=&quot;text-align: center;&quot;&gt;Los routers envían toda su tabla de enrutamiento a los routers vecinos.&lt;/td&gt;  &lt;td style=&quot;text-align: center;&quot;&gt;Los routers envían solo los cambios de sus tablas de enrutamiento a los routers vecinos.&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td style=&quot;text-align: center;&quot;&gt;La convergencia de la red depende del período con que se actualizan las tablas de enrutamiento.&lt;/td&gt;  &lt;td style=&quot;text-align: center;&quot;&gt;La convergencia de la red es más rápida, dado que ante un cambio, éste se anuncia inmediatamente.&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: Verdana,sans-serif; text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Verdana,sans-serif; text-align: justify;&quot;&gt;Para ver cómo se configuran los equipos Cisco mediante enrutamiento estático puedes ver la entrada &lt;a href=&quot;http://notasensistemas.blogspot.com/2011/09/enrutamiento-estatico-en-routers-cisco.html&quot;&gt;Enrutamiento Estático con Routers Cisco&lt;/a&gt;, también te pueden interesar las entradas &lt;a href=&quot;http://notasensistemas.blogspot.com/2011/09/enrutamiento-dinamico-rip-con-routers.html&quot;&gt;Enrutamiento Dinámico con RIP en Routers Cisco&lt;/a&gt; y &lt;a href=&quot;http://notasensistemas.blogspot.com/2011/09/enrutamiento-dinamico-ospf-en-routers.html&quot;&gt;Enrutamiento Dinámico con OSPF en Routers Cisco&lt;/a&gt;, donde vemos la configuración de equipos Cisco para los protocolos RIP y OPSF respectivamente.&lt;br /&gt;
&lt;br /&gt;
Fuentes: &lt;a href=&quot;http://docwiki.cisco.com/wiki/Routing_Basics&quot;&gt;Routing Basics&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://docwiki.cisco.com/wiki/Internetworking_Technology_Handbook#Routing&quot;&gt;Internetworking Technology Handbook&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://notasensistemas.blogspot.com/feeds/4758760937054929407/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://notasensistemas.blogspot.com/2011/09/diferencias-entre-enrutamiendo-estatico.html#comment-form' title='4 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/4758760937054929407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1406353607070992173/posts/default/4758760937054929407'/><link rel='alternate' type='text/html' href='http://notasensistemas.blogspot.com/2011/09/diferencias-entre-enrutamiendo-estatico.html' title='Diferencias entre Enrutamiento Estático y Dinámico, Protocolo Vector-Distancia y Estado de Enlace'/><author><name>Administrador</name><uri>http://www.blogger.com/profile/11009646950683399947</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry></feed>