<?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>Java HowTo Guide &#187; Java Basics</title>
	<atom:link href="http://www.javahowtoguide.com/category/java-basics/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javahowtoguide.com</link>
	<description>Learn JAVA with US</description>
	<lastBuildDate>Tue, 20 Dec 2011 10:10:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>JAVA &#8211; Condition (Decision-making) Statements</title>
		<link>http://www.javahowtoguide.com/condition-decision-making-statements/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=condition-decision-making-statements</link>
		<comments>http://www.javahowtoguide.com/condition-decision-making-statements/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 05:06:42 +0000</pubDate>
		<dc:creator>Java Tutor</dc:creator>
				<category><![CDATA[Statement]]></category>
		<category><![CDATA[Decision-making Statements]]></category>

		<guid isPermaLink="false">http://www.javahowtoguide.com/?p=62</guid>
		<description><![CDATA[ <p> </p> <p> </p> <p> </p> <p>Unlike the sequential statements, the Control flow statements enable execution of parts of a code only, based on a particular condition. These control flow statements enable decision making on the program. The common decision-making statements that we use in different Java programs are:</p> if statement if-else statement if-else-if statement Nested if statement Switch <p>We will look at each of these statements in detail.</p> <p> </p> ]]></description>
			<content:encoded><![CDATA[<p><strong><br />
</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p>Unlike the sequential statements, the Control flow statements enable execution of parts of a code only, based on a particular condition. These control flow statements enable decision making on the program. The common decision-making statements that we use in different Java programs are:</p>
<ul>
<li>if      statement</li>
<li>if-else      statement</li>
<li>if-else-if      statement</li>
<li>Nested      if statement</li>
<li>Switch</li>
</ul>
<p>We will look at each of these statements in detail.</p>
<p><strong> </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowtoguide.com/condition-decision-making-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAVA &#8211; Control Statements</title>
		<link>http://www.javahowtoguide.com/java-control-statements/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-control-statements</link>
		<comments>http://www.javahowtoguide.com/java-control-statements/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 06:12:23 +0000</pubDate>
		<dc:creator>Java Tutor</dc:creator>
				<category><![CDATA[Java Basics]]></category>
		<category><![CDATA[Statement]]></category>
		<category><![CDATA[Control Statements]]></category>

		<guid isPermaLink="false">http://www.javahowtoguide.com/?p=63</guid>
		<description><![CDATA[<p> </p> <p>As you’ve learned in the sequential statements topic, the computer while running a java program, starts executing from the topmost line of the code. It reads the first line of the code, and continues doing so till the last line. Control statements help you run a program in a manner you define. These statements are used to change the computer’s control from reading and executing the statements in a given sequence to the way you define.</p> <p>Control statements always base the program execution on a set of conditions. Let’s take an example of a programmer designing a program for a financial institute. The data for such programs is confidential and cannot be accessed by all the users. You would provide such an access to the user only if they provide the correct username and password. “Only” if both the passwords and the username are correct, should the program code allow them to see the records. The “else” part of code will run for people who don’t have valid password and enter incorrect information.</p> <p>As you can see, the control statements help you check a certain condition. You can also put one control statement into another. Such statements are then known as nested control statements. In the example given above, the financial institute software provides 3 chances o each user. If the user enters incorrect information in all the three chances, their records are locked for a particular period. A sample algorithm that would help you design such a program is shown below:</p> <p></p> <p>1. Set Variable_counter_1 to 0; 2. Show the computer screen that asks you to enter your password; 3. If the password you enter is correct, run the code that allows the user to see the records which he wanted to see; 4. Else increment Variable_counter_1  <p>Continue reading <a href="http://www.javahowtoguide.com/java-control-statements/">JAVA &#8211; Control Statements</a></p>]]></description>
			<content:encoded><![CDATA[<p><strong><br />
</strong></p>
<p>As you’ve learned in the sequential statements topic, the computer while running a java program, starts executing from the topmost line of the code. It reads the first line of the code, and continues doing so till the last line. Control statements help you run a program in a manner you define. These statements are used to change the computer’s control from reading and executing the statements in a given sequence to the way you define.</p>
<p>Control statements always base the program execution on a set of conditions. Let’s take an example of a programmer designing a program for a financial institute. The data for such programs is confidential and cannot be accessed by all the users. You would provide such an access to the user only if they provide the correct username and password. “Only” if both the passwords and the username are correct, should the program code allow them to see the records. The “else” part of code will run for people who don’t have valid password and enter incorrect information.</p>
<p>As you can see, the control statements help you check a certain condition. You can also put one control statement into another. Such statements are then known as <strong>nested</strong> control statements. In the example given above, the financial institute software provides 3 chances o each user. If the user enters incorrect information in all the three chances, their records are locked for a particular period. A sample algorithm that would help you design such a program is shown below:</p>
<p><span id="more-63"></span></p>
<p><code><em>1. </em></code><code><em>Set</em></code><code><em> Variable_counter_1 to 0; </em></code><em><br />
<code>2. Show the computer screen that asks you to enter your password; </code><br />
<code>3. If the password you enter is correct, run the code that allows the user to see the records which he wanted to see; </code><br />
<code>4. Else increment Variable_counter_1  i.e. add one to the Variable_counter_1; </code><br />
<code>5. If Variable_counter_1 is not equal to 3, then return back to line two and Show the computer screen again that asks you to enter your password;</code><br />
<code>6. Else if Variable_counter_1  equals 3 then lock the records and display the "goodbye" screen (If the counter equals 3 this means user have tried 3 times to enter the password and he does not have valid password so the user does not have valid rights.)</code><br />
</em><br />
The code given above is a pseudo code. Since this code is written in simple English, it is understood by any person, but not by the computer.  In this pseudo code one if else statement is place within another if else statement. The manner in which the code would be executed is:</p>
<ol>
<li><code><em>1. </em></code><code><em>Enter the password</em></code></li>
<li><code><em>2. </em></code><code><em>If the password is correct, skip lines dealing with incorrect passwords i.e. lines 4,5 and 6</em></code></li>
<li><code><em>3. </em></code><code><em>Else, if the password is incorrect, read line 4 instead of reading end of line 3</em></code></li>
<li><code><em>4. </em></code><code><em>If the counter does not equal to 3, do not run line 6; but go back and run line 4 and 5</em></code></li>
<li><code><em>5. </em></code><code><em>Else, if the password is incorrect for the third time, don’t run line 4 and 5 but run line 6</em></code></li>
</ol>
<p>The control statements used in Java language are simple and can be understood by the computer easily. Because of this, they are very simple and are used extensively.  In case your condition has a complex structure, you can build it by combining a number of complex statements that contain a number of if-else statements.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowtoguide.com/java-control-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAVA &#8211; Console Input</title>
		<link>http://www.javahowtoguide.com/java-console-input/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-console-input</link>
		<comments>http://www.javahowtoguide.com/java-console-input/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 13:47:29 +0000</pubDate>
		<dc:creator>Java Tutor</dc:creator>
				<category><![CDATA[Input /Output]]></category>
		<category><![CDATA[Console Input]]></category>

		<guid isPermaLink="false">http://www.javahowtoguide.com/?p=64</guid>
		<description><![CDATA[<p> </p> <p> </p> <p>Console input refers to keyboard. Most of the times we assign value s to the variables while declaring them. However, there are times when the program depends on the user provided inputs also. For example:</p> <p>String your_name_example;</p> <p>your_name_example  = Console.ReadLine();</p> <p>In this example, first statement declares a string variable ` your_name_example &#8216;. Next statement, the Console.ReadLine command will read the value from console that is value which is entered by the user and store it in the variable ` your_name_example &#8216;.</p> <p>This command works great if you assigning and entering the values into string variables. However, the input that the computer receives from using the command Console.ReadLine(); does not work with data types such as integers or doubles. This command will accept inputs in the text format only. If you try to input other types of variables using Console.ReadLine() command, an error message is generated.</p> <p>Instead you can use the parse command as shown below:</p> <p>int num_var_1;</p> <p>num_var_1 = int.Parse(Console.ReadLine());</p> <p>In the above example, the int.Parse command will convert the text input from the string output of  Console.ReadLine() into an integer variable num_var_1.</p> <p>Similarly, the command double.parse is used to enter a double data type user defined value.</p> <p>Not only this, the command `Console.WriteLine&#8217; can be used to display messages and values stored in variables. For example,</p> <p>Console.WriteLine(&#8220;Hello. This is an example of display message on screen&#8221;);</p> <p></p> <p>The code snippet given below displays the use of the command `Console.WriteLine&#8217; -</p> <p>static void Main(string[] args) { int num_var_1;</p> <p>Console.WriteLine(&#8220;Please enter a number&#8221;); num_var_1=int.Parse(Console.ReadLine()); Console.WriteLine(&#8220;The number you have entered is {0}&#8221;, num_var_1); }</p> <p>In the above code snippet, the first `Console.WriteLine&#8217; command is used to display a simple message: “Please enter a number. “</p> <p>The second `Console.WriteLine&#8217; statement, makes use of a {0} with the message, where <p>Continue reading <a href="http://www.javahowtoguide.com/java-console-input/">JAVA &#8211; Console Input</a></p>]]></description>
			<content:encoded><![CDATA[<p><strong><br />
</strong><strong> </strong></p>
<p><strong> </strong></p>
<p>Console input refers to keyboard. Most of the times we assign value s to the variables while declaring them. However, there are times when the program depends on the user provided inputs also. For example:</p>
<p>String your_name_example;</p>
<p>your_name_example  = Console.ReadLine();</p>
<p>In this example, first statement declares a string variable ` your_name_example &#8216;. Next statement, the Console.ReadLine command will read the value from console that is value which is entered by the user and store it in the variable ` your_name_example &#8216;.</p>
<p>This command works great if you assigning and entering the values into string variables. However, the input that the computer receives from using the command Console.ReadLine(); does not work with data types such as integers or doubles. This command will accept inputs in the text format only. If you try to input other types of variables using Console.ReadLine() command, an error message is generated.</p>
<p>Instead you can use the <em>parse</em> command as shown below:</p>
<p>int num_var_1;</p>
<p>num_var_1 = int.Parse(Console.ReadLine());</p>
<p>In the above example, the <em>int.Parse</em> command will convert the text input from the string output of  Console.ReadLine() into an integer variable num_var_1.</p>
<p>Similarly, the command <em>double.parse</em> is used to enter a double data type user defined value.</p>
<p>Not only this, the command `Console.WriteLine&#8217; can be used to display messages and values stored in variables. For example,</p>
<p>Console.WriteLine(&#8220;Hello. This is an example of display message on screen&#8221;);</p>
<p><span id="more-64"></span></p>
<p>The code snippet given below displays the use of the command `Console.WriteLine&#8217; -</p>
<p>static void Main(string[] args) { int num_var_1;</p>
<p>Console.WriteLine(&#8220;Please enter a number&#8221;); num_var_1=int.Parse(Console.ReadLine()); Console.WriteLine(&#8220;The number you have entered is {0}&#8221;, num_var_1); }</p>
<p>In the above code snippet, the first `Console.WriteLine&#8217; command is used to display a simple message: “<strong>Please enter a number</strong>. “</p>
<p>The second `Console.WriteLine&#8217; statement, makes use of a {0} with the message, where 0 acts as a placeholder. When the computer displays the output, it replaces the placeholder with the variable specified after the comma (,), which is num_var_1 in the example</p>
<p>If the user enters the number 56, the message that will be displayed is:</p>
<p><strong>The number you have entered are 56.</strong></p>
<p>Just as a single placeholder is used to input a single variable or value, multiple placeholders can be used to show multiple values or variables. The code snippet given below illustrates the use of this concept:</p>
<p>static void Main(string[] args) {</p>
<p>int num_var_1;</p>
<p>string string_variable_name;</p>
<p>Console.WriteLine(&#8220;Please enter name of your best friend&#8221;);</p>
<p>string_variable_name = Console.ReadLine();</p>
<p>Console.WriteLine(&#8220;Next, please enter age of your best friend&#8221;);</p>
<p>num_var_1=int.Parse(Console.ReadLine());</p>
<p>Console.WriteLine(&#8220;Your best friend {0} is {1} years old&#8221;, string_variable_name, num_var_1);</p>
<p>}</p>
<p>In the example given above, the last `Console.WriteLine&#8217; statement uses two placeholders. When the program is run and the output is displayed, the first placeholder {0} will be replaced by the value stored in the variable ` string_variable_name &#8216;. Similarly, the second placeholder {1} will be replaced by the value stored in variable ` num_var_1&#8242;.</p>
<p>If we input John as name of best friend and 32 as his age, the final output of this program will be – “Your best friend John is 32 years old”.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowtoguide.com/java-console-input/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAVA &#8211; Console Output Commands</title>
		<link>http://www.javahowtoguide.com/java-console-output-commands/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-console-output-commands</link>
		<comments>http://www.javahowtoguide.com/java-console-output-commands/#comments</comments>
		<pubDate>Tue, 11 May 2010 06:27:44 +0000</pubDate>
		<dc:creator>Java Tutor</dc:creator>
				<category><![CDATA[Input /Output]]></category>
		<category><![CDATA[Java Basics]]></category>
		<category><![CDATA[Console Output Commands]]></category>

		<guid isPermaLink="false">http://www.javahowtoguide.com/?p=65</guid>
		<description><![CDATA[<p> </p> <p> </p> <p> </p> <p>Just as the Console Input command, accepts the user defined input, the Console. Output command displays the output on the monitor. In the Java programming language, you can write programs that write text lines to the console, which is a DOS based command window.</p> <p>Though it’s not as popular as a Graphical User Interface or a GUI, the Console.Output command is used sometimes by programmers. Also, the Console.Output command doesn’t work properly with applets, WebStart applications and normal GUI programs. A sample code that shows the dialog or the console output program for simple input/output command is shown below:</p> <p>public class example_Console_Output</p> <p>{</p> <p>public static void main(String[] args) {</p> <p>System.out.println(&#8220;Hello, This is the example of Console Output command. &#8220;);</p> <p>}</p> <p>}</p> <p>The System.out.println command is used to display an entire line of output on the console. The message passed as an argument to the System.out.println command is printed on the console. The println is the short form of print line command and originates from the Pascal programming language.</p> <p></p> <p>You can also substitute the println command with the print command. This command also prints the output to the console. However, it does not start a new line after the output is displayed.</p> <p>Therefore, we can say that println is a method called by the System.out object used for displaying the console output. In this method, as you’ve already seen the data that needs to be displayed is passed as an argument to this command. The command uses a (+) sign to connenct two or more items. Not only this, each time the println command is invoked, it generates a new line once it has finished printing on the console. The example given below displays this:</p> <p>System.out.println(&#8220;The answer to the question is &#8221; + 9390);</p> ]]></description>
			<content:encoded><![CDATA[<p><strong><br />
</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p>Just as the Console Input command, accepts the user defined input, the Console. Output command displays the output on the monitor. In the Java programming language, you can write programs that write text lines to the console, which is a DOS based command window.</p>
<p>Though it’s not as popular as a Graphical User Interface or a GUI, the Console.Output command is used sometimes by programmers. Also, the Console.Output command doesn’t work properly with applets, WebStart applications and normal GUI programs. A sample code that shows the dialog or the console output program for simple input/output command is shown below:</p>
<p>public class example_Console_Output</p>
<p>{</p>
<p>public static void main(String[] args) {</p>
<p>System.out.println(&#8220;Hello, This is the example of Console Output command. &#8220;);</p>
<p>}</p>
<p>}</p>
<p>The <strong>System.out.println</strong> command is used to display an entire line of output on the console. The message passed as an argument to the <strong>System.out.println</strong> command is printed on the console. The println is the short form of print line command and originates from the Pascal programming language.</p>
<p><span id="more-65"></span></p>
<p>You can also substitute the println command with the <strong>print </strong>command. This command also prints the output to the console. However, it does not start a new line after the output is displayed.</p>
<p>Therefore, we can say that println is a method called by the System.out object used for displaying the console output. In this method, as you’ve already seen the data that needs to be displayed is passed as an argument to this command. The command uses a (+) sign to connenct two or more items. Not only this, each time the println command is invoked, it generates a new line once it has finished printing on the console. The example given below displays this:</p>
<p>System.out.println(&#8220;The answer to the question is &#8221; + 9390);</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowtoguide.com/java-console-output-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAVA Expressions</title>
		<link>http://www.javahowtoguide.com/java-expressions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-expressions</link>
		<comments>http://www.javahowtoguide.com/java-expressions/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 10:07:16 +0000</pubDate>
		<dc:creator>Java Tutor</dc:creator>
				<category><![CDATA[Java Basics]]></category>
		<category><![CDATA[Statement]]></category>
		<category><![CDATA[Expression and statement]]></category>

		<guid isPermaLink="false">http://www.javahowtoguide.com/?p=66</guid>
		<description><![CDATA[<p> </p> <p> </p> <p> </p> <p> </p> <p>Let’s first look at expressions. An expression is a program construct defined according to the syntax of the programming language, which uses variables, operators, and methods. Let’s now look at some examples of expressions:</p> <p>int category_var = 0; </p> <p> </p> <p>cat_Array[0]=200;</p> <p> </p> <p>Now you can use these variables in the following expression:</p> <p>System.out.println(&#8220;An element 1 at index 0: &#8221; + cat_Array[0]);</p> <p> </p> <p>int result_operator = 22 + 40; // result is now 62</p> <p>The data type of resultant value returned by an expression depends on the data types of the operand used in the expression.  In the example shown above, the data type of the expression category_var = 0 return an int. This is because the assignment operator returns the value of int data type. Apart from int, the expressions can also return data of other types also such as Boolean or String.</p> <p>Not only this, you can also construct compound expressions in the Java programming language. These compound expressions can be constructed by combining a number of smaller expressions. The only condition being the data type of the left side of the expression should match the data type of the right type.</p> <p>The following code snippet displays the following compound expression:</p> <p>3 * 4 * 5</p> <p>In this example, apart from the product obtained from this expression, it is also important to note the order in which this expression is evaluated by the compiler. The outcome or the product of the expression always remains same irrespective of the order in which they appear in the expression.</p> <p></p> <p>For example, in the expression given below, the result or the outcome would vary depending on the use or evaluation of the division or the addition operator.</p> <p>Num_var_1 + Num_var_2 / <p>Continue reading <a href="http://www.javahowtoguide.com/java-expressions/">JAVA Expressions</a></p>]]></description>
			<content:encoded><![CDATA[<p><strong><br />
</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p>Let’s first look at <strong>expressions</strong>. An expression is a program construct defined according to the syntax of the programming language, which uses variables, operators, and methods. Let’s now look at some examples of expressions:</p>
<p>int category_var = 0;<strong> </strong></p>
<p><strong> </strong></p>
<p>cat_Array[0]=200;</p>
<p><strong> </strong></p>
<p>Now you can use these variables in the following expression:</p>
<p>System.out.println(&#8220;An element 1 at index 0: &#8221; + cat_Array[0]);</p>
<p><strong> </strong></p>
<p>int result_operator = 22 + 40; // result is now 62</p>
<p>The data type of resultant value returned by an expression depends on the data types of the operand used in the expression.  In the example shown above, the data type of the expression category_var = 0 return an int. This is because the assignment operator returns the value of int data type. Apart from <strong>int</strong>, the expressions can also return data of other types also such as <strong>Boolean</strong> or <strong>String</strong>.</p>
<p>Not only this, you can also construct compound expressions in the Java programming language. These compound expressions can be constructed by combining a number of smaller expressions. The only condition being the data type of the left side of the expression should match the data type of the right type.</p>
<p>The following code snippet displays the following compound expression:</p>
<p>3 * 4 * 5</p>
<p>In this example, apart from the product obtained from this expression, it is also important to note the order in which this expression is evaluated by the compiler. The outcome or the product of the expression always remains same irrespective of the order in which they appear in the expression.</p>
<p><span id="more-66"></span></p>
<p>For example, in the expression given below, the result or the outcome would vary depending on the use or evaluation of the division or the addition operator.</p>
<p>Num_var_1 + Num_var_2 / 25     // an unclear expression</p>
<p>The use of parenthesis in such expression makes them clear and helps determine the order of precedence.</p>
<p>Let’s see how the use of parenthesis helps in making the above unclear expression clear.</p>
<p>(Num_var_1 + Num_var_2) / 25    // use of parenthesis to rectify an unclear statement</p>
<p>The operator precedence defined within an expression takes precedence and the output is determined in that manner, if you don’t explicitly define the order of operators.  As you’ve already learnt operators having higher precedence are evaluated before the others. In the expression we just saw, the division operator would be evaluated before the addition operator.  Therefore, the result or the output of the following two statements would be the same:</p>
<p>Num_var_1 + Num_var_2 / 10</p>
<p>Num_var_1 + (Num_var_2 / 25)   // use of parenthesis to rectify an unclear statement</p>
<p>When defining compound expressions, it is important to explicitly define the order of operator precedence with the use of parenthesis. It will also help a programmer to make the code more readable and maintainable.</p>
<p>You can convert expressions into a statement by terminating the expression with a semicolon (;). Some such expressions are:</p>
<ul>
<li>Assignment      expressions</li>
<li>Use  of ++ or &#8211;</li>
<li>Method      invocations</li>
<li>Object      creation expressions</li>
</ul>
<p>These statements are known as expression statements. Some examples of expression statements are:</p>
<p>Sample_Value_var = 9834.435;</p>
<p>Sample_Value_var++;</p>
<p>System.out.println(&#8220;Hello! How are you?&#8221;);</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowtoguide.com/java-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

