{"id":23804,"date":"2023-05-17T10:02:45","date_gmt":"2023-05-17T10:02:45","guid":{"rendered":"https:\/\/www.booksofall.com\/?post_type=product&#038;p=23804"},"modified":"2023-05-17T10:05:52","modified_gmt":"2023-05-17T10:05:52","slug":"scala-book","status":"publish","type":"product","link":"https:\/\/www.booksofall.com\/fr\/scala-book\/","title":{"rendered":"Scala Book"},"content":{"rendered":"<h2>Chapter &#8211; 1 Introduction<\/h2>\n<p>In these pages,\u00a0<i>Scala Book\u00a0<\/i>provides a quick introduction and overview of the <a href=\"https:\/\/www.scala-lang.org\/\">Scala programming language<\/a>. The book is written in an informal style, and consists of more than 50 small lessons. Each lesson is long enough to give you an idea of how the language features in that lesson work, but short enough that you can read it in fifteen minutes or less.<\/p>\n<p>One note before beginning:<\/p>\n<ul>\n<li>In regards to programming style, most Scala programmers indent their code with two spaces, but we use four spaces because we think it makes the code easier to read, especially in a book format.<\/li>\n<\/ul>\n<p>To begin reading, click the \u201cnext\u201d link, or select the\u00a0<i>Prelude: A Taste of Scala\u00a0<\/i>lesson in the table of contents.<\/p>\n<h2>Chapter &#8211; 2\u00a0 Prelude: A Taste of Scala<\/h2>\n<p>Our hope in this book is to demonstrate that Scala is a beautiful, modern, expressive <a href=\"https:\/\/www.simplilearn.com\/best-programming-languages-start-learning-today-article\">programming language<\/a>. To help demonstrate that, in this first chapter we\u2019ll jump right in and provide a whirlwind tour of Scala\u2019s main features. After this tour, the book begins with a more traditional \u201cGetting Started\u201d chapter.<\/p>\n<p>In this book we assume that you\u2019ve used a language like <a href=\"https:\/\/www.java.com\/en\/\">Java<\/a> before, and are ready to see a series of Scala examples to get a feel for what the language looks like. Although it\u2019s not 100% necessary, it will also help if you\u2019ve already downloaded and installed Scala so you can test the examples as you go along. You can also test these examples online with ScalaFiddle.io.<\/p>\n<h4>2.1 Overview<\/h4>\n<p>Before we jump into the examples, here are a few important things to know about Scala:<\/p>\n<ul>\n<li>It\u2019s a high-level language<\/li>\n<li>It\u2019s statically typed<\/li>\n<li>Its syntax is concise but still readable \u2014 we call it <i>expressive<\/i><\/li>\n<li>It supports the <a href=\"https:\/\/www.techtarget.com\/searchapparchitecture\/definition\/object-oriented-programming-OOP\">object-oriented programming (OOP)<\/a> paradigm<\/li>\n<li>It supports the<a href=\"https:\/\/www.codingdojo.com\/blog\/what-is-functional-programming\"> functional programming (FP)<\/a> paradigm<\/li>\n<li>It has a sophisticated<a href=\"https:\/\/en.wikipedia.org\/wiki\/Type_inference\"> type inference<\/a> system<\/li>\n<li>Scala code results in <i>.class\u00a0<\/i>files that run on the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Java_virtual_machine\">Java Virtual Machine (JVM)<\/a><\/li>\n<li>It\u2019s easy to use Java libraries in Scala<\/li>\n<\/ul>\n<h4>2.2 Hello, world<\/h4>\n<p>Ever since the book,\u00a0<i>C Programming Language<\/i>, it\u2019s been a tradition to begin programming books with a \u201cHello, world\u201d example, and not to disappoint, this is one way to write that example in Scala:<br \/>\nobject Hello extends App {<br \/>\nprintln(&#8220;Hello, world&#8221;)<br \/>\n}<\/p>\n<p>After you save that code to a file named\u00a0<i>Hello.scala<\/i>, you can compile it with scalac:<br \/>\n$ scalac Hello.scala<\/p>\n<p>If you\u2019re coming to Scala from Java, scalac is just like javac, and that command creates two files:<\/p>\n<ul>\n<li><i>Hello$.class<\/i><\/li>\n<li><i>Hello.class<\/i><\/li>\n<\/ul>\n<p>These are the same \u201c.class\u201d bytecode files you create with javac, and they\u2019re ready to run in the JVM. You run the Hello application with the scala command:<br \/>\n$ scala Hello<\/p>\n<p>We share more \u201cHello, world\u201d examples in the lessons that follow, so we\u2019ll leave that introduction as-is for now.<\/p>\n<h4>2.3 The Scala REPL<\/h4>\n<p>The <a href=\"https:\/\/docs.scala-lang.org\/overviews\/repl\/overview.html\">Scala REPL<\/a> (\u201cRead-Evaluate-Print-Loop\u201d) is a command-line interpreter that you use as a \u201cplayground\u201d area to test your Scala code. We introduce it early here so you can use it with the code examples that follow.<\/p>\n<p>To start a REPL session, just type scala at your operating system command line, and you\u2019ll see something like this:<\/p>\n<p>$ scala<br \/>\nWelcome to Scala 2.13.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131). Type in expressions for evaluation. Or try :help.<\/p>\n<p>scala&gt; _<\/p>\n<p>Because the REPL is a command-line interpreter, it just sits there waiting for you to type something. Inside the REPL you type Scala expressions to see how they work:<\/p>\n<p>scala&gt; val x = 1<br \/>\nx: Int = 1<\/p>\n<p>scala&gt; val y = x + 1<br \/>\ny: Int = 2<\/p>\n<p>As those examples show, after you type your expressions in the REPL, it shows the result of each expression on the line following the prompt.<\/p>\n<h4>2.4 Two types of variables<\/h4>\n<p>Scala has two types of variables:<\/p>\n<ul>\n<li>val is an immutable variable \u2014 like final in Java \u2014 and should be preferred<\/li>\n<li>var creates a mutable variable, and should only be used when there is a specific reason to use it<\/li>\n<li>Examples:<\/li>\n<\/ul>\n<p>val x = 1 \/\/immutable<br \/>\nvar y = 0 \/\/mutable<\/p>\n<h4>2.5 Declaring variable types<\/h4>\n<p>In Scala, you typically create variables without declaring their type:<\/p>\n<p>val x = 1<br \/>\nval s = &#8220;a string&#8221;<br \/>\nval p = new Person(&#8220;Regina&#8221;)<\/p>\n<p>When you do this, Scala can usually infer the data type for you, as shown in these REPL examples:<\/p>\n<p>scala&gt; val x = 1<br \/>\nval x: Int = 1<\/p>\n<p>scala&gt; val s = &#8220;a string&#8221;<br \/>\nval s: String = a string<\/p>\n<p>This feature is known as\u00a0<i>type inference<\/i>, and it\u2019s a great way to help keep your code concise. You can also\u00a0<i>explicitly\u00a0<\/i>declare a variable\u2019s type, but that\u2019s not usually necessary:<\/p>\n<p>val x: Int = 1<br \/>\nval s: String = &#8220;a string&#8221;<br \/>\nval p: Person = new Person(&#8220;Regina&#8221;)<\/p>\n<p>As you can see, that code looks unnecessarily verbose.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><iframe style=\"width: 100%; height: 750px; border: none;\" src=\"https:\/\/online.visual-paradigm.com\/share\/book\/scala-book-1cw1oydmng?p=1\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n","protected":false},"featured_media":23808,"template":"","meta":{"_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"Scala is a powerful programming language that seamlessly combines object-oriented and functional programming concepts. earn more here with this book now"},"product_brand":[],"product_cat":[388],"product_tag":[],"class_list":{"0":"post-23804","1":"product","2":"type-product","3":"status-publish","4":"has-post-thumbnail","6":"product_cat-scala","8":"first","9":"instock","10":"shipping-taxable","11":"product-type-simple"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Scala Book - BooksOfAll French<\/title>\n<meta name=\"description\" content=\"Scala is a powerful programming language that seamlessly combines object-oriented and functional programming concepts. earn more here with this book now\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.booksofall.com\/fr\/scala-book\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scala Book - BooksOfAll French\" \/>\n<meta property=\"og:description\" content=\"Scala is a powerful programming language that seamlessly combines object-oriented and functional programming concepts. earn more here with this book now\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.booksofall.com\/fr\/scala-book\/\" \/>\n<meta property=\"og:site_name\" content=\"BooksOfAll French\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-17T10:05:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/05\/Scala-Book.jpg\" \/><meta property=\"og:image\" content=\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/05\/Scala-Book.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"827\" \/>\n\t<meta property=\"og:image:height\" content=\"1169\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/05\/Scala-Book.jpg\" \/>\n<meta name=\"twitter:label1\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.booksofall.com\/fr\/scala-book\/\",\"url\":\"https:\/\/www.booksofall.com\/fr\/scala-book\/\",\"name\":\"Scala Book - BooksOfAll French\",\"isPartOf\":{\"@id\":\"https:\/\/www.booksofall.com\/fr\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.booksofall.com\/fr\/scala-book\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/fr\/scala-book\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/05\/Scala-Book.jpg\",\"datePublished\":\"2023-05-17T10:02:45+00:00\",\"dateModified\":\"2023-05-17T10:05:52+00:00\",\"description\":\"Scala is a powerful programming language that seamlessly combines object-oriented and functional programming concepts. earn more here with this book now\",\"breadcrumb\":{\"@id\":\"https:\/\/www.booksofall.com\/fr\/scala-book\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.booksofall.com\/fr\/scala-book\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/www.booksofall.com\/fr\/scala-book\/#primaryimage\",\"url\":\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/05\/Scala-Book.jpg\",\"contentUrl\":\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/05\/Scala-Book.jpg\",\"width\":\"827\",\"height\":\"1169\",\"caption\":\"Scala Book\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.booksofall.com\/fr\/scala-book\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.booksofall.com\/fr\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Categories\",\"item\":\"https:\/\/www.booksofall.com\/fr\/categories\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Scala Book\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.booksofall.com\/fr\/#website\",\"url\":\"https:\/\/www.booksofall.com\/fr\/\",\"name\":\"BooksOfAll French\",\"description\":\"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.\",\"publisher\":{\"@id\":\"https:\/\/www.booksofall.com\/fr\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.booksofall.com\/fr\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.booksofall.com\/fr\/#organization\",\"name\":\"BooksOfAll French\",\"url\":\"https:\/\/www.booksofall.com\/fr\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/www.booksofall.com\/fr\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2022\/06\/booksofall-logo-2.png\",\"contentUrl\":\"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2022\/06\/booksofall-logo-2.png\",\"width\":166,\"height\":30,\"caption\":\"BooksOfAll French\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/fr\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scala Book - BooksOfAll French","description":"Scala is a powerful programming language that seamlessly combines object-oriented and functional programming concepts. earn more here with this book now","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:\/\/www.booksofall.com\/fr\/scala-book\/","og_locale":"fr_FR","og_type":"article","og_title":"Scala Book - BooksOfAll French","og_description":"Scala is a powerful programming language that seamlessly combines object-oriented and functional programming concepts. earn more here with this book now","og_url":"https:\/\/www.booksofall.com\/fr\/scala-book\/","og_site_name":"BooksOfAll French","article_modified_time":"2023-05-17T10:05:52+00:00","og_image":[{"url":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/05\/Scala-Book.jpg","type":"","width":"","height":""},{"width":827,"height":1169,"url":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/05\/Scala-Book.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_image":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/05\/Scala-Book.jpg","twitter_misc":{"Dur\u00e9e de lecture estim\u00e9e":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.booksofall.com\/fr\/scala-book\/","url":"https:\/\/www.booksofall.com\/fr\/scala-book\/","name":"Scala Book - BooksOfAll French","isPartOf":{"@id":"https:\/\/www.booksofall.com\/fr\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.booksofall.com\/fr\/scala-book\/#primaryimage"},"image":{"@id":"https:\/\/www.booksofall.com\/fr\/scala-book\/#primaryimage"},"thumbnailUrl":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/05\/Scala-Book.jpg","datePublished":"2023-05-17T10:02:45+00:00","dateModified":"2023-05-17T10:05:52+00:00","description":"Scala is a powerful programming language that seamlessly combines object-oriented and functional programming concepts. earn more here with this book now","breadcrumb":{"@id":"https:\/\/www.booksofall.com\/fr\/scala-book\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.booksofall.com\/fr\/scala-book\/"]}]},{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.booksofall.com\/fr\/scala-book\/#primaryimage","url":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/05\/Scala-Book.jpg","contentUrl":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2023\/05\/Scala-Book.jpg","width":"827","height":"1169","caption":"Scala Book"},{"@type":"BreadcrumbList","@id":"https:\/\/www.booksofall.com\/fr\/scala-book\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.booksofall.com\/fr\/"},{"@type":"ListItem","position":2,"name":"Categories","item":"https:\/\/www.booksofall.com\/fr\/categories\/"},{"@type":"ListItem","position":3,"name":"Scala Book"}]},{"@type":"WebSite","@id":"https:\/\/www.booksofall.com\/fr\/#website","url":"https:\/\/www.booksofall.com\/fr\/","name":"BooksOfAll French","description":"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.","publisher":{"@id":"https:\/\/www.booksofall.com\/fr\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.booksofall.com\/fr\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/www.booksofall.com\/fr\/#organization","name":"BooksOfAll French","url":"https:\/\/www.booksofall.com\/fr\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.booksofall.com\/fr\/#\/schema\/logo\/image\/","url":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2022\/06\/booksofall-logo-2.png","contentUrl":"https:\/\/www.booksofall.com\/fr\/wp-content\/uploads\/sites\/6\/2022\/06\/booksofall-logo-2.png","width":166,"height":30,"caption":"BooksOfAll French"},"image":{"@id":"https:\/\/www.booksofall.com\/fr\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/product\/23804","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/product"}],"about":[{"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/types\/product"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/media\/23808"}],"wp:attachment":[{"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/media?parent=23804"}],"wp:term":[{"taxonomy":"product_brand","embeddable":true,"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/product_brand?post=23804"},{"taxonomy":"product_cat","embeddable":true,"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/product_cat?post=23804"},{"taxonomy":"product_tag","embeddable":true,"href":"https:\/\/www.booksofall.com\/fr\/wp-json\/wp\/v2\/product_tag?post=23804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}