<?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>Novoda &#187; Languages &amp; syntax</title>
	<atom:link href="http://novoda.com/category/blog/android/languages-syntax/feed/" rel="self" type="application/rss+xml" />
	<link>http://novoda.com</link>
	<description>Android mobile development and consultancy</description>
	<lastBuildDate>Wed, 05 Oct 2011 11:15:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Scala on Android</title>
		<link>http://novoda.com/2009/10/17/scala-on-android/</link>
		<comments>http://novoda.com/2009/10/17/scala-on-android/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 19:31:43 +0000</pubDate>
		<dc:creator>Akshay Dashrath</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Languages & syntax]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://www.novoda.com/blog/?p=154</guid>
		<description><![CDATA[
The Scala Programming Language:
The Scala programming Language is an object oriented functional programming language designed to run on the JVM. It is ideal for programming on the Dalvik Platform as code written with the Scala language is more compact, readable and could possibly have performance benefits (which will be analysed at a later date) and [...]]]></description>
			<content:encoded><![CDATA[<div class="style2">
<p><strong>The Scala<span> </span>Programming Language:</strong></p>
<p>The Scala programming Language is an object oriented functional programming language designed to run on the JVM. It is ideal for programming on the Dalvik Platform as code written with the Scala language is more compact, readable and could possibly have performance benefits (which will be analysed at a later date) and it also supports Java and Android APIs.</p>
<p><span>You can easily build DSL with Scala and the trait (e.g. mixin) aspect of Scala is very attractive in order to build intricate activities which mixes different logic.</span></p>
<p><strong></strong></p>
<p><strong> </strong><strong>Requirements:</strong></div>
<ul type="disc">
<li class="style2">Eclipse IDE<span> </span>– Galileo Classic v3.6</li>
<li class="style2">Android ADT<span> </span>plugin v0.93</li>
<li class="style2">Android SDK v1.6r1</li>
<li class="style2">Scala<span> </span>eclipse plug-in latest</li>
<li class="style2">Scala-android library      latest</li>
</ul>
<div>
<p><strong><span><br />
Step 1: Setting up the environment</span></strong></p>
<p>The Scala project is rather heavy on resources therefore we would need to increase the heap size of the eclipse VM and of the dx tool which is present in the SDK.</p>
<p><strong></strong></p>
<p><strong> </strong><strong>Editing the eclipse memory size:</strong></p>
<p><span>In order to increase the maximum permissible memory of the IDE we need to edit the <em>exlipse.ini</em> file that resides in the root folder of the IDE (in my case C:/Program Files/eclipse or /opt/eclipse). Open the file with your favourite text editor and edit the files as shown in the figure below and add the following lines to the file:</span></p>
<p><code><span> 256m<br />
-vmargs<br />
-Xms256m<br />
-Xmx1024m<br />
-XX:PermSize=64m</span></code></p>
<p><code> </code></p>
<p><img src="http://docs.google.com/File?id=dc2cgzjn_175g325cwdg_b" alt="" /></p>
<p><strong></strong></p>
<p><strong> </strong></p>
<p><strong> </strong><strong></strong></p>
<p><strong> </strong><strong>Editing dx.bat/dx.sh:</strong></p>
<p><span>The file <em>dx.bat</em>/dx.sh is located in the &lt;ANDROID_HOME&gt;\platforms\android-1.6\tools. Open dx.bat/dx.sh with your favourite text editor and uncomment the javaOpts line while changing the value to 512M:</span><br />
<strong><span><img src="http://docs.google.com/File?id=dc2cgzjn_176cjr7rbg7_b" alt="" /></span></strong></p>
<p><strong> </strong><strong>Step 2: Install Scala</strong></p>
<p>I installed both the stand alone Scala installer as well as the Eclipse IDE plugin, which I recommend to get the system working stable.</p>
<p><strong></strong></p>
<p><strong> </strong><strong>The Scala Installer:</strong></p>
<p><span>On writing this post the latest version of Scala available for download was the 2.7.6 version, which can be downloaded from: <a href="http://www.scala-lang.org/downloads/distrib/files/scala-2.7.6.final-installer.jar">http://www.scala-lang.org/downloads/distrib/files/scala-2.7.6.final-installer.jar</a> . The installation procedure is quite trivial and further information can be found on the Scala website. The installer consists of a sequence of simple steps which on completion result in the installation of Scala on your system.</span></p>
<p><strong></strong></p>
<p><strong> </strong><strong>Eclipse Plugin:</strong></p>
<p><span>In order to install the eclipse plugin we have to goto the <em>Help-&gt;Install New Software-&gt;Add</em> and then enter the following:</span></p>
<p><span>Name: Scala<br />
Location: http://www.scala-lang.org/scala-eclipse-plugin</span></p>
<p><span>You should then see <em>&#8220;Scala Eclipse Plugin&#8221;</em> offered for installation. Click on the <em>&#8220;Install&#8221;</em> button and follow the instructions from there.</span></p>
<p><strong></strong></p>
<p><strong>Step 3: Download scala-android.jar</strong></p>
<p><strong> </strong></p>
<p><span>Open a new shell prompt window in administrator mode. Navigage to the &lt;SCALA_HOME&gt;/bin directory defined in the previous Scala installation step. Then enter the following commands</span></p>
<p><span>sbaz install scala-android</span></p>
<p><span>The scala-android library will be installed in &lt;SCALA_HOME&gt;/lib directory.</span></p>
<p><strong></strong></p>
<p><strong> </strong><strong>Step 4: Creating a Scala Project</strong></div>
<p class="style2"><span>In order to create our first Scala project we go about creating first an Android Project in the Eclipse IDE (<em>File-&gt;New-&gt;Android Project</em>).</span></p>
<p class="style2"><span><img class="aligncenter" src="http://docs.google.com/File?id=dc2cgzjn_177d9d5msgd_b" alt="" /></span></p>
<div class="style2">
<p><span>Then right mouse click on the project in the package workspace and navigate down to the <em>Scala</em> menu, then click on <em>Add Scala Nature, </em>once this is completed the project would look like:</span></div>
<p class="style2"><span><!--[if gte vml 1]&gt;--><br />
<img class="aligncenter" src="http://docs.google.com/File?id=dc2cgzjn_178f8n8fsc8_b" alt="" /></span></p>
<p align="center">
<div class="style2">
<p><span>Once this is complete, right mouse click on the project again and click on the <em>Properties-&gt;Builders</em> tab, and make sure the Scala Builder is in the position as shown in the figure (you will have to move it down two places)</span></div>
<p class="style2"><span><img class="aligncenter" src="http://docs.google.com/File?id=dc2cgzjn_179dnmn3hcc_b" alt="" /></span></p>
<div class="style2">
<p><span>Then open the <em>Java Build Path-&gt;Libraries</em> tab and remove the <em>Scala Library Version 2.6 final</em> , then add the scala-android.jar file by click on <em>Add External Jar. </em>You will then have the menu resembling:</span></div>
<p class="style2"><span><img class="aligncenter" src="http://docs.google.com/File?id=dc2cgzjn_1806f42mrcz_b" alt="" /></span></p>
<div class="style2">
<p><span>Note: The build process needs to compile the scala files into classes which then compiles them into dex files. If you receive errors upon compilation or classpath, try to clean and rebuild the project.</span></p>
<p><strong></strong></p>
<p><strong> </strong><strong>Step 5: Creating ScalaTest.scala</strong></p>
<p>Now goto the <em>ScalaTest-&gt;src-&gt;com.scala</em> package and delete the the file ScalaTest.java. Right mouse click on the package and then click on <em>New-&gt;Other-Scala</em> <em><span>Class</span></em><span> , call this class ScalaTest.</span></p>
<div class="style2"><span></p>
<p>Open the file <em>ScalaTest.scala</em> and enter the following code and save it:</p>
<p><code><span>package test.scala<br />
import android.app.Activity<br />
import android.os.Bundle<br />
import android.widget.TextView<br />
class ScalaTest extends Activity {<br />
override def onCreate(savedInstanceState: Bundle) {<br />
super.onCreate(savedInstanceState)<br />
val tv = new TextView(this)<br />
tv.setText("Hello Android, it's me, Scala!")<br />
setContentView(tv)<br />
}}</span></code></p>
<p><strong></strong></p>
<p><strong></strong></p>
<p><strong> </strong><strong>Step 6: Running the application</strong></p>
<p>In order to run the application goto <em><span>Run-&gt;Run Configuration-&gt;Android Application </span></em><span>and run set it up as shown in the figure below, and then click on Run.</span></p>
<p><span><!--[if gte vml 1]&gt;--></span></p>
<p><img src="http://docs.google.com/File?id=dc2cgzjn_182d26wm9c4_b" alt="" /></p>
<p><span>If everything was set up right you’d then see the emulator load up and run your application</span></p>
<p>:</p>
<p><span><img src="http://docs.google.com/File?id=dc2cgzjn_183dqtpg6ft_b" alt="" /></span></p>
<p><em>References:</em></p>
<p></span></div>
<ul type="disc">
<li class="style2">http://www.scala-lang.org/node/160</li>
<li class="style2">http://www.ibm.com/developerworks/opensource/library/os-eclipse-scala/index.html?ca=dgr-jw64Android-Scaladth-o&amp;S_TACT=105AGY46&amp;S_CMP=grjw64#</li>
<li class="style2"><span>http://www.scala-lang.org/node/1403</span></li>
</ul>
</div>



Share this post:


	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Fnovoda.com%2F2009%2F10%2F17%2Fscala-on-android%2F&amp;partner=sociable" title="Print"><img src="http://novoda.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="mailto:?subject=Scala%20on%20Android&amp;body=http%3A%2F%2Fnovoda.com%2F2009%2F10%2F17%2Fscala-on-android%2F" title="email"><img src="http://novoda.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fnovoda.com%2F2009%2F10%2F17%2Fscala-on-android%2F&amp;title=Scala%20on%20Android&amp;bodytext=%0D%0A%0D%0AThe%20Scala%20Programming%20Language%3A%0D%0A%0D%0AThe%20Scala%20programming%20Language%20is%20an%20object%20oriented%20functional%20programming%20language%20designed%20to%20run%20on%20the%20JVM.%20It%20is%20ideal%20for%20programming%20on%20the%20Dalvik%20Platform%20as%20code%20written%20with%20the%20Scala%20language%20is%20more" title="Digg"><img src="http://novoda.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fnovoda.com%2F2009%2F10%2F17%2Fscala-on-android%2F&amp;title=Scala%20on%20Android&amp;notes=%0D%0A%0D%0AThe%20Scala%20Programming%20Language%3A%0D%0A%0D%0AThe%20Scala%20programming%20Language%20is%20an%20object%20oriented%20functional%20programming%20language%20designed%20to%20run%20on%20the%20JVM.%20It%20is%20ideal%20for%20programming%20on%20the%20Dalvik%20Platform%20as%20code%20written%20with%20the%20Scala%20language%20is%20more" title="del.icio.us"><img src="http://novoda.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fnovoda.com%2F2009%2F10%2F17%2Fscala-on-android%2F&amp;title=Scala%20on%20Android" title="Reddit"><img src="http://novoda.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=Scala%20on%20Android%20-%20http%3A%2F%2Fnovoda.com%2F2009%2F10%2F17%2Fscala-on-android%2F" title="Twitter"><img src="http://novoda.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fnovoda.com%2F2009%2F10%2F17%2Fscala-on-android%2F&amp;title=Scala%20on%20Android&amp;annotation=%0D%0A%0D%0AThe%20Scala%20Programming%20Language%3A%0D%0A%0D%0AThe%20Scala%20programming%20Language%20is%20an%20object%20oriented%20functional%20programming%20language%20designed%20to%20run%20on%20the%20JVM.%20It%20is%20ideal%20for%20programming%20on%20the%20Dalvik%20Platform%20as%20code%20written%20with%20the%20Scala%20language%20is%20more" title="Google Bookmarks"><img src="http://novoda.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fnovoda.com%2F2009%2F10%2F17%2Fscala-on-android%2F&amp;t=Scala%20on%20Android" title="Facebook"><img src="http://novoda.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fnovoda.com%2F2009%2F10%2F17%2Fscala-on-android%2F&amp;t=Scala%20on%20Android" title="HackerNews"><img src="http://novoda.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fnovoda.com%2F2009%2F10%2F17%2Fscala-on-android%2F" title="Technorati"><img src="http://novoda.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Fnovoda.com%2F2009%2F10%2F17%2Fscala-on-android%2F&amp;partner=sociable" title="PDF"><img src="http://novoda.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://novoda.com/2009/10/17/scala-on-android/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

