Monday, 29 May 2017

JAVA VS SCALA

JAVA VS SCALA


















POJO IN JAVA VS SCALA


The Java version of a simple POJO:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public class PostJ {
    private String title;
    private String text;
    private String author;
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getText() {
        return text;
    }
    public void setText(String text) {
        this.text = text;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
}


And the Scala version.

1
case class Post(title: String, text: String, author: String)



Variables :

Java Syntax:
------------------

<data type>  <variable name> = <value> ;
   int                    a                    = 10;
   String               s                   = "Big Data";

Scala Syntax:
------------------

val <variable name> : <data type> = <value>
val            a                :  Int              = 10
val             s               :   String        = "Spark"

var is immutable.

NOTE: SCALA SUPPORTS " TYPE INFER"= automatically find the data type from value.
 val           a    = 10;
val            s=   "Spark"
var <variable name> : <data type> = <value>

var is mutable.



4 comments:

  1. I enjoy what you guys are usually up too. This sort of clever work and coverage! Keep up the wonderful works guys I’ve added you guys to my blog roll.
    Hadoop Training in Bangalore

    ReplyDelete
  2. It is really nice to see the best blog for Hadoop .This blog helped me a lot easily understandable too.
    Hadoop Training in Velachery | Hadoop Training .
    Hadoop Training in Chennai | Hadoop .

    ReplyDelete
  3. It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.Digital Marketing Training in Chennai

    ReplyDelete
  4. Big data marketingis all about using the tools available to you to acquire, organize and use data in the best possible way. Things can get complicated quickly if you don’t know what you are doing. The following article will help you start to get your big data marketing on the right track.

    ReplyDelete