How to declare a variable in Scala

0 votes
How to declare a variable in Scala?
Nov 16, 2020 in Big Data Hadoop by Rajiv
• 8,880 points
76 views

1 answer to this question.

0 votes

The following is an example program that explains the process of variable declaration in Scala. This program declares four variables — two variables are defined with type declaration and the remaining two are without type declaration.

Example

object Demo {
   def main(args: Array[String]) {
      var myVar :Int = 10;
      val myVal :String = "Hello Scala with datatype declaration.";
      var myVar1 = 20;
      val myVal1 = "Hello Scala new without datatype declaration.";
      
      println(myVar); println(myVal); println(myVar1); 
      println(myVal1);
   }
}

Save the above program in Demo.scala. The following commands are used to compile and execute this program.

Command

\>scalac Demo.scala
\>scala Demo

Output

10
Hello Scala with datatype declaration.
20
Hello Scala without datatype declaration.
answered Nov 16, 2020 by Gitika
• 65,870 points

Related Questions In Big Data Hadoop

0 votes
7 answers

How to run a jar file in hadoop?

I used this command to run my ...READ MORE

answered Dec 10, 2018 in Big Data Hadoop by Dasinto
14,950 views
0 votes
1 answer

How to print the content of a file in console present in HDFS?

Yes, you can use hdfs dfs command ...READ MORE

answered Apr 19, 2018 in Big Data Hadoop by Shubham
• 13,480 points
2,902 views
0 votes
1 answer

How to groupBy/count then filter on count in Scala

I think the exception is caused because ...READ MORE

answered Apr 19, 2018 in Big Data Hadoop by kurt_cobain
• 9,390 points
22,293 views
0 votes
1 answer

How to start working with scala?

Scala can be installed on any UNIX ...READ MORE

answered Nov 16, 2020 in Big Data Hadoop by Gitika
• 65,870 points
56 views
0 votes
1 answer

How to execute scala programming?

We can execute a Scala program in ...READ MORE

answered Nov 16, 2020 in Big Data Hadoop by Gitika
• 65,870 points
95 views
0 votes
1 answer

How to import scala packages?

Scala packages can be imported so that ...READ MORE

answered Nov 16, 2020 in Big Data Hadoop by Gitika
• 65,870 points
57 views
0 votes
1 answer

How to create an objects using a keyword new?

Example import java.io._ class Point(val xc: Int, val yc: ...READ MORE

answered Nov 16, 2020 in Big Data Hadoop by Gitika
• 65,870 points
54 views
0 votes
1 answer

How to write a Scala program in script mode?

Open notepad and add the following code ...READ MORE

answered Nov 16, 2020 in Big Data Hadoop by Gitika
• 65,870 points
93 views
0 votes
1 answer

How to create a file in Linux from terminal window?

Hey, Nothing to worry about creating any file ...READ MORE

answered May 13, 2019 in Big Data Hadoop by Gitika
• 65,870 points
94 views