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

–2 votes
Can anyone explain how the Java’s “If..Else” and Scala’s “If..Else” are different?
closed with the note: basic
Jul 31, 2019 in Apache Spark by Dhiman

closed Jul 31, 2019 73 views
There is no difference in any programming language If-Else.

Syntax:

if(Boolean_expression){
   //Executes when the Boolean expression is true
} else{
   //Executes when the Boolean expression is false
}
0 votes

Hey,

Java’s “If. Else”:
In Java, “If. Else” is a statement, not an expression. It does not return a value and cannot assign it to a variable.

Here is an example you can follow to get the difference:

int year;

if(count == 00

year = 2014;

else

year = 2015;

Scala’s “If. Else”:
In Scala, “If. Else” is an expression. It evaluates a value i.e. returns a value. You can assign it to a variable.

val year = if (count == 0) 2014 else 2015

Scala’s “If. Else” works like Java’s Ternary Operator. You can use Scala’s “If. Else” like Java’s “If. Else” statement as shown below:

val year = 0 

if( count == 0) 

year = 2014 

else

year = 2015

answered Jul 31, 2019 by Gitika
• 25,460 points

Related Questions In Apache Spark

+1 vote
3 answers

What is the difference between rdd and dataframes in Apache Spark ?

Comparison between Spark RDD vs DataFrame 1. Release ...READ MORE

answered Aug 27, 2018 in Apache Spark by shams
• 3,580 points
19,716 views
0 votes
1 answer

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

Hey, There is one main difference. This statement ...READ MORE

answered Jul 29, 2019 in Apache Spark by Gitika
• 25,460 points
46 views
0 votes
1 answer

What's the difference between 'filter' and 'where' in Spark SQL?

Both 'filter' and 'where' in Spark SQL ...READ MORE

answered May 23, 2018 in Apache Spark by nitinrawat895
• 10,840 points
9,601 views
0 votes
1 answer

What is the difference between Apache Spark SQLContext vs HiveContext?

Spark 2.0+ Spark 2.0 provides native window functions ...READ MORE

answered May 25, 2018 in Apache Spark by nitinrawat895
• 10,840 points
2,357 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,840 points
3,930 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,840 points
543 views
+1 vote
11 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyFr ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
20,961 views
0 votes
1 answer

What is the difference between persist() and cache() in apache spark?

Hi, persist () allows the user to specify ...READ MORE

answered Jul 3, 2019 in Apache Spark by Gitika
• 25,460 points
761 views
0 votes
1 answer