scala_reserved_words_-_scala_keywords

Scala Reserved Words - Scala Keywords

Scala Reserved Words

This list includes keywords that are reserved in Scala. These keywords have special meaning in Scala programming and are part of the Scala language's syntax. They cannot be used as identifiers, such as Scala names for Scala variables, Scala functions, Scala classes, etc.

  • abstract - Specifies an abstract class or an abstract member.
  • case - Used for pattern matching and case class definitions.
  • catch - Catches exceptions generated by try blocks.
  • class - Declares a class.
  • def - Defines a method.
  • do - Begins a do-while loop.
  • else - Specifies an alternative branch in conditional expressions.
  • extends - Indicates that a class inherits from a superclass or a trait.
  • false - Boolean literal representing false.
  • final - Declares that an entity cannot be overridden.
  • finally - Specifies cleanup code that is always executed.
  • for - Begins a for loop or for-comprehension.
  • if - Begins a conditional expression.
  • implicit - Marks a declaration as available for implicit conversions and parameters.
  • import - Imports other Scala entities.
  • lazy - Delays the initialization of a value.
  • match - Used for pattern matching.
  • new - Creates a new instance of a class.
  • null - Represents a null reference.
  • object - Declares a singleton object.
  • override - Indicates that a member overrides another member.
  • package - Declares a package.
  • private - Restricts access to the containing class or object.
  • protected - Restricts access to subclasses of the containing class.
  • return - Returns a value from a method.
  • sealed - Restricts subclassing to the same file.
  • super - Refers to the superclass.
  • this - Refers to the current object.
  • throw - Throws an exception.
  • trait - Declares a trait.
  • try - Begins a block of code that is tested for exceptions.
  • true - Boolean literal representing true.
  • type - Declares a type alias or type parameter.
  • val - Declares an immutable value.
  • var - Declares a mutable variable.
  • while - Begins a while loop.
  • with - Specifies mixin composition.
  • yield - Produces values from a for-comprehension.

For more detailed information on each keyword and its use in Scala programming, refer to the official Scala documentation: https://docs.scala-lang.org/scala3/reference/soft-modifier.html Official Scala Documentation

This list provides a comprehensive overview of the keywords reserved by the Scala programming language, each serving a specific purpose within the language's syntax and semantics. Note that the provided URL points to the Scala 3 documentation, which covers the most recent version of the language as of my last update. Scala's official documentation is a valuable resource for understanding the role of these keywords in detail.


Creating a glossary of the top 60 Scala reserved words, sorted by their most common usage, presents a unique challenge since Scala, much like other modern programming languages, has a rich set of keywords and also allows many operations to be performed using its Scala standard library. Scala blends Scala object-oriented and Scala functional programming paradigms, and its Scala syntax allows for concise and expressive code. Scala does not have 60 reserved words in the strict sense, as its core is much smaller, but we will cover the essential keywords and include some important Scala concepts that are commonly used in Scala programming.

Scala Language Reserved Words Glossary

This glossary lists some of the most frequently used Scala reserved words and concepts, along with short Scala code examples to illustrate their usage. Scala's design allows for expressive code, blending object-oriented and functional programming paradigms.

val

Scala val: Declares a Scala immutable variable.

val x = 10

var

Scala var: Declares a Scala mutable variable.

var y = 5

def

Scala def: Defines a Scala method.

def add(a: Int, b: Int): Int = a + b

if

Scala if: Scala Conditional expression.

if (x > 0) "positive" else "non-positive"

else

Scala else: Part of a Scala conditional expression.

if (x > 0) "positive" else "non-positive"

while

Scala while: A Scala loop that executes as long as a condition is true.

while (x < 10) { x += 1 }

do

Scala do: Starts a Scala do-while loop, executing the Scala code block at least once.

do { x += 1 } while (x < 10)

for

Scala for: A Scala loop that Scala iterates over Scala elements in a Scala collection.

for (i <- 1 to 5) println(i)

yield

Scala yield: Used with Scala for-comprehensions to produce a new Scala collection.

val squares = for (i <- 1 to 5) yield i * i

match

Scala match: Scala Pattern matching expression.

x match {
  case 1 => "one"
  case _ => "other"
}

case

Scala case: Defines a case in a Scala match expression or a Scala case class.

case class Person(name: String, age: Int)

class

Scala class: Defines a class.

class MyClass

object

Scala object: Defines a singleton object.

object MyObject

trait

extends

Scala extends: Indicates that a Scala class inherits from another class or Scala trait.

class MyClass extends MyTrait

with

Scala with: Used to Scala mix in Scala traits.

class MyClass extends MyTrait with AnotherTrait

new

Scala new: Creates a new Scala instance of a class.

val obj = new MyClass

import

Scala import: Imports Scala classes, Scala objects, or Scala members.

import scala.collection.mutable.ArrayBuffer

package

Declares a package.

package com.example

final

Marks a member or class as not extendable.

final class MyFinalClass

private

Restricts access to the enclosing class or package.

private class MyClass

protected

Restricts access to subclasses and the enclosing package.

protected def myMethod = {}

override

Indicates that a member overrides a base class member.

override def toString = "MyClass"

try

Starts a block for exception handling.

try {
  riskyMethod()
} catch {
  case e: Exception => println(e)
}

catch

Catches exceptions thrown in the try block.

catch {
  case e: Exception => println(e)
}

finally

Defines a block that executes after try/catch, regardless of exceptions.

finally {
  cleanUp()
}

lazy

Lazily initializes a value the first time it is accessed.

lazy val myLazyVal = computeIntensiveOperation()

implicit

Marks a parameter or definition as implicit.

implicit val myImplicitVal: Int = 5

null

Represents a null reference.

val str: String = null

true, false

Boolean literals.

val myTrue: Boolean = true
val myFalse: Boolean = false

object

Defines a singleton object, which is a class with exactly one instance.

object Singleton

type

Defines a type alias.

type StringList = List[String]

this

Refers to the current object.

class MyClass {
  def printThis: Unit = println(this)
}

null

Represents the absence of a value for reference types.

val str: String = null

super

Refers to the superclass version of a method or field.

override def toString = super.toString + " with extra"

sealed

Restricts subclassing to the same file (used with traits and classes).

sealed trait MySealedTrait

This glossary covers foundational concepts and reserved words in Scala, designed to provide a quick reference for both beginners and seasoned programmers. Scala's syntax and rich library support enable developers to write concise and expressive code, leveraging both object-oriented and functional programming paradigms.

This concise glossary, formatted for MediaWiki, covers essential Scala concepts and keywords with examples, providing a valuable resource for learning or reference.

Snippet from Wikipedia: Scala (programming language)

Scala ( SKAH-lah) is a strong statically typed high-level general-purpose programming language that supports both object-oriented programming and functional programming. Designed to be concise, many of Scala's design decisions are intended to address criticisms of Java.

Scala source code can be compiled to Java bytecode and run on a Java virtual machine (JVM). Scala can also be compiled to JavaScript to run in a browser, or directly to a native executable. On the JVM Scala provides language interoperability with Java so that libraries written in either language may be referenced directly in Scala or Java code. Like Java, Scala is object-oriented, and uses a syntax termed curly-brace which is similar to the language C. Since Scala 3, there is also an option to use the off-side rule (indenting) to structure blocks, and its use is advised. Martin Odersky has said that this turned out to be the most productive change introduced in Scala 3.

Unlike Java, Scala has many features of functional programming languages (like Scheme, Standard ML, and Haskell), including currying, immutability, lazy evaluation, and pattern matching. It also has an advanced type system supporting algebraic data types, covariance and contravariance, higher-order types (but not higher-rank types), anonymous types, operator overloading, optional parameters, named parameters, raw strings, and an experimental exception-only version of algebraic effects that can be seen as a more powerful version of Java's checked exceptions.

The name Scala is a portmanteau of scalable and language, signifying that it is designed to grow with the demands of its users.

Research More

Scala on the Cloud

Scala on Containers

Scala Courses

Fair Use Source

Scala: Scala Fundamentals, Scala 3, Scala 2, SBT-Maven-Gradle, JVM, Scala Keywords, Scala Built-In Data Types, Scala Data Structures - Scala Algorithms, Scala Syntax, Scala OOP - Scala Design Patterns, Scala Installation (Scala 3 on Windows, Scala 3 on Linux, Scala 3 on macOS), Scala Containerization, Scala Configuration, Scala IDEs (JetBrains IntelliJ), Scala Linter, Scala on JVM, Scala Development Tools, Scala Compiler, Scala Transpiler (Scala.js, Scala Native), Scala REPL, Scala Testing (ScalaTest, ScalaCheck, JUnit, Hamcrest, Mockito, Selenium, TestNG), Scala Data Science - Scala DataOps, Scala Machine Learning - Scala MLOps, Scala Deep Learning, Functional Scala, Scala Concurrency - Scala Parallel Programming, Scala Libraries (Akka Toolkit), Scala Frameworks (Play Framework, Scalatra), Scala History, Scala Bibliography, Manning Scala Series, Scala Courses, Scala Glossary, Scala Topics, Scala Research, Scala GitHub, Written in Scala (Apache Spark, Apache Kafka, Apache Helix), Scala Popularity, Scala Awesome. (navbar_scala - see also navbar_scala_standard_library, navbar_scala_libraries, navbar_scala_reserved_words, navbar_scala_functional, navbar_scala_concurrency)

Reserved Keywords: (Also called: Language Keywords, Reserved Keyword, Reserved Word, Keywords, Reserved Identifier, Reserved Identifiers) Ada Keywords, ALGOL 68 Keywords, Angular Keywords, Android Keywords, Apple iOS Keywords, ARM Assembly Keywords, Assembly Keywords, AWK Keywords, Bash Keywords, BASIC Keywords, C Keywords (https://en.cppreference.com/w/c/keyword), C# Keywords, .NET Keywords, C++ Keywords (https://en.cppreference.com/w/cpp/keyword), Clojure Keywords, COBOL Keywords, Dart Keywords, Delphi Keywords, Django Keywords, Elixir Keywords, Erlang Keywords, F Sharp Keywords, Fortran Keywords, Flask Keywords, Golang Keywords, Groovy Keywords, Haskell Keywords, Jakarta EE Keywords, Java Keywords, JavaScript Keywords, JCL Keywords, Julia Keywords, Kotlin Keywords, Lisp Keywords (Common Lisp Keywords), Lua Keywords, MATHLAB Keywords, Objective-C Keywords, OCaml‎ Keywords, Pascal Keywords, Perl Keywords, PHP Keywords, PL/I Keywords, PowerShell Keywords, Python Keywords, Quarkus Keywords, R Language Keywords, React.js Keywords, Rexx Keywords, RPG Keywords, Ruby Keywords, Rust Keywords, Scala Keywords, Spring Keywords, SQL Keywords, Swift Keywords, Transact-SQL Keywords, TypeScript Keywords, Visual Basic Keywords, Vue.js Keywords, X86 Assembly Keywords, X86-64 Assembly Keywords. (navbar_reserved_keywords - see also navbar_cpp_keywords)


© 1994 - 2024 Cloud Monk Losang Jinpa or Fair Use. Disclaimers

SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.


scala_reserved_words_-_scala_keywords.txt · Last modified: 2024/04/28 03:12 (external edit)