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 in Apache Spark by Nidha
32 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 by Gitika
• 25,420 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
103 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 in Apache Spark by Gitika
• 25,420 points
176 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 in Apache Spark by Gitika
• 25,420 points
47 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,350 points
962 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,350 points
506 views
+1 vote
1 answer
0 votes
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,760 points
3,539 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 in Apache Spark by Gitika
• 25,420 points
57 views