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 1,971 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
• 65,770 points
if you intend to reassign you cannot declare year as val
Thanks, @Divija for your contribution.

Please register at Edureka Community and earn credits for every contribution. A contribution could be asking a question, answering, commenting or even upvoting/downvoting an answer or question.

These credits can be used to get a discount on the course. Also, you could become the admin at Edureka Community with certain points.

Thanks!

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 28, 2018 in Apache Spark by shams
• 3,670 points
43,083 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
• 65,770 points
1,043 views
0 votes
1 answer

What is the difference between spark streaming and spark structured streaming?

Hi@akhtar Generally, Spark streaming  is used for real time ...READ MORE

answered Feb 4, 2020 in Apache Spark by MD
• 95,460 points
3,785 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
• 11,380 points
34,400 views
+1 vote
2 answers
+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
• 11,380 points
11,037 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
• 11,380 points
2,545 views
+2 votes
11 answers

hadoop fs -put command?

Hi, You can create one directory in HDFS ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
108,872 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
• 65,770 points
3,583 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP