<?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-3164099021048373617</id><updated>2011-11-27T15:45:01.529-08:00</updated><title type='text'>grumpy old programmer</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://grumpyoldprogrammer.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3164099021048373617/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://grumpyoldprogrammer.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Filip Bulovic</name><uri>http://www.blogger.com/profile/18302976643246249328</uri><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>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3164099021048373617.post-6579474221675743589</id><published>2009-08-05T13:34:00.000-07:00</published><updated>2009-08-06T17:35:54.173-07:00</updated><title type='text'>Quantum Superpositions and other Scary Stuff</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;p&gt;Quantum::Superpositions, Quantum::Entanglement and Quantum::Usrn, as one may note, are related to quantum mechanics. Those are not packages to solve equations characteristic to quantum mechanics, but to bring quantum ideas and logic into Perl and programming in general. All three packages are interesting and deserve attention but only Quantum::Superpositions achieved wider recognition and become part of Perl 6. For that reason (limited space also plays a role) I would concentrate only on Quantum::Superpositions.&lt;/p&gt; &lt;p&gt;Welcome to Hilbert space and no, you do not have to have quantum computer at home to play with madness. With a little help from your friends (whom you manage to find on Internet) your good old computer will do just fine. &lt;/p&gt; &lt;p&gt;If you are running Ubuntu or Debian, use sudo; if not, just run terminal as root:&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;span style='font-family: Courier New,monospace;'&gt;&lt;span style='font-size: 85%;'&gt;sudo perl -MCPAN -e shell&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;As mentioned, to invoke CPAN shell you must use root. If you never used it then do the update.&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;span style='font-family: Courier New,monospace;'&gt;&lt;span style='font-size: 85%;'&gt;cpan[1]&amp;gt; install Bundle::CPAN&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;That may take some time. &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;span style='font-family: Courier New,monospace;'&gt;&lt;span style='font-size: 85%;'&gt;cpan[2]&amp;gt; reload cpan &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;And finally, why we started all this - installation of Quantum::Superpositions:&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;span style='font-family: Courier New,monospace;'&gt;&lt;span style='font-size: 85%;'&gt;cpan[3]&amp;gt; install Quantum::Superpositions&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;CPAN shell will ask for permission to download dependencies, and when all is done type in q or quit and hit enter to release the lock.&lt;/p&gt; &lt;p&gt;There is a philosophycal background to this package and the author, Damian Conway, gently mentioned it in documentation. Naturally, very few readers have the knowledge of quantum mechanics (that thing is worse than maths) and for the majority we will nicely disect the package through trusty old trial and error aproach. Quantum::Superpositions introduces two operators - any and all. Those operators are mapping a set of scalars to a single scalar variable, the author calls those scalar variables eigenstates. You see how that quantum mechanic may be dangerous and contageous, short exposure to it and you are already appending German words to English ones creating a new language which nobody understands. Without further ado we start with the code:&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;use Quantum::Superpositions;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;use Data::Dumper;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;$temp = all(1 .. 5);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;print "$temp";&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;print "\n";&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;print Dumper($temp);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;From the output we may conclude that to string method is overloaded and that $temp is a reference to anonymous array blessed to Quantum::Superpositions::Conj. If we do the same for any we see that $temp is a reference to anonymous array now blessed to Quantum::Superpositions::Disj. If you can't remember that reference to anonymous array, here it is:&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;$temp = [1, 2, 3]&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;Beside string conversion, the package overloads all other commonly used operators. Locating Superpositions.pm and inspecting the code may be highly beneficial here. Trivial:&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;$test++;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;will increase all eigenvalues, irrespective of whether we are using any or all. Multiplication and addition becomes real fun:&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;$temp = any(1 .. 3)*any(4, 5);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;print "$temp";&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;will produce:&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;any(8,4,10,12,15,5)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;We will also note that any ignores duplicate values (or eigenvalues?) and all doesn't. Commutativity is satisfied for any*any or all*all but not for all*any. For example:&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;any(1 .. 3)*all(4, 5) = any() &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p&gt;but&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;all(4, 5)*any(1 .. 3) = all(any(8,4,12),any(10,15,5)) &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p&gt;The type of the first operand determines the type of the result of multiplication. If we try addition then:&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;$temp = all(4, 5)+any(1 .. 3); &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;print "$temp"; &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;print "\n"; &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;print Dumper($temp);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;produces a very interesting result:&lt;/p&gt; &lt;p&gt;   	 	 	 	&lt;style type='text/css'&gt; 	&lt;/style&gt;   	 	 	 	&lt;style type='text/css'&gt; 	&lt;/style&gt;&lt;font size='2'&gt;&lt;font face='Courier 10 Pitch'&gt;6 7 &lt;br/&gt;$VAR1 = bless( [ &lt;br/&gt;                 bless( [ &lt;br/&gt;                          5, &lt;br/&gt;                          6, &lt;br/&gt;                          7 &lt;br/&gt;                        ], 'Quantum::Superpositions::Disj' ), &lt;br/&gt;                 bless( [ &lt;br/&gt;                          6, &lt;br/&gt;                          7, &lt;br/&gt;                          8 &lt;br/&gt;                        ], 'Quantum::Superpositions::Disj' ) &lt;br/&gt;               ], 'Quantum::Superpositions::Conj' ); &lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;The result is an array containing common subset. From this (pretending that we did not read help file) we can easily draw the formula for finding common subset:&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;$temp = all(any(1 .. 5), any(4, 5, 6), any(3, 4, 5));&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;Small warning here: if one tries @$temp it will not produce expected 4 and 5 but:&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;any(4,1,3,2,5) any(6,4,5) any(4,3,5)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;To pull subset into array properly we must use eigenstates method.&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;@subset = eigenstates(all(any(1 .. 5), any(4, 5, 6), any(3, 4, 5)));&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;Now the question do elements of array @b contain all the elements of array @a becomes:&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;@a = (1, 2, 3);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;@b = (1 .. 5);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;if(@a == eigenstates(all(any(@a), any(@b)))){&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt; print "Yes @a is subset of @b\n";&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=''&gt;&lt;span style='font-size: 85%;'&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;Which is really a neat way of coding compared to usual nested loops. &lt;/p&gt; &lt;p&gt;If you download the source as well, it contains demo directory where we can see GCD and factoring and generally get some idea on how the package may be used. While the package brings ideas from quantum computing, it doesn't turn your old computer into a quantum one, so some algorithms may still execute in exponential time. If you find this interesting here is a small advertisment for Quantum::Entanglement, its demo directory contains implementation of Shor's algorithm for factoring numbers.&lt;/p&gt;&lt;br/&gt;&lt;br/&gt;&lt;div class='zemanta-pixie'&gt;&lt;img src='http://img.zemanta.com/pixy.gif?x-id=4ae904f1-1464-837f-8def-881630c3691a' alt='' class='zemanta-pixie-img'/&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3164099021048373617-6579474221675743589?l=grumpyoldprogrammer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://grumpyoldprogrammer.blogspot.com/feeds/6579474221675743589/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://grumpyoldprogrammer.blogspot.com/2009/08/quantum-superpositions-and-other-scary.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3164099021048373617/posts/default/6579474221675743589'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3164099021048373617/posts/default/6579474221675743589'/><link rel='alternate' type='text/html' href='http://grumpyoldprogrammer.blogspot.com/2009/08/quantum-superpositions-and-other-scary.html' title='Quantum Superpositions and other Scary Stuff'/><author><name>Filip Bulovic</name><uri>http://www.blogger.com/profile/18302976643246249328</uri><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-3164099021048373617.post-4508482362318849983</id><published>2009-07-20T01:43:00.000-07:00</published><updated>2009-07-20T02:20:42.974-07:00</updated><title type='text'>Pascal's triangle, Perl, and homework</title><content type='html'>Frequently, an evil professor gives to his students homework and sometimes it may be a request to write code which prints Pascal's triangle. Naturally, the student cranks up Firefox (that is synonym for web browser) and goes googling around for examples. A nice elegant solution comes up in the form of:&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-size:85%;"&gt;sub pascal { &lt;br /&gt;   my @row; &lt;br /&gt;   foreach (1 .. shift) { &lt;br /&gt;      push @row =&amp;gt; 1; &lt;br /&gt;      $row [$_] += $row [$_ - 1] for reverse 1 .. @row - 2; &lt;br /&gt;      print "@row\n"; &lt;br /&gt;   } &lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I picked up that one on http://www.perlmonks.org/?node=175586, naturally very few students will understand, right away, what is happening in this code. In order to make the code shorter the author did some Perl tricks, which made it difficult to read and understand the code. In the first transformation I will introduce one unnecessary variable and also make function call more C or Java like.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-size:85%;"&gt;sub pascal {&lt;br /&gt;   my $size = shift();&lt;br /&gt;   my @row;&lt;br /&gt;   foreach (1 .. $size) {&lt;br /&gt;      push (@row, 1);&lt;br /&gt;      $row [$_] += $row [$_ - 1] for reverse 1 .. @row - 2;&lt;br /&gt;      print "@row\n";&lt;br /&gt;   }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Already looks better. Inner loop still looks odd and we are not quite sure what it does and which $_ is used, one from foreach or one from for reverse. In order to see, let us add one debug loop:&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-size:85%;"&gt;sub pascal {&lt;br /&gt;   my $size = shift();&lt;br /&gt;   my @row;&lt;br /&gt;   foreach (1 .. $size) {&lt;br /&gt;      push (@row, 1);&lt;br /&gt;      for (reverse 1 .. @row - 2){&lt;br /&gt;          print $row [$_]," + ",$row [$_ - 1]," store in \$row[$_]\n";&lt;br /&gt;       }&lt;br /&gt;      $row [$_] += $row [$_ - 1] for reverse 1 .. @row - 2;&lt;br /&gt;      print "@row\n";&lt;br /&gt;   }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Output will look like this:&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-size:85%;"&gt;1 &lt;br /&gt;1 1 &lt;br /&gt;1 + 1 store in $row[1] &lt;br /&gt;1 2 1 &lt;br /&gt;1 + 2 store in $row[2] &lt;br /&gt;2 + 1 store in $row[1] &lt;br /&gt;1 3 3 1 &lt;br /&gt;1 + 3 store in $row[3] &lt;br /&gt;3 + 3 store in $row[2] &lt;br /&gt;3 + 1 store in $row[1] &lt;br /&gt;1 4 6 4 1 &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now it is obvious that outer loop just pushes ones and inner loop does all difficult work.&lt;br /&gt;One small thing is left, printout doesn't look nice, it is somehow skew. To remedy that we add some pretty printing:&lt;br /&gt;&lt;pre style="font-size:85%;"&gt;sub pascal {&lt;br /&gt;    my $size = shift;&lt;br /&gt;    my $count;&lt;br /&gt;    my $margin;&lt;br /&gt;    my @row;&lt;br /&gt;    foreach (1 .. $size) {&lt;br /&gt;       push (@row, 1);&lt;br /&gt;       $row [$_] += $row [$_ - 1] for reverse 1 .. @row - 2;&lt;br /&gt;       $margin = "   " x ($size - $count - 1);&lt;br /&gt;       print "$margin";&lt;br /&gt;       $count++;&lt;br /&gt;       foreach (@row){&lt;br /&gt;           printf "%6d",$_;&lt;br /&gt;        }&lt;br /&gt;       print "\n";&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If we call it and pass 16 as parameter it will print this:&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-size:66%;" &gt;                                                 1&lt;br /&gt;                                              1     1&lt;br /&gt;                                           1    2     1&lt;br /&gt;                                        1    3    3     1&lt;br /&gt;                                     1    4    6    4     1&lt;br /&gt;                                  1    5    10   10    5     1&lt;br /&gt;                               1    6    15   20   15    6     1&lt;br /&gt;                            1    7    21   35    35   21    7     1&lt;br /&gt;                         1    8    28   56    70   56   28    8     1&lt;br /&gt;                      1    9    36   84   126  126    84   36    9     1&lt;br /&gt;                   1    10   45   120   210  252   210  120    45   10     1&lt;br /&gt;                1    11   55   165   330  462   462   330  165    55  11     1&lt;br /&gt;             1    12   66   220   495  792   924   792  495   220   66   12     1&lt;br /&gt;          1    13   78   286   715 1287  1716  1716  1287  715   286   78   13     1&lt;br /&gt;       1    14   91   364  1001  2002 3003  3432  3003  2002 1001   364   91   14     1&lt;br /&gt;    1    15  105   455  1365  3003 5005  6435  6435  5005 3003  1365   455  105   15     1 &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Not quite equilateral, one would say.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3164099021048373617-4508482362318849983?l=grumpyoldprogrammer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://grumpyoldprogrammer.blogspot.com/feeds/4508482362318849983/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://grumpyoldprogrammer.blogspot.com/2009/07/pascals-triangle-perl-and-homework.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3164099021048373617/posts/default/4508482362318849983'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3164099021048373617/posts/default/4508482362318849983'/><link rel='alternate' type='text/html' href='http://grumpyoldprogrammer.blogspot.com/2009/07/pascals-triangle-perl-and-homework.html' title='Pascal&apos;s triangle, Perl, and homework'/><author><name>Filip Bulovic</name><uri>http://www.blogger.com/profile/18302976643246249328</uri><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-3164099021048373617.post-1457029227719815005</id><published>2009-07-07T07:19:00.001-07:00</published><updated>2009-07-07T07:19:33.756-07:00</updated><title type='text'>Install JDK on Ubuntu 9.04</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;style type='text/css'&gt; 	 	&lt;/style&gt;  &lt;p&gt;Occasionally there is need to switch between JDK's. For example DrJava works nicely only with JDK downloaded from the Sun website. Also Eclipse and NetBeans may show some funny behaviours if they are using JDK from Ubuntu repositories. But before I go about creating config files and setting up this or that JDK to be default, let me explain how to install any JDK on Ubuntu.&lt;/p&gt; &lt;h2 class='western'&gt;Vanilla Ubuntu JDK&lt;/h2&gt; &lt;p&gt;There are two main methods which can be used to install Java Development Kit on Ubuntu. The first one is you use Ubuntu repositories. GUI way is go to System -&amp;gt; Administration -&amp;gt; Synaptic Package Manager. It will ask you for a password. When it is up type in Java into Quick search box. Further, locate the JDK that you want, tick check box next to it (from context menu select Mark for installation) and hit Apply button. Under the bonnet packages will be downloaded, unpacked, installed and symbolic links created. If you want you can use command line and apt-get instead. Go to Applications -&amp;gt; Acessories -&amp;gt; Terminal, when terminal shows up type in:&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;apt-cache search java | more&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;That does search for packages which are somehow related to Java. Part of the command '| more' prints single screen at the time; to see the next batch of results hit the space bar. When you locate what you need then you install it:&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;sudo apt-get install openjdk-6-jdk&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;sudo gives you temporary root authority and will ask you for password. You may want to install sun-java6-jdk instead, or maybe both of them.&lt;/p&gt; &lt;p&gt;If you decided to install more than one JDK then you may wish to alternate between them from time to time. To achieve that run:&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;update-java-alternatives -l&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;That should produce a list of JDK's. What is it and what does it actually do? It is bash script located in /usr/sbin/ and it is part of java-common. To see what else is in java-common use:&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;dpkg -L java-common&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;It goes to /usr/lib/jvm/ and looks for *.jinfo files. Those files are hidden files, their name starts with dot, for example .java-6-sun.jinfo. In order to see hidden files in Nautilus press Ctl+H. Their content looks something like this:&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;name=java-6-openjdk &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;alias=java-6-openjdk &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;priority=1061 &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;section=main &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;hl java /usr/lib/jvm/java-6-openjdk/jre/bin/java &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;hl keytool /usr/lib/jvm/java-6-openjdk/jre/bin/keytool &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;...&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;hl jexec /usr/lib/jvm/java-6-openjdk/jre/lib/jexec &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;jre javaws /usr/lib/jvm/java-6-openjdk/jre/bin/javaws &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;jre pluginappletviewer /usr/lib/jvm/java-6-openjdk/jre/bin/pluginappletviewer &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;jre policytool /usr/lib/jvm/java-6-openjdk/jre/bin/policytool &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;jdk appletviewer /usr/lib/jvm/java-6-openjdk/bin/appletviewer &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;...&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;jdk jar /usr/lib/jvm/java-6-openjdk/bin/jar &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;jdk jarsigner /usr/lib/jvm/java-6-openjdk/bin/jarsigner &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;jdk javac /usr/lib/jvm/java-6-openjdk/bin/javac &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;...&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;jdk wsgen /usr/lib/jvm/java-6-openjdk/bin/wsgen &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;jdk wsimport /usr/lib/jvm/java-6-openjdk/bin/wsimport &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;jdk xjc /usr/lib/jvm/java-6-openjdk/bin/xjc &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;plugin xulrunner-1.9-javaplugin.so /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/gcjwebplugin.so&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;If your Firefox or Chrome gives you hard time with Java applets, you know where to look.&lt;/p&gt; &lt;p&gt;Back to list of available JDK's, pick one and set it as default:&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;sudo update-java-alternatives -s java-6-sun&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;Now when you try java -version it should print out your current JDK version.  &lt;/p&gt; &lt;h2 class='western'&gt;Using JDK which is not from Ubuntu Repository&lt;/h2&gt; &lt;p&gt;Usually that is JDK downloaded directly from Sun website. It usually comes as shell script and it is named jdk-6u13-linux-i586.bin; update version may be different. When you run it (double click and select Run from dialogue) it will show EULA and extract JDK right there where you downloaded it. If you expected that it will be installed and become the main supplier of Java Virtual Machine - sorry that is not the case. There are two options, the first one is quick and dirty. In order to make your ~/install/jdk1.6.0_13/bin/java main supplier of Java do the following:&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;sudo update-alternatives --install /usr/bin/java java /home/JDKPATH/install/jdk1.6.0_13/bin/java 300 &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;sudo update-alternatives --auto java &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;a name='DDE_LINK'/&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;sudo update-alternatives --install /usr/bin/javac javac /home/JDKPATH/jdk1.6.0_13/bin/javac 300 &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;sudo update-alternatives --auto javac&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;That should be enough to get you going. If the need arises, you may wish to append more of those symbolic links to the collection.&lt;/p&gt; &lt;p&gt;The more appropriate solution would be how Debian developers are doing it, cd to where JDK is and execute the following:&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;sudo apt-get install fakeroot java-package&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;fakeroot make-jpkg jdk-6u13-linux-i586.bin&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;After the process of packaging JDK is over there should be sun-j2sdk1.6_1.6.0+update13_i386.deb which you can double click to start GDebi and install it. Finally execute:&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;sudo update-alternatives --config java&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;It will list what is available on your box and you type in number for /usr/lib/j2sdk1.6-sun/bin/java to set it as default.&lt;/p&gt; &lt;br/&gt;&lt;br/&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3164099021048373617-1457029227719815005?l=grumpyoldprogrammer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://grumpyoldprogrammer.blogspot.com/feeds/1457029227719815005/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://grumpyoldprogrammer.blogspot.com/2009/07/install-jdk-on-ubuntu-904.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3164099021048373617/posts/default/1457029227719815005'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3164099021048373617/posts/default/1457029227719815005'/><link rel='alternate' type='text/html' href='http://grumpyoldprogrammer.blogspot.com/2009/07/install-jdk-on-ubuntu-904.html' title='Install JDK on Ubuntu 9.04'/><author><name>Filip Bulovic</name><uri>http://www.blogger.com/profile/18302976643246249328</uri><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-3164099021048373617.post-3713657639193228507</id><published>2009-07-06T04:54:00.001-07:00</published><updated>2009-07-06T04:54:55.288-07:00</updated><title type='text'>Concatenate empty String with Integer or not</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;style type='text/css'&gt; 	 	&lt;/style&gt;  &lt;p&gt;Recently I was lucky enough to take part in some damage control mission. At the site I discovered many interesting things. Tomcat was deployed in development mode in production environment and log file was well over 6GB. For some unknown reason they preferred to use Tomcat and solve connection polling manualy (using Proxool). Naturally, the client wanted everything upgraded to Java 6, which may not be such a good idea with Proxool. I hope that one can imagine the amount of work invested in Proxool and appreciate equally the complicated dependencies like Cglib or Asm. Anyway, why would one use Glassfish, TopLink, JSF and EJB 3.0 when with Tomcat we can do nicely our own thread-connection-pulling management, do user interface using Velocity and so on.&lt;/p&gt; &lt;p&gt;Luckily, there was no documentation and the reason for all those architectural decisions can't be clearly established. The unofficial version is that on the same project (but old version) there was a small group of developers using Delphi and Sybase. After years of work they knew business logic so well. Then the client decided to start using Oracle and Java. Since the guys were so familiar with business logic, the fact that they did not know much about Java was not that important. They didn't quite understand the need for build process, source versioning and other boring stuff. So they will check in and out source, do bug fixes, compile at will, drop classes into Tomcat's WEB-INF folder. Mostly people were using Eclipse incremental compiler, but some used ant and javac. Tagging was non-existing and eventually nobody knew what was deployed where - which version of the source. So it was required to discover through decompiling what was deployed in production environment. Through the process I discovered the most original way of converting number to string. Here is the small example of original and common way of obtaining string representation of integer:&lt;/p&gt; &lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt; &lt;p&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;public class Main {&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;    &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;public static void main(String[] args) {&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;        &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;System.out.print(useInteger(11));&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;        &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;System.out.print(hereIsYourString(12));&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;    &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;    &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;static String hereIsYourString(int i){&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;        &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;return ""+i;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;    &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;    &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;static String useInteger(int i){&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;        &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;return Integer.toString(i);&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;    &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;br/&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;Now some people would maybe like less typing idea more. OK, the question is how does one explain to an inexperienced Java programmer to stay out of those shortcuts?&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;I think the best way is to disassemble class using the Java Class File Disassembler and take a look at bytecode. The best way to start with javap is this:&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;br/&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;~$ javap -help &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;Usage: javap &amp;lt;options&amp;gt; &amp;lt;classes&amp;gt;... &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;br/&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;where options include: &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;-c                       Disassemble the code &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;-classpath &amp;lt;pathlist&amp;gt;     Specify where to find user class files &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;-extdirs &amp;lt;dirs&amp;gt;           Override location of installed extensions &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;-help                    Print this usage message &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;-J&amp;lt;flag&amp;gt;                 Pass &amp;lt;flag&amp;gt; directly to the runtime system &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;-l                       Print line number and local variable tables &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;-public                  Show only public classes and members &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;-protected               Show protected/public classes and members &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;-package                 Show package/protected/public classes &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;                             &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;and members (default) &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;-private                 Show all classes and members &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;-s                       Print internal type signatures &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;-bootclasspath &amp;lt;pathlist&amp;gt; Override location of class files loaded &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;                             &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;by the bootstrap class loader &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;-verbose                 Print stack size, number of locals and args for methods &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;                             &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;If verifying, print reasons for failure &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;br/&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;Using info I will cd to /MyProjects/JavaApplication22/build/classes/javaapplication22 and that is where the product of compilation is. Then I will do dissasembling:&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;br/&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;~/MyProjects/JavaApplication22/build/classes/javaapplication22$ javap -c -classpath . Main &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;Compiled from "Main.java" &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;public class javaapplication22.Main extends java.lang.Object{ &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;public javaapplication22.Main(); &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;  &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;Code: &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;0:	aload_0 &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;1:	invokespecial	#1; //Method java/lang/Object."&amp;lt;init&amp;gt;":()V &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;4:	return &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;br/&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;public static void main(java.lang.String[]); &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;  &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;Code: &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;0:	getstatic	#2; //Field java/lang/System.out:Ljava/io/PrintStream; &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;3:	bipush	11 &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;5:	invokestatic	#3; //Method useInteger:(I)Ljava/lang/String; &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;8:	invokevirtual	#4; //Method java/io/PrintStream.print:(Ljava/lang/String;)V &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;11:	getstatic	#2; //Field java/lang/System.out:Ljava/io/PrintStream; &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;14:	iconst_1 &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;15:	invokestatic	#5; //Method hereIsYourString:(I)Ljava/lang/String; &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;18:	invokevirtual	#4; //Method java/io/PrintStream.print:(Ljava/lang/String;)V &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;21:	return &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;br/&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;static java.lang.String hereIsYourString(int); &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;  &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;Code: &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;0:	new	#6; //class java/lang/StringBuilder &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;3:	dup &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;4:	invokespecial	#7; //Method java/lang/StringBuilder."&amp;lt;init&amp;gt;":()V &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;7:	ldc	#8; //String &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;9:	invokevirtual	#9; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;12:	iload_0 &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;13:	invokevirtual	#10; //Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder; &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;16:	invokevirtual	#11; //Method java/lang/StringBuilder.toString:()Ljava/lang/String; &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;19:	areturn &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;br/&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;static java.lang.String useInteger(int); &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;  &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;Code: &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;0:	iload_0 &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;1:	invokestatic	#12; //Method java/lang/Integer.toString:(I)Ljava/lang/String; &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;   &lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;4:	areturn &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;br/&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;font face='Courier 10 Pitch'&gt;&lt;font size='2' style='font-size: 9pt;'&gt;} &lt;/font&gt;&lt;/font&gt; &lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;&lt;br/&gt;&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;At the first sight output may look confusing, but if we take a better look everything is there and comparing to Java source helps identify our methods. Here you have it: concatenating empty string with integer generates few more instructions than calling static Integer.toString.&lt;/p&gt; &lt;p style='margin-bottom: 0cm;'&gt;If one would like to explore what happens further eg. inside  Integer.toString or  StringBuilder.append I would warmly recommend downloading OpenJDK, alternatively make a break until such an idea goes away.&lt;/p&gt; &lt;br/&gt;&lt;br/&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3164099021048373617-3713657639193228507?l=grumpyoldprogrammer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://grumpyoldprogrammer.blogspot.com/feeds/3713657639193228507/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://grumpyoldprogrammer.blogspot.com/2009/07/concatenate-empty-string-with-integer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3164099021048373617/posts/default/3713657639193228507'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3164099021048373617/posts/default/3713657639193228507'/><link rel='alternate' type='text/html' href='http://grumpyoldprogrammer.blogspot.com/2009/07/concatenate-empty-string-with-integer.html' title='Concatenate empty String with Integer or not'/><author><name>Filip Bulovic</name><uri>http://www.blogger.com/profile/18302976643246249328</uri><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-3164099021048373617.post-6644331872387061496</id><published>2009-07-05T06:39:00.001-07:00</published><updated>2009-07-05T06:43:46.689-07:00</updated><title type='text'>Home SMS Gateway using Perl, Ubuntu and Nokia</title><content type='html'>&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;style type="text/css"&gt;    &lt;/style&gt;  &lt;p style="margin-bottom: 0cm; page-break-before: always;"&gt;Thinking what would be good for the start. SMS gateway sounds quite interesting.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;On a large scale one is inclined to look at Kannel as a starting point. There are a few traps with Kannel. While being open source (bearerbox and smsbox), the most interesting parts like smppbox are not open source, so be prepared to spit out about 4000 Euros for it when the volume becomes critical. Also, Kannel doesn't like SuSE Linux Enterprise Server very much, and for some reason that one is used here by the government and big companies. Apparently, Novell sells support cheaper than Red Hat and it is friendlier with MS. So, if you like Kannel-based solution - use Red Hat or Debian. That is stated in Kannel's documentation and they know what they are talking about.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;What else may one use to roll out SMS gateway?&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Java and its enormous wealth of open source libraries, application servers and development tools. Assembling SMS gateway with SMPP API should be quite easy.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;How about deploying SMS gateway on Windows?&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;You cannot be serious.  &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Now we may leave alone make-millions-from-spamming enterprise projects and check something more appropriate for common people. How do you create your own SMS gateway? Not so long ago I wrote a small article about sending SMS using Nokia S60 phone as a modem from Ubuntu and  Device::Gsm Pearl module. Now lot of people will ask why Perl? If you want to do something simple and effective on Ubuntu (or any other kind of Linux), Pearl is the way to go. If you want to do some massive development with tens of thousands of line of code, do not use Perl.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;I tried this using Nokia N81 as a modem. There is no need to go that high, any phone which can act as a modem will do. USB wireless modems, like Huawei E220 should do as well. Operating system is Ubuntu 8.04, but you can try that using any OS where Perl can be installed.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;For the start we need to install  Device::Gms.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;$ sudo perl -MCPAN -e shell&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Super user is required to do that, now from CPAN shell we update our CPAN&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;cpan[1]&amp;gt; install Bundle::CPAN&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;That may take some time.  &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;cpan[2]&amp;gt; reload cpan &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;And finally why we started all this:&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;cpan[3]&amp;gt; install Device::Gsm &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;It may be needed to install dependencies, like Device::Modem, CPAN will suggest that it downloads and installs dependencies. Home page of Device::Gsm is here &lt;a href="http://search.cpan.org/%7Ecosimo/Device-Gsm/Gsm.pm"&gt;http://search.cpan.org/~cosimo/Device-Gsm/Gsm.pm&lt;/a&gt;, I suggest visiting it and reading it - carefully.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Now we can grab the USB cable and connect Nokia (or whatever you are using) and PC, from phone menu we select PC Suite. On Ubuntu we activate terminal and execute dmesg, only the last few lines are interesting.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;[11869.492522] usb 2-5: new full speed USB device using ohci_hcd and address 2 &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;[11869.727885] usb 2-5: configuration #1 chosen from 1 choice &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;[11870.010452] cdc_acm 2-5:1.8: ttyACM0: USB ACM device &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;[11870.015377] usbcore: registered new interface driver cdc_acm &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;[11870.015387] /build/buildd/linux-2.6.24/drivers/usb/class/cdc-acm.c: v0.25:USB Abstract Control Model driver for USB modems and ISDN adapters &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;[11870.053566] usbcore: registered new interface driver cdc_ether &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;[11870.056287] usb 2-5: bad CDC descriptors &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;[11870.056308] usbcore: registered new interface driver rndis_host &lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;We now locate the following line of code on Device::Gsm home page&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;my $gsm = new Device::Gsm( port =&amp;gt; '/dev/ttyS1', pin =&amp;gt; 'xxxx' );&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;From dmesg otput we find out where the phone is and also we enter appropriate PIN&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;my $gsm = new Device::Gsm( port =&amp;gt; '/dev/ttyACM0', pin =&amp;gt; 'here comes your PIN' );&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;We are now ready to go:&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;#!/usr/bin/perl -w&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;use Device::Gsm;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;my $gsm = new Device::Gsm( port =&amp;gt; '/dev/ttyACM0', pin =&amp;gt; 'XXXX' );&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;if( $gsm-&amp;gt;connect() ) {&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;  &lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;print "connected!\n";&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;} else {&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;  &lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;print "sorry, no connection with gsm phone on serial port!\n";&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;my $imei = $gsm-&amp;gt;imei();&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;print "$imei\n";&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;my $model = $gsm-&amp;gt;model();&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;print "$model\n";&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Copy and paste this into new file, name it test.pl and execute from terminal perl test.pl. That will print IMEI and phone model.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;By further modification of initial example from Device::Gsm home page we have    &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;#!/usr/bin/perl -w&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;   &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;use Device::Gsm;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;my $gsm = new Device::Gsm( port =&amp;gt; '/dev/ttyACM0', pin =&amp;gt; 'XXXX' , log =&amp;gt; 'file,network.log', loglevel =&amp;gt; 'debug');&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;if( $gsm-&amp;gt;connect() ) {&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;  &lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;print "connected!\n";&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;} else {&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;  &lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;print "sorry, no connection with gsm phone on serial port!\n";&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;$gsm-&amp;gt;register();&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;$gsm-&amp;gt;send_sms(&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;  &lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;recipient =&amp;gt; '+2774XXXXXXX',&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;  &lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;content  =&amp;gt; 'Here is your Ubuntu talking',&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;  &lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;class    =&amp;gt; 'normal'&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-family:Courier New, monospace;"&gt;&lt;span style="font-size: 9pt;font-size:85%;" &gt;);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Naturally, replace XXXX with what is your pin number. Start of recipient is +27 for South Africa and 74 for network, it may need adjustment as well. Reusing test.pl is a good idea. To send an SMS takes a while.  In network.log we will find the story, if everything went well do not even look at it - 160 Kb of log per SMS. Now typically one would like to combine this with some kind of HTTP or maybe TCP access, but that is quite easy and well explained all over the web so I will not bother you with it.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;If you happen to be in Italy, Cosimo Streppone may be happy to know that you are using his library, look for send_to_cosimo.pl in examples folder.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3164099021048373617-6644331872387061496?l=grumpyoldprogrammer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://grumpyoldprogrammer.blogspot.com/feeds/6644331872387061496/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://grumpyoldprogrammer.blogspot.com/2009/07/home-sms-gateway-using-perl-ubuntu-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3164099021048373617/posts/default/6644331872387061496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3164099021048373617/posts/default/6644331872387061496'/><link rel='alternate' type='text/html' href='http://grumpyoldprogrammer.blogspot.com/2009/07/home-sms-gateway-using-perl-ubuntu-and.html' title='Home SMS Gateway using Perl, Ubuntu and Nokia'/><author><name>Filip Bulovic</name><uri>http://www.blogger.com/profile/18302976643246249328</uri><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>
