<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5138474113628691399</id><updated>2011-04-22T03:13:30.485+08:00</updated><title type='text'>IT1838 mPowered!</title><subtitle type='html'>This is a blog created for the sharing of information for the teaching of IT1838 under the mPowered Programme!</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://it1838.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://it1838.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>weimeng</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5138474113628691399.post-4023122631864299539</id><published>2007-06-03T23:22:00.001+08:00</published><updated>2007-06-03T23:34:38.215+08:00</updated><title type='text'>Arrays</title><content type='html'>Using arrays is a way to extend the storage of variables to include a list of values, instead of just a single value. It is a way for programmers to handle large quantity of data efficiently.&lt;br /&gt;&lt;br /&gt;Arrays are specified using a square bracket (&lt;span style="font-family: courier new;"&gt;int marks[]&lt;/span&gt;) and individual elements in an array can be referred to by their index:&lt;pre&gt;   marks[21] = 68;&lt;br /&gt;  marks[14] = 79;&lt;/pre&gt;Because the index is just an integer value, we can always use a variable to represent the index so that we can parse through the array elements one by one.&lt;pre&gt;   for(int i=0; i&amp;lt;marks.length; i++)&lt;br /&gt;   {&lt;br /&gt;      marks[i] = 0;&lt;br /&gt;   }&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5138474113628691399-4023122631864299539?l=it1838.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://it1838.blogspot.com/feeds/4023122631864299539/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5138474113628691399&amp;postID=4023122631864299539' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/4023122631864299539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/4023122631864299539'/><link rel='alternate' type='text/html' href='http://it1838.blogspot.com/2007/06/arrays.html' title='Arrays'/><author><name>weimeng</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5138474113628691399.post-8638489455699801900</id><published>2007-06-01T23:09:00.000+08:00</published><updated>2007-06-03T23:39:21.561+08:00</updated><title type='text'>Methods</title><content type='html'>Sorry for the non-update last week; was busy attending a conference.&lt;br /&gt;&lt;br /&gt;The concept of methods is central to the OO (Object-oriented) methodology, and is also central to the understanding of any programming languages, since programming languages always comes with loads of pre-defined methods or functions (in the form of libraries) that programmers can use to simplify their programs.&lt;br /&gt;&lt;br /&gt;As mentioned in the lecture, there are broadly 2 types of methods, the pre-defined ones and the ones that programmers write themselves within an application.&lt;br /&gt;&lt;br /&gt;Java has loads of pre-defined methods that comes in packages and can be accessed at this URL (&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/" target="_blank"&gt;http://java.sun.com/j2se/1.5.0/docs/api/&lt;/a&gt;) for the JDK that we are using. You might not need it now, but the list will come in handy during your projects in later semesters when you need to write complicated Java programs.&lt;br /&gt;&lt;br /&gt;For programmer-defined methods, you will need to remember to write the method header and method body (refer to Q1 of Lab 5), and to do a method call (refer to Q2 of Lab 5) in the main method so that the method gets executed.&lt;br /&gt;&lt;br /&gt;Take note that the variables declared in a method is only valid within a method, and cannot be accessed outside a method. So if you used a variable &lt;span style="font-family: courier new;"&gt;num1&lt;/span&gt; in a method &lt;span style="font-family: courier new;"&gt;findAverage()&lt;/span&gt;, you need to declare it in the method itself and not in &lt;span style="font-family: courier new;"&gt;main()&lt;/span&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5138474113628691399-8638489455699801900?l=it1838.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://it1838.blogspot.com/feeds/8638489455699801900/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5138474113628691399&amp;postID=8638489455699801900' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/8638489455699801900'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/8638489455699801900'/><link rel='alternate' type='text/html' href='http://it1838.blogspot.com/2007/06/methods.html' title='Methods'/><author><name>weimeng</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5138474113628691399.post-4887150128984302269</id><published>2007-05-20T16:51:00.000+08:00</published><updated>2007-05-20T17:58:39.302+08:00</updated><title type='text'>Repetition Structure</title><content type='html'>This week we continue with the 3rd control structure of programming, namely Repetition Structure.&lt;br /&gt;&lt;br /&gt;Repetition structure is used to make certain portions of the program code run repeatedly, to achieve certain logic that you want. There are 3 Java statements to do repetition, &lt;span style="font-family: courier new;"&gt;while()&lt;/span&gt;, &lt;span style="font-family: courier new;"&gt;for()&lt;/span&gt; and &lt;span style="font-family: courier new;"&gt;do-while()&lt;/span&gt;. Refer to your lab 4 or the textbook for the syntax.&lt;br /&gt;&lt;br /&gt;The characteristics for these loops are:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new; font-weight: bold;"&gt;while()&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; loop:&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;this is a pre-test loop, meaning the condition is tested before going into the loop.&lt;/li&gt;&lt;li&gt;for a counter-controlled loop, need to specify the starting value for the counter (&lt;span style="font-family: courier new;"&gt;int i = 0;&lt;/span&gt;), the continuation condition (&lt;span style="font-family: courier new;"&gt;while(i&lt;5)&lt;/span&gt;) and the increment (&lt;span style="font-family: courier new;"&gt;i++;&lt;/span&gt;). The starting value is to be specified &lt;span style="font-style: italic;"&gt;before the loop&lt;/span&gt;, and the increment is to be &lt;span style="font-style: italic;"&gt;within the loop&lt;/span&gt;.&lt;/li&gt;&lt;li&gt;for a sentinel-controlled loop, need to ensure that the value to be checked/compared against the sentinel value is being changed within the loop, either by some calculations, or by requesting input from the user.&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family: courier new; font-weight: bold;"&gt;for()&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; loop:&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;a &lt;span style="font-family: courier new;"&gt;for()&lt;/span&gt; loop works exactly the same as a counter-controlled &lt;span style="font-family: courier new;"&gt;while()&lt;/span&gt; loop by collecting all the 3 necessary statements and putting them together in the &lt;span style="font-family: courier new;"&gt;for()&lt;/span&gt; statement.&lt;/li&gt;&lt;li&gt;a &lt;span style="font-family: courier new;"&gt;for()&lt;/span&gt; loop is particularly useful when we are dealing with arrays.&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family: courier new; font-weight: bold;"&gt;do-while()&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; loop:&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;a &lt;span style="font-family: courier new;"&gt;do-while()&lt;/span&gt; loop is a post-test loop, meaning the statements within the loop is ran first before the condition is checked/tested if the loop is to be repeated.&lt;/li&gt;&lt;li&gt;the only difference between &lt;span style="font-family: courier new;"&gt;do-while()&lt;/span&gt; loop and &lt;span style="font-family: courier new;"&gt;while()&lt;/span&gt; loop is that statements are ran &lt;span style="font-style: italic;"&gt;at least once&lt;/span&gt; for a &lt;span style="font-family: courier new;"&gt;do-while()&lt;/span&gt; loop, and statements &lt;span style="font-style: italic;"&gt;may not be ran at all&lt;/span&gt; for a &lt;span style="font-family: courier new;"&gt;while()&lt;/span&gt; loop.&lt;/li&gt;&lt;li&gt;for the &lt;span style="font-family: courier new;"&gt;while()&lt;/span&gt; statement in a &lt;span style="font-family: courier new;"&gt;do-while()&lt;/span&gt; loop, you need to put a semi-colon (&lt;span style="font-family: courier new;"&gt;;&lt;/span&gt;) at the end of the statement.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;That's about the important things that you should take note.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5138474113628691399-4887150128984302269?l=it1838.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://it1838.blogspot.com/feeds/4887150128984302269/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5138474113628691399&amp;postID=4887150128984302269' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/4887150128984302269'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/4887150128984302269'/><link rel='alternate' type='text/html' href='http://it1838.blogspot.com/2007/05/repetition-structure.html' title='Repetition Structure'/><author><name>weimeng</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5138474113628691399.post-1538818816348995686</id><published>2007-05-15T22:45:00.000+08:00</published><updated>2007-05-15T23:07:16.300+08:00</updated><title type='text'>More selection structure</title><content type='html'>Another selection structure which achieves multiple branching is the &lt;span style="font-family: courier new;"&gt;switch()&lt;/span&gt; structure. This structure is a multiple &lt;span style="font-family: courier new;"&gt;if()&lt;/span&gt; and the broadest use it to create a menu structure for a program.&lt;br /&gt;&lt;pre&gt;switch(&lt;span style="font-style: italic; font-weight: bold;"&gt;integer variable&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;  case &lt;span style="font-style: italic; font-weight: bold;"&gt;C1&lt;/span&gt;: //Write statements to do if variable == C1&lt;br /&gt;           break;&lt;br /&gt;&lt;br /&gt;  case &lt;span style="font-style: italic; font-weight: bold;"&gt;C2&lt;/span&gt;: //Write statements to do if variable == C2&lt;br /&gt;           break;&lt;br /&gt;&lt;br /&gt;  default: //Write statements to do if variable is other values&lt;br /&gt;}&lt;/pre&gt;Things to note for a &lt;span style="font-family: courier new;"&gt;switch()&lt;/span&gt; structure:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;it can only evaluate an integer value (including char)&lt;br /&gt;&lt;/li&gt;&lt;li&gt;values for the cases are exact values and it does not allow range of values (e.g. C1 &gt; 20)&lt;/li&gt;&lt;li&gt;all cases should have a break statement to prevent statements from falling through&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5138474113628691399-1538818816348995686?l=it1838.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://it1838.blogspot.com/feeds/1538818816348995686/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5138474113628691399&amp;postID=1538818816348995686' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/1538818816348995686'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/1538818816348995686'/><link rel='alternate' type='text/html' href='http://it1838.blogspot.com/2007/05/more-selection-structure.html' title='More selection structure'/><author><name>weimeng</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5138474113628691399.post-384256190989308203</id><published>2007-05-15T21:56:00.000+08:00</published><updated>2007-05-15T22:42:08.860+08:00</updated><title type='text'>Selection structure</title><content type='html'>The Selection structure is primarily achieved by using the &lt;span style="font-family:courier new;"&gt;if()&lt;/span&gt; condition (flowchart attached below).&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.leepoint.net/notes-java/flow/if/evalscore-flowchart.gif"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 289px;" src="http://www.leepoint.net/notes-java/flow/if/evalscore-flowchart.gif" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;The &lt;span style="font-family:courier new;"&gt;if()&lt;/span&gt; condition allows branching of program codes based on a condition. The general structure looks like this:&lt;br /&gt;&lt;pre&gt;if(condition)&lt;br /&gt;{&lt;br /&gt;  // Write statements to do if condition is true&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;  // Write statements to do if condition is false&lt;br /&gt;}&lt;/pre&gt;We can also nest (put) &lt;span style="font-family:courier new;"&gt;if()&lt;/span&gt; conditions within another &lt;span style="font-family:courier new;"&gt;if()&lt;/span&gt; conditions to form complex logic for our programs. Do take care of the curly brackets, and always use tabs to indent the statements properly to aid debugging.&lt;br /&gt;&lt;br /&gt;Things to note about &lt;span style="font-family: courier new;"&gt;if()&lt;/span&gt; conditions:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;an &lt;span style="font-family: courier new;"&gt;if()&lt;/span&gt; can have one and only one &lt;span style="font-family: courier new;"&gt;else&lt;/span&gt; or not at all&lt;/li&gt;&lt;li&gt;a &lt;span style="font-family: courier new;"&gt;else&lt;/span&gt; must come with a &lt;span style="font-family: courier new;"&gt;if()&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: courier new;"&gt;if()&lt;/span&gt; conditions are independent of each other&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5138474113628691399-384256190989308203?l=it1838.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://it1838.blogspot.com/feeds/384256190989308203/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5138474113628691399&amp;postID=384256190989308203' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/384256190989308203'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/384256190989308203'/><link rel='alternate' type='text/html' href='http://it1838.blogspot.com/2007/05/selection-structure.html' title='Selection structure'/><author><name>weimeng</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5138474113628691399.post-1278404209467276854</id><published>2007-05-06T17:53:00.000+08:00</published><updated>2007-05-06T18:10:17.436+08:00</updated><title type='text'>Comparing Strings</title><content type='html'>As mentioned in the previous post, relational operators are meant for comparing variables declared in the primitive data types, and not strings. Since strings are objects of the String class, we need to use methods to perform the comparison.&lt;br /&gt;&lt;br /&gt;We introduced 3 methods for comparing strings.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family: courier new;"&gt;compareTo()&lt;/span&gt; - This method compares 2 strings and returns an integer value. If the 2 strings are exactly the same (including the case), a &lt;span style="font-family: courier new;"&gt;0&lt;/span&gt; will be returned. Else, the method will return the difference between the 2 strings. Using the return value, we can use it to help us sort strings. Refer to Lab 3 for an example, which I will also elaborate in class.&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: courier new;"&gt;equals()&lt;/span&gt; - This method also compares 2 strings but returns only the boolean values TRUE (when the strings are exactly the same) or FALSE (when the strings are not the same).&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: courier new;"&gt;equalsIgnoreCase()&lt;/span&gt; - This method does the same thing as &lt;span style="font-family: courier new;"&gt;equals()&lt;/span&gt; but ignores the case.&lt;/li&gt;&lt;/ul&gt;We will be using these methods in Lab 3 and I hope it becomes clearer to you how the method works, when you get to use them in real programs.&lt;br /&gt;&lt;br /&gt;As usual, leave comments if you have questions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5138474113628691399-1278404209467276854?l=it1838.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://it1838.blogspot.com/feeds/1278404209467276854/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5138474113628691399&amp;postID=1278404209467276854' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/1278404209467276854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/1278404209467276854'/><link rel='alternate' type='text/html' href='http://it1838.blogspot.com/2007/05/comparing-strings.html' title='Comparing Strings'/><author><name>weimeng</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5138474113628691399.post-3511372359196609864</id><published>2007-05-06T17:44:00.000+08:00</published><updated>2007-05-06T17:53:07.809+08:00</updated><title type='text'>Comparing Numbers</title><content type='html'>In Java, we use relational operators (&lt;span style="font-family: courier new;"&gt;==, !=, &gt;, &lt;, &gt;=, &lt;=&lt;/span&gt;) to help us compare numbers, which are represented by variables of the 8 primitive data types. Take note that we cannot compare a string with a number; we can only compare (use the relational operators) variables declared in the primitive data types.&lt;br /&gt;&lt;br /&gt;The common error that students always make when writing relational operators is to mixed up the double equal sign (==) which is to check if 2 values are the same, with the single equal sign (=) which is to assign a value to a variable.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5138474113628691399-3511372359196609864?l=it1838.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://it1838.blogspot.com/feeds/3511372359196609864/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5138474113628691399&amp;postID=3511372359196609864' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/3511372359196609864'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/3511372359196609864'/><link rel='alternate' type='text/html' href='http://it1838.blogspot.com/2007/05/comparing-numbers.html' title='Comparing Numbers'/><author><name>weimeng</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5138474113628691399.post-5388342782813030701</id><published>2007-05-06T17:04:00.000+08:00</published><updated>2007-05-06T17:44:31.335+08:00</updated><title type='text'>Control Structures in Java</title><content type='html'>Control structures are the basic building blocks of any programming language, and hence is not specific to only Java.&lt;br /&gt;&lt;br /&gt;There are 3 basic control structures for Java:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Sequential - This means that all Java statements are executed line-by-line, one after another. This is already inherent within the language itself as you write the codes.&lt;/li&gt;&lt;li&gt;Selection - This control structure instructs the computer to make a selection (or branching) of the portion of the program based on a decision, made by doing a comparison. There are 2 selection structures in Java, the &lt;span style="font-family:courier new;"&gt;if()&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;switch()&lt;/span&gt; structures.&lt;/li&gt;&lt;li&gt;Repetition - This structure instructs the computer to perform a repetition of a block of code, and there various methods to terminate the repetition. There are 3 repetition structures, the &lt;span style="font-family:courier new;"&gt;for()&lt;/span&gt; loop, the &lt;span style="font-family:courier new;"&gt;while()&lt;/span&gt; loop and the &lt;span style="font-family:courier new;"&gt;do-while()&lt;/span&gt; loop.&lt;/li&gt;&lt;/ul&gt;A complete computer program often needs to make use of a combination of these control structures. Do make a note of these structures as we will go through them in detail in the coming weeks.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5138474113628691399-5388342782813030701?l=it1838.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://it1838.blogspot.com/feeds/5388342782813030701/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5138474113628691399&amp;postID=5388342782813030701' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/5388342782813030701'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/5388342782813030701'/><link rel='alternate' type='text/html' href='http://it1838.blogspot.com/2007/05/control-structures-in-java.html' title='Control Structures in Java'/><author><name>weimeng</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5138474113628691399.post-5784275231329030239</id><published>2007-04-29T15:29:00.000+08:00</published><updated>2007-05-01T16:13:33.427+08:00</updated><title type='text'>Simple Input and Output</title><content type='html'>We have also started on doing some simple input and output using Java, because a program is only useful if it can interact with users to get inputs to the program and produce output for the user to see.&lt;br /&gt;&lt;br /&gt;In Java, there are 2 ways to perform input and output, namely through the command line and through &lt;a href="http://en.wikipedia.org/wiki/Graphical_user_interface" target="_blank"&gt;GUI&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;u&gt;Command Line&lt;/u&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;To perform an output to the command prompt window, you would use &lt;span style="font-family:courier new;"&gt;System.out.print()&lt;/span&gt; or &lt;span style="font-family:courier new;"&gt;System.out.println()&lt;/span&gt;.&lt;/li&gt;&lt;li&gt;To get an input from the user, you would use a &lt;span style="font-family:courier new;"&gt;Scanner&lt;/span&gt; class, as in the example program in Lab 1 Practice 4.&lt;/li&gt;&lt;li&gt;You use &lt;span style="font-family:courier new;"&gt;entry.nextInt()&lt;/span&gt; to get an integer value, &lt;span style="font-family:courier new;"&gt;entry.nextDouble()&lt;/span&gt; to get a double value, and &lt;span style="font-family:courier new;"&gt;entry.nextLine()&lt;/span&gt; to get a string.&lt;/li&gt;&lt;/ul&gt;&lt;u&gt;Graphical User Interface&lt;/u&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;To perform an output to a GUI window, you would use the &lt;span style="font-family:courier new;"&gt;showMessageDialog()&lt;/span&gt; method in the &lt;span style="font-family:courier new;"&gt;JOptionPane&lt;/span&gt; class.&lt;/li&gt;&lt;li&gt;To get an input from the user, you would use the &lt;span style="font-family:courier new;"&gt;showInputDialog()&lt;/span&gt; method, as in the example program in Lab 1 Practice 5.&lt;/li&gt;&lt;li&gt;Do take note that getting input from the user in a GUI is a 2-step process. The input value is always captured as a String object and you need to convert it into the appropriate data types in the 2nd step.&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5138474113628691399-5784275231329030239?l=it1838.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://it1838.blogspot.com/feeds/5784275231329030239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5138474113628691399&amp;postID=5784275231329030239' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/5784275231329030239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/5784275231329030239'/><link rel='alternate' type='text/html' href='http://it1838.blogspot.com/2007/05/simple-input-and-output.html' title='Simple Input and Output'/><author><name>weimeng</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5138474113628691399.post-8907543326253787327</id><published>2007-04-29T15:16:00.000+08:00</published><updated>2007-05-01T16:25:32.167+08:00</updated><title type='text'>Data in Programming</title><content type='html'>This week we started with basic programming in Java. First off, we need to understand the concept of Data in Programming.&lt;br /&gt;&lt;br /&gt;Every computer program needs data to manipulate to make it useful. Data are values that the program uses when it is performing some mathematical calculation or simple using it as a counter for loops. Data are stored as variables in Java and we went through the way to declare variables in Java. Declaring variables ensures that the computer reserves memory storage areas for our variables. In declaring variables, the key thing to note is that every variable has to be associated with a data type, so that the computer knows how much memory space to allocate. Do read up Chapter 2 of the Johnson book to get more details of variable declaration and data types.&lt;br /&gt;&lt;br /&gt;Some examples of variable declaration:&lt;br /&gt;&lt;pre&gt;   double myLength, myDepth;&lt;br /&gt;   int englishMarks;&lt;br /&gt;   boolean isOK;&lt;/pre&gt;We have also seen how to perform arithmetic operations (+, -, *, /, %) in Java. Basically, arithmetic operations are evaluated the same way as in mathematics, with the exception of the '=' operator, which acts as the assignment operator. The assignment operator will take the result (value) of the evaluation on the right-hand-side and store it into the variable on its left-hand-side.&lt;br /&gt;&lt;br /&gt;For example, in the program code:&lt;br /&gt;&lt;pre&gt;   a = 2, b = 8, c = 4;&lt;br /&gt;   answer = b * b - 4 * a * c;&lt;br /&gt;&lt;/pre&gt;the evaluation on the RHS will result in a value of 32 and this will be stored in the variable &lt;span style="font-family: courier new;"&gt;answer&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;As usual, do leave comments if you have questions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5138474113628691399-8907543326253787327?l=it1838.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://it1838.blogspot.com/feeds/8907543326253787327/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5138474113628691399&amp;postID=8907543326253787327' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/8907543326253787327'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/8907543326253787327'/><link rel='alternate' type='text/html' href='http://it1838.blogspot.com/2007/04/data-in-programming.html' title='Data in Programming'/><author><name>weimeng</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5138474113628691399.post-500892402319196497</id><published>2007-04-22T14:42:00.000+08:00</published><updated>2007-05-01T15:15:02.421+08:00</updated><title type='text'>First Week</title><content type='html'>As with all first weeks of your life (and mine too, although its a little longer than yours 8-), its hectic and full of unknowns. Not knowing where the classrooms are, not knowing what the module is about, not knowing if the lecturer/s is/are good or not. Welcome to the real world. 8-)&lt;br /&gt;&lt;br /&gt;As I have mentioned in the previous post, this blog will primarily contain the archive of the salient points of the module as we go along. I will strive to update it once a week, the keyword being strive. 8-) If you have any questions, please feel free to leave a comment so that we can all learn from each other.&lt;br /&gt;&lt;br /&gt;Ok, for the first week, as it is only the start of the semester, we introduced the concept of programming and what writing computer programs is all about. Remember the &lt;a href="http://www.thepcmanwebsite.com/media/pacman_flash/" target="_blank"&gt;PacMan&lt;/a&gt; game that I mentioned, as an example of a simple computer program? Right, so:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;a computer program is simply a set of instructions that you give to the computer for it to perform some actions for you,&lt;/li&gt;&lt;li&gt;programming languages are the languages used to 'talk' or 'tell' the instructions to the computer,&lt;/li&gt;&lt;li&gt;Java is just one of the many programming languages&lt;/li&gt;&lt;/ul&gt;So in the weeks to come, we will be learning the syntax, or the rules, of the Java programming language, as well as the logic, or algorithm, of computer programming so that we can write useful computer programs.&lt;br /&gt;&lt;br /&gt;We also started with Lab 1 on writing simple logic or algorithms, in pseudo codes, to get our brains to think logically so that we can later formulate the logic into Java codes to program into the computer. The key thing to note in writing pseudo codes (whether using pen and paper or mentally in your brain) is to try to be as explicit and clear as possible. Remember that the computer cannot think, so it will not be able to do intelligent actions for you unless you instruct it to. Hence instructions, in the form of pseudo codes, need to be thorough and clear.&lt;br /&gt;&lt;br /&gt;In the lab, we wrote (or at least you, I have written mine long ago 8-) our first Java program, &lt;a href="http://www2.latech.edu/%7Eacm/HelloWorld.shtml" target="_blank"&gt;HelloWorld.java&lt;/a&gt;, using TextPad and JDK. Do remember these steps on writing a Java program, as you will be doing this on your own from next week onwards.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Open TextPad and type in your Java codes.&lt;/li&gt;&lt;li&gt;Save the file as &lt;classname&gt;.java.&lt;/li&gt;&lt;li&gt;Open up a command prompt window and navigate to the folder where you saved the Java file.&lt;/li&gt;&lt;li&gt;Use the command: javac &lt;classname&gt;.java to compile the Java program.&lt;/li&gt;&lt;li&gt;Use the command: java &lt;classname&gt; to run the Java program to see if it works according to what you want it to work.&lt;/li&gt;&lt;/ul&gt;Do leave comments if you have questions on what was covered this week!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5138474113628691399-500892402319196497?l=it1838.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://it1838.blogspot.com/feeds/500892402319196497/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5138474113628691399&amp;postID=500892402319196497' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/500892402319196497'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/500892402319196497'/><link rel='alternate' type='text/html' href='http://it1838.blogspot.com/2007/04/first-week.html' title='First Week'/><author><name>weimeng</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5138474113628691399.post-3994267138262716186</id><published>2007-04-01T21:38:00.000+08:00</published><updated>2007-04-02T21:45:20.115+08:00</updated><title type='text'>Welcome!</title><content type='html'>This is the first post for the IT1838 mPowered blog!&lt;br /&gt;&lt;br /&gt;The orientation is starting next week from 2 April to 5 April and semester will start on 16 April. This new semester we will do something different from other semesters, and I intend to use this blog to document down the salient points discussed in the lectures and the labs. This not only serves as an archive, for you to refer to when you study for your exam (yes, this module is examinable) but also as a communication platform for us to exchange ideas on the module.&lt;br /&gt;&lt;br /&gt;And since this is the first post, I will not bore you with what the module is about. 8-)&lt;br /&gt;&lt;br /&gt;Enjoy your stay in NYP!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5138474113628691399-3994267138262716186?l=it1838.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://it1838.blogspot.com/feeds/3994267138262716186/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5138474113628691399&amp;postID=3994267138262716186' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/3994267138262716186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5138474113628691399/posts/default/3994267138262716186'/><link rel='alternate' type='text/html' href='http://it1838.blogspot.com/2007/04/welcome.html' title='Welcome!'/><author><name>weimeng</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
