Scala beginner has some questions

Hey Guys! I have some questions, because I am a Scala novice (And my English is not the best).

  1. I use Intellij and I have downloaded the Scala plugin. Have I installed Scala on my computer or have I to download it with an extra file?

  2. In IntelliJ when you creat a project, what should I choose when they question comes if I take, sbt or Lightbend Project Starter or IDEA. Which of them should I take?

  3. When I have created a project and add a new Scala class, it asks me which kind of class I need. Class or Object or Trait. Which of them should I take and what are the differences between them?

  4. When I created a Project with (2. Question) IDEA and (3.Question) Object, is it possible that I create a class too and I write my functions in my class and import it in the object and run it there?

  5. Are there any informations that are really good to know?

Best regards, Lockna

  1. If you want to work from the IDE exclusively, you don’t need to install anything else. The Scala compiler is usually downloaded by a build tool or your IDE, which also ensures the right version is used. Installing Scala is only required, if you want to use its command line tools. You need a Java runtime, but if Intellij is running you already have that :wink:
  2. I usually choose sbt, which is a build tool (like Maven or Gradle, if you come from a Java background). Lightbend Project Starter also creates an sbt project, but uses a template from a list, which is useful for some libraries, which require more setup than just adding a dependency. It is also sometimes used for example usages of libraries.
    For learning Scala, an IDEA project is also ok, which stores all build settings in an IDEA-specific format, but as soon as you want to use external libraries, using a build tool like SBT is much more convenient (and also not specific to one IDE).
  3. A class is the same as in other languages: a thing that can have several instances, which may have different parameters. An object is similar to a singleton in other languages: it has only one instance. If you come from Java, the most important thing to know here is that Scala does not have static methods, instead you put such methods into an object in Scala. A method on a class can only be called on a previously created instance of that class, while an object always is an instance on which you can call the methods directly. For a longer explanation of objects see the tutorial. A trait is like an interface in Java, but it can do some things interfaces can’t, but those uses are more advanced, the tutorial on traits also does not mention them.
    For a small application, you’d start with an object, as the main method needs to be on one (it is static in Java).
  4. As explained, if you put methods in a class, you need to create an instance (e.g. new MyClass) to use its methods. If you just want to group mostly independent methods into a namespace, use an object. You can then import them via import path.to.MyOtherObject.methodName, or import path.to.MyOtherObject._ for all members of MyOtherObject (where path.to is the package it is located in)
  5. When learning a language, I always find it helpful to try things out in the REPL (interactive command line). In IDEA, it is called “Scala Console”. You can enter single lines of Scala in it and see their results immediately. Scala worksheets also work like that, they create a split window in IDEA, you can write code without an object or class around it in the editor window and the right split shows the result of every line.
    And I recommend the official tutorial.

– crater2150

1 Like

Thanks for this very good answer :slight_smile:

how could i get back my email address from your website?
I’m not interested in receiving such mails that in a few hours of my arrival and since I joined your group, you are sending to me!!!

I’m just looking for a good from to have conversation about scala!

not such spams

at bottom of each email: To unsubscribe from these emails, click here where click here is a link.

thank Sir,
I’m not good at English

if i choosed my world in a way that was not gentle, plz forgive me.

highly appreciate your attention.