{"id":1093,"date":"2018-01-03T04:27:58","date_gmt":"2018-01-03T04:27:58","guid":{"rendered":"http:\/\/blog.cloudxlab.com\/?p=1093"},"modified":"2018-01-03T08:23:35","modified_gmt":"2018-01-03T08:23:35","slug":"scala-tutorial-part-1","status":"publish","type":"post","link":"https:\/\/cloudxlab.com\/blog\/scala-tutorial-part-1\/","title":{"rendered":"A Simple Tutorial on Scala &#8211; Part &#8211; 1"},"content":{"rendered":"<p>Welcome to the Scala tutorial. We will cover the Scala in two-part blog series. In this part, we will learn the following topics<\/p>\n<ul class=\"ili-indent\">\n<li>Scala Features<\/li>\n<li>Variables and Methods<\/li>\n<li>Condition and Loops<\/li>\n<li>Variables and Type Inference<\/li>\n<li>Classes and Objects<\/li>\n<\/ul>\n<p>For better understanding, do hands-on with this tutorial. We&#8217;ve made this post in such a way that the reader will find easy to follow the tutorial with hands-on.<\/p>\n<h2>Scala Features<\/h2>\n<p>Scala is a modern multi-paradigm programming language designed to express common programming patterns in a concise, elegant, and type-safe way.<\/p>\n<p>It is a statically typed language. Which means it does type checking at compile-time as opposed to run-time. Let me give you an example to better understand this concept.<\/p>\n<p>When we deploy jobs which will run for hours in production, we do not want to discover midway that the code has unexpected runtime errors. With Scala, you can be sure that your code will not give you unexpected errors while running in production.<\/p>\n<p>Since Scala is statically typed we get performance and speed over dynamic languages.<\/p>\n<h3>How is Scala different than Java?<\/h3>\n<p>Unlike Java, in Scala, we do not have to write quite as much code to perform simple tasks and its syntax is very similar to other data-centric languages. You could say that Scala is the modified version of Java with less boilerplate code.<\/p>\n<p><!--more--><\/p>\n<p>Let&#8217;s look back at the origin of the Scala.<\/p>\n<p>In 1990, Martin Odersky, creator of Scala, made Java better by introducing generics in javac &#8211; the Java Compiler.<\/p>\n<p>In 2001, he decided to create even better Java and in 2003, there was the first experimental release of Scala. To prove the correctness of Scala, scala2.0 was compiled in Scala itself in 2005.<\/p>\n<p>In 2011, corporate stewardship was brought to ensure that the language was enterprise-ready at all times.<\/p>\n<p>Scala compiler compiles Scala code into Java bytecode. The resulting bytecode is executed by a JVM &#8211; the Java virtual machine.<\/p>\n<p>Since Scala and Java have a common runtime, Java libraries may be used directly in Scala code and vice versa.<\/p>\n<p>The best way to learn a programming language is by writing code. So, Please do not just read this tutorial. Instead, work with it.<\/p>\n<p>Let&#8217;s get started. <a href=\"https:\/\/cloudxlab.com\/lab\/?utm_source=blog&amp;utm_medium=scala-part-1\">Login to Cloudxlab<\/a>.<\/p>\n<p>Scala provides a nice interactive console which would give us result instantaneously. It is also called REPL &#8211; read-evaluate-print-loop. To start Scala console or REPL, type Scala after logging into Cloudxlab web console.<\/p>\n<h2>Variables and Methods<\/h2>\n<p><span style=\"font-weight: 400;\">In the previous step, we started Scala successfully. Let&#8217;s continue from there. You can use this Scala console a very simple calculator as well.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So, if you type 2+4 it would compute the sum. <\/span><\/p>\n<pre class=\"lang:scala decode:true\">scala&gt; 2 + 4\r\nres0: Int = 6<\/pre>\n<p><span style=\"font-weight: 400;\">You can see that it has given the answer as 6 and also defined a variable called res0 which contains the result. The data type of res0 is Int which means integer.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To see the value of a variable you can simply type the name of the variable and it would print the value contained in the variable.<\/span><\/p>\n<pre class=\"lang:scala decode:true \">scala&gt; res0\r\nres1: Int = 6<\/pre>\n<p><span style=\"font-weight: 400;\">You can see that it has displayed the value of res0.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We can also define our own variables by using var. So, if I say var x = 10, it would create x having value as 10.<\/span><\/p>\n<pre class=\"lang:scala decode:true\">scala&gt; var x = 10\r\nx: Int = 10<\/pre>\n<p><span style=\"font-weight: 400;\">Also, we can use x in other calculation. For example, var y = x * 4 So, this first multiplies x by 4 and then it assigns the result to y. You can see that the value of y is 40.<\/span><\/p>\n<pre class=\"lang:scala decode:true\">scala&gt; var y = x * 4\r\ny: Int = 40<\/pre>\n<p><span style=\"font-weight: 400;\">We have used addition and multiplication operators so far. Similarly, we also have name operators called methods. These methods take inputs via arguments and optionally returns the result.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For example, print displays the value on the screen. Let&#8217;s see.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">if you type: print(&#8220;Hello, World&#8221;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">It prints the &#8220;Hello, World&#8221; on the screen.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here print method takes a string or text as input by the way of the first argument. Also, notice that we define a string by enclosing something in double quotes.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Also, note that we define a single character by enclosing it in single quotes. <\/span><\/p>\n<pre class=\"lang:scala decode:true\">scala&gt; var a = 'h'\r\na: Char = h<\/pre>\n<p><span style=\"font-weight: 400;\">You can see that we defined a variable &#8220;a&#8221; having character &#8220;h&#8221; as the value.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This print is an inbuilt method. There are some other libraries of methods which are provided by Scala. For example, math library.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let import all functions from maths library by typing: import math._ <\/span><\/p>\n<pre class=\"lang:scala decode:true \">scala&gt; import math._\r\nimport math._<\/pre>\n<p><span style=\"font-weight: 400;\">Now we can use functions such as sqrt() for computing square root of a value.<\/span><\/p>\n<pre class=\"lang:scala decode:true\">scala&gt; sqrt(25)\r\nres3: Double = 5.0<\/pre>\n<p><span style=\"font-weight: 400;\">You can see the square root of 25 is 5.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now, let&#8217;s practice the variable and methods by computing simple interest.<\/span><\/p>\n<p><a href=\"https:\/\/cloudxlab.com\/lab\/?utm_source=blog&amp;utm_medium=scala-part-1\"><img class=\"aligncenter size-full wp-image-1109\" src=\"http:\/\/blog.cloudxlab.com\/wp-content\/uploads\/2018\/01\/Practice-lab-1.png\" alt=\"Practice scala on cloudxlab\" width=\"810\" height=\"450\" srcset=\"https:\/\/cloudxlab.com\/blog\/wp-content\/uploads\/2018\/01\/Practice-lab-1.png 810w, https:\/\/cloudxlab.com\/blog\/wp-content\/uploads\/2018\/01\/Practice-lab-1-300x167.png 300w, https:\/\/cloudxlab.com\/blog\/wp-content\/uploads\/2018\/01\/Practice-lab-1-768x427.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s define our principal amount, rate, and duration.<\/span><\/p>\n<pre class=\"lang:default decode:true \">scala&gt; var principal = 10\r\nprincipal: Int = 10\r\n\r\nscala&gt; var rate = 10\r\nrate: Int = 10\r\n\r\nscala&gt; var duration = 4\r\nduration: Int = 4<\/pre>\n<p>We will be using the simple interest formula, i.e. principal * rate * duration \/ 100<\/p>\n<pre class=\"lang:scala decode:true \">scala&gt; var interest = principal * rate * duration \/ 100\r\ninterest: Int = 4<\/pre>\n<p><span style=\"font-weight: 400;\">So, you can see the interest is 4.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now, we change the principal amount to 100. And re-execute the formula.<\/span><\/p>\n<pre class=\"lang:default decode:true \">scala&gt; principal = 100\r\nprincipal: Int = 100\r\n\r\nscala&gt; var interest = principal * rate * duration \/ 100\r\ninterest: Int = 40<\/pre>\n<p>What if you need to calculate\u00a0interest for multiple values of principal or rate or duration? It is indeed tiring to write the formula every time we change the value.<\/p>\n<p><span style=\"font-weight: 400;\">We can also define our own methods so that we don&#8217;t need to write the same code again and again.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s define a method called simpleInterest in the following way:\u00a0<\/span><\/p>\n<pre class=\"lang:scala decode:true\">scala&gt; def simpleInterest(principal: Int, rate: Double, duration: Int):\r\n           Double = { var interest = principal * rate * duration \/ 100;\r\n                      return interest; }\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">Our first argument is principal which is an integer, the second argument is rate which is double, and the third argument is the duration (years) which is an integer.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">And the return type is of type double.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We start the body of the method after the open curly bracket. Inside this function, we are going to return the simpleinterest which is principal * rate * duration divided by 100.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Then we close the curly brackets to mark the end of the method definition.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s try to call the method that we have just defined by providing principal as 700, rate of interest is 7, and duration as 4 years.<\/span><\/p>\n<pre class=\"lang:scala decode:true \">scala&gt; simpleInterest(700, 7, 4)\r\nres0: Double = 196.0<\/pre>\n<p><span style=\"font-weight: 400;\">You can see that the interest is 196.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So, we have created our own interest computing machine which we can use as many times as we want.<\/span><\/p>\n<h2>Condition and Loops<\/h2>\n<p><span style=\"font-weight: 400;\">In programming, the first step of logic is a conditional statement such as if-else.<\/span><\/p>\n<p>Let&#8217;s do a hands-on on variables. Login to CloudxLab and type scala to launch the Scala shell.<\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s redefine our function and put a conditional check in our method of simple interest. If someone enters negative principal that is less than 0, we print &#8220;Wrong principal&#8221; and return 0 as result.<\/span><\/p>\n<pre class=\"lang:scala decode:true \">def simpleInterest(principal: Int, rate: Double, duration: Int): Double = {\r\n    if (principal &lt; 0) {\r\n        println(\"Wrong principal\");\r\n        return 0;\r\n     }\r\n     var interest = principal * rate * duration \/ 100;\r\n     return interest;\r\n  }<\/pre>\n<p><span style=\"font-weight: 400;\">Everything between curly brackets of if block will be executed if the condition &#8220;principal less than 0&#8221; is true. If the condition is false, the statement outside the if block will be executed and our interest is calculated and returned as usual.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s check by calling our method with principal amount as negative 100.<\/span><\/p>\n<pre class=\"lang:scala decode:true \">scala&gt; simpleInterest(-100, 7, 4)\r\nwrong principal\r\nres1: Double = 0.0<\/pre>\n<p>You can see that it has printed &#8220;wrong principal&#8221; and the interest is 0.<\/p>\n<p><span style=\"font-weight: 400;\">Sometimes you may need to operate on the list of things. For that, Scala provides a List data type.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let define our list having numbers 4, 9, and 8 and store in the variable a.\u00a0<\/span><\/p>\n<pre class=\"lang:default decode:true\">scala&gt; var a = List(4, 9, 8)\r\na: List[Int] = List(4,9,8)<\/pre>\n<p><span style=\"font-weight: 400;\">We can operate on a list in a variety of ways. One of the most common ways is to go through every element using a for loop.<\/span><\/p>\n<p>Now we write a for loop that will print the numbers in the list.<\/p>\n<pre class=\"lang:scala decode:true \">scala&gt; for (x &lt;- a) {\r\n           println(x)\r\n       }<\/pre>\n<p><span style=\"font-weight: 400;\">It is always best to refer (x &lt;- a) as &#8216;x&#8217; in &#8216;a&#8217;, where &#8216;a&#8217; is a list and &#8216;x&#8217; is the current element. We are printing x i.e. each value of a.\u00a0<\/span><\/p>\n<h3>While Loop<\/h3>\n<p><span style=\"font-weight: 400;\">There is another way of executing a logic multiple times &#8211; A while loop.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A while loop has two parts &#8211; one condition and another body. The body keeps getting executed as long as the condition is true. If the condition remains true forever, it would keep executing the body forever.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s print all numbers less than 15.\u00a0 So, we define a variable x with value 15.<\/span><\/p>\n<pre class=\"lang:default decode:true\">scala&gt; var x = 15;\r\nx: Int = 15\r\n\r\nscala&gt; while(x &gt; 0) {\r\n           println(x);\r\n           x = x - 1\r\n       }<\/pre>\n<p><span style=\"font-weight: 400;\">Inside while loop we have two statements &#8211; one for printing value of x and another decreases the value of x by 1.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This loop will stop as soon as the value of x is zero.<\/span><\/p>\n<pre class=\"lang:scala decode:true\">scala&gt; var x = 9;\r\nx: Int = 9\r\n\r\nscala&gt; while(x &gt; 0) {\r\n           println(x);\r\n           x = x - 1\r\n       }\r\n9\r\n8\r\n7\r\n6\r\n5\r\n4\r\n3\r\n2\r\n1<\/pre>\n<p><span style=\"font-weight: 400;\">As you can see we have printed all the number less than 9 but greater than 0.<\/span><\/p>\n<h2>Variable and Type Inference<\/h2>\n<p><span style=\"font-weight: 400;\">Variables are nothing but reserved memory locations to store values. This means that when we create a variable, the compiler allocates a memory based on its data type.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">There are two types of variables in Scala &#8211; Mutable and Immutable. <\/span><\/p>\n<p><img class=\"aligncenter size-large wp-image-1106\" src=\"http:\/\/blog.cloudxlab.com\/wp-content\/uploads\/2018\/01\/Scala-Introduction-1024x767.png\" alt=\"scala variable types\" width=\"840\" height=\"629\" srcset=\"https:\/\/cloudxlab.com\/blog\/wp-content\/uploads\/2018\/01\/Scala-Introduction-1024x767.png 1024w, https:\/\/cloudxlab.com\/blog\/wp-content\/uploads\/2018\/01\/Scala-Introduction-300x225.png 300w, https:\/\/cloudxlab.com\/blog\/wp-content\/uploads\/2018\/01\/Scala-Introduction-768x576.png 768w, https:\/\/cloudxlab.com\/blog\/wp-content\/uploads\/2018\/01\/Scala-Introduction-1200x899.png 1200w, https:\/\/cloudxlab.com\/blog\/wp-content\/uploads\/2018\/01\/Scala-Introduction.png 1365w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Mutable variables are defined using var keyword and their value can be changed. Immutable variables are defined using val keyword and their value can not be changed once assigned. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s define an immutable variable x of integer type with value 8. Type val x: Int = 8. Now try changing the value of x to 9. <\/span><\/p>\n<pre class=\"lang:scala decode:true\">scala&gt; val x: Int = 8\r\nx: Int = 8\r\n\r\nscala&gt; x = 9\r\n&lt;console&gt; error: reassignment to val\r\n         x = 9\r\n           ^<\/pre>\n<p><span style=\"font-weight: 400;\">We have got an error. As discussed we can not change the value of an immutable variable.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s define a mutable variable &#8220;y&#8221; of integer type with value 7. Type var y: Int = 7. Now try changing the value of &#8220;y&#8221; to 9. <\/span><\/p>\n<pre class=\"lang:scala decode:true\">scala&gt; var y: Int = 7\r\ny: Int = 7\r\n\r\nscala&gt; y = 9\r\ny: Int = 9<\/pre>\n<p><span style=\"font-weight: 400;\">We can see that its value is now 9.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s understand why do we need immutable variables?<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In large systems, we do not want to be in a situation where a variable&#8217;s value changes unexpectedly as this may lead to unpredictable results.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the case of Threads, APIs, functions, and classes, we may not want some of the variables to change.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In these scenarios, we define the variables as immutable variables.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In Scala, we can define the variables without specifying their datatype. The Scala compiler can understand the type of the variable based on the value assigned to it. This is called variable type inference.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let us define a variable x and assign it a value &#8220;hi&#8221;. Type var x = &#8220;hi&#8221; in the Scala shell. You will see that Scala determines the type of variable x as &#8220;String&#8221;.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">But, we should always try to explicitly define a type of variable to ensure that the code is compiled faster and to avoid any unpredictable results.<\/span><\/p>\n<h2>Classes and Objects<\/h2>\n<p><span style=\"font-weight: 400;\">What is a class? A class is a way of creating your own data type. A class is a way of representing a type of value inside the system. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">For example, we can create a data type that represents a customers using a class. A customer would have states like first name, last name, age, address and contact number. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">A customer class might represent behaviors for how these states can be transformed. For example how to change a customer&#8217;s address or name. These behaviors are called methods. A class is not concrete until it has been instantiated using a \u201cnew\u201d keyword.<\/span><\/p>\n<pre class=\"lang:scala decode:true\">scala&gt; class Person(val fname: String, val lname: String, val anage: Int) {\r\n            val firstname: String = fname;\r\n            val lastname: String = lname;\r\n            val age = anage;\r\n        }<\/pre>\n<p><span style=\"font-weight: 400;\">As you can see on the screen, we&#8217;ve defined a person class and it has three parameters &#8211; first name of string type, last name of string type and age of integer type.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We&#8217;ve assigned these parameters to immutable class variables. Let&#8217;s create an instance of the class. <\/span><\/p>\n<pre class=\"lang:scala decode:true \">scala&gt; val obj = new Person(\"Robin\", \"Gill\", 42)<\/pre>\n<p><span style=\"font-weight: 400;\">We&#8217;ve created an instance of Person class with firstname as Robin, lastname as Gill and age as 42.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We can access class variables from the instance by the following way. <\/span><\/p>\n<pre class=\"lang:scala decode:true\">scala&gt; obj.firstname\r\nres0: String = Robin\r\n\r\nscala&gt; obj.age\r\nres1: Int = 42<\/pre>\n<p><span style=\"font-weight: 400;\">Let&#8217;s define a class method to get the full name of the person.<\/span><\/p>\n<pre class=\"lang:scala decode:true \">scala&gt; class Person(val fname: String, val lname: String, val anage: Int) {\r\n            val firstname: String = fname;\r\n            val lastname: String = lname;\r\n            val age = anage;\r\n            def getFullName():String = {\r\n                return firstname + \" \" + lastname;\r\n              }\r\n        }<\/pre>\n<p><span style=\"font-weight: 400;\">As you can see on the screen, we have defined a method getFullName. This method concatenates firstname and lastname and returns a full name which is of string type.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Objects in Scala are Singleton. A singleton is a class which can only have one instance at any point in time.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Methods and values that aren\u2019t associated with individual instances of a class belong in singleton objects.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A singleton class can be directly accessed via its name. We can create a singleton class using the keyword object.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s create an object Hello which has a method message which returns a string &#8220;hello&#8221;. <\/span><\/p>\n<pre class=\"lang:scala decode:true \">scala&gt; object Hello {\r\n            def message(): String = { \r\n                return \"Hello!\";\r\n            }\r\n       }\r\n\r\nscala&gt; Hello.message\r\nres0: String = Hello!<\/pre>\n<p><span style=\"font-weight: 400;\">We can access the method message without instantiating the instance of &#8220;Hello&#8221;. This is because Hello is a singleton object and it is already instantiated for us when we try to call the message method.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Objects are useful in defining constants and utility methods as they are not related to any specific instance of the class. Utility methods take parameters and return values based on a calculation and transformation<\/span><\/p>\n<h2>Next Steps on Scala Tutorial?<\/h2>\n<p>If you like the post, please share it with your friends and family who you think might find it useful. Also, we will cover the remaining topics in part 2 of the Scala series. Meanwhile, you can go through our <a href=\"https:\/\/cloudxlab.com\/blog\/linux-tutorial-part-1\/\">Linux series here.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to the Scala tutorial. We will cover the Scala in two-part blog series. In this part, we will learn the following topics Scala Features Variables and Methods Condition and Loops Variables and Type Inference Classes and Objects For better understanding, do hands-on with this tutorial. We&#8217;ve made this post in such a way that &hellip; <a href=\"https:\/\/cloudxlab.com\/blog\/scala-tutorial-part-1\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;A Simple Tutorial on Scala &#8211; Part &#8211; 1&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1104,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>A Simple Scala Tutorial - Part - 1 | CloudxLab Blog<\/title>\n<meta name=\"description\" content=\"Learn Scala through this simple Scala tutorial. This tutorial is designed in such a way that the reader will find it easy to do hands-on.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudxlab.com\/blog\/scala-tutorial-part-1\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A Simple Scala Tutorial - Part - 1 | CloudxLab Blog\" \/>\n<meta property=\"og:description\" content=\"Learn Scala through this simple Scala tutorial. This tutorial is designed in such a way that the reader will find it easy to do hands-on.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudxlab.com\/blog\/scala-tutorial-part-1\/\" \/>\n<meta property=\"og:site_name\" content=\"CloudxLab Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cloudxlab\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-03T04:27:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-03T08:23:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudxlab.com\/blog\/wp-content\/uploads\/2018\/01\/learn-scala-3.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CloudxLab\" \/>\n<meta name=\"twitter:site\" content=\"@CloudxLab\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"12 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudxlab.com\/blog\/#website\",\"url\":\"https:\/\/cloudxlab.com\/blog\/\",\"name\":\"CloudxLab Blog\",\"description\":\"Learn AI, Machine Learning, Deep Learning, Devops &amp; Big Data\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/cloudxlab.com\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/cloudxlab.com\/blog\/scala-tutorial-part-1\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/cloudxlab.com\/blog\/wp-content\/uploads\/2018\/01\/learn-scala-3.png\",\"contentUrl\":\"https:\/\/cloudxlab.com\/blog\/wp-content\/uploads\/2018\/01\/learn-scala-3.png\",\"width\":1024,\"height\":512},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudxlab.com\/blog\/scala-tutorial-part-1\/#webpage\",\"url\":\"https:\/\/cloudxlab.com\/blog\/scala-tutorial-part-1\/\",\"name\":\"A Simple Scala Tutorial - Part - 1 | CloudxLab Blog\",\"isPartOf\":{\"@id\":\"https:\/\/cloudxlab.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cloudxlab.com\/blog\/scala-tutorial-part-1\/#primaryimage\"},\"datePublished\":\"2018-01-03T04:27:58+00:00\",\"dateModified\":\"2018-01-03T08:23:35+00:00\",\"author\":{\"@id\":\"https:\/\/cloudxlab.com\/blog\/#\/schema\/person\/0efa3c54df68406de820ea466f002d3c\"},\"description\":\"Learn Scala through this simple Scala tutorial. This tutorial is designed in such a way that the reader will find it easy to do hands-on.\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudxlab.com\/blog\/scala-tutorial-part-1\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudxlab.com\/blog\/scala-tutorial-part-1\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudxlab.com\/blog\/scala-tutorial-part-1\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudxlab.com\/blog\/\",\"url\":\"https:\/\/cloudxlab.com\/blog\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@id\":\"https:\/\/cloudxlab.com\/blog\/scala-tutorial-part-1\/#webpage\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudxlab.com\/blog\/#\/schema\/person\/0efa3c54df68406de820ea466f002d3c\",\"name\":\"Abhinav Singh\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/cloudxlab.com\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/fc74fe31169bf872f6ab11bbab621d53?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/fc74fe31169bf872f6ab11bbab621d53?s=96&d=mm&r=g\",\"caption\":\"Abhinav Singh\"},\"sameAs\":[\"https:\/\/cloudxlab.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/posts\/1093"}],"collection":[{"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/comments?post=1093"}],"version-history":[{"count":14,"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/posts\/1093\/revisions"}],"predecessor-version":[{"id":1116,"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/posts\/1093\/revisions\/1116"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/media\/1104"}],"wp:attachment":[{"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/media?parent=1093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/categories?post=1093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudxlab.com\/blog\/wp-json\/wp\/v2\/tags?post=1093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}