

{"id":12665,"date":"2018-04-07T11:50:20","date_gmt":"2018-04-07T11:50:20","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=12665"},"modified":"2021-12-04T10:16:36","modified_gmt":"2021-12-04T04:46:36","slug":"scala-syntax","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/scala-syntax\/","title":{"rendered":"Scala Syntax: An Introductory Scala Tutorial"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:1904,&quot;href&quot;:&quot;https:\\\/\\\/www.scala-lang.org&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251206135355\\\/https:\\\/\\\/www.scala-lang.org\\\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-10 07:41:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-15 07:30:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-18 15:55:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-23 02:56:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-27 16:24:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-02 02:40:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-05 13:44:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-09 08:06:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-12 14:24:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-17 17:26:33&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-20 17:57:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-24 15:52:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-30 14:21:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-02 14:58:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-05 16:39:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 17:17:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-16 04:52:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-19 13:39:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-24 17:10:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-28 04:44:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-03 07:25:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-08 21:46:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 18:02:22&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 20:15:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-05 11:05:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-10 19:22:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-14 07:59:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-17 16:14:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-21 23:18:28&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-26 09:13:01&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-29 14:23:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-07 12:16:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-13 10:20:22&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-18 15:54:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-22 05:55:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-25 08:30:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-29 13:12:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-02 14:06:47&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-02 14:06:47&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>This article aims to explain to you the basic Scala Syntax. Though it is a bit different from Java Syntax or C++, we\u2019ll get used to it. Along with this, we will learn\u00a0Scala Keywords,\u00a0Scala Identifiers,\u00a0Scala Packages, and\u00a0Scala Comments.<\/p>\n<p>So, let\u2019s begin the Scala Syntax Tutorial.<\/p>\n<h3>Introduction to Scala Syntax<\/h3>\n<p>We can look at a Scala program as a collection of objects that invoke each other\u2019s methods to communicate. One major difference between Scala and Java is that here, in Scala, we don\u2019t need to end each statement with a semicolon(;).<\/p>\n<h3>Basic Scala Constructs<\/h3>\n<p>Let\u2019s start with the basic structures- expressions, blocks, classes, objects, functions, methods, traits, Main method, fields, and closures.<\/p>\n<h4>a. Scala Expression<\/h4>\n<p>An expression is a computable statement. For example, the following is an expression:<br \/>\n1+2<br \/>\nWe use println() to print the output of an expression:<\/p>\n<pre class=\"EnlighterJSRAW\">println(1) \/\/1\r\nprintln(1+2) \/\/3\r\nprintln(\u201cHi\u201d) \/\/Hi\r\nprintln(\u201cHi\u201d+\u201d User\u201d) \/\/Hi User<\/pre>\n<ol>\n<li><b> Values<\/b><\/li>\n<\/ol>\n<p>An expression returns a result; we can name it using the \u2018val\u2019 keyword.<\/p>\n<pre class=\"EnlighterJSRAW\">val name=\u2019Ayushi\u2019\r\nprintln(name)<\/pre>\n<p>Such an entity has only one value; we cannot reassign it. Also, when we reference it again, that does not recompute its value.<\/p>\n<pre class=\"EnlighterJSRAW\">val name=\u201dAyushi\u201d\r\nname=\u201dMegha\u201d \/\/This doesn\u2019t compile<\/pre>\n<p>Usually, Scala will infer the type of an expression- type inference, as we\u2019ve discussed in Features of Scala. But we can also explicitly state the type:<\/p>\n<pre class=\"EnlighterJSRAW\">val roll:Int = 30<\/pre>\n<ol>\n<li><b>Scala Variables<\/b><\/li>\n<\/ol>\n<p>A variable is a value that we can reassign. To declare a variable, we use the \u2018var\u2019 keyword. Scala Syntax for Variables are given below.<\/p>\n<pre class=\"EnlighterJSRAW\">var x=2\r\nx=3 \/\/This changes the value of x from 2 to 3\r\nprintln(x*x) \/\/This prints 9<\/pre>\n<p>We can declare the type of the variable:<\/p>\n<p>var roll:Int = 30<\/p>\n<h4>b. Scala Block<\/h4>\n<p>A block is a group of expressions delimited by curly braces({}). A block returns whatever its last expression returns. The Scala Syntax for the Same is Below.<\/p>\n<pre class=\"EnlighterJSRAW\">println\r\n(\r\n{\r\nval x=1+1\r\nx+1\r\n}\r\n) \/\/3<\/pre>\n<h4>c. Scala Class<\/h4>\n<p>Scala class is a blueprint that we can use to create an object. It may hold values, variables, types, classes, functions, methods, objects, and traits. We collectively call them members. To declare a class, we use the keyword \u2018class\u2019 and an identifier.<\/p>\n<p>object Main extends App<\/p>\n<pre class=\"EnlighterJSRAW\"> {\r\n    class Fruit{}\r\n    val orange=new Fruit\r\n}<\/pre>\n<p>Here, to create an instance of this, we use the keyword \u2018new\u2019. An instance of a class can have behaviors and states. For example, a car has states- brand, model, color, and behaviors- start, turn, stop. Here, orange is an instance of class Fruit.<\/p>\n<p>We\u2019ll see more on classes and objects in a later tutorial.<\/p>\n<h4>d. Scala Object<\/h4>\n<p>It is a single instance of its own definition(a singleton of its own class). To define an object, we use the keyword \u2018object\u2019.<\/p>\n<pre class=\"EnlighterJSRAW\">object Main extends App {\r\n    object MyObject{\r\n        def plusthree()={\r\n        val x=3*3\r\n        x+3}\r\n    }\r\n    println(MyObject.plusthree) \/\/This prints 12\r\n}<\/pre>\n<p>We\u2019ll cover this in a later tutorial.<\/p>\n<h4>e. Scala Function<\/h4>\n<p>A function is an expression that takes parameters. First, let\u2019s observe an anonymous function.<\/p>\n<pre class=\"EnlighterJSRAW\">(x:Int)=&gt;x*x<\/pre>\n<p>This function takes an Integer argument x, and returns its square.<\/p>\n<p>So, here we see that on the left of =&gt; is the list of parameters, and on the right is an expression it will return. Now, let\u2019s give it a name.<\/p>\n<pre class=\"EnlighterJSRAW\">val squared=(x:Int)=&gt;x*x<\/pre>\n<p>To get the output, we call the function:<\/p>\n<pre class=\"EnlighterJSRAW\">println(squared(3)) \/\/This prints 9<\/pre>\n<p>A function may also take multiple parameters or none.<\/p>\n<pre class=\"EnlighterJSRAW\">val add=(x:Int,y:Int,z:Int)=&gt;x+y+z\r\nprintln(add(2,3,7)) \/\/This prints 12\r\nval sayhi=()=&gt;(println(\u201cHi\u201d)) \/\/We could also have put the println in a block as {print(\u201cHi\u201d)}\r\nsayhi() \/\/This prints Hi<\/pre>\n<h4>f. Scala Method<\/h4>\n<p>A method is similar to a function, but we define it using the keyword \u2018def\u2019. What follows is an identifier, parameter lists, a return type, and a body. Let\u2019s take an example.<\/p>\n<pre class=\"EnlighterJSRAW\">def squared(x:Int):Int=x*x\r\nprintln(squared(3)) \/\/This prints 9<\/pre>\n<p>We denote the return type after a colon after the parameter list. Also, here, we use = instead of =&gt;.<br \/>\nA method can also take multiple parameter lists.<\/p>\n<pre class=\"EnlighterJSRAW\">def mymethod(x:Int,y:Int)(z:Int):Int={(x+y)*z}\r\nprintln(mymethod(2,3)(4)) \/\/This prints 20 from ((2+3)*4)\r\nNow, let\u2019s try something with no parameter lists.\r\ndef method1():String=\"Hello\"\r\nprintln(method1) \/\/This would work too:    println(method1())<\/pre>\n<p>A method can have multiline expressions:<\/p>\n<pre class=\"EnlighterJSRAW\">def method2(x:Int,y:Int)(z:Int):Int={\r\n    val a=z+y+x\r\n    (x+y)*a\r\n}\r\nprintln(method2(2,3)(4))<\/pre>\n<p>The last expression is the return value. Scala does have a \u2018return\u2019 keyword, but we\u2019ll see that later.<\/p>\n<h4>g. Scala Trait<\/h4>\n<p>A trait holds fields and methods, and we define it using the \u2018trait\u2019 keyword. We can also combine traits.<\/p>\n<pre class=\"EnlighterJSRAW\">trait greeter\r\n{\r\n    def greet(name:String):Unit\r\n}<\/pre>\n<p>We\u2019ll see this in detail later.<\/p>\n<h4>h. Scala Main Method<\/h4>\n<p>The main method is an entry point for the program. JVM needs a method with an argument which is an array of strings.<\/p>\n<pre class=\"EnlighterJSRAW\">object Main\r\n{\r\ndef main(args: Array[String]): Unit =\r\nprintln(\"Hello, Scala developer!\")\r\n}<\/pre>\n<h4>i. Fields<\/h4>\n<p>A unique set of instance variables belongs to each object. These are fields, and they define the object\u2019s state.<\/p>\n<h4>j. Closure<\/h4>\n<p>Any function whose return value depends on variables declared outside it.<br \/>\nAny Doubt yet in Scala Syntax? Please Comment.<\/p>\n<h3>An Example of Scala Program<\/h3>\n<p>Let\u2019s try the first \u201cHello, World!\u201d program in Scala. Like many other languages, we may execute a Scala program in one of two modes- interactive mode and script mode.<\/p>\n<h4>a. Interactive Mode<\/h4>\n<p>Open the Command Prompt on Windows using \u2018cmd\u2019 in Run. Then, type \u2018scala\u2019.<\/p>\n<p>Microsoft Windows [Version 10.0.16299.309]<\/p>\n<p>(c) 2017 Microsoft Corporation. All rights reserved.<\/p>\n<p>C:\\Users\\lifei&gt;scala<\/p>\n<p>Welcome to Scala 2.12.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_151).<\/p>\n<p>Type in expressions for evaluation. Or try :help.<\/p>\n<p>scala&gt;<\/p>\n<p>Now, you can execute any statement here.<\/p>\n<h4>b. Script Mode<\/h4>\n<p>To execute a program in script mode, type your program in the Notepad.<br \/>\nobject hello extends App<\/p>\n<pre class=\"EnlighterJSRAW\">{\r\n    println(\"Hello\")\r\n}<\/pre>\n<p>Now, get back to the command prompt, and get to the location where your file is.<\/p>\n<p>C:\\Users\\lifei&gt;cd Desktop<\/p>\n<p>C:\\Users\\lifei\\Desktop&gt;<\/p>\n<p>Then, to compile your program, type the following:<\/p>\n<p>C:\\Users\\lifei\\Desktop&gt;scalac hw.scala<\/p>\n<p>This creates some class files in the current directory. One of these is hello.class. This is the<\/p>\n<p>bytecode, and finally, to run this bytecode, use the command scala:<\/p>\n<p>C:\\Users\\lifei\\Desktop&gt;scala hello<\/p>\n<p>Hello<\/p>\n<h3>Scala Syntax Rules<\/h3>\n<p>There are some basic syntax rules we must take care of while coding with Scala. Let\u2019s discuss those.<\/p>\n<h4>a. Case-Sensitive<\/h4>\n<p>Scala is case-sensitive. This means that it treats the identifiers \u2018hello\u2019 and \u2018Hello\u2019 differently.<\/p>\n<h4>b. Class Names<\/h4>\n<p>You should name a class in Pascal case. This means that instead of naming it like \u2018hihelloworld\u2019, you will name it \u2018HiHelloWorld\u2019.<\/p>\n<h3>c. Method Names<\/h3>\n<p>A method\u2019s name should be in Camel case. So, the correct way would be something like \u2018sayHelloToTheWorld()\u2019.<\/p>\n<h3>Scala Keywords<\/h3>\n<p>Scala reserves some words so it can function. These are:<\/p>\n<p>Abstract\u00a0\u00a0\u00a0 case\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 catch\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 class<\/p>\n<p>def\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 do\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 else\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 extends<\/p>\n<p>false\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 final\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 finally\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 for<\/p>\n<p>forSome\u00a0\u00a0\u00a0 if\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 implicit\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 import<\/p>\n<p>lazy\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 match\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 new\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 Null<\/p>\n<p>object\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 override\u00a0\u00a0\u00a0 package\u00a0\u00a0\u00a0 private<\/p>\n<p>protected\u00a0\u00a0\u00a0 return\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 sealed\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 super<\/p>\n<p>this\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 throw\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 trait\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 Try<\/p>\n<p>true\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 type\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 val\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 Var<\/p>\n<p>while\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 with\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 yield\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 &#8211;<\/p>\n<p>:\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 =\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 =&gt;\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 &lt;-<\/p>\n<p>&lt;:\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 &lt;%\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 &gt;:\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 #<\/p>\n<p>@<\/p>\n<p>We can\u2019t use any of these words as identifiers or constants.<\/p>\n<h3>Scala Identifiers<\/h3>\n<p>What names can we use for entities like objects, classes, methods, and variables? We call them identifiers, and there are some rules to what names we can use for this purpose:<\/p>\n<ol>\n<li>It cannot be a reserved keyword.<\/li>\n<li>It is case-sensitive.<\/li>\n<\/ol>\n<p>Scala supports four kinds of identifiers:<\/p>\n<h4>a. Alphanumeric Identifiers in Scala<\/h4>\n<p>These begin with a letter(A-Z\/a-z) or an underscore. This can be followed by letters, digits, or underscores. You cannot use \u2018$\u2019, since it is a keyword.<\/p>\n<p>Legally valid examples: age, _8bit, __magic__<\/p>\n<p>Legally invalid examples: $99, 9lives, -23.47<\/p>\n<h4>b. Operator Identifiers in Scala<\/h4>\n<p>These may have one or more operator characters. So, what are operator characters? Printable ASCII characters like +, :, ?, ~, or #.<\/p>\n<p>Legally valid examples:<\/p>\n<p>+<\/p>\n<p>++<\/p>\n<p>:::<\/p>\n<p>&lt;?&gt;<\/p>\n<p>:&gt;<\/p>\n<p>The compiler internally mangles these to turn them into legal Java identifiers with embedded $ characters. For example, it would represent :-&gt; as $colon$minus$greater.<\/p>\n<h4>c. Mixed Identifiers in Scala<\/h4>\n<p>These contain an alphanumeric identifier followed by an underscore and an operator identifier.<\/p>\n<p>Legally valid examples:<\/p>\n<p>unary_+<\/p>\n<p>mine_=<\/p>\n<h4>d. Literal Identifiers in Scala<\/h4>\n<p>Such an identifier is an arbitrary string delimited by back ticks(`\u2026..`).<\/p>\n<p>Legally valid examples:<\/p>\n<p>`x`<\/p>\n<p>`yield`<\/p>\n<p>`hello`<\/p>\n<h3>Scala Comments<\/h3>\n<p>Just like Java, Scala supports single-line and multiline comments.<\/p>\n<p>\/\/ This is a single-line comment<\/p>\n<p>\/* This is the first line of a multiline comment<\/p>\n<p>This is the middle<\/p>\n<p>And this is the last*\/<\/p>\n<p>The compiler ignores comments. Read up on Comments in Scala for a detailed explanation on comments.<\/p>\n<h3>Blank Lines and Whitespace<\/h3>\n<p>A line that contains only whitespace, and possibly comments, is a blank line, and Scala just ignores it. Also, we can separate tokens by whitespace characters and\/or comments.<\/p>\n<h3>Newline Characters<\/h3>\n<p>Scala is line-oriented; we may terminate statements with semicolons(;) or with newlines. This means that semicolons are optional to end a statement. If only a single statement appears on a line, we don\u2019t have to use it necessarily. But if we must fit multiple statements into one line, we must separate them with semicolons:<\/p>\n<pre class=\"EnlighterJSRAW\">val x=7; println(x)<\/pre>\n<h3>Scala Packages<\/h3>\n<p>A module of code is a package with a name. For example, take a look at the Lift utility package<\/p>\n<p>net.liftweb.util. In the source file, the package declaration is the first non-comment line:<\/p>\n<p>package com.liftcode.stuff<\/p>\n<p>To refer a package in the current compilation scope, we can import a package:<\/p>\n<p>import scala.xml._<\/p>\n<p>We can also import a single class and object from a package:<\/p>\n<p>import scala.collection.mutable.HashMap<\/p>\n<p>And to import more than one class or object:<\/p>\n<p>import scala.collection.immutable.{TreeMap, TreeSet}<\/p>\n<p>This was all about the Scala Syntax.<\/p>\n<h3>Conclusion<\/h3>\n<p>We can guarantee you\u2019ll be able to write basic Scala code now. Tell us how it works for you. Also leave your doubts and comments regarding the Scala Syntax in the comment section.<\/p>\n<p><strong><a href=\"https:\/\/www.scala-lang.org\/\">Reference<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article aims to explain to you the basic Scala Syntax. Though it is a bit different from Java Syntax or C++, we\u2019ll get used to it. Along with this, we will learn\u00a0Scala Keywords,\u00a0Scala&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":31217,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[8030,9060,9377,12556,16509,14119,14883],"class_list":["post-12665","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scala","tag-keywords","tag-newline-characters","tag-packages","tag-scala-syntax","tag-synatx-in-scala","tag-syntax-rules","tag-trait"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Scala Syntax: An Introductory Scala Tutorial - DataFlair<\/title>\n<meta name=\"description\" content=\"Scala Syntax: Learn Introduction to Scala Syntax, Basic Scala Constructs, Scala Identifiers, Scala Comments, Blank Lines and Whitespace, Scala Packages\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/scala-syntax\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scala Syntax: An Introductory Scala Tutorial - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Scala Syntax: Learn Introduction to Scala Syntax, Basic Scala Constructs, Scala Identifiers, Scala Comments, Blank Lines and Whitespace, Scala Packages\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/scala-syntax\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-04-07T11:50:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-04T04:46:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/Scala-Syntax-01-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scala Syntax: An Introductory Scala Tutorial - DataFlair","description":"Scala Syntax: Learn Introduction to Scala Syntax, Basic Scala Constructs, Scala Identifiers, Scala Comments, Blank Lines and Whitespace, Scala Packages","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/scala-syntax\/","og_locale":"en_US","og_type":"article","og_title":"Scala Syntax: An Introductory Scala Tutorial - DataFlair","og_description":"Scala Syntax: Learn Introduction to Scala Syntax, Basic Scala Constructs, Scala Identifiers, Scala Comments, Blank Lines and Whitespace, Scala Packages","og_url":"https:\/\/data-flair.training\/blogs\/scala-syntax\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-04-07T11:50:20+00:00","article_modified_time":"2021-12-04T04:46:36+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/Scala-Syntax-01-1.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/scala-syntax\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/scala-syntax\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Scala Syntax: An Introductory Scala Tutorial","datePublished":"2018-04-07T11:50:20+00:00","dateModified":"2021-12-04T04:46:36+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/scala-syntax\/"},"wordCount":1499,"commentCount":2,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/scala-syntax\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/Scala-Syntax-01-1.jpg","keywords":["Keywords","Newline Characters","Packages","Scala Syntax","Synatx in Scala","Syntax Rules","Trait"],"articleSection":["Scala Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/scala-syntax\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/scala-syntax\/","url":"https:\/\/data-flair.training\/blogs\/scala-syntax\/","name":"Scala Syntax: An Introductory Scala Tutorial - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/scala-syntax\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/scala-syntax\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/Scala-Syntax-01-1.jpg","datePublished":"2018-04-07T11:50:20+00:00","dateModified":"2021-12-04T04:46:36+00:00","description":"Scala Syntax: Learn Introduction to Scala Syntax, Basic Scala Constructs, Scala Identifiers, Scala Comments, Blank Lines and Whitespace, Scala Packages","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/scala-syntax\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/scala-syntax\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/scala-syntax\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/Scala-Syntax-01-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/Scala-Syntax-01-1.jpg","width":1200,"height":628,"caption":"Scala Syntax: An Introductory Scala Tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/scala-syntax\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Scala Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/scala\/"},{"@type":"ListItem","position":3,"name":"Scala Syntax: An Introductory Scala Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/12665","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=12665"}],"version-history":[{"count":7,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/12665\/revisions"}],"predecessor-version":[{"id":104807,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/12665\/revisions\/104807"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/31217"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=12665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=12665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=12665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}