The difference between the Scala language and Java (1)

Source: Internet
Author: User
Tags case statement message queue

  1. Scala supports associative mappings, such as a key-value pair that can be represented by (key, value)

  2. All types in Scala are objects, including basic data types

  3. The case statement in Scala is used to determine the received message, which is more than the switch...case in Java ... More focused

    receive{Case msg = action ()}

  4. The Scala action class implements the concurrency abstraction on top of threads, communicates with each other by sending messages, and each action class automatically maintains a message queue and implements the basic operations of sending and receiving messages.

    Receriver! Msg

  5. Scala is a static type, which requires that you determine the type of the parameter before compiling, similar to the parameterized type of C + +

  6. Scala contains two types of variables, and the Val variable is equivalent to Const,var in Java, which is a regular variable

  7. The basic data type in Scala comes from the class encapsulation of the corresponding data type in Java, the same as the string type

  8. Scala has type inference, and can omit a type description if it can be inferred from the context, such as: val x = 4

  9. Scala defines a function using the DEF keyword, which returns the last computed value of the function in the case of the default explicit return statement

  10. Scala uses println direct output to standard output without System.out.println

  11. The array index in Scala is args (0), not args[0 in Java]

  12. The Scala array contains the method foreach (action), where action is an incoming function, for example: x = println (x)

  13. Scala provides instruction: for (args <- args) println (ARG)


The difference between the Scala language and Java (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.