<?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>JavaBeat &#187; Smita</title>
	<atom:link href="http://www.javabeat.net/author/smita/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javabeat.net</link>
	<description>Java Technology News</description>
	<lastBuildDate>Tue, 21 May 2013 13:43:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Java HelloWorld vs Scala HelloWorld</title>
		<link>http://www.javabeat.net/2012/06/java-helloworld-vs-scala-helloworld/</link>
		<comments>http://www.javabeat.net/2012/06/java-helloworld-vs-scala-helloworld/#comments</comments>
		<pubDate>Sun, 17 Jun 2012 01:39:00 +0000</pubDate>
		<dc:creator>Smita</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[compare java scala]]></category>
		<category><![CDATA[main]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=4126</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>As a first step into learning Scala and as one who is familiar with Java, let us compare the customary Helloworld programs in Java and Scala. You might already know that to run a Java program, there must be a public class with a main method that takes one parameter, a String[], and has a void return [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><a id="dd_start"></a><p>As a first step into learning Scala and as one who is familiar with Java, let us compare the customary Helloworld programs in Java and Scala. You might already know that to run a Java program, there must be a public class with a main method that takes one parameter, a String[], and has a void return type. For example:</p>
<pre class="brush: java; title: ; notranslate">
package javaapplication;
public class Main {
   public static void main(String[] args) {
       System.out.println(&quot;Hello World&quot;);
   }
}
</pre>
<p>In Scala, an equivalent program looks something as follows -</p>
<pre class="brush: java; title: ; notranslate">
 package scalaapplication
 object Main {
def main(args: Array[String]): Unit = {
println(&quot;Hello World&quot;)
}
 }
</pre>
<p>The output of both of the above programs is to print out Hello World. We compare and contrast the first programs in Java and Scala as follows:</p>
<ul>
<li>Both the programs begin with a <span style="color: #993366;">package declaration</span>. While the package statement or rather every statement in the Java program ends with a semi-colon, semicolon is not mandatory in the Scala program. In a Scala program, the compiler does not care whether a statement ends with a semicolon or not. Newline marks end of a statement and beginning of another. Semicolon is required though when multiple statements are written in a single line.</li>
</ul>
<ul>
<li>While <span style="color: #993366;">import statement</span> is not shown in the above simple programs, they can both be part of a program in Java as well as Scala. Scala provides an easier and more concise way to import multiple statements as we will see in a later post.</li>
</ul>
<ul>
<li>The major contrast between the two programs is that while the Java program has a <span style="color: #993366;">class declaration</span>, the Scala program has an <span style="color: #993366;">object declaration</span>.</li>
</ul>
<p>Conceptually, a class is a blueprint for objects. An object is a concrete instance of a class.</p>
<p>In Java, we create an object using the new keyword followed by the class name. In Scala, we can directly define an object as shown above. We can also, of course, define classes and create objects using new keyword as in Java. The reason why we have defined an object instead of a class in the equivalent Scala program is described in a short while.</p>
<ul>
<li>Before we move on, in both programs, the Java class and the Scala object are <span style="color: #993366;">public</span>. In Java, the modifier named public needs to be used to mark a class/class member as public. In Scala, by default a class/class member is public. That is, when there is no access modifier, it means that the class/class member has  public access.</li>
</ul>
<ul>
<li>Main Methods are defined in very similar yet different ways in Java and Scala programs. An illustration for the main method definitions as they compare with each other in the two languages follows -</li>
</ul>
<p><a href="http://www.javabeat.net/wp-content/uploads/2012/06/Untitled.jpg"><img class="size-full wp-image-4249 aligncenter" src="http://www.javabeat.net/wp-content/uploads/2012/06/Untitled.jpg" alt="" width="562" height="212" /></a></p>
<p><em>def</em> is the keyword that marks the beginning of any function definition in Scala. There is no such equivalent keyword in Java. The main point of difference is the <span style="color: #800080;">absence of the static</span> keyword in the Scala main method definition.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>As Scala is a purely objected oriented language, there are no static things in Scala. Nevertheless, in order to achieve a similar behavior, Scala allows defining of something called as singleton objects. Just for now, a singleton object is one which looks like a class definition but with keyword object instead of class. In the above Scala program, Main is a standalone singleton object. To put it simplistically, for a Java programmer, a singleton object in Scala, is an equivalent holder of static methods if it were Java. So, now we know why we have defined an object in the above Scala program instead of a class.</p>
<p>The next important thing that can be noticed is the keyword &#8216;<span style="color: #800080;">Unit</span>&#8216; in the Scala main method definition. Unit is a return type for a function. Unit is used as a result type in a method, if all the method does is produce a side effect and not return any specific value as such. In our case, the side effect is printing out &#8220;Hello World&#8221;.</p>
<ul>
<li>Both the programs use curly braces to mark the beginning and end of method or class.</li>
</ul>
<ul>
<li>While Java implicitly imports members of the package java.lang into every Java source file, Scala implicitly imports members of the <span style="color: #800080;">packages java.lang and scala as well as members of the singleton object named Predef</span> into every Scala source file.</li>
</ul>
<p>The println method call in the Scala example above is actually made on Predef.</p>
<ul>
<li>In Java, a public class must be in a file of the same name. In contrast, in Scala, a public class need not necessarily be in a file of the same name. Though, it is thoroughly recommended to have it in a file of the same name just to make it easier for the programmers to locate classes.</li>
</ul>
<ul>
<li>Now, lets try and run the above programs at the command prompt.</li>
</ul>
<p>Java :</p>
<pre class="brush: java; title: ; notranslate">
$ javac Main.java
$ java Main
$ Hello World
</pre>
<p>Scala:</p>
<pre class="brush: java; title: ; notranslate">
$ scalac Main.scala
$ scala Main
$ Hello World
</pre>
<p>As we can see, running the programs in the two languages is pretty similar. The output of a java compiler as well as a scala compiler is a Java class file. This class file can then run on the same JVM to produce the output</p>
<pre class="brush: java; title: ; notranslate">
$ Hello World
</pre>
<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'><div class='dd_button_v'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http%3A%2F%2Fwww.javabeat.net%2Fauthor%2Fsmita%2Ffeed%2F" send="false" show_faces="false"  layout="box_count" width="50"  ></fb:like></div><div style='clear:left'></div><div class='dd_button_v'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='tall' href='http://www.javabeat.net/author/smita/feed/'></g:plusone></div><div style='clear:left'></div><div class='dd_button_v'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.javabeat.net/author/smita/feed/" data-count="vertical" data-text="" data-via="javabeat" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style='clear:left'></div><div class='dd_button_extra_v'><script type="text/javascript">jQuery(document).load(function(){ stLight.options({publisher:'bab47279-62c9-46af-addc-79fd1fe8fee0'}); });</script><div class="st_email_custom"><span id='dd_email_text'>email</span></div></div><div style='clear:left'></div><div class='dd_button_extra_v'><div id='dd_print_button'><span id='dd_print_text'><a href='javascript:window:print()'>print</a></span></div></div><div style='clear:left'></div></div></div></div><script type="text/javascript">var dd_offset_from_content = 44; var dd_top_offset_from_content = 0;</script><script type="text/javascript" src="http://www.javabeat.net/wp-content/plugins/digg-digg//js/diggdigg-floating-bar.js?ver=5.3.0"></script><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2012/06/java-helloworld-vs-scala-helloworld/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HelloWorld with Netbeans 7.2 beta and Scala 2.9</title>
		<link>http://www.javabeat.net/2012/06/helloworld-with-netbeans-7-2-beta-and-scala-2-9/</link>
		<comments>http://www.javabeat.net/2012/06/helloworld-with-netbeans-7-2-beta-and-scala-2-9/#comments</comments>
		<pubDate>Tue, 05 Jun 2012 00:00:16 +0000</pubDate>
		<dc:creator>Smita</dc:creator>
				<category><![CDATA[NetBeans]]></category>
		<category><![CDATA[netbeans 7.2]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[scala 2.9]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=4117</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Here is the step by step procedure to set up the scala(2.9) environment with Netbeans(7.2) on a Windows Vista system 1. Install Netbeans 7.2 Beta if not already installed from here. 2. Download the Scala installable from here. Install Scala on your system. 3. Set the environment variable SCALA_HOME pointing it to the Scala installation directory. (On Windows [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>Here is the step by step procedure to set up the <strong>scala(2.9)</strong> environment with Netbeans(7.2) on a Windows Vista system</p>
<p>1. Install <strong>Netbeans 7.2</strong> Beta if not already installed from <a href="http://netbeans.org/community/releases/72/">here</a>.</p>
<p>2. Download the <strong>Scala</strong> installable from <a href="http://www.scala-lang.org/downloads">here</a>. Install <strong>Scala</strong> on your system.</p>
<p>3. Set the environment variable SCALA_HOME pointing it to the <strong>Scala</strong> installation directory. (On Windows Vista, Go to Start Menu -&gt;Right click on Computer -&gt; Select Properties -&gt; From the left menu, Click on Advanced system Settings -&gt; Click on the Environment variables button on the bottom right corner -&gt; Create new System variable named SCALA_HOME pointing to the Scala installation directory).</p>
<p>4. Now we need to install <strong>Scala</strong> plugin for <strong>Netbeans</strong>. Download the plugin <a href="http://plugins.netbeans.org/plugin/38999/nbscala-2-9-x-0-9">here</a> and extract the content into an appropriate folder.</p>
<p>5. Open Netbeans IDE.</p>
<p>6. On the Menu Bar, choose Tools -&gt; Plugin</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2012/06/Tools_Plugins.jpg"><img class=" wp-image-4193 aligncenter" src="http://www.javabeat.net/wp-content/uploads/2012/06/Tools_Plugins.jpg" alt="" width="423" height="263" /></a></p>
<p>7. Choose Downloaded tab. Click on Add Plugins button. Browse to the folder containing scala plugins. Choose all the *.nbm files and hit the Install button on the bottom left corner.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2012/06/AddPlugins_Select1.jpg"><img class="aligncenter  wp-image-4187" src="http://www.javabeat.net/wp-content/uploads/2012/06/AddPlugins_Select1-e1339180670328-1024x506.jpg" alt="Add plugin and select all nbm files" width="423" height="263" /></a></p>
<p>5. You need to hit the Next / Continue button and accept the agreements on all the windows that pop up after that.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2012/06/Install_SelectedPlugins.jpg"><img class="aligncenter  wp-image-4189" src="http://www.javabeat.net/wp-content/uploads/2012/06/Install_SelectedPlugins-e1339180828864-1024x508.jpg" alt="Install_SelectedPlugins" width="423" height="263" /></a></p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2012/06/ContinueUnsigned-e1339179865267.jpg"><img class="aligncenter  wp-image-4201" src="http://www.javabeat.net/wp-content/uploads/2012/06/ContinueUnsigned-e1339179865267-1024x503.jpg" alt="" width="423" height="263" /></a></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2012/06/Install_SelectedPluginsCont-e1339180958393.jpg"><img class="aligncenter  wp-image-4190" src="http://www.javabeat.net/wp-content/uploads/2012/06/Install_SelectedPluginsCont-e1339180958393-1024x508.jpg" alt="" width="423" height="263" /></a></p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2012/06/SuccessInstalled.jpg"><img class="aligncenter  wp-image-4192" src="http://www.javabeat.net/wp-content/uploads/2012/06/SuccessInstalled-e1339181197586-1024x506.jpg" alt="" width="423" height="263" /></a></p>
<p>Plugin auto installs everything.</p>
<p>6. Create New Project. You should now be able to see a new category named Scala. Choose Scala Application. Choose your project name / location and click on Finish. An object named Main which prints out &#8220;Hello World&#8221; gets created by default. You can run this file as is by hitting Shift+F6 just to check if the environment is correctly set. HelloWorld should get printed as output.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2012/06/NewScalaProject-e1339181343297.jpg"><img class="aligncenter  wp-image-4191" src="http://www.javabeat.net/wp-content/uploads/2012/06/NewScalaProject-e1339181343297-1024x506.jpg" alt="" width="423" height="263" /></a></p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2012/06/HelloWorld.jpg"><img class="aligncenter  wp-image-4188" src="http://www.javabeat.net/wp-content/uploads/2012/06/HelloWorld-e1339181397675-1024x508.jpg" alt="" width="423" height="263" /></a></p>
<p>Writing a first <strong>Scala</strong> program on <strong>Netbeans 7.2</strong> seemed a breeze. No headache of conf file changes. But <strong>Netbeans 7.2</strong> does seem a lot lot slower than its earlier version 7.0(I have not tried 7.1). Probably because it still is a Beta version.</p>
<p>Following are <span style="text-decoration: underline;"><strong>some gotchas</strong></span> if you are trying to get Scala to work on <strong>Netbeans 7.0</strong> or an earlier version of Scala-</p>
<p>1. After installing the plugin, you should be able to create a new Scala project. In case you are not, check if any of the scala plugins are not activated. Select them and activate them.</p>
<p>2. Error message &#8211; Could not load definitions from resource scala/tools/ant/antlib.xml. It could not be found.</p>
<p>Solution &#8211; Check if <strong>Scala</strong> has been correctly installed. Append &#8220;-J-Dscala.home=scalahomepath&#8221; property to the end of &#8220;netbeans_default_options&#8221; in NetBeansInstallationPath/etc/netbeans.conf where scalahomepath is the actual path to the Scala installation directory.</p>
<p>Please do let me know how your Scala environment setup with Netbeans went. I will be happy to respond to your questions if any. Please feel free to add your comments below.</p>
<p><em>Adios</em> until the next post !</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2012/06/helloworld-with-netbeans-7-2-beta-and-scala-2-9/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
