<?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>Conor&#039;s Blog &#187; College</title>
	<atom:link href="http://conor.macaoidh.ie/blog/category/college/feed/" rel="self" type="application/rss+xml" />
	<link>http://conor.macaoidh.ie</link>
	<description>PHP, Music, Linux</description>
	<lastBuildDate>Mon, 07 Jul 2014 10:53:35 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>Compiling GCC 4.3.6</title>
		<link>http://conor.macaoidh.ie/blog/2013/11/13/compiling-gcc-4-3-6/</link>
		<comments>http://conor.macaoidh.ie/blog/2013/11/13/compiling-gcc-4-3-6/#comments</comments>
		<pubDate>Wed, 13 Nov 2013 15:59:20 +0000</pubDate>
		<dc:creator><![CDATA[Conor]]></dc:creator>
				<category><![CDATA[College]]></category>
		<category><![CDATA[Compilers]]></category>
		<category><![CDATA[FYP]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[compilers]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gcc 4.3.6]]></category>
		<category><![CDATA[gmp]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[mpc]]></category>
		<category><![CDATA[mpfr]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://conor.macaoidh.ie/?p=517</guid>
		<description><![CDATA[Today I needed to compile a copy of gcc 4.3.6 from source in order to successfully build ACCGen, though there are many other reasons you would like to do this. Much of this is based on an article located here. First download gcc, gmp, mpfr and mpc: wget http://ftp.gnu.org/gnu/gcc/gcc-4.3.6/gcc-4.3.6.tar.gz wget ftp://ftp.gnu.org/gnu/gmp/gmp-4.3.2.tar.gz wget ftp://ftp.gnu.org/gnu/mpfr/mpfr-2.4.2.tar.gz wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Today I needed to compile a copy of gcc 4.3.6 from source in order to successfully build <a href="http://archc.sourceforge.net/blog.2013-03-01.accgen.html">ACCGen</a>, though there are many other reasons you would like to do this. Much of this is based on an article located <a href="http://openwall.info/wiki/internal/gcc-local-build">here</a>.</p>
<p>First download gcc, gmp, mpfr and mpc:</p>
<pre>wget http://ftp.gnu.org/gnu/gcc/gcc-4.3.6/gcc-4.3.6.tar.gz                                                      
wget ftp://ftp.gnu.org/gnu/gmp/gmp-4.3.2.tar.gz                                                                 
wget ftp://ftp.gnu.org/gnu/mpfr/mpfr-2.4.2.tar.gz                                                               
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz</pre>
<p>Extract, create install directories:</p>
<pre>                                                                                                         
tar xzf gcc-4.3.6.tar.gz                                                                                        
tar xzf gmp-4.3.2.tar.gz                                                                                        
tar xzf mpfr-2.4.2.tar.gz                                                                                       
tar xzf mpc-0.8.1.tar.gz                                                                                        
mkdir /opt/gcc-4.3.6                                                                                            
mkdir /opt/gmp-4.3.2                                                                                            
mkdir /opt/mpfr-2.4.2                                                                                           
mkdir /opt/mpc-0.8.1</pre>
<p>Build gmp-4.3.2:</p>
<pre>cd gmp-4.3.2                                                                                                    
./configure --prefix=/opt/gmp-4.3.2 --enable-cxx                                                                
nice -n 19 time make -j8                                                                                        
make install                                                                                                    
cd ..</pre>
<p>Build mpfr-2.4.2:</p>
<pre>cd mpfr-2.4.2                                                                                                   
./configure --prefix=/opt/mpfr-2.4.2 --with-gmp=/opt/gmp-4.3.2                                                  
nice -n 19 time make -j8                                                                                        
make install                                                                                                    
cd ..</pre>
<p>Build mpc-0.8.1:</p>
<pre>cd mpc-0.8.1                                                                                                    
LD_LIBRARY_PATH=/opt/gmp-4.3.2/lib:/opt/mpfr-2.4.2/lib ./configure --prefix=/opt/mpc-0.8.1 --with-gmp=/opt/gmp-4.3.2 --with-mpfr=/opt/mpfr-2.4.2
LD_LIBRARY_PATH=/opt/gmp-4.3.2/lib:/opt/mpfr-2.4.2/lib nice -n 19 time make -j8                                 
make install                                                                                                    
cd ..</pre>
<p>Build gcc-4.3.6:</p>
<pre>cd gcc-4.3.6                                                                                                    
LD_LIBRARY_PATH=/opt/gmp-4.3.2/lib:/opt/mpfr-2.4.2/lib:/opt/mpc-0.8.1/lib ./configure --prefix=/opt/gcc-4.3.6 --with-gmp=/opt/gmp-4.3.2 --with-mpfr=/opt/mpfr-2.4.2 --with-mpc=/opt/mpc-0.8.1 --disable-multilib                                                                                                                                                                                          
LD_LIBRARY_PATH=/opt/gmp-4.3.2/lib:/opt/mpfr-2.4.2/lib:/opt/mpc-0.8.1/lib nice -n 19 time make -j8              
make install                                                                                                    
cd ..</pre>
<p>Now, gcc-4.3.6 should be available:</p>
<pre>$ /opt/gcc-4.3.6/bin/gcc --version
gcc (GCC) 4.3.6
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
</pre>
]]></content:encoded>
			<wfw:commentRss>http://conor.macaoidh.ie/blog/2013/11/13/compiling-gcc-4-3-6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Compiling SystemC on Fedora with GCC 4.8</title>
		<link>http://conor.macaoidh.ie/blog/2013/10/06/compiling-systemc-on-fedora-with-gcc-4-8/</link>
		<comments>http://conor.macaoidh.ie/blog/2013/10/06/compiling-systemc-on-fedora-with-gcc-4-8/#comments</comments>
		<pubDate>Sun, 06 Oct 2013 19:44:24 +0000</pubDate>
		<dc:creator><![CDATA[Conor]]></dc:creator>
				<category><![CDATA[ADL]]></category>
		<category><![CDATA[College]]></category>
		<category><![CDATA[Compilers]]></category>
		<category><![CDATA[FYP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[4.8]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[Fedora]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[make]]></category>
		<category><![CDATA[systemc]]></category>

		<guid isPermaLink="false">http://conor.macaoidh.ie/blog/?p=466</guid>
		<description><![CDATA[I had some difficulty getting SystemC to compile on Fedora 19 and gcc 4.8.1. After configuring correctly, make issued the following error: In file included from ../../../src/sysc/datatypes/bit/sc_bv_base.h:50:0, from ../../../src/sysc/datatypes/bit/sc_lv_base.h:56, from sc_signal.cpp:102: ../../../src/sysc/datatypes/bit/sc_bit_proxies.h:716:16: error: reference ‘m_obj’ cannot be declared ‘mutable’ [-fpermissive] mutable X&#38; m_obj; ^ ../../../src/sysc/datatypes/bit/sc_bit_proxies.h:1193:18: error: reference ‘m_left’ cannot be declared ‘mutable’ [-fpermissive] mutable X&#38; [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I had some difficulty getting SystemC to compile on Fedora 19 and gcc 4.8.1. After configuring correctly, make issued the following error:</p>
<pre>In file included from ../../../src/sysc/datatypes/bit/sc_bv_base.h:50:0,
                 from ../../../src/sysc/datatypes/bit/sc_lv_base.h:56,
                 from sc_signal.cpp:102:
../../../src/sysc/datatypes/bit/sc_bit_proxies.h:716:16: error: reference ‘m_obj’ cannot be declared ‘mutable’ [-fpermissive]
     mutable X&amp; m_obj;
                ^
../../../src/sysc/datatypes/bit/sc_bit_proxies.h:1193:18: error: reference ‘m_left’ cannot be declared ‘mutable’ [-fpermissive]
     mutable X&amp;   m_left;
                  ^
../../../src/sysc/datatypes/bit/sc_bit_proxies.h:1194:18: error: reference ‘m_right’ cannot be declared ‘mutable’ [-fpermissive]
     mutable Y&amp;   m_right;
                  ^
../../../src/sysc/datatypes/bit/sc_bit_proxies.h:1196:18: error: reference ‘m_refs’ cannot be declared ‘mutable’ [-fpermissive]
     mutable int&amp; m_refs;</pre>
<p>The following patches obtained from <a href="http://stackoverflow.com/questions/7285049/installing-systemc-2-2-0-compilation-with-gcc-4-6-and-package-for-fedora">stack overflow</a> fixed this problem for me. Save them in a text file with a .patch extension:</p>
<p><b>sc_bit_proxies.patch</b></p>
<pre>--- src/sysc/datatypes/bit/sc_bit_proxies.h 2007-03-14 17:47:49.000000000 +0000
+++ src/sysc/datatypes/bit/sc_bit_proxies.h.mod 2011-09-02 13:53:34.318379140 +0000
@@ -713,7 +713,7 @@

 protected:

-    mutable X&amp; m_obj;
+    X&amp;         m_obj;
     int        m_hi;
     int        m_lo;
     int        m_len;
@@ -1190,10 +1190,10 @@

 protected:

-    mutable X&amp;   m_left;
-    mutable Y&amp;   m_right;
+            X&amp;   m_left;
+            Y&amp;   m_right;
     mutable int  m_delete;
-    mutable int&amp; m_refs;
+            int&amp; m_refs;</pre>
<p><b>sc_utils_ids.patch</b></p>
<pre>--- src/sysc/utils/sc_utils_ids.cpp     2006-12-15 20:31:39.000000000 +0000
+++ src/sysc/utils/sc_utils_ids.cpp.mod 2011-11-02 15:49:10.431948273 +0000
@@ -59,6 +59,9 @@
 //

 #include "sysc/utils/sc_report.h"
+// Jeremy Bennett 2 Nov 11. Patched for GCC 4.6.
+#include 
+#include 

 namespace sc_core {</pre>
<p>Then for each patch, execute the following:</p>
<pre>patch -p1 &lt; filename.patch</pre>
<p>You may have to specify the file to be patched (just copy and paste the file referenced in the first line of the patch).</p>
<p>Then <i>make</i> should run smoothly.</p>
]]></content:encoded>
			<wfw:commentRss>http://conor.macaoidh.ie/blog/2013/10/06/compiling-systemc-on-fedora-with-gcc-4-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slot Machine Game</title>
		<link>http://conor.macaoidh.ie/blog/2011/02/20/slot-machine-game/</link>
		<comments>http://conor.macaoidh.ie/blog/2011/02/20/slot-machine-game/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 00:09:42 +0000</pubDate>
		<dc:creator><![CDATA[Conor]]></dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[College]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[college]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[machine]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[slot]]></category>

		<guid isPermaLink="false">http://blog.conormacaoidh.com/?p=427</guid>
		<description><![CDATA[I wrote a slot machine game for a college project over the last week or two. The specification was as follows: For this assignment, you are asked to implement a command line version of a slot machine in C. The slot machine consists of three columns, and each column can hold one of three possible [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I wrote a slot machine game for a college project over the last week or two. The specification was as follows:</p>
<p><em>For this assignment, you are asked to implement a command line version of a slot machine in C. The slot machine consists of three columns, and each column can hold one of three possible values: ‘APPLE’, ‘ORANGE’ or ‘PEAR’.<br />
When the slot machine begins, the player is asked to bet X amount of their initial credit, I (default value for I should be 10 credits), where X &lt;= I. For each play of the slot machine there are three possible outcomes:<br />
1.    Full house – all 3 columns contain the same value. Player wins the amount they bet (i.e. X). X (winnings) should be added to current credit balance (or I if initial run) to form new credit balance.<br />
2.    Half house –2 of the 3 columns contain the same value. Player wins half the amount they bet (i.e. X/2). X/2 (winnings) should be added to current credit balance (or I if initial run) to form new credit balance.<br />
3.    Empty house &#8211; all 3 columns contain different values. Player loses 10 credits. 10 credits should be removed from current credit balance (or I if initial run) to form new credit balance.</em></p>
<p>We had four weeks to finish the project which was way more than was really required to write it. There were a few other requirements which aren&#8217;t mentioned here. Anyway I have included a link to a downloadable and executable version of the game. The download includes SlotMacine ( a binary file ), SlotMachine.exe ( the same as SlotMachine, filename just makes it easier to execute under Windows ) and SlotMachine.c</p>
<h2><a href="http://files.macaoidh.name/Download/SlotMachine.zip">Download Slot Machine Game</a></h2>
<p>Feel free to leave feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://conor.macaoidh.ie/blog/2011/02/20/slot-machine-game/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Essence of Computer Science</title>
		<link>http://conor.macaoidh.ie/blog/2010/12/10/the-essence-of-computer-science/</link>
		<comments>http://conor.macaoidh.ie/blog/2010/12/10/the-essence-of-computer-science/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 13:34:19 +0000</pubDate>
		<dc:creator><![CDATA[Conor]]></dc:creator>
				<category><![CDATA[College]]></category>
		<category><![CDATA[Languages]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=410</guid>
		<description><![CDATA[This is my end of semester essay for CS. Oh and the thing about me not knowing what programming languages were before college is untrue but it adds to the essay! The Essence of Computer Science – that is what I am here to learn. Through the few weeks of college, we were given an [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>This is my end of semester essay for CS. Oh and the thing about me not knowing what programming languages were before college is untrue but it adds to the essay!</p>
<p>The Essence of Computer Science – that is what I am here to learn. Through the few weeks of college, we were given an outline of the course and what we had to learn and understand to become computer scientists. So far, we have learned what programming languages are and, more importantly, why they are used. We have attended a vast range of lectures on subjects such as search engines, design patterns, compression, databases and much much more. The lecturers did not delve too deeply into these but outlined some of the areas of Computer Science in which we will be working. In this essay, I will discuss these topics in detail to show you my understanding of Computer Science (CS).</p>
<p>The first question that dawned on me when I started CS was: What is a programming language and why must we use it? Now I think I have the answer. Programming languages were created to replace the flaws in most communicative languages with a precise, definitive syntax. In English, words may have many meanings. Take this sentence for example: ‘<em>If she calls, please tell Teresa I’ve gone to bed.’</em> In this case the word ‘call’ could mean a telephone call, or a literal call. Moreover, it is not certain whether Teresa is the ‘she’ that might call, or whether it is another woman. There is no precise interpretation of this sentence. Programming languages are designed to remove the ambiguities and multiple interpretations that are present in common communicative languages.</p>
<p>If that’s true, then why are there so many different languages? We were told at the beginning of the course that we would be studying a host of languages including C, C++, Java and Perl but there are many more: PHP, Haskel, ASP, Basic, Assembler&#8230; the list goes on. The answer is that these languages all serve different purposes. C, for example, offers great freedom but developers must suffer slow programming to produce fast programs. Interpreted languages such as Perl and PHP offer a simplified syntax resulting in low programming times but slower programs. C is more appropriate for system programming whereas PHP was designed to build dynamic web pages. One of the major points I learned is that CS is not all about programming. There are many aspects of CS and I learnt in the ‘Computer Science at Work’ submodule that business plays a big role in the industry.</p>
<p>The first topic that we covered this year was ‘Search Engines’. Everyone who uses the internet uses a search engine and there are many out there: Google, Bing, Yahoo, Startpage etc. The future of web searching is much debated. The current market leader is Google, which has adopted a vast amount of techniques that make searching easier. Google is without a doubt the smartest, fastest and most efficient search engine that I have used. However, there is controversy surrounding the amount of information that Google collects from its users. This has sparked a number of competitors, such as Scroogle and Startpage, which don’t collect any information about their users – even ip addresses remain anonymous. Websites’ page ranks on Google and other search engines define how popular they are and page-ranking has become extremely important to businesses. The page rank of a website is determined by quite a few factors, including the number of links to a website and a summary of the key words to be included in the Meta-tags of a site’s code. The process of improving a website’s page rank is called Search Engine Optimisation (SEO).</p>
<p>There are a number of ‘web apps’ which take different forms and give the user access to various aspects of the internet. We tested one of these apps, called HeyStaks, in one of our first practicals. HeyStaks is a Firefox add-on/plugin which serves to extend the capacity of Google, Yahoo and Bing, the three most popular search engines. I perceive Heystaks as the future direction of search engines because it integrates aspects of social networking with the searching process. With HeyStaks, users create ‘Staks’, collections of searches on particular topics. It is then possible to share these Staks with other users via the HeyStaks website. Eventually, a vast database of Staks will be created to streamline the searching process. Users won’t be depending on a machine’s opinion of what page is relevant – they will depend instead on the experiences of other users.</p>
<p>Google was the first major search engine and it has risen far higher than expected. However, it was not the first search engine – there were eighteen others before it. The architecture of a search engine was first proposed in the 1940s but there was no implementation of the technique at that time. Tim Berners-Lee is the father of the world wide web. He created the first web directory, essentially a list of all the websites in the world. It failed because of exponential growth in the number of search engines. Ten years later in 1998, Google was released. The web is so big these days that it is almost impossible to measure it. Around 12.4 billion English language websites are now listed by Google.</p>
<p>What made Google succeed where others failed? It is impossible to calculate recall for the web – there are simply too many pages to search. That’s why Google uses indexes and evaluates searches by their relevance. When searching for the query, ‘Is drinking red wine more effective at reducing your risk of heart attacks than white wine?’, only half of the results returned are accurate. Evaluation is about putting the science in Computer Science and comparing the performance of systems and algorithms. These factors are important in a search engine: the relevance of queries; speed; clear user-interface; free; discreet adds. Google used all of these techniques to create an incredibly efficient search engine. That is why it succeeded.</p>
<p>The future of web searching will be in the customisation of results specific to a particular user. Google has already done this to a certain extent. The homepage has a customisable background and the engine collects information on users to display a certain extent of user-specific content. There is no doubt that Google is the market leader at the moment but something big has happened recently which might just knock the company off its high chair. Recently, Facebook has signed a deal with Microsoft’s Bing to integrate social networking into the search engine. Facebook is quoted as saying that it went for Bing instead of Google because the ‘underdog’ has more incentive to work. It will be interesting to see what changes come to the process of searching the internet in the next few years.</p>
<p>Our guest lecturer, Dr Mel Ó Cinnéide, discussed ‘Learning and Patterns’ with us. He showed us examples of how patterns are used everywhere in life and told us that they have an implementation in programming as well. He told us that patterns are related to how we learn and said that it’s likely that a person will learn more in the first three or four years of their lives than in the rest of their lives.</p>
<p>There are three stages of learning: the cognitive stage, learning the basic elements; the associative stage, learning how the elements fit together; the autonomous stage, automatic and apparently effortless combining of elements. The autonomous stage consists of being a master in a certain field. An example of this is tying a shoelace. It seems simple to us now because we learnt it so long ago, but if we tried to learn how to do it now we would find it incredibly difficult. These three stages of learning were interpreted in the Middle Ages by the apprentice, the journeyman and the master. Bruce Lee is a master who has learnt a martial art and discovered its simplicity: <em>‘Now that I’ve understood the art, a punch is just a punch, a kick just a kick.’ </em>Masters often don’t know how exactly they do things. They are aware on a subconscious level of what they are doing but often it’s not necessary for them to think about it. Consider cycling a bike; we may not be able to answer detailed questions about how to cycle in theory but in practice we can all (well, most of us can) cycle.</p>
<p>One of the questions the lecturer asked us was: Do you think beauty is objective? I think it’s very subjective. People’s opinions of beauty differ but we are the same species and there are likely to be things that we all find beautiful, such as nature, the stars etc. If beauty was completely subjective then we would all like completely different things. The answer Dr Ó Cinnéide gave us was that beauty is a combination of the two, i.e. sometimes we don’t agree about what is beautiful but there are aspects of beauty which we all considered appealing. Christopher Alexander was a 1960s architect who attempted to find similarities between objects (such as doors) to discover the essence of what we consider beauty to be. In his own words: <em>‘Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice.’</em></p>
<p>A pattern is a proven solution to a recurring problem in a certain context. It isn’t a once off, it’s something that happens again and again, perhaps a bit different every time. On the surface, two problems might look different but there are probably aspects that connect them that can be exploited by patterns. The Gang of Four is a group of computer scientists who read about Alexander’s work (largely ignored by other architects) and wrote a book called <em>Design Patterns</em>. The book was a massive success and now almost all programmers use <em>Design Patterns</em> at some stage. It received 20,611 citations – 14,457 more than any of Einstein’s papers. The Gang of Four implemented Alexander’s understanding of patterns in programming.</p>
<p>Similar to patterns, objects can be used in programming to perform work. They are ideal because we don’t necessarily need to know how they work to use them. They are similar to the predefined functions in C – we don’t know how they work and most of us don’t need to know. If a software developer writes a lot of complicated code-using objects, then other programmers can easily use that code without needing to know the details of how it works. This is called Object Orientated Programming.</p>
<p>Algorithms are another example of programming techniques which use patterns. Computer scientists must learn to solve problems effectively using algorithms. <em>‘An algorithm is an effective method for solving a problem expressed as a finite sequence of steps.’ [</em><span style="text-decoration: underline;"><a href="http://en.wikipedia.org/wiki/Algorithm">http://en.wikipedia.org/wiki/Algorithm</a></span><em>]. </em>In a problem-solving process, a computer scientist should plan out an algorithm before programming it. A prime example of an algorithm is the Boyer-Moore String Search Algorithm, which implements a smart and incredibly efficient method of searching strings.</p>
<p>Another topic we covered with Dr Neil Hurley was ‘Lossless and Lossy Compression’. He highlighted how important compression is to computer scientists. Dr Hurley reiterated that mathematics is essential for Computer Science – the principles with which we design computer systems are based almost entirely on mathematics.</p>
<p>Everyone who uses a computer these days uses compression whether they know it or not. MP3 files are compressed and when we listen to them we are uncompressing them. Videos and some files are compressed or encoded. Compression is also used in digital communication. When a message is sent by instant messenger or email, the message is compressed, encoded and sent. Then it is decoded and uncompressed on the other side. Crackles on the phone line are an example of an error in encoding. Dr Hurley posed the question: What is a message? Every message is made of information and redundancy. If we remove the redundancy from the message we can still understand the points of the message. This is compression. A form of this is text messaging. Texting language uses abbreviations to reduce the redundancy in a message whilst retaining the essential information.</p>
<p>Compression enables fast communication but it is difficult to determine how much one should compress. Huffman coding is an easy method of effective compression. An uncompressed letter is represented in the computer by an eight-bit binary number. The computer uses ASCII coding to determine which eight-bit combination means which letter. There are 256 combinations of this eight-bit string. This is more than sufficient for the English language but not nearly enough for languages such as Chinese. Huffman asked why can there be only eight bits in the encoding scheme. He suggested that there could be different amount of bits allocated to each letter. Frequently used letters such as ‘a’ or ‘e’ should be stored with a small amount of bits representing them. Letters such as ‘z’ should have more bits representing them. This system would be more efficient than the current one. A Huffman tree can be used to further increase the efficiency of the encoding scheme. In this scheme the most frequently used letters have fewer bits than the least frequently used. After creating a Huffman tree and encoding the sentence ‘aaron adamson’, it is possible to improve the efficiency of the current system and reduce the sentence to 36% of its original size. Originally the sentence took up 104 bits of space but after applying the new Huffman tree it can be reduced to 38 bits.</p>
<p>Redundancy is a scheme which can be used to detect errors that occur when transmitting data over a channel. For example: when transmitting one bit of information – a true or false value – it is possible to send two bits rather than one, the second being for error detection. Hamming code can be used to detect and correct a single-bit error. Parity bits (extra bits) are placed at powers of 2 locations in the message. Adding this mathematical property allows us to tell not only when a single-bit error has occurred but where it occurred. It can also detect and correct certain errors. If we didn’t have error correction we wouldn’t be able to communicate reliably.</p>
<p>Huffman coding is an example of lossless compression. From a compressed message it is possible to recover the exact original message. This is contrary to lossy compression, which discards information that it doesn’t think is useful. Lossy compression uses sines and co-sines from the Fourier series to function. Lossy coding schemes use human limitation to compress information. For example, when compressing audio files, the compression engine takes into consideration the range of hertz that humans can hear and then eliminates inaudible sound from the file.</p>
<p>Images are compressed by representing how much of each color is present in each pixel. Videos are similar as they are just frames of images in a sequence. For example, if compression was not used in YouTube videos then it would take almost two minutes to load a second of the video. Image compression also exploits the limitations of the eye. An image can be compressed to 1% of its original size and still be completely recognisable. This is because compression methods know how the human eye works and aim to satisfy it. Compression and decompression are becoming quicker and more effective because of improvements in computer hardware. Compression is essential for many computer functions – without it things would take a hell of a lot longer to do!</p>
<p>Databases play a big role in Computer Science. Our lecture on Spatial Information Systems (SIS) gave us an insight into databases and how they can be used to store vast amounts of information and to save time. Data and information are important in Computer Science. Data overload is an increasing problem because of the accumulation of data on servers and computers. A database system provides efficient, reliable, convenient and safe multi-user storage of and access to massive amounts of persistent data. The idea is that can you search a lot of data and easily extract only the data that you want. Here are some examples of databases: websites storing users information; database of student grades – university data; bank databases (payroll information, customers etc.). One thing is for sure – there is a lot of money in the database (DB) industry. In 2006, DB revenue was $15.2 billion, and it’s still increasing.</p>
<p>A Database Management System (DBMS) is a piece of software that interacts with the DB and the user application programs that use the data stored in the DB. An example of a database is Amazon – an online bookseller. This system collects all sorts of information about the users and stores it in a database. It would be inefficient for the site to load all of the information on every page load, so the database splits up the information and loads only the relevant data. Data is the raw facts to be interpreted and correlated in order to provide information. Relational databases store information in columns. Most databases use this relational model to access information efficiently.</p>
<p>The Structured Query Language (SQL) is the standard DB language. This language is not necessary using a GUI such as Microsoft Access or equivalent programs. GUIs require the user to have little or no knowledge of database theory, therefore inconsistency is common among Access databases. Duplicates are an inconsistency as a table with a duplicate entry may return incorrect information. There are methods of avoiding inconsistencies, which we will study next year.</p>
<p>Spatial data is becoming increasingly important these days. <em>‘Also known as </em><em>geospatial data</em><em> or </em><em>geographic information</em><em> it is the data or information that identifies the geographic location of features and boundaries on Earth, such as natural or constructed features, oceans, and more.’ [</em><span style="text-decoration: underline;"><a href="http://www.webopedia.com/TERM/S/spatial_data.html">http://www.webopedia.com/TERM/S/spatial_data.html</a></span><em>]</em>. This data is usually stored as coordinates or as vectors. Spatial Data plays a massive role in data overload. For example, NASA’s Earth Observation System generates one terabyte of data every day. Companies such as Google Maps and the volunteering organisation OpenStreetMap also contribute to this problem. In fact, over 80% of all data on earth has a spatial component. More and more available data is being linked to location and more people are becoming interested in this. Organisations and companies are increasingly trying to establish where most of their customers come from and they are exploiting this information to do so. Google Earth is an example of an application using spatial data. Its API is open source, which allows people to access its information and interact with it. Spatial queries require complex algorithms to work and to select specific information from databases. Companies currently developing spatial applications are: MapFlow, e-Spatial, ESRI, Oracle, Google.</p>
<p>After considering all of these topics among others that we have studied, I think I have a better idea of what it means to be a computer scientist. I have also learned a great deal about what paths I can take into the industry – the choices are vast. Computer scientists are people who diagnose and solve problems, test, think and program. They must understand the technicalities of computers but have the ability to communicate them in a non-technical way. In conclusion, the essence of Computer Science is thinking outside the box.</p>
]]></content:encoded>
			<wfw:commentRss>http://conor.macaoidh.ie/blog/2010/12/10/the-essence-of-computer-science/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C rsync Program</title>
		<link>http://conor.macaoidh.ie/blog/2010/11/26/c-rsync-program/</link>
		<comments>http://conor.macaoidh.ie/blog/2010/11/26/c-rsync-program/#comments</comments>
		<pubDate>Fri, 26 Nov 2010 14:30:03 +0000</pubDate>
		<dc:creator><![CDATA[Conor]]></dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[College]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[copy]]></category>
		<category><![CDATA[destination]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[rsyc]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=405</guid>
		<description><![CDATA[An improvement on the previous post about a copy program in C. This program is more similar to rsync &#8211; it checks if the file exists and only copies chars that are different thus reducing compute time ( hopefully! ). /** * rsync.c * * copys a file to a different location - only * [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>An improvement on the previous post about a copy program in C. This program is more similar to rsync &#8211; it checks if the file exists and only copies chars that are different thus reducing compute time ( hopefully! ).</p>
<pre class="brush: php">/**
 * rsync.c
 *
 * copys a file to a different location - only
 * copys nessecary chars
 *
 * @author     Conor Mac Aoidh &lt;conormacaoidh@gmail.com&gt;
 * @version    1.0
 */

#include &lt;stdio.h&gt;

/**
 * main
 *
 * main function
 */
int main( int argc, char *argv[ ] ){

 FILE *fopen( ), *source, *destination, *exists;
 int c;

 source = fopen( argv[ 1 ], "r" );
 destination = fopen( argv[ 2 ], "wt" );

 if( argc != 3 ){
   printf( "Please supply arguments in the form:\ncopy &lt;source&gt; &lt;destination&gt;\n" );
   return 1;
 }

 if( source == NULL ){
   printf( "Could not open &lt;%s&gt; for reading.\n", argv[ 1 ] );
   return 1;
 }
 else if( destination == NULL ){
   printf( "Could not open &lt;%s&gt; for writing.\n", argv[ 2 ] );
   return 1;
 }

/**
 * check if destination file exists already
 */
 if ( exists = fopen( argv[ 2 ], "r") ){
   /**
    * destination file exists so compare files
    * only copying whats nessecary
    */
    int s;

    c = getc( source );
    s = getc( exists );

    while( c != EOF ){

       if( c == s ){
          c = getc( source );
          s = getc( exists );
          continue;
       }
       else{
          putc( c, destination );
          c = getc( source );
          s = getc( exists );
       }
    }
 }
 else{
    /**
     * file does not exist so copy char for char
     */
    c = getc( source );

    while( c != EOF ){
       putc( c, destination );
       c = getc( source );
    }
 }
}
</pre>
<p>Doing Perl next week.. can&#8217;t wait! A chance to actually understand regex!</p>
]]></content:encoded>
			<wfw:commentRss>http://conor.macaoidh.ie/blog/2010/11/26/c-rsync-program/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C Copy Program</title>
		<link>http://conor.macaoidh.ie/blog/2010/11/26/c-copy-program/</link>
		<comments>http://conor.macaoidh.ie/blog/2010/11/26/c-copy-program/#comments</comments>
		<pubDate>Fri, 26 Nov 2010 13:49:08 +0000</pubDate>
		<dc:creator><![CDATA[Conor]]></dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[College]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[copy]]></category>
		<category><![CDATA[destination]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=401</guid>
		<description><![CDATA[Wrote a quick program in C today which basically does the same thing as the UNIX cp command and the copy command on DOS. Thought I&#8217;d post it since I haven&#8217;t posted anything in a while! /** * copy.c * * copys a file to a different location * * @author     Conor Mac Aoidh &#60;conormacaoidh@gmail.com&#62; [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Wrote a quick program in C today which basically does the same thing as the UNIX cp command and the copy command on DOS. Thought I&#8217;d post it since I haven&#8217;t posted anything in a while!</p>
<pre class="brush:php">/**
 * copy.c
 *
 * copys a file to a different location
 *
 * @author     Conor Mac Aoidh &lt;conormacaoidh@gmail.com&gt;
 * @version    1.0
 */

#include &lt;stdio.h&gt;

/**
 * main
 *
 * main function 
 */
void main( int argc, char *argv[ ] ){

 FILE *fopen( ), *source, *destination;
 int c;

 source = fopen( argv[ 1 ], "r" );
 destination = fopen( argv[ 2 ], "wt" );

 if( argc != 3 ){
   printf( "Please supply arguments in the form:\ncopy &lt;source&gt; &lt;destination&gt;\n" );
   exit( 1 );
 }

 if( source == NULL ){
   printf( "Could not open &lt;%s&gt; for reading.\n", argv[ 1 ] );
   exit( 1 );
 }
 else if( destination == NULL ){
   printf( "Could not open &lt;%s&gt; for writing.\n", argv[ 2 ] );
   exit( 1 );
 }

 c = getc( source );
 while( c != EOF ){
   putc( c, destination );
   c = getc( source );
 }

}</pre>
]]></content:encoded>
			<wfw:commentRss>http://conor.macaoidh.ie/blog/2010/11/26/c-copy-program/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>10339063_160910</title>
		<link>http://conor.macaoidh.ie/blog/2010/09/16/10339063_160910/</link>
		<comments>http://conor.macaoidh.ie/blog/2010/09/16/10339063_160910/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 18:55:42 +0000</pubDate>
		<dc:creator><![CDATA[Conor]]></dc:creator>
				<category><![CDATA[College]]></category>
		<category><![CDATA[Learning Journal]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=394</guid>
		<description><![CDATA[For the next few weeks I will be posting Learning Journals on my blog. I will be writing one a week as they are a requirement of the course I&#8217;m studying (Computer Science, UCD). It would be appreciated if the reviewer could respond by comment on my blog, if possible. Learning Journal Lecture 10130, Computer [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>For the next few weeks I will be posting <em>Learning Journals</em> on my blog. I will be writing one a week as they are a requirement of the course I&#8217;m studying (Computer Science, UCD). It would be appreciated if the reviewer could respond by comment on my blog, if possible.</p>
<h1>Learning Journal</h1>
<p><strong>Lecture 10130, Computer Science in Practice, Prof. Mark Keane</strong></p>
<p><em>Name: Conor Mac Aoidh</em></p>
<p><em>Student Number: 10339063</em></p>
<h1>Lecture Summary</h1>
<ul>
<li>This 	lecture was basically an overview of how different types of 	graphs work. It began by explaining the correlation between 	variables in maths and variables in programming and then moved on to 	the implementation of graphs in Computer Science (CS).</li>
<li>It 	showed that CS is about putting aspects of everyday life into a 	program. An example of which is the <em>Tesco 	Clubcard</em>, 	through which <em>Tesco</em> can analyse what we buy on a day to day basis and use those 	statistics to figure out what we like or want to buy and the current 	trends in consumer society.</li>
<li>Prof. 	Mark Keane went on to describe the role that graphs and statistics 	play in CS. He presented a case of the distribution of height in the 	Irish population. Some interesting results were found when this 	distribution was plotted on a graph. An  average height was 	established which most people fit into, with unusually small and 	tall people falling further outside the average. This is called a 	normal distribution graph, an example of which is shown below:<br />
<a href="http://blog.macaoidh.name/wp-content/uploads/2010/09/Normal-Distribution-Graph.gif"><img class="size-full wp-image-398 aligncenter" title="Normal Distribution Graph" src="http://blog.macaoidh.name/wp-content/uploads/2010/09/Normal-Distribution-Graph.gif" alt="" width="366" height="276" /></a><br />
A different graph appeared when analysing 	the number of hits to websites in Ireland – a power-law graph in 	which 20% of the sites received 80% of the hits and vice-versa.</li>
<li>The 	lecturer then went on to discuss the Graph Theory which is used for 	modeling pairwise relations between objects in a collection. He then 	discusses how the internet, like all networks, is basically a graph 	and that that is exploited by Google&#8217;s searching algorithms.</li>
<li>Finally, 	the lecture explained how the Internet is constantly expanding to a 	state where it is almost un-measurable. In the year 2000 an attempt 	to estimate the size of the Internet crawled 200M pages and 1.5b 	links. Google&#8217;s most recent estimates are that the indexable web 	contains at least 25.21 billion pages and over a trillion unique URLs.</li>
</ul>
<p><strong>Key Messages</strong></p>
<p>The key message of this lecture was that almost everything is graphable and that graphs will become an essential tool to us as Computer Scientists.</p>
<p><strong>Evaluation and Insights</strong></p>
<p>I found the explanation of the different types of graphs and their use in making our programs smarter quite interesting.</p>
<p>The lecture gave me an insight into the structure of networks and compared them to the structure of a graph – and even to the shape of a fractal. Fractals, like the internet, are infinitely complex as they appear similar at all levels of magnification.</p>
]]></content:encoded>
			<wfw:commentRss>http://conor.macaoidh.ie/blog/2010/09/16/10339063_160910/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Java &#8211; Drawing Squares</title>
		<link>http://conor.macaoidh.ie/blog/2009/12/05/java-drawing-squares/</link>
		<comments>http://conor.macaoidh.ie/blog/2009/12/05/java-drawing-squares/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 03:28:07 +0000</pubDate>
		<dc:creator><![CDATA[Conor]]></dc:creator>
				<category><![CDATA[College]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[drawing]]></category>
		<category><![CDATA[icsp]]></category>
		<category><![CDATA[reges]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[shape]]></category>
		<category><![CDATA[squares]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=284</guid>
		<description><![CDATA[This weeks ICSP assignment was to write a program which draws squares. The task was to draw squares from a set list in an array, but I opted rather to accept a command line argument in my script. To write this I had to delve back into regular expression, which I hate because I don&#8217;t [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>This weeks ICSP assignment was to write a program which draws squares. The task was to draw squares from a set list in an array, but I opted rather to accept a command line argument in my script. To write this I had to delve back into regular expression, which I hate because I don&#8217;t understand!</p>
<p>The program source is below. You should execute the program from the command line giving the with and height of the square you wish to draw, for example:</p>
<pre class="brush: bash">
java Squares 4x4
</pre>
<p>And the code:</p>
<pre class="brush: java">
import java.lang.String;
import java.util.regex.*;

public class Squares{
        public int dimensions[];

        public Squares(String[] args){
                if(args.length==1){
                        Pattern form=Pattern.compile("^\\S+x\\S+$");
                        Matcher fit=form.matcher(args[0]);
                        if(fit.matches()){
                                try{
                                        String[] dims=args[0].split("x");
                                        int width=Integer.parseInt(dims[0]);
                                        int height=Integer.parseInt(dims[1]);
                                        this.dimensions=new int[] {width,height};
                                }
                                catch(NumberFormatException e){
                                        System.err.println("Argument must be a string, width by height, in the form 6x6");
                                        System.exit(1);
                                }
                        }
                        else{
                                System.out.println("Argument must be a string, width by height, in the form 6x6");
                                System.exit(1);
                        }
                }
                else{
                        System.err.println("Please supply an argument, which must be a string, width by height, in the form 6x6");
                        System.exit(0);
                }
        }

        public String draw(){
                int i;
                int z;
                int width=this.dimensions[0];
                int height=this.dimensions[1];
                String square="";

                for(i=0;i&lt;height ;i++){
                        for(z=0;z&lt;width;z++){
                                if((i==0||i==height-1)&#038;&#038;(z==0||z==width-1))
                                        square+="+";
                                else if(z==0||z==width-1)
                                        square+="|";
                                else if((i==0||i==height-1))
                                        square+="-";
                                else
                                        square+=" ";
                        }
                        square+="\n";
                }

                return square;
        }

        public static void main(String[] args){
                Squares square=new Squares(args);
                String draw=square.draw();
                System.out.println(draw);
        }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://conor.macaoidh.ie/blog/2009/12/05/java-drawing-squares/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java &#8211; Calculate Taxi Fares</title>
		<link>http://conor.macaoidh.ie/blog/2009/12/02/java-calculate-taxi-fares/</link>
		<comments>http://conor.macaoidh.ie/blog/2009/12/02/java-calculate-taxi-fares/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 00:21:25 +0000</pubDate>
		<dc:creator><![CDATA[Conor]]></dc:creator>
				<category><![CDATA[College]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[fare]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Scratch]]></category>
		<category><![CDATA[taxi]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=281</guid>
		<description><![CDATA[This week my ICSP assignment was to calculate taxi fares. The task was: Using the fare table write a program that calculates the fares and test if it is correct. Upload your .java or your Scratch file. A template file for java will be provided. (Hint, only the boundary values needs to be tested. The [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>This week my ICSP assignment was to calculate taxi fares. The task was:</p>
<blockquote><p>Using the fare table write a program that calculates the fares and test if it is correct. Upload your .java or your Scratch file. A template file for java will be provided. (Hint, only the boundary values needs to be tested. The fare table is also presented in the slides. The compile command for java should be &#8220;javac TaxiRide.java&#8221;)</p>
<table border="0">
<tbody>
<tr>
<th colspan="2">Fare table</th>
</tr>
<tr>
<th>Distance (km)</th>
<th>Cost (€)</th>
</tr>
<tr>
<td>&gt;50</td>
<td>30</td>
</tr>
<tr>
<td>50-100</td>
<td>25, plus 9 for each km &gt; 50</td>
</tr>
<tr>
<td>100 &#8211; 2000</td>
<td>190, plus 8 for each km &gt; 100</td>
</tr>
<tr>
<td>&gt; 2000</td>
<td>1800</td>
</tr>
</tbody>
</table>
</blockquote>
<p>It wasn&#8217;t the hardest task. The only thing that confused me was the Java switch syntax. In PHP you can have conditions in a switch statement such as:</p>
<pre class="brush:php">
&lt;?php
switch($num){
        case ($num&lt;10):
                // blah
        break;
        case ($num&lt;100):
                // blah
        break;
        default:
                //blah
?&gt;
</pre>
<p>I couldn&#8217;t get Java to accept anything other than a value for the variable bring switched. So I did it the old-fashioned way! My code is below&#8230;</p>
<pre class="brush:java">
public class TaxiRide{
        public int distance=0;

        public TaxiRide(String arg){
                try{
                        int distance=Integer.parseInt(arg);
                        this.distance=distance;
                }
                catch(NumberFormatException e){
                        System.err.println("Arguement must be an integer representing the distance traveled");
                        System.exit(1);
                }
        }

        public int calculateFare(){
                int distance=this.distance;
                int fare=0;
                int i=0;
                if(distance&lt;50){
                        return 30;
                }
                if(distance%lt;100){
                        fare=25;
                        distance-=50;
                        for(i=0;i&lt;distance;i++){
                                fare+=9;
                        }
                        return fare;
                }
                if(distance&lt;2000){
                        fare=190;
                        distance-=100;
                        for(i=0;i&lt;distance;i++){
                                fare+=8;
                        }
                        return fare;
                }
                return 1800;
        }

        public static void main(String[] args){
                TaxiRide taxiRide = new TaxiRide(args[0]);
                int fare=taxiRide.calculateFare();
                System.out.println("The fare is: "+fare+" euro for traveling "+taxiRide.distance+"kM\n Thank you\n");
        }
}
</pre>
<p>I feel i am learning a lot from this course. Lately I have been experimenting in a few different languages. I added a bit to the Scratch Linux installer, written in Perl, so that it added an icon in the applications menu during installation. I&#8217;ve also been messing around with bash, trying to automate some of my most common commands&#8230; was thinking of writing a small bash script that backed up my data when my external hard drive is plugged in, similar to Time Machine on OSX.</p>
]]></content:encoded>
			<wfw:commentRss>http://conor.macaoidh.ie/blog/2009/12/02/java-calculate-taxi-fares/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Visual Hello World Popup</title>
		<link>http://conor.macaoidh.ie/blog/2009/11/15/java-visual-hello-world-popup/</link>
		<comments>http://conor.macaoidh.ie/blog/2009/11/15/java-visual-hello-world-popup/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 13:07:19 +0000</pubDate>
		<dc:creator><![CDATA[Conor]]></dc:creator>
				<category><![CDATA[College]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[add text to jframe]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[jar]]></category>
		<category><![CDATA[jbutton]]></category>
		<category><![CDATA[jframe]]></category>
		<category><![CDATA[jpanel]]></category>
		<category><![CDATA[popup]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[visual]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=261</guid>
		<description><![CDATA[I spent yesterday going a bit deeper into Java with one of my lecturers. I decided to try and write a more complicated hello world app. It&#8217;s quite simple really once you get around the strict OOP and different syntax&#8230; This is how I did it: First you need to import some of the java [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I spent yesterday going a bit deeper into Java with one of my lecturers. I decided to try and write a more complicated hello world app. It&#8217;s quite simple really once you get around the strict OOP and different syntax&#8230; This is how I did it:</p>
<p>First you need to import some of the java libraries that we will be using:</p>
<pre class="brush: java">
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
</pre>
<p>Then add the class, Popup. Make sure to name the file Popup.java</p>
<pre class="brush: java">
public class Popup{
private JFrame frame=new JFrame("Hello!");
private JPanel panel=new JPanel();
private JButton button=new JButton("Say Hello");
private JLabel label=new JLabel("Click the button to say hello...",SwingConstants.CENTER);
private ButtonListener buttonListener=new ButtonListener();
</pre>
<p>What that actually means is create a new instance of JFrame, JPanel, JButton and JLabel and store them in the frame,panel, button and label variables. As for the ButtonListener, we will deal with that later. Now we will deal with the launchFrame function which does what it says on the tin &#8211; launches the frame! Basically it just connects all of the pieces of information stored into the variables above and displays them together.</p>
<pre class="brush: java">
public void launchFrame(){
int height=400, width=600;
frame.setSize(width,height);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
</pre>
<p>Above we create two new integers which store the width and height of our frame. The next line sets the variables to the frame size. The final line tells the Java application to close when the window, or JFrame, is closed. Now that we have the configuration out of the way we can move on to adding the variables to the frame.</p>
<pre class="brush: java">
frame.getContentPane().add(label,BorderLayout.CENTER);
panel.add(button);
frame.getContentPane().add(panel,BorderLayout.WEST);
button.addActionListener(buttonListener);
frame.setVisible(true);
}
</pre>
<p>The code above adds the label to the frame, then adds the button to the panel and then the panel to the frame. Once again disregard the button.addAction.. line for now. The final line simply sets the frame to visible so we can see it.</p>
<p>Now that we have the frame settled, we need to add our essential main function to start up the execution:</p>
<pre class="brush: java">
public static void main(String args[]){
Popup popup=new Popup();
popup.launchFrame();
}
}
</pre>
<p>This code basically creates an instance of our class, Popup and then executes the function launchFrame which we have created in that class.</p>
<p>That&#8217;s the guts of it, but now we need to talk about these lines:</p>
<pre class="brush: java">
private ButtonListener buttonListener=new ButtonListener();</pre>
<pre class="brush: java">
 public void launchFrame(){
....
button.addActionListener(buttonListener);
</pre>
<p>Basically we have previously created a button, but these lines define what happens when the button is pressed. The second line of code tells the machine to listen out for the clicking of the button, and when that happens to execute the variable buttonListener. We have created the variable buttonListener, which creates a new instance of the ButtonListener class which we have yet to create.</p>
<p>That is the next step, to create that class. Create a new file called ButtonListener.java and add this code:</p>
<pre class="brush: java">
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;</pre>
<pre class="brush: java">
public class ButtonListener implements ActionListener{
</pre>
<p>The first four lines import the libraries that we are using. The final line is important. It states that our class, ButtonListener is implementing the ActionListener class. Below is the content of our new class:</p>
<pre class="brush: java">
private JFrame pressed=new JFrame("Hello World!");</pre>
<pre class="brush: java">
public void actionPerformed(ActionEvent actionEvent){
</pre>
<p>First, we create a new JFrame for our popup just like we did in the other file. The function actionPerformed is  a function from the ActionListener class that we are implementing. The parameters for the function are predefined so we need them. The rest of the code is very similar to the previous code so I won&#8217;t explain it in depth. Basically it just configures the new frame, adds the label and then displays it:</p>
<pre class="brush: java">
int height=160, width=200;
pressed.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel pressedtext=new JLabel("Hello World!",SwingConstants.CENTER);
pressed.getContentPane().add(pressedtext,BorderLayout.CENTER);
pressed.setSize(width,height);
pressed.setVisible(true);
}</pre>
<p>Save that file and then compile both files by executing:</p>
<pre class="brush: bash">
javac ButtonListener.java Popup.java
</pre>
<p>Now if you run the program you should see a nice visual dialogue:</p>
<pre class="brush: bash">
java Popup
</pre>
<p>You can download a jar archive of the program <a href="http://files.macaoidh.name/Download/Java-Popup-Hello-World">here</a>.</p>
<p>The full code is below. Popup.java:</p>
<pre class="brush: java">
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class Popup{
        private JFrame frame=new JFrame("Hello!");
        private JPanel panel=new JPanel();
        private JButton button=new JButton("Say Hello");
        private JLabel label=new JLabel("Click the button to say hello...",SwingConstants.CENTER);
        private ButtonListener buttonListener=new ButtonListener();

        public void launchFrame(){
                int height=400, width=600;
                frame.setSize(width,height);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.getContentPane().add(label,BorderLayout.CENTER);
                panel.add(button);
                frame.getContentPane().add(panel,BorderLayout.WEST);
                button.addActionListener(buttonListener);
                frame.setVisible(true);
        }

        public static void main(String args[]){
                Popup popup=new Popup();
                popup.launchFrame();
        }
}
</pre>
<p>ButtonListener.java:</p>
<pre class="brush: java">
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class ButtonListener implements ActionListener{
        private JFrame pressed=new JFrame("Hello World!");

        public void actionPerformed(ActionEvent actionEvent){
                int height=160, width=200;
                pressed.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                JLabel pressedtext=new JLabel("Hello World!",SwingConstants.CENTER);
                pressed.getContentPane().add(pressedtext,BorderLayout.CENTER);
                pressed.setSize(width,height);
                pressed.setVisible(true);
        }

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://conor.macaoidh.ie/blog/2009/11/15/java-visual-hello-world-popup/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
