{"id":1343,"date":"2021-06-17T06:48:27","date_gmt":"2021-06-17T06:48:27","guid":{"rendered":"https:\/\/blog.amt.in\/?p=1343"},"modified":"2021-06-17T06:48:27","modified_gmt":"2021-06-17T06:48:27","slug":"introduction-to-scala","status":"publish","type":"post","link":"https:\/\/blog.amt.in\/index.php\/2021\/06\/17\/introduction-to-scala\/","title":{"rendered":"Introduction to Scala"},"content":{"rendered":"<p>Scala\u00c2\u00a0is a\u00c2\u00a0general-purpose\u00c2\u00a0programming language\u00c2\u00a0providing support for\u00c2\u00a0functional programming\u00c2\u00a0and a strong\u00c2\u00a0static\u00c2\u00a0type system. Designed to be concise,\u00c2\u00a0many of Scala&#8217;s design decisions aimed to address\u00c2\u00a0criticisms of Java.<\/p>\n<p>Scala source code is intended to be compiled to\u00c2\u00a0Java bytecode, so that the resulting executable code runs on a\u00c2\u00a0Java virtual machine. Scala provides\u00c2\u00a0language interoperability\u00c2\u00a0with Java, so that libraries written in both languages may be referenced directly in Scala or Java code.\u00c2\u00a0Like Java, Scala is\u00c2\u00a0object-oriented, and uses a curly-brace syntax reminiscent of the\u00c2\u00a0C programming language. Unlike Java, Scala has many features of\u00c2\u00a0functional programming\u00c2\u00a0languages like\u00c2\u00a0Scheme,\u00c2\u00a0Standard ML\u00c2\u00a0and\u00c2\u00a0Haskell, including\u00c2\u00a0currying,\u00c2\u00a0type inference,\u00c2\u00a0immutability,\u00c2\u00a0lazy evaluation, and\u00c2\u00a0pattern matching. It also has an advanced type system supporting\u00c2\u00a0algebraic data types,\u00c2\u00a0covariance and contravariance,\u00c2\u00a0higher-order types\u00c2\u00a0(but not\u00c2\u00a0higher-rank types), and\u00c2\u00a0anonymous types. Other features of Scala not present in Java include\u00c2\u00a0operator overloading, optional parameters,\u00c2\u00a0named parameters, and\u00c2\u00a0raw strings. Conversely, a feature of Java not in Scala is\u00c2\u00a0checked exceptions, which have proved controversial.<\/p>\n<p>Scala runs on the\u00c2\u00a0Java platform\u00c2\u00a0(Java virtual machine) and is compatible with existing\u00c2\u00a0Java\u00c2\u00a0programs.\u00c2\u00a0As\u00c2\u00a0Android\u00c2\u00a0applications are typically written in Java and translated from Java bytecode into\u00c2\u00a0Dalvik\u00c2\u00a0bytecode (which may be further translated to native machine code during installation) when packaged, Scala&#8217;s Java compatibility makes it well-suited to Android development, more so when a functional approach is preferred.<\/p>\n<p>The reference Scala software distribution, including compiler and libraries, is released under a\u00c2\u00a0BSD license.<\/p>\n<p>Scala.js is a Scala compiler that compiles to JavaScript, making it possible to write Scala programs that can run in web browsers.<\/p>\n<p>Scala Native is a Scala\u00c2\u00a0compiler\u00c2\u00a0that targets the\u00c2\u00a0LLVM\u00c2\u00a0compiler infrastructure to create executable code that uses a lightweight managed runtime, which uses the\u00c2\u00a0Boehm garbage collector. The project is led by Denys Shabalin and had its first release, 0.1, on 14 March 2017. Development of Scala Native began in 2015 with a goal of being faster than\u00c2\u00a0just-in-time compilation\u00c2\u00a0for the JVM by eliminating the initial runtime compilation of code and also providing the ability to call native routines directly.<\/p>\n<p>A reference Scala compiler targeting the\u00c2\u00a0.NET Framework\u00c2\u00a0and its\u00c2\u00a0Common Language Runtime\u00c2\u00a0was released in June 2004,\u00c2\u00a0but was officially dropped in 2012.<\/p>\n<p>Scala has the same compiling model as\u00c2\u00a0Java\u00c2\u00a0and\u00c2\u00a0C#, namely separate compiling and\u00c2\u00a0dynamic class loading, so that Scala code can call Java libraries.<\/p>\n<p>Scala&#8217;s operational characteristics are the same as Java&#8217;s. The Scala compiler generates byte code that is nearly identical to that generated by the Java compiler.\u00c2\u00a0In fact, Scala code can be\u00c2\u00a0decompiled\u00c2\u00a0to readable Java code, with the exception of certain constructor operations. To the\u00c2\u00a0Java virtual machine\u00c2\u00a0(JVM), Scala code and Java code are indistinguishable. The only difference is one extra runtime library,\u00c2\u00a0<code>scala-library.jar<\/code>.<\/p>\n<p>Scala adds a large number of features compared with Java, and has some fundamental differences in its underlying model of expressions and types, which make the language theoretically cleaner and eliminate several\u00c2\u00a0corner cases\u00c2\u00a0in Java.<\/p>\n<p>The most well-known open-source cluster-computing solution written in Scala is\u00c2\u00a0Apache Spark. Additionally,\u00c2\u00a0Apache Kafka, the\u00c2\u00a0publish\u00e2\u20ac\u201csubscribe\u00c2\u00a0message queue\u00c2\u00a0popular with Spark and other stream processing technologies, is written in Scala.<\/p>\n<p>There are several ways to test code in Scala.\u00c2\u00a0ScalaTest\u00c2\u00a0supports multiple testing styles and can integrate with Java-based testing frameworks.\u00c2\u00a0ScalaCheck\u00c2\u00a0is a library similar to Haskell&#8217;s\u00c2\u00a0QuickCheck.\u00c2\u00a0specs2\u00c2\u00a0is a library for writing executable software specifications.\u00c2\u00a0ScalaMock\u00c2\u00a0provides support for testing high-order and curried functions.\u00c2\u00a0JUnit\u00c2\u00a0and\u00c2\u00a0TestNG\u00c2\u00a0are popular testing frameworks written in Java.<\/p>\n<p>The above is a brief about Scala. Watch this space for more information on the latest trends in Technology.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scala\u00c2\u00a0is a\u00c2\u00a0general-purpose\u00c2\u00a0programming language\u00c2\u00a0providing support for\u00c2\u00a0functional<\/p>\n","protected":false},"author":1,"featured_media":1344,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[154,259,7],"tags":[156,260,18],"class_list":["post-1343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming-language","category-scala","category-techtrends","tag-programming-language","tag-scala","tag-technology"],"_links":{"self":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/1343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/comments?post=1343"}],"version-history":[{"count":1,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/1343\/revisions"}],"predecessor-version":[{"id":1345,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/1343\/revisions\/1345"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/media\/1344"}],"wp:attachment":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/media?parent=1343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/categories?post=1343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/tags?post=1343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}