<?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</title>
	<atom:link href="http://www.javahowtoguide.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javahowtoguide.com</link>
	<description>Learn JAVA with US</description>
	<lastBuildDate>Thu, 26 Aug 2010 06:12:23 +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 &#8211; Control Statements</title>
		<link>http://www.javahowtoguide.com/java-control-statements/?utm_source=rss&amp;utm_medium=rss&amp;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[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 [...]]]></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&amp;utm_medium=rss&amp;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[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: String your_name_example; your_name_example  = Console.ReadLine(); In this example, first statement declares a string variable ` your_name_example &#8216;. Next statement, the [...]]]></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&amp;utm_medium=rss&amp;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[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. Though it’s not as popular as a Graphical User Interface or [...]]]></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&amp;utm_medium=rss&amp;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[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: int category_var = 0; cat_Array[0]=200; Now you can use these variables in the following expression: System.out.println(&#8220;An element 1 at index 0: [...]]]></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>
		<item>
		<title>Sequential Statements in JAVA</title>
		<link>http://www.javahowtoguide.com/sequential-statements-in-java/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sequential-statements-in-java</link>
		<comments>http://www.javahowtoguide.com/sequential-statements-in-java/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 06:37:18 +0000</pubDate>
		<dc:creator>Java Tutor</dc:creator>
				<category><![CDATA[Java Basics]]></category>
		<category><![CDATA[Statement]]></category>
		<category><![CDATA[Sequential Statements]]></category>

		<guid isPermaLink="false">http://www.javahowtoguide.com/?p=67</guid>
		<description><![CDATA[A program is defined as a group of statements executed in a given order to achieve a predetermined result.  Therefore, a program executes the statements in a sequential manner, either from top to bottom or vice versa. These are executed in the manner that they appear in the program code, called the sequential execution or [...]]]></description>
			<content:encoded><![CDATA[<p><strong><br />
</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p>A program is defined as a group of statements executed in a given order to achieve a predetermined result.  Therefore, a program executes the statements in a sequential manner, either from top to bottom or vice versa. These are executed in the manner that they appear in the program code, called the sequential execution or sequential control flow.</p>
<p>The sequential statements can also be used in Processes, Procedures and Functions. These are further divided into:</p>
<ul>
<li>Expressions</li>
<li>Console Input      statements</li>
<li>Console Output      statements</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowtoguide.com/sequential-statements-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAVA &#8211; Different type of Statements</title>
		<link>http://www.javahowtoguide.com/java-different-type-of-statements/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=java-different-type-of-statements</link>
		<comments>http://www.javahowtoguide.com/java-different-type-of-statements/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 14:35:03 +0000</pubDate>
		<dc:creator>Java Tutor</dc:creator>
				<category><![CDATA[Statement]]></category>
		<category><![CDATA[JAVA Statement]]></category>

		<guid isPermaLink="false">http://www.javahowtoguide.com/?p=68</guid>
		<description><![CDATA[A statement is a command given by the programmer to the computer program. Statements are used by different computer programming languages, such as Java, C, and C++. The syntax for declaring and using statements varies in each language. A simple example of a statement can be: println “Hello ! I hope you are enjoying your [...]]]></description>
			<content:encoded><![CDATA[<p><strong><br />
</strong></p>
<p>A statement is a command given by the programmer to the computer program. Statements are used by different computer programming languages, such as Java, C, and C++. The syntax for declaring and using statements varies in each language. A simple example of a statement can be:</p>
<p><strong>println “Hello ! I hope you are enjoying your stay here”</strong></p>
<p>The statement uses a set of words <strong>“Hello! I hope you are enjoying your stay here?”</strong> and other details, such as what will be printed on screen.  The command <strong>println</strong> tells the computer to show the output on the monitor and not on the printer. The computer understands this command in the following two ways:</p>
<p>The programmer can give the command to the computer in the running mode, as the program is being executed.</p>
<p>They can also store a statement or a set of statements in a text file and execute it as and when required. This will then save the task of executing the statements again and again. For example, the command we just saw can be saved in a file <strong>Hello.txt</strong> and give this file to the computer.</p>
<p>As stated above, you can also save a set of multiple statements in a text file, which will then be executed in the top to bottom order. This means that the statement on the top will be executed first, followed by all other statements in that order.</p>
<p><span id="more-68"></span></p>
<p>Continuing with the above example, the file <strong>“Hello.txt”</strong> can contain multiple statements in a single file:</p>
<p><strong>println “Hello! I hope you are enjoying your stay here.”</strong></p>
<p><strong>println “How was the dinner yesterday?”</strong></p>
<p><strong>println “Enjoy your lunch.”</strong></p>
<p>As stated above, each of these commands will be performed from top to bottom in a sequential manner. On seeing the text file, the computer:</p>
<ul>
<li>Reads the first statement from the text file</li>
<li>Determines if it is a <strong><em>println</em></strong> statement</li>
<li>Determines the text that needs to be printed</li>
<li>Displays the text on screen.</li>
</ul>
<p>Therefore, the first command to be displayed on the screen would be: <strong>Hello! I hope you are enjoying your stay here.</strong></p>
<p>The last statement would be: What is the duration of the course</p>
<p>The question marks that you saw in the code are not displayed on the computer screen. These punctuation marks are used to tell the computer where the statement would begin and end respectively. The computer then reads the second line, followed by the third line and displays the output in the following manner:</p>
<p><strong>Hello! I hope you are enjoying your stay here.</strong></p>
<p><strong>How was the dinner yesterday?</strong></p>
<p><strong>Enjoy your lunch.</strong></p>
<p>The computer stops reading the file once it reaches the end of the file. It is important to provide correct code in these text files, otherwise the code can also be erroneous.</p>
<p>Different programming languages use different types of computer statements. For example, a language can use a <strong>beep</strong> statement directing the computer to produce a beep in its speakers. Similarly, a <strong>window</strong> statement can direct the computer to popup a new window.</p>
<p>Not only this, different programming languages display and code statements differently. The set of rules such as <strong>println</strong> used to describe a statement is known as its <em>syntax</em>, while the actual message that needs to be displayed in known as its <strong>library.</strong></p>
<p>Therefore, we can say that statements are used to change the value of variables, process input, display the desired output, or produce an action in response to user mouse or keyboard actions.</p>
<p>Different types of statements that we will commonly come across in the Java are:</p>
<ul>
<li>Assignment Statements</li>
<li>Message Statements</li>
<li>Statement Blocks</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowtoguide.com/java-different-type-of-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAVA &#8211; Logical /Boolean Operator</title>
		<link>http://www.javahowtoguide.com/java-logical-boolean-operator/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=java-logical-boolean-operator</link>
		<comments>http://www.javahowtoguide.com/java-logical-boolean-operator/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 13:18:29 +0000</pubDate>
		<dc:creator>Java Tutor</dc:creator>
				<category><![CDATA[Operator]]></category>
		<category><![CDATA[Logical /Boolean Operator in JAVA]]></category>

		<guid isPermaLink="false">http://www.javahowtoguide.com/?p=69</guid>
		<description><![CDATA[The relational operators work well in conditions where only a single condition needs to be checked. Logical operators either return a True value or a False value based on the state of the Variables. The six logical or Boolean, operators used in the Java programming language are: AND conditional AND OR conditional OR exclusive OR [...]]]></description>
			<content:encoded><![CDATA[<p><strong><br />
</strong><strong> </strong></p>
<p><strong> </strong></p>
<p>The relational operators work well in conditions where only a single condition needs to be checked. Logical operators either return a True value or a False value based on the state of the Variables. The six logical or Boolean, operators used in the Java programming language are:</p>
<ul>
<li>AND</li>
<li>conditional AND</li>
<li>OR</li>
<li>conditional OR</li>
<li>exclusive OR</li>
<li>NOT</li>
</ul>
<p>A logical operator accepts only arguments declared as Boolean data types. Also, these operators return value of Boolean data type.</p>
<p>These operators unlike the relational operators, that you already know, are used to check whether a set of conditions is true or not. In such as case, if statements are used. The code snippet below shows example of this:</p>
<pre><code>if (num_var_1 == 4) {</code></pre>
<pre><code>  if (num_var_2 != 4) {</code></pre>
<pre><code>     System.out.println("Both conditions are true.");</code></pre>
<pre><code>   }</code></pre>
<pre><code>}</code></pre>
<p>However, as you can see this is not a user-friendly code, and is both harder to write and read. Such a code snippet becomes difficult to manage when multiple conditions are used. Let’s now look at the use of the following three conditional operators:<code>&amp;&amp;</code>, <code>||</code> and <code>!</code>.</p>
<p><code>The logical operator &amp;&amp; combines two Boolean values and gives a True result </code>if and only if both of its operands are true. This is shown in the following code snippet:</p>
<pre><code>Boolean c;</code></pre>
<pre><code>num_var_1 = 51 &gt; 49 &amp;&amp; 13 &lt; 13; // num_var_1 is true</code></pre>
<pre><code>num_var_1 = 44 &gt; 52 &amp;&amp; 7 &lt; 9; // num_var_1 is now false</code></pre>
<p><code>Similarly, the logical operator <strong>||</strong></code> combines two Boolean variables or expressions. It returns a true result only if either or both of its operands are true. Let’s look at the following code snippet which shows the rule:</p>
<pre><code>Boolean d;</code></pre>
<pre><code>num_var_4 = 51 &gt; 49 || 73 &lt; 91; // num_var_4 is true</code></pre>
<pre><code>num_var_4 = 49 &gt; 51 || 73 &lt; 91; // num_var_4 is still true</code></pre>
<pre><code>num_var_4 = 49 &gt; 51 || 73 &gt; 91; // now num_var_4 is false</code></pre>
<p>The third and the last logic operator which we will look at is “!”  Which denotes “<strong>not”</strong>. The “!” logical operator reverses the value of a Boolean expression.</p>
<p>According to this logical operator:</p>
<p>if <code>x</code> is true <code>!x</code> is false.</p>
<p>If <code>x </code>is false  !x is true.</p>
<pre><code>boolean bol_var_1;</code></pre>
<pre><code>bol_var_1 = !(4 &gt; 5); // bol_var_1 is false</code></pre>
<pre><code>bol_var_1 = !(5 &gt; 4); // bol_var_1 is true</code></pre>
<p>As already stated logical operators allow you to test and use multiple conditions. For example, we can use the logical operators in the code snippet we saw above as follows:</p>
<pre><code>if (var_num_1 == 2 &amp;&amp; var_num_2 != 2) {</code></pre>
<pre><code>  System.out.println("Both conditions are true.");</code></pre>
<pre><code>}</code></pre>
<p>Let’s look at a code snippet Demo_of_Logical_Operators which makes use of multiple logical operators:</p>
<p>public class Demo_of_Logical_Operators</p>
<p>{</p>
<p>public Demo_of_Logical_Operators () {</p>
<p>boolean bol_var_1 = true;</p>
<p>boolean bol_var_2 = false;</p>
<p>System.out.println(&#8220;bol_var_1 &amp; bol_var_2 : &#8221; + (bol_var_1 &amp; bol_var_2));</p>
<p>System.out.println(&#8220;bol_var_1 &amp;&amp; bol_var_2 : &#8221; + (bol_var_1 &amp;&amp; bol_var_2));</p>
<p>System.out.println(&#8220;bol_var_1 | bol_var_2 : &#8221; + (bol_var_1 | bol_var_2));</p>
<p>System.out.println(&#8220;bol_var_1 || bol_var_2: &#8221; + (bol_var_1 || bol_var_2));</p>
<p>System.out.println(&#8220;bol_var_1 ^ bol_var_2 : &#8221; + (bol_var_1 ^ bol_var_2));</p>
<p>System.out.println(&#8220;!bol_var_1 : &#8221; + (!bol_var_1));</p>
<p>}</p>
<p>public static void main(String args[]) {</p>
<p>new Demo_of_Logical_Operators ();</p>
<p>The table given below defines the different Boolean operators, if x and y are both Boolean expressions.</p>
<table border="1" cellspacing="0" cellpadding="0" width="508">
<tbody>
<tr>
<td width="80" valign="top"><strong>x</strong><strong> </strong></td>
<td width="80" valign="top"><strong>y</strong><strong> </strong></td>
<td width="80" valign="top"><strong>!x </strong></td>
<td width="100" valign="top"><strong>x &amp;   y </strong></p>
<p><strong>x   &amp;&amp; y</strong></td>
<td width="100" valign="top"><strong>x | y </strong></p>
<p><strong>x || y </strong></td>
<td width="68" valign="top"><strong>x ^ y </strong></td>
</tr>
<tr>
<td valign="top">true</td>
<td valign="top">true</td>
<td valign="top">false</td>
<td valign="top">true</td>
<td valign="top">true</td>
<td valign="top">false</td>
</tr>
<tr>
<td valign="top">true</td>
<td valign="top">false</td>
<td valign="top">false</td>
<td valign="top">false</td>
<td valign="top">true</td>
<td valign="top">true</td>
</tr>
<tr>
<td valign="top">false</td>
<td valign="top">true</td>
<td valign="top">true</td>
<td valign="top">false</td>
<td valign="top">true</td>
<td valign="top">true</td>
</tr>
<tr>
<td valign="top">false</td>
<td valign="top">false</td>
<td valign="top">true</td>
<td valign="top">false</td>
<td valign="top">false</td>
<td valign="top">false</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowtoguide.com/java-logical-boolean-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAVA &#8211; Relational Operators</title>
		<link>http://www.javahowtoguide.com/java-relational-operators/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=java-relational-operators</link>
		<comments>http://www.javahowtoguide.com/java-relational-operators/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 13:17:40 +0000</pubDate>
		<dc:creator>Java Tutor</dc:creator>
				<category><![CDATA[Operator]]></category>
		<category><![CDATA[Relational Operators in JAVA]]></category>

		<guid isPermaLink="false">http://www.javahowtoguide.com/?p=70</guid>
		<description><![CDATA[The relational operators are used to determine if one operand is equal to, greater than, less than, or not equal to the other operand with which it is compared. Just like mathematical operators, most of these operators are just like the normal operators we use in the everyday life. But certain operators are used in [...]]]></description>
			<content:encoded><![CDATA[<p><strong><br />
</strong><strong> </strong></p>
<p><strong> </strong></p>
<p>The relational operators are used to determine if one operand is equal to, greater than, less than, or not equal to the other operand with which it is compared. Just like mathematical operators, most of these operators are just like the normal operators we use in the everyday life. But certain operators are used in a different manner also.</p>
<p>For example, in place of “=” operator that we generally use for comparing two operands are equal, the relational operators in the Java programming language use  “==’.</p>
<p>The relational operators are defined as binary expressions, while their operands are numeric expressions.</p>
<p>When applying these operators, the rules that apply to the binary operators are applied and their evaluation returns a numeric value. Not only this, the operator precedence of relational operators is higher than assignment operators but lower than arithmetic operators.</p>
<p>The six relational operators used in Java and their uses are listed in the table below:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="308" valign="top">Relational Operator</td>
<td width="308" valign="top">Description</td>
</tr>
<tr>
<td width="308" valign="top">Equal to</td>
<td width="308" valign="top">==</td>
</tr>
<tr>
<td width="308" valign="top">Not equal to</td>
<td width="308" valign="top">!=</td>
</tr>
<tr>
<td width="308" valign="top">Greater than</td>
<td width="308" valign="top">&gt;</td>
</tr>
<tr>
<td width="308" valign="top">Greater than or equal to</td>
<td width="308" valign="top">&gt;=</td>
</tr>
<tr>
<td width="308" valign="top">Less than</td>
<td width="308" valign="top">&lt;</td>
</tr>
<tr>
<td width="308" valign="top">Less than or equal to</td>
<td width="308" valign="top">&lt;=</td>
</tr>
</tbody>
</table>
<p>Next, let’s look at the code for the program demo_of_relational_operator that shows the use of the comparison operators.</p>
<p>class demo_of_relational_operator {</p>
<p>public static void main(String[] args){</p>
<p>int num_var_1 = 32;</p>
<p>int num_var_2 = 47;</p>
<p>if(num_var_1 == num_var_2) System.out.println(&#8220;num_var_1 == num_var_2&#8243;);</p>
<p>if(num_var_1 != num_var_2) System.out.println(&#8220;num_var_1 != num_var_2&#8243;);</p>
<p>if(num_var_1 &gt; num_var_2) System.out.println(&#8220;num_var_1 &gt; num_var_2&#8243;);</p>
<p>if(num_var_1 &lt; num_var_2) System.out.println(&#8220;num_var_1 &lt; num_var_2&#8243;);</p>
<p>if(num_var_1 &lt;= num_var_2) System.out.println(&#8220;num_var_1 &lt;= num_var_2&#8243;);</p>
<p>}</p>
<p>}</p>
<p>Output:</p>
<p>num_var_1 != num_var_2</p>
<p>num_var_1 &lt; num_var_2</p>
<p>num_var_1 &lt;= num_var_2</p>
<p>Next, let’s look at another code snipped displaying the use of different relational operators.</p>
<p>public class Demo_of_Relational_Operators</p>
<p>{</p>
<p>public Demo_of_Relational_Operators ( )</p>
<p>{</p>
<p>int num_var_1 = 10, num_var_2 = 5;</p>
<p>System.out.println(”num_var_1 &gt; num_var_2 : “+(num_var_1 &gt; num_var_2 ));</p>
<p>System.out.println(”num_var_1 &lt; num_var_2 : “+(num_var_1 &lt; num_var_2 ));</p>
<p>System.out.println(”num_var_1 &gt;= num_var_2 : “+(num_var_1 &gt;= num_var_2 ));</p>
<p>System.out.println(”num_var_1 &lt;= num_var_2 : “+(num_var_1 &lt;= num_var_2 ));</p>
<p>System.out.println(”num_var_1 == num_var_2 : “+(num_var_1 == num_var_2 ));</p>
<p>System.out.println(”num_var_1 != num_var_2 : “+(num_var_1 != num_var_2 ));</p>
<p>}</p>
<p>public static void main(String args[]){</p>
<p>new Demo_of_Relational_Operators ();</p>
<p>}</p>
<p>}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowtoguide.com/java-relational-operators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAVA &#8211; Arithmetic Operators</title>
		<link>http://www.javahowtoguide.com/java-arithmetic-operators/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=java-arithmetic-operators</link>
		<comments>http://www.javahowtoguide.com/java-arithmetic-operators/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 13:16:32 +0000</pubDate>
		<dc:creator>Java Tutor</dc:creator>
				<category><![CDATA[Operator]]></category>
		<category><![CDATA[Arithmetic Operators in JAVA]]></category>

		<guid isPermaLink="false">http://www.javahowtoguide.com/?p=71</guid>
		<description><![CDATA[The Java programming language provides operators that perform simple mathematical operations such as addition, subtraction, multiplication, and division. These operators resemble the basic mathematics symbols that we all are aware of. Unlike the normal mathematical symbols, the “%”operator divides one operand by another and returns a remainder in the result. The Java programming languages uses [...]]]></description>
			<content:encoded><![CDATA[<p><strong><br />
</strong></p>
<p><strong> </strong></p>
<p>The Java programming language provides operators that perform simple mathematical operations such as addition, subtraction, multiplication, and division. These operators resemble the basic mathematics symbols that we all are aware of. Unlike the normal mathematical symbols, the “%”operator divides one operand by another and returns a remainder in the result.</p>
<p>The Java programming languages uses the following symbols:</p>
<ul>
<li>+ Additive      operator: This operator is not only used for addition, but is also used      for String concatenation purposes.</li>
<li>- Subtraction      operator: This operator is used for subtracting the operands.</li>
<li>* Multiplication      operator:  This operator is used for      multiplying the operands.</li>
<li>/ Division      operator: This operator is used for dividing two or more operands.</li>
<li>% remainder      operator: This operator is used for obtaining the remainder by dividing      one operand with another.</li>
</ul>
<p>Let’s now look at a small program, Demo_of_operator_program, which shows the use of different arithmetic operators.</p>
<p><strong>class Demo_of_operator_program {</strong></p>
<p><strong> public static void main (String[] args){</strong></p>
<p><strong> int result_operator = 20 + 42; // The result_operator is now 62</strong></p>
<p><strong> System.out.println(result_operator);</strong></p>
<p><strong> result_operator = result_operator &#8211; 22; // The result_operator is now 40</strong></p>
<p><strong> System.out.println(result_operator);</strong></p>
<p><strong> result_operator = result_operator * 3; // The result_operator is now 120</strong></p>
<p><strong> System.out.println(result_operator);</strong></p>
<p><strong> result_operator = result_operator / 2; // The result_operator is now 60</strong></p>
<p><strong> System.out.println(result_operator);</strong></p>
<p><strong> result_operator = result_operator + 10; // The result_operator is now 70</strong></p>
<p><strong> result_operator = result % 14; // The result_operator is now 5</strong></p>
<p><strong> System.out.println(result_operator);</strong></p>
<p><strong> }</strong></p>
<p><strong>}</strong></p>
<p><strong> </strong></p>
<p>The arithmetic operators listed above can be combined with the simple assignment operator to create compound assignments. For example the compound assignments such as, y+=1; and y=y+1; both increment the value of y by 1.</p>
<p>Not only this, you can also use the + or the additive operator for joining or concatenating two strings together. The Demo_of_Concat_Stings program displayed below displays a sample of string concatenation:</p>
<p><strong>class Demo_of_Concat_Stings {</strong></p>
<p><strong> public static void main(String[] args){</strong></p>
<p><strong> String first_normal_String = &#8220;This is an&#8221;;</strong></p>
<p><strong> String second_normal_String = &#8221; arithmetic operator&#8221;;</strong></p>
<p><strong> String third_concataneted_String = first_normal_String+second_normal_String;</strong></p>
<p><strong> System.out.println(third_concataneted_String);</strong></p>
<p><strong> }</strong></p>
<p><strong>}</strong></p>
<p>This program displays the result: <strong>“This is an arithmetic operator.”</strong> which gets stored in the variable <strong>third_concataneted_String.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowtoguide.com/java-arithmetic-operators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Operators in Java</title>
		<link>http://www.javahowtoguide.com/operators-in-java/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=operators-in-java</link>
		<comments>http://www.javahowtoguide.com/operators-in-java/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 09:31:48 +0000</pubDate>
		<dc:creator>Java Tutor</dc:creator>
				<category><![CDATA[Operator]]></category>
		<category><![CDATA[JAVA Operators]]></category>

		<guid isPermaLink="false">http://www.javahowtoguide.com/?p=72</guid>
		<description><![CDATA[Computer operators are special symbols that perform specific operations on operands to return a result. Most computer programming languages support pre-defined set of operators, similar in function to mathematical operators. Many a times, these operators are built-into a programming language, while at other times these may be defined in the program itself.  Therefore, languages such [...]]]></description>
			<content:encoded><![CDATA[<p align="center"><strong><br />
</strong></p>
<p align="center"><strong> </strong></p>
<p align="center"><strong> </strong></p>
<p>Computer operators are special symbols that perform specific operations on operands to return a result. Most computer programming languages support pre-defined set of operators, similar in function to mathematical operators.</p>
<p>Many a times, these operators are built-into a programming language, while at other times these may be defined in the program itself.  Therefore, languages such as C support built-in operators, while C++ and Java contain program-defined operators.</p>
<p>Operator precedence and associativity are defined in computer programming language specifications. Similarly, the position of the computer operator with respect to the computer operands can be prefix, postfix, or infix.</p>
<p>In the Java programming language, the operators act according to their precedence. Therefore, it is important that we know in advance about the operators with highest precedence, as these operators are evaluated before the operators with lower precedence. On the other hand, all the operators appearing on the same line have equal precedence. The Java compiler evaluates all operators, except the binary operators from left to right. Only the assignment operators are evaluated from right to left.</p>
<p>The following table lists the operators according to their precedence.</p>
<p><span id="more-72"></span></p>
<p align="center"><strong>Operator Precedence</strong></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="308" valign="top">Name of Operator</td>
<td width="308" valign="top">Order of Precedence</td>
</tr>
<tr>
<td width="308" valign="top">Postfix</td>
<td width="308" valign="top">expr&#8211;,  expr++</td>
</tr>
<tr>
<td width="308">Unary</td>
<td width="308">++expr, &#8211;expr, +expr, -expr, ~ !</td>
</tr>
<tr>
<td width="308">Multiplicative</td>
<td width="308">* / %</td>
</tr>
<tr>
<td width="308">Additive</td>
<td width="308">+, -</td>
</tr>
<tr>
<td width="308">Shift</td>
<td width="308">&lt;&lt;, &gt;&gt;, &gt;&gt;&gt;</td>
</tr>
<tr>
<td width="308">Relational</td>
<td width="308">&lt;, &gt;, &lt;=, &gt;=, instanceof</td>
</tr>
<tr>
<td width="308">Equality</td>
<td width="308">==, !=</td>
</tr>
<tr>
<td width="308">Bitwise AND</td>
<td width="308">&amp;</td>
</tr>
<tr>
<td width="308">Bitwise exclusive OR</td>
<td width="308">^</td>
</tr>
<tr>
<td width="308">Bitwise inclusive OR</td>
<td width="308">|</td>
</tr>
<tr>
<td width="308">Logical AND</td>
<td width="308">&amp;&amp;</td>
</tr>
<tr>
<td width="308">Logical OR</td>
<td width="308">||</td>
</tr>
<tr>
<td width="308">Ternary</td>
<td width="308">?, :</td>
</tr>
<tr>
<td width="308">Assignment</td>
<td width="308">= ,+=, -=, *=, /= ,%=, &amp;=, ^=, |=, &lt;&lt;=, &gt;&gt;=   &gt;&gt;&gt;=</td>
</tr>
</tbody>
</table>
<p>Programmers tend to use some operators mot than the others. For example, they tend to us the assignment operator “=”much more than the unsigned left shift operator “&gt;&gt;&gt;=”</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowtoguide.com/operators-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
