How the if-else statement is different for Scala and Java?

0 votes
Can anyone explain the differences between the if-else statements for Scala and Java?
Jul 29, 2019 in Apache Spark by Nidha
50 views

1 answer to this question.

0 votes

Hey,

There is one main difference. This statement is an expression in Scala, but not in Java. There, we cannot assign it to a variable because it doesn’t return a value.

Here is an example below:

scala> val x=3

x: Int = 3

scala> val kind= if(x%2==0) "even" else "odd"

kind: String = odd

Java:

int x=3;

String kind;

if(x%2==0)

kind=”even”;

else

kind=”odd”;

Hope it helps.

answered Jul 29, 2019 by Gitika
• 26,110 points

Related Questions In Apache Spark

0 votes
1 answer

How is Apache Spark different from the Hadoop approach?

In Hadoop MapReduce the input data is ...READ MORE

answered May 7, 2018 in Apache Spark by BD Master
142 views
0 votes
1 answer

How SparkSQL is different from HQL and SQL?

Hi, SparkSQL is a special component on the ...READ MORE

answered Jul 3, 2019 in Apache Spark by Gitika
• 26,110 points
392 views
0 votes
0 answers
0 votes
1 answer

How can we optimize and minimize the memory when work with scala use case?

Hi, There is a term in Scala that is ...READ MORE

answered Jul 5, 2019 in Apache Spark by Gitika
• 26,110 points
63 views
0 votes
1 answer

Moving files in Hadoop using the Java API?

I would recommend you to use FileSystem.rename(). ...READ MORE

answered Apr 15, 2018 in Big Data Hadoop by Shubham
• 13,380 points
1,149 views
0 votes
1 answer

Hadoop giving java.io.IOException, in mkdir Java code.

I am not sure about the issue. ...READ MORE

answered May 3, 2018 in Big Data Hadoop by Shubham
• 13,380 points
669 views
+1 vote
1 answer
+1 vote
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,870 points
4,500 views
0 votes
1 answer
–2 votes
1 answer

What is the difference in Java’s “If..Else” and Scala’s “If..Else”?

Hey, Java’s “If. Else”: In Java, “If. Else” is a statement, ...READ MORE

answered Jul 31, 2019 in Apache Spark by Gitika
• 26,110 points
116 views