<commit_before>---
layout: post
published: true
title: Why Java developers should consider Scala
subtitle: You been a Java developer for a while and you are bored
date: '2017-01-03'
---
##    Happy New Year 2017 !!! 
    
If you are like me, you are a veteran Java developer for more than a decade. You are bored of writing boiler plate Java code year after year. The only Java changes you heard in a decade are Java version changes every four years or so. 
    
    
If you have been to hackactons or Startupweekends, you can see Ruby on Rails developers, AngularJS developers hack away building full stack web apps in couple of hours. In contrast as a Java developer you are still trying to create the folder structure for a traditional Java/J2EE application. How do you compete when your core skillset, Java in a JVM environment is such a big disadvantage? 
 
### New Kid on the block

#### You have a new language to the rescue. Welcome to Scala language !!!

Scala is a functional programming language built to run on Java JVM. That's right Scala needs Java JDK to run. <NAME> created scala after realizing all the downfalls of Java. In fact, Martin was original member of Java compiler team. Scala has no boilerplate code compared to Java.
        
* Scala has no boiler plate code

* To try some of these samples [download](http://scala-ide.org/) Eclipse IDE for Scala. 

#### Java version

```java
package com.harishblog;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SquareOfNumberCalculator {
 
  public static void main(String[] args) {
   
      List<Integer> myList = Arrays.asList(1, 2, 3, 4, 5);
      SquareOfNumberCalculator calculator = new SquareOfNumberCalculator();
      List<Integer> squaredNumbers = calculator.squareOfNumbers(myList);

      //Print original list
      System.out.println("Printing original numbers");
      calculator.printNumbers(myList);
      //Print squared list
      System.out.println("Printing squared numbers");
      calculator.printNumbers(squaredNumbers);
  }
	
   public void printNumbers(List<Integer> numbers) {
      
      for (Integer i : numbers) {
         System.out.println(" i --> " + i);
      }
   }

   public List<Integer> squareOfNumbers(List<Integer> numbers) {
       
       List<Integer> squaredNumbers = new ArrayList<Integer>();
       for (Integer i : numbers ) {
           squaredNumbers.add(i * i);
       }
       
       return squaredNumbers; 
    }

}
```

#### Scala version

```scala
package main.scala

object SquareOfNumberScalaCalculator extends App {
  
     //Define a function to print elements in list    
     def printList(listToPrint: List[Int]) {
       
       //Call foreach method on each element of list
        listToPrint.foreach(println( _ ))
      }
        
      //Create a list
      val list = List(1, 2, 3, 4, 5)
    
      println("Printing original list")
      printList(list)
    
      //Square every element in the list by calling map method on list
      val squaredList = list.map( x => x * x)
      println("Priting squared list")
      printList(squaredList)
}
```
<commit_msg>Added first line explanation of scala code<commit_after>---
layout: post
published: true
title: Why Java developers should consider Scala
subtitle: You been a Java developer for a while and you are bored
date: '2017-01-03'
---
##    Happy New Year 2017 !!! 
    
If you are like me, you are a veteran Java developer for more than a decade. You are bored of writing boiler plate Java code year after year. The only Java changes you heard in a decade are Java version changes every four years or so. 
    
    
If you have been to hackactons or Startupweekends, you can see Ruby on Rails developers, AngularJS developers hack away building full stack web apps in couple of hours. In contrast as a Java developer you are still trying to create the folder structure for a traditional Java/J2EE application. How do you compete when your core skillset, Java in a JVM environment is such a big disadvantage? 
 
### New Kid on the block

#### You have a new language to the rescue. Welcome to Scala language !!!

Scala is a functional programming language built to run on Java JVM. That's right Scala needs Java JDK to run. <NAME> created scala after realizing all the downfalls of Java. In fact, Martin was original member of Java compiler team. Scala has no boilerplate code compared to Java.
        
* Scala has no boiler plate code

* To try some of these samples [download](http://scala-ide.org/) Eclipse IDE for Scala. 

#### Java version

```java
package com.harishblog;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SquareOfNumberCalculator {
 
  public static void main(String[] args) {
   
      List<Integer> myList = Arrays.asList(1, 2, 3, 4, 5);
      SquareOfNumberCalculator calculator = new SquareOfNumberCalculator();
      List<Integer> squaredNumbers = calculator.squareOfNumbers(myList);

      //Print original list
      System.out.println("Printing original numbers");
      calculator.printNumbers(myList);
      //Print squared list
      System.out.println("Printing squared numbers");
      calculator.printNumbers(squaredNumbers);
  }
	
   public void printNumbers(List<Integer> numbers) {
      
      for (Integer i : numbers) {
         System.out.println(" i --> " + i);
      }
   }

   public List<Integer> squareOfNumbers(List<Integer> numbers) {
       
       List<Integer> squaredNumbers = new ArrayList<Integer>();
       for (Integer i : numbers ) {
           squaredNumbers.add(i * i);
       }
       
       return squaredNumbers; 
    }

}
```

#### Scala version

```scala
package main.scala

object SquareOfNumberScalaCalculator extends App {
  
     //Define a function to print elements in list    
     def printList(listToPrint: List[Int]) {
       
       //Call foreach method on each element of list
        listToPrint.foreach(println( _ ))
      }
        
      //Create a list
      val list = List(1, 2, 3, 4, 5)
    
      println("Printing original list")
      printList(list)
    
      //Square every element in the list by calling map method on list
      val squaredList = list.map( x => x * x)
      println("Priting squared list")
      printList(squaredList)
}
```
The first line

**object SquareOfNumberScalaCalculator extends App**

Keyword **_object_** makes this a Singleton class. The **_extends App_** makes all the code within like a main method in Java.

{'fraction_non_alphanumeric': 0.07956989247311828, 'fraction_numerical': 0.00706605222734255, 'mean_word_length': 3.0166563849475634, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '979507', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1719, 'n_words': 762}