Mostrando entradas con la etiqueta fibonaci en java. Mostrar todas las entradas
Mostrando entradas con la etiqueta fibonaci en java. Mostrar todas las entradas

5 nov 2008

Embedding Google Maps in Java Server Faces using GMaps4JSF

Esto me parecio interesante para aquello javeros de corazon y de puño y letra y cincel, no me parecio correcto traducirlo por en si el contenido es explicito por si mismo asi que lean....

GMaps4JSF allows Google Maps to be easily integrated with any JSF application. This blog shows how to use this library with Mojarra - JSF implementation delivered from the GlassFish community.

This explains how to create a simple JSF 2.0 application and deploy on GlassFish v3 prelude using Mojarra 2.0 EDR2. The application allows to create a database of cities/country that you like. It uses integrated Facelets and the newly introduced JavaScript APIs to expose Ajax functionality. This blog shows how to extend that application to display a Google Map and Street View of the entered city using this library.

  1. Configure GMapsJSF library in the NetBeans project (created as described in TOTD #50)
    1. Download gmaps4jsf-core-1.1.jar.
    2. In the existing NetBeans project, right-click on the project, select Properties, Libraries, click on "Add JAR/Folder" and point to the recently download JAR.
    3. Configure Facelets support for this library. This is an important step since Facelets are the default viewing technology in JSF 2.0.
  2. In the NetBeans project, create a new Java class "server.CityCoordinates" that will use Google Geocoding APIs to retrieve latitude and longitude of the entered city. It also create a "details" entry by concatenating city and country name. Use the code listed below:

    private float latitude;
    private float longitude;
    private String details;
    @ManagedProperty(value="#{cities}")
    private Cities cities;
    private final String BASE_GEOCODER_URL = "http://maps.google.com/maps/geo?";
    private final String ENCODING = "UTF-8";
    private final String GOOGLE_MAPS_KEY = "GOOGLE_MAPS_API_KEY";
    private final String OUTPUT_FORMAT = "CSV";
    public String getLatLong() throws IOException {
    details = cities.getCityName() + ", " + cities.getCountryName();
    String GEOCODER_REQUEST =
    BASE_GEOCODER_URL +
    "q=" + URLEncoder.encode(details, ENCODING) +
    "&key=" + GOOGLE_MAPS_KEY +
    "&output=" + OUTPUT_FORMAT;
    BufferedReader reader = new BufferedReader(
    new InputStreamReader(
    new URL(GEOCODER_REQUEST).openStream()));
    String line = null;
    int statusCode = -1;
    while ((line = reader.readLine()) != null) {
    // 200,4,37.320052,-121.877636
    // status code,accuracy,latitude,longitude
    statusCode = Integer.parseInt(line.substring(0, 3));
    if (statusCode == 200) {
    int secondComma = line.indexOf(",", 5);
    int lastComma = line.lastIndexOf(",");
    latitude = Float.valueOf(line.substring(secondComma+1, lastComma));
    longitude = Float.valueOf(line.substring(lastComma+1));
    System.out.println("Latitude: " + latitude);
    System.out.println("Longitude: " + longitude);
    }
    }
    return "map";
    }
    // getters and setters

    "getLatLong()" method retrieves geocoding information using HTTP by passing the city and country name, Google Maps API key and CSV output format. The result is then processed to retrieve status code, latitude and longitude. Add the following annotation to this class:

    @ManagedBean(name="coords", scope="request")

    This ensures that "server.CityCoordinates" is injected as a managed bean in the runtime.

  3. Add a new button in "welcome.xhtml" right after "submit" button as:

    <h:commandButton action="#{coords.getLatLong}" value="map"/>

  4. Add a new page "map.xhtml" as:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:m="http://code.google.com/p/gmaps4jsf/">
    <head>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAF9QYjrVEsD9al2QCyg8e-hTwM0brOpm-All5BF6PoaKBxRWWERRHQdtsJnNsqELmKZCKghs54I-0Uw" type="text/javascript"> </script>
    </head>
    <body>
    <m:map
    latitude="#{coords.latitude}"
    longitude="#{coords.longitude}"
    width="500px"
    height="300px"
    zoom="14"
    addStretOverlay="true">
    <m:marker draggable="true">
    <m:eventListener eventName="dragend" jsFunction="showStreet"/>
    </m:marker>
    <m:htmlInformationWindow htmlText="#{coords.details}"/>
    <m:mapControl name="GLargeMapControl" position="G_ANCHOR_BOTTOM_RIGHT"/>
    <m:mapControl name="GMapTypeControl"/>
    </m:map>
    <br/> <br/>
    <m:streetViewPanorama width="500px" height="200px"
    latitude="#{coords.latitude}" longitude="#{coords.longitude}"
    jsVariable="pano1" />
    <script type="text/javascript">
    function showStreet(latlng) {
    pano1.setLocationAndPOV(latlng);
    }
    </script>
    <form jsfc="h:form">
    <input jsfc="h:commandButton" action="back" value="Back"/>
    </form>
    </body>
    </html>

    The code is borrowed and explained in An Introduction to GMaps4JSF. Basically the code displays a Google Map and Street View where the latitude and longitude are bound by "server.CityCoordinates" managed bean. And these attributes are populated using the geocoding information earlier. The Street View corresponds to marker in the Map which is draggable. So if the marker is dropped to a different location in the map then the Street View changes accordingly.

  5. Add new navigation rules to "faces-config.xml" as:

    <navigation-rule>
    <from-view-id>/welcome.xhtml</from-view-id>
    <navigation-case>
    <from-outcome>map</from-outcome>
    <to-view-id>/map.xhtml</to-view-id>
    </navigation-case>
    </navigation-rule>
    <navigation-rule>
    <from-view-id>/map.xhtml</from-view-id>
    <navigation-case>
    <from-outcome>back</from-outcome>
    <to-view-id>/welcome.xhtml</to-view-id>
    </navigation-case>
    </navigation-rule>

That's it, now your application is ready!
Now when a city and country name are entered on "welcome.xhtml" and "map" button is clicked then the corresponding Google Map along with the street view are shown in next page.
If "San Jose" is entered on "http://localhost:8080/Cities/faces/welcome.xhtml" then the following page is shown:

Clicking on "map" button shows the following page:

If the marker is drag/dropped to 280 and 87 junction, then the page looks like:

Embedding Google Maps in Java Server Faces using GMaps4JSF

8 oct 2008

Conocimientos Basicos Para un Desarrollador de Java WEB

El candidato ideal debe poseer las siguientes aptitudes:

Tecnicos:
* Manos fuertes en Desarrollo de Java
*Fuert presentacion de sus conocimientos en HTML,CSS, Javascript con AJAX y similares tecnologias.
*Diseño en interfaz y conocimientos de prueba y usabilidad.
*Conocimiento en los siguientes frameworks(web, MVC, AOP, acceso de datos), Hibernate y JDBC
*Alguna experiencia en bases de datos relacionales.
*Recien Experiencia de JSP/Servlet idealmente en Apache/Tomcat
*Desarrollo y diseño en Orientado a Objetos incluyendo UML asi como patrones de Diseño.
* Experiencia de desarrollo en Linux/Unix
*Experiencia demostrable en trabajo en todas las fases del desarrollo del ciclo de vida(Tipos)
*Ingenieria, Licenciatura en Ciencias computacionales u otros grados de acreditacion academica.

No Tecnicos:
Buenas aptitudes interperosnales y la habilidad de comunicacion tanto oral como escritura.
Debe tener la capaciad de trabajar en aquipo como personal.
Fuertes aptitudes tanto en organizacion y analisis.
Debe adaptarse bien al cambio.
Debe de demostrar capaciad intelectual tanto para aprender rapidamente y adaptarse a situaciones complejas en un ambiente demandante.

2 ago 2008

Programas Java

Me hicieron hacer esto pequeños programas en Java, realemnte hace mucho que no lo hacia ya que me dedique a programar en javascript pero valio la pena jeje

Selección: Este método consiste en buscar el elemento más pequeño del array y ponerlo en primera posición; luego, entre los restantes, se busca el elemento más pequeño y se coloca en segudo lugar, y así sucesivamente hasta colocar el último elemento. Por ejemplo, si tenemos el array {40,21,4,9,10,35}, los pasos a seguir son:

{4,21,40,9,10,35} <-- Se coloca el 4, el más pequeño, en primera posición : se cambia el 4 por el 40.
{4,9,40,21,10,35} <-- Se coloca el 9, en segunda posición: se cambia el 9 por el 21.
{4,9,10,21,40,35} <-- Se coloca el 10, en tercera posición: se cambia el 10 por el 40.
{4,9,10,21,40,35} <-- Se coloca el 21, en tercera posición: ya está colocado.
{4,9,10,21,35,40} <-- Se coloca el 35, en tercera posición: se cambia el 35 por el 40.

class Algoritmo1 {
public static void main(String[] args){
int caja[]=new int[6];
caja[0]=14;
caja[1]=21;
caja[2]=40;
caja[3]=9;
caja[4]=35;
caja[5]=10;
System.out.println("Se muestra el arreglo en desorden");
for(int i=0;i<caja.length;i++){
System.out.print(caja[i]);
}
System.out.println("Se muestra ahora el arreglo ordenado");
int x;
int y;
int tempo, min;
int cap=caja.length;
y=0;
while (y<cap-1){
min=y;
for(x=y+1;x<cap; x++){
if (caja[x]<caja[min]){
min=y;
tempo=caja[x];
caja[x]=caja[min];
caja[min]=tempo;
}
}
y++;
}
for(int i=0;i<caja.length;i++)
System.out.println(caja[i]);

}
}

Array contenido en uno mas grande. Dados dos arrays de números enteros A y B de longitud n y m respectivamente, siendo n >= m, determinar si B está contenido en A. Ejemplo:
A = {2,3,4,5,6,7,-3}
B = {7,-3} -> contenido; B = {5,7} -> no contenido; B = {3,2} -> no contenido

public class algoritmo7 {
public static void main(String[] args){
int A[] = {2,3,4,5,6,7,-3};
int B[]={6,7,-3};
int m=0;
boolean sigue=false;
for(int i=0; i<A.length;i++){
for (int j=0; j<B.length;j++){
if(B[j]==A[i]){
//C[j]=A[i];
m++;
sigue=true;
}else{
sigue=false;
}
}
}
if ((m==B.length) && (sigue==true)){
System.out.println("Contenido");
}else
System.out.println("NO Contenido");
}

}

Potencia. Dados dos números a (número entero) y b (número natural mayor o igual que cero) determinar a^b.

public class algoritmo4 {
static int potencias(int a, int b){
if(b==0){
return 1;
} else
return a * potencias(a,b-1);
}

public static void main(String[] args){
System.out.println(potencias(3,6));
}
}

Related Posts Plugin for WordPress, Blogger...