<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WillxD &#187; Java</title>
	<atom:link href="http://willxd.com/category/tutoriales/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://willxd.com</link>
	<description>La magia no existe, la programación sí !</description>
	<lastBuildDate>Wed, 23 Jun 2010 21:28:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Java desde cero #3</title>
		<link>http://willxd.com/java-desde-cero-3/</link>
		<comments>http://willxd.com/java-desde-cero-3/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 20:49:47 +0000</pubDate>
		<dc:creator>WillxD</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://willxd.com/?p=402</guid>
		<description><![CDATA[Hoy les hablare del control de flujo, dirán que es eso?? bueno les explico rápidamente..  en un programa las instrucciones se ejecutan una a una, pero en el orden que estan escritas ( siempre de arrriba hacia abajo y de izquierda a derecha) pero bueno, existe una forma de indicarle a Java de que cierto [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy les hablare del <strong>control de flujo</strong>, dirán que es eso??<strong> </strong>bueno les explico rápidamente..  en un programa las instrucciones se ejecutan una a una, pero en el orden que estan escritas ( siempre de arrriba hacia abajo y de izquierda a derecha) pero bueno, existe una forma de indicarle a Java de que cierto grupo de instrucciones se ejecuten mediante una <strong>condición</strong>, por ejemplo cuando queremos salir aveces nos ponen condiciones como que debemos limpiar nuestra habitación xD sino no salimos, Java es igual, mientras no se cumpla dicha condición no ejecutará las instrucciones..</p>
<p><span id="more-402"></span></p>
<p>Java nos proporciona varios mecanismos para conseguir este control y decidir qué partes del código ejecutar cuando se cumplan las condiciones, mediante sus sentencias de ramificación. Entre estos mecanismo tenemos los de <strong>if-else,break,switch,return</strong> que explicaré rápidamente x) espero que se entienda.</p>
<p><strong>if-else<br />
</strong>if-else es como un si-no <img src='http://willxd.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Si ordenas tu escritorio vas al cine, sino no sales.<br />
Es así de simple xD pero bueno veamoslo más seriamente..<br />
veamos su estructura:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size:13px;"><span style="color: #000000; font-weight: bold;">if</span>  <span style="color: #009900;">&#40;</span> expresión<span style="color: #339933;">-</span>booleana <span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #009900;">&#123;</span>Instrucción <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">else</span>
&nbsp;
<span style="color: #009900;">&#123;</span>Intrucción <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>Preguntaran qué es la expresión-booleana, bueno esto es lo mismo que la condición, para construir una expresión booleana podemos usar variables,constantes, relaciones de desigualdad y otros más.<br />
Les daré algunos ejemplos de expresiones booleanas:</p>
<ul>
<li>edad&lt;16</li>
<li> numero!=7</li>
<li>valor==20</li>
<li>(numero%3)!=0</li>
<li>numero&gt;=10  &amp;&amp;  numero&lt;=20</li>
</ul>
<p>Vamos con un ejemplo, veamos como hallar los números positivos, negativos, pares e impares:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size:13px;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> edad
    <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>args<span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>
        <span style="color: #009900;">&#123;</span>
         <span style="color: #003399;">InputStreamReader</span> isr<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">in</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">BufferedReader</span> br<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span>isr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Evaluando un número ^^ &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Teclea un número:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> texto1<span style="color: #339933;">=</span>br.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> n1<span style="color: #339933;">=</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>texto1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>n1<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;El número es negativo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">else</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>n1<span style="color: #339933;">%</span>2<span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;El número es par&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #000000; font-weight: bold;">else</span>
                    <span style="color: #009900;">&#123;</span>
                        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;El número es impar&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Analizando rápidamente el código; si (if) el número es menor que cero entonces nos mostrará que el número es negativo, en caso contrario(else) tendremos 2 opciones, si (if) el número es divisible entre 2, mostrará que el número es par, en caso contrario (else) nos mostrará que el número es impar.</p>
<p><strong>Switch</strong><br />
La estructura switch a diferencia de if-else que solo nos permitía escoger entre dos opciones, nos permite escoger entre finitas opciones. Su estructura es la siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size:13px;"><span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>expresion<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #009900;">&#40;</span>valor1<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> intrucciones1<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #009900;">&#40;</span>valor2<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> instrucciones2<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
    .
    .
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #009900;">&#40;</span>valorN<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> instruccionesN<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #339933;">:</span> instruccionesDefault<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Deben saber que el valor de la expresion debe ser int,char, byte o short. La sentencia <strong>break</strong> finaliza la ejecución de esta estructura.</p>
<p>Veamos un ejemplo:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size:13px;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Estacion
<span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>args<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>caso<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">:</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Estamos en Verano&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Fin del caso 1</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">:</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Estamos en Otoño&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Fin del caso 2</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">3</span> <span style="color: #339933;">:</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Estamos en Invierno&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Fin del caso 3</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">4</span> <span style="color: #339933;">:</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Estamos en Primavera&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Fin del caso 4</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No se en que estacion estoy..&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// Fin de instruccion switch</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// Fin del método main</span>
<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">// Fin de la clase Estacion</span></pre></div></div>

<p>Eso es todo por ahora, Salu2 !</p>


<p>Related posts:<ol><li><a href='http://willxd.com/java-desde-cero-2/' rel='bookmark' title='Permanent Link: Java desde cero #2'>Java desde cero #2</a></li>
<li><a href='http://willxd.com/java-desde-cero-1/' rel='bookmark' title='Permanent Link: Java desde cero #1'>Java desde cero #1</a></li>
<li><a href='http://willxd.com/leer-el-teclado-en-java/' rel='bookmark' title='Permanent Link: Leer el teclado en java'>Leer el teclado en java</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://willxd.com/java-desde-cero-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java desde cero #2</title>
		<link>http://willxd.com/java-desde-cero-2/</link>
		<comments>http://willxd.com/java-desde-cero-2/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 18:54:41 +0000</pubDate>
		<dc:creator>WillxD</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[identificador]]></category>
		<category><![CDATA[IOException]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://willxd.com/?p=384</guid>
		<description><![CDATA[Ahora surge la necesidad de almacenar y manipular datos u otros. Por este motivo necesitamos de variables. Una variable reserva un espacio dentro de la memoria del computador de un valor que puede ir variando en el tiempo. Ahora debemos saber que al nombre de la variable se le conoce como identificador. Para cada variable [...]]]></description>
			<content:encoded><![CDATA[<p>Ahora surge la necesidad  de almacenar y manipular datos u otros. Por este motivo necesitamos de <strong>variables</strong>.</p>
<p>Una variable reserva un espacio dentro de la memoria del computador de un valor que puede ir variando en el tiempo.</p>
<p>Ahora debemos saber que al nombre de la variable se le conoce como <strong>identificador.</strong></p>
<p><span id="more-384"></span></p>
<p>Para cada variable debemos decirle al PC que reserve un espacio, a esto se le conoce como <strong>Declaración de una Variable</strong>.</p>
<p>Además debemos especificar que clase de valor se almacenará en la variable, a esto se le llama<strong> Tipo de variable</strong>.</p>
<p>Aca veremos algunos tipos de variables:</p>
<ul>
<li> Boolean: No es un valor numérico, solo admite los valores true o false.</li>
<li> Char: Usa el código UNICODE y ocupa cada carácter 16 bits.</li>
<li> Enteros: Son variables que almacenan números enteros.Pueden ser:
<ul>
<li> Byte: 1 byte.</li>
<li> Short: 2 bytes.</li>
<li> Int: 4 bytes.</li>
<li> Long: 8 bytes.</li>
</ul>
</li>
<li> Reales en punto flotante: igual que los enteros también difieren en las precisiones y pueden ser positivos o negativos.
<ul>
<li> Float: 4 bytes.</li>
<li> Double: 8 bytes.</li>
</ul>
</li>
</ul>
<p>Para almacenar cadenas de caracteres se empleará una <strong>variable referenciada</strong> asociada a la clase <strong>String</strong>.</p>
<p>Ahora vamos con algunos ejemplos <img src='http://willxd.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size:13px;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Datos
<span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>args<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//Declarando las variables..</span>
    <span style="color: #000066; font-weight: bold;">int</span> edad, peso<span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// Variable entera</span>
    <span style="color: #000066; font-weight: bold;">double</span> estatura<span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">// Variable real</span>
    <span style="color: #003399;">String</span> ap,am,nomb<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Cadenas..</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//Asignando valores a las variables..</span>
    ap<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Cadillo&quot;</span><span style="color: #339933;">;</span>
    am<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Sifuentes&quot;</span><span style="color: #339933;">;</span>
    nomb<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;William&quot;</span><span style="color: #339933;">;</span>
    edad <span style="color: #339933;">=</span> <span style="color: #cc66cc;">16</span><span style="color: #339933;">;</span>
    peso <span style="color: #339933;">=</span> <span style="color: #cc66cc;">55</span><span style="color: #339933;">;</span>
    estatura <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1.63</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//Imprimiendo en la pantalla..</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Datos personales: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Edad: &quot;</span> <span style="color: #339933;">+</span> edad <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; años.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Peso: &quot;</span> <span style="color: #339933;">+</span> peso <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; kg.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Estatura: &quot;</span> <span style="color: #339933;">+</span> estatura <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; mts.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Apellido Paterno: &quot;</span><span style="color: #339933;">+</span>ap<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Apellido Materno: &quot;</span><span style="color: #339933;">+</span>am<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Nombre: &quot;</span><span style="color: #339933;">+</span>nomb<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>luego de la ejecución en la pantalla nos mostrará:</p>
<blockquote><p>Datos personales:<br />
Edad: 16 años.<br />
Peso: 55 kg.<br />
Estatura: 1.63 mts.<br />
Apellido Paterno: Cadillo<br />
Apellido Materno: Sifuentes<br />
Nombre: William</p></blockquote>
<p>A una variable tambien podemos asignarle el resultado de una <strong>expresión</strong>. Una expresión puede estar compuesta por constantes, operadores,variables.</p>
<p>Debemos tener cuidado con las expresiones ya que Java realiza las operaciones según los tipos de datos de los operandos con ciertas suposiciones.<br />
Por ejemplo:<br />
Si operamos 9/4 nos resultará 2 ( diran estas loco! como va a salir 4!!) Java "supone" que como 9 y 4 son enteros, el resultado saldrá un entero.<br />
Pero en cambio si operamos 9/4.0 nos resultará 2.25. Esto se debe a que al poner 4.0 Java supone una división real y el resultado debe ser un real.<br />
Ahora un ejemplo <img src='http://willxd.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size:13px;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Operaciones
<span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>args<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//Declarando variables</span>
<span style="color: #000066; font-weight: bold;">int</span> n1<span style="color: #339933;">=</span><span style="color: #cc66cc;">20</span>, n2<span style="color: #339933;">=</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//Imprimiendo en la pantalla..</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Operaciones&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> n1<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;+&quot;</span><span style="color: #339933;">+</span> n2 <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>n1<span style="color: #339933;">+</span>n2<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Suma</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> n1<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;-&quot;</span><span style="color: #339933;">+</span> n2 <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>n1<span style="color: #339933;">-</span>n2<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Resta</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> n1<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;*&quot;</span><span style="color: #339933;">+</span> n2 <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>n1<span style="color: #339933;">*</span>n2<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Producto</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> n1<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">+</span> n2 <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>n1<span style="color: #339933;">/</span>n2<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//División</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> n1<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;%&quot;</span><span style="color: #339933;">+</span> n2 <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>n1<span style="color: #339933;">%</span>n2<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// &quot;%&quot; es para hallar el resto</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">+</span> <span style="color: #cc66cc;">4</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// División entera</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">+</span> <span style="color: #cc66cc;">4.0</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">4.0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//División Real</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>En la pantalla nos mostrará</p>
<blockquote><p>Operaciones<br />
20+3=23<br />
20-3=17<br />
20*3=60<br />
20/3=6<br />
20%3=2<br />
9/4=2<br />
9/4.0=2.25</p></blockquote>
<p>Como veran en el ejemplo anterior la variable es una variable fija, ahora veamos cuando la variable sea un dato de entrada.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size:13px;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> datos_entrada
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>args<span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>
 	<span style="color: #009900;">&#123;</span>
 	<span style="color: #003399;">InputStreamReader</span> isr<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">in</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">BufferedReader</span> br<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span>isr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Elevando al Cuadrado un Número: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Teclea un número:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">String</span> texto1<span style="color: #339933;">=</span>br.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">int</span> n1<span style="color: #339933;">=</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>texto1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;El cuadrado de &quot;</span><span style="color: #339933;">+</span> n1 <span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; es &quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>n1<span style="color: #339933;">*</span>n1<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	 <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Analizemos un poco el ejemplo anterior <img src='http://willxd.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<ol>
<li>Invocamos a la librería de entrada y salida <strong>io</strong>. ( Import java.io*) Selecciona todas las clases disponibles de la librería <strong>io</strong>.</li>
<li>Ahora lo nuevo es <strong>throws IOException, </strong>indica que cualquier error de entrada o salida de datos, será manejado en forma interna (automática) por el programa.</li>
<li><em>InputStreamReader isr = new InputStreamReader(System.in);<br />
</em>Declaramos una variable <strong>isr</strong> de<strong> </strong>tipo<strong> InputStreamReader.</strong> Ahora creamos un objeto <strong>new</strong> <strong>InputStreamReader()</strong> , lo que va entre las paréntesis es el <strong>InputStream</strong> que queremos        convertir a <strong>Reader.</strong></li>
<li> <em>BufferedReader br=new BufferedReader(isr);</em><br />
<strong>BufferedReader</strong> es una clase perteneciente a la librería <strong>io</strong> que crea un buffer de entrada donde se almacenarán los carácteres ingresados por el teclado.</li>
<li> <em>String texto1=br.readLine();</em><br />
Lee del teclado un String y lo guarda en la variable <strong>texto1.</strong></li>
<li><em>int n1=Integer.parseInt(texto1);<br />
</em>Esto intenta convertir <strong>texto1</strong> en un int(entero) y  guarda el resultado en una variable int llamada <strong>n1</strong>.</li>
</ol>
<p>Eso es todo por ahora <img src='http://willxd.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>


<p>Related posts:<ol><li><a href='http://willxd.com/java-desde-cero-3/' rel='bookmark' title='Permanent Link: Java desde cero #3'>Java desde cero #3</a></li>
<li><a href='http://willxd.com/java-desde-cero-1/' rel='bookmark' title='Permanent Link: Java desde cero #1'>Java desde cero #1</a></li>
<li><a href='http://willxd.com/leer-el-teclado-en-java/' rel='bookmark' title='Permanent Link: Leer el teclado en java'>Leer el teclado en java</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://willxd.com/java-desde-cero-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Leer el teclado en java</title>
		<link>http://willxd.com/leer-el-teclado-en-java/</link>
		<comments>http://willxd.com/leer-el-teclado-en-java/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 18:13:55 +0000</pubDate>
		<dc:creator>WillxD</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://willxd.com/?p=380</guid>
		<description><![CDATA[Veamos como leer desde el teclado en Java. Java es enigmático en esto xD asi es que vamos por partes. La Clase InputStream: El Objeto System.in Asi como vimos que Java nos ofrece System.out para la salida de datos por la pantalla, también tenemos System.in para la entrada de datos. System.in es un objeto de [...]]]></description>
			<content:encoded><![CDATA[<p>Veamos como leer desde el teclado en Java.  Java es enigmático en esto xD<br />
asi es que vamos por partes.</p>
<h4>La Clase InputStream: El Objeto System.in</h4>
<p>Asi como vimos que Java nos ofrece System.out para la salida de datos por la pantalla, también tenemos <strong>System.in</strong> para la entrada de datos. System.in es un objeto de una clase llamada <strong>InputStream. </strong><strong>InputStream</strong> es para leer bytes y sólo tiene métodos para leer bytes.<br />
Pero nosotros no queremos leer bytes, sino queremeos leer letras y números del teclado :@ !! Por ejemplo si escribimos en el        teclado una A mayúscula y la leemos con <strong>System.in</strong>,        obtendremos un entero de valor 65, que es el valor del byte correspondiente a la A.</p>
<p><span id="more-380"></span></p>
<hr />
<h4>Los Reader</h4>
<p>La clase <strong>Reader</strong> es una clase que lee carácteres, un <strong>Reader</strong> tiene métodos para leer caracteres.</p>
<p>Ahora el problema es :<br />
¿ Cómo convertir el <strong>System.in</strong> en <strong>Reader</strong>?<br />
Pues para felicidad de nosotros, existe la clase <strong>InputStreamReader</strong>, que hace esta conversión.</p>
<p>¿Cómo obtener un <strong>Reader</strong>?<br />
Debemos instanciar un <strong>InputStreamReader</strong> , pasando en el constructor un <strong>InputStream</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size:13px;"><span style="color: #003399;">InputStreamReader</span> isr <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">in</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Declaramos la variable <strong>isr</strong> de tipo <strong>StreamReader</strong>.Luego creamos un objeto de esta clase escribiendo <strong>new InputStreamReader()</strong>. Entre las paréntesis le pasamos el <strong>InputStream</strong> que queremos pasar a <strong>Reader</strong>. Y ya tenemos nuestro Reader <img src='http://willxd.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>¿Ahora, cómo es su funcionamiento?<br />
InputStreamReader es un Reader. Al construirlo le hemos pasado un InputStream.<br />
Cuando pedimos caracteres a InputStreamReader, él le pide al InputStream que es el que tiene guardado los bytes, luego estos bytes los convierte a caracteres y nos lo devuelve.</li>
<hr />
<h4>La Clase BufferedReader</h4>
<p>La clase <strong>InputStreamReader</strong> nos da los caracteres <em>sueltos</em> y como son caracteres sueltos debemos decirle cúantos caracteres queremos que lea. Y si tuvieramos solo la clase InputStreamReader sería bastante código.<br />
Pero para la solución existe la clase <strong>BuffeerReader</strong>. El mecanismo para obtener un <strong>BufferReader</strong> a partir de otro <strong>Reader</strong> es similar al que usamos antes.<br />
Lo instanciamos pasándole en el constructor el <strong>Reader</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size:13px;"><span style="color: #003399;">BufferedReader</span> br <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span> <span style="color: #009900;">&#40;</span>isr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>En cuanto al funcionamiento es similar al del <strong>InputStreamReader</strong>. Cuando pedimos una línea de caracteres (<strong>String</strong>), ella se lo pide al <strong>Reader</strong>, los convierte en <strong>String</strong> y nos lo devuelve.</p>
<p>Para pedir un <strong>String </strong>se usa el método <strong>readline()</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size:13px;"><span style="color: #003399;">String</span> texto1 <span style="color: #339933;">=</span> br.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Esto lee del teclado un String y lo guarda en la variable <strong>texto1</strong></li>
<hr />
<h4>Convertir una Cadena (String) a un Entero (Int)</h4>
<p>Ahora que pasa si queremos convertir un String a un Entero, por ejemplo si escribimos "4285", con la clase <strong>BufferReader</strong> obtendremos un String de 4 caracteres. Y eso no es igual al número 4285.</p>
<p>Para convertir usaremos la clase <strong>Integer</strong>, pero esta clase es bien estricta asi es que tenga cuidado con ella =P , para convertir un String a int es necesareo que el String sea un int. Por ejemplo si escribimos "java" nunca podra ser convertido a int. Otro caso seria si escribimos "42 85" tampoco sería convertido ya que el espacio entre el 42 y el 85 hace que falle, ya que el espacio lo toma como un caracter.<br />
La conversión se realiza de la siguiente manera:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size:13px;"><span style="color: #000066; font-weight: bold;">int</span> valor <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>texto1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>El código anterior intenta cambiar lo que esta almacenado en la variable texto1 a un valor entero, siempre y cuando texto1 sea un int.</p>
<hr />
<h4>Aplicación Simple Leyendo desde el teclado</h4>
<p>Aca les dejo una simple aplicación para que todo lo explicado anteriormente quede más claro.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size:13px;"><span style="color: #666666; font-style: italic;">// Importando la librería io (Entrada y Salida)</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LeerTeclado <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Habilitando el teclado para el ingreso de datos</span>
        <span style="color: #003399;">BufferedReader</span> teclado<span style="color: #339933;">;</span>
	teclado <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">in</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Declaración de variables</span>
	<span style="color: #000066; font-weight: bold;">float</span> importe<span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> nombre<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//Entrada de datos</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Digite el nombre del cliente =&gt; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    	<span style="color: #666666; font-style: italic;">// usamos el método readLine para guardar lo escrito como String</span>
		nombre <span style="color: #339933;">=</span> teclado.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Digite el importe de compra de &quot;</span><span style="color: #339933;">+</span>nombre<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; =&gt; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Por defecto lo que escribimos se almacena como cadena o String</span>
		<span style="color: #666666; font-style: italic;">// Para guardarlo como entero usamos la clase Integer y el método parseInt</span>
        	importe <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>teclado.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Salida de Datos</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;El importe de &quot;</span> <span style="color: #339933;">+</span> nombre <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;es &quot;</span> <span style="color: #339933;">+</span> importe<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>



<p>Related posts:<ol><li><a href='http://willxd.com/java-desde-cero-2/' rel='bookmark' title='Permanent Link: Java desde cero #2'>Java desde cero #2</a></li>
<li><a href='http://willxd.com/java-desde-cero-1/' rel='bookmark' title='Permanent Link: Java desde cero #1'>Java desde cero #1</a></li>
<li><a href='http://willxd.com/java-desde-cero-3/' rel='bookmark' title='Permanent Link: Java desde cero #3'>Java desde cero #3</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://willxd.com/leer-el-teclado-en-java/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Java desde cero #1</title>
		<link>http://willxd.com/java-desde-cero-1/</link>
		<comments>http://willxd.com/java-desde-cero-1/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 02:26:14 +0000</pubDate>
		<dc:creator>WillxD</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://willxd.com/?p=376</guid>
		<description><![CDATA[Bueno me anime a realizar esta mini guía de Java donde pondré todos mis conocimientos que vaya adquiriendo con el tiempo (6) ya que no hay mejor manera que aprender que enseñando los conocimientos . Comenzaré por explicar un poco de Java Estructurado (sé que Java es orientado a objetos) pero para principiantes como YO [...]]]></description>
			<content:encoded><![CDATA[<p>Bueno me anime a realizar esta mini guía de Java donde pondré todos mis conocimientos que vaya adquiriendo con el tiempo (6) ya que no hay mejor manera que aprender que enseñando los conocimientos <img src='http://willxd.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  .</p>
<p>Comenzaré por explicar un poco de Java Estructurado (<del datetime="2009-01-13T07:58:15+00:00">sé que Java es orientado a objetos</del>) pero para principiantes como YO es necesario saber la programación estructurada o tal vez este errado, pero bueno la cuestión es aprender <img src='http://willxd.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><span id="more-376"></span></p>
<p>Bueno para este curso es necesario tener mucha lógica.</p>
<p>Primero que nada deben saber que Java es un lenguaje para darle instrucciones al computador (lo tiene “pisado” xD ).</p>
<p>Java como cualquier lenguaje está compuesto por “oraciones”, en nuestro caso por “instrucciones” y cada instrucción tiene un significado para la PC.</p>
<p>Debemos escribir bien las instrucciones de tal manera que la PC las pueda entender y también tener cuidado a que las instrucciones escritas tengan el significado que hará cumplir nuestros objetivos. Ya basta de palabreos.. =D</p>
<p>Se me estaba olvidando un pequeño detalle =# aun no he hablado del IDE que utilizaremos para programar en Java.</p>
<p>Aca les dejo la lista de algunos :</p>
<ul>
<li><a href="http://www.jcreator.com/">Jcreator</a></li>
<li><a href="http://www.eclipse.org/">Eclipse</a></li>
<li><a href="http://www.netbeans.org/">Netbeans</a></li>
</ul>
<p>Algunos se preguntaran para que sirven estas “IDE”, el IDE es un entorno de desarrollo, es un programa que trae herramientas como un editor de código, un compilador, un depurador y un constructor de interfaz gráfica. Más información en <a href="http://es.wikipedia.org/wiki/Ambiente_integrado_de_desarrollo">Wikipedia</a></p>
<p>Directo al grano, haremos nuestro “primer programa”</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size:13px;"><span style="color: #666666; font-style: italic;">//Nuestro Primer Programa!</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Primer_Programa_Java
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Me gusta Java xD&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ahora explicaré línea por línea de lo que signfica el código anterior ( pero no se acostumbren <img src='http://willxd.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  )</p>
<ol>
<li>La primera línea solo es un comentario,  que empieza luego del comando "<strong>//</strong>" , esta línea no se ejecutará en el programa.</li>
<li>En la segunda línea definimos la clase "Primer_Programa_Java" (no poner espacios dentro de una clase).</li>
<li>Dentro de la clase "Primer_Programa_Java" definimos el método <strong><em>main</em></strong>,  <em>public static void</em> quiere decir que el método es público, estático y void indica que el método main no retorna ningún valor. La forma (String args[]) es la definición de los argumentos que recibe el método main.  Main recibe como argumento un arreglo de strings.</li>
<li>La instrucción:

<div class="wp_syntax"><div class="code"><pre class="php" style="font-size:13px;"><span style="color: #009900;">&#123;</span> <span style="color: #990000;">System</span><span style="color: #339933;">.</span>out<span style="color: #339933;">.</span>println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Me gusta Java xD&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Muestra una cadena de texto o string. No olvidar terminar la instrucción con un punto y coma, es una regla, asi como en el esañol terminamos una oración con el punto.</li>
</ol>
<p>Ahora compilamos y guardamos con la extension ".java"</p>
<p>El programa realizado solo imprime un mensaje en la pantalla.</p>
<p>Bueno eso es todo por ahora, acepto críticas constructivas <img src='http://willxd.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>


<p>Related posts:<ol><li><a href='http://willxd.com/java-desde-cero-3/' rel='bookmark' title='Permanent Link: Java desde cero #3'>Java desde cero #3</a></li>
<li><a href='http://willxd.com/java-desde-cero-2/' rel='bookmark' title='Permanent Link: Java desde cero #2'>Java desde cero #2</a></li>
<li><a href='http://willxd.com/leer-el-teclado-en-java/' rel='bookmark' title='Permanent Link: Leer el teclado en java'>Leer el teclado en java</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://willxd.com/java-desde-cero-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
