Java Type erosure

Type Erasure Generics were introduced to the Java language to provide tighter type checks at compile time and to support generic programming. To implement generics, the Java compiler applies type erasure to: Replace all type parameters in generic types with their bounds or Object if the type parameters are unbounded…

printf on Java

Java printf( ) MethodQuick Reference System.out.printf( “format-string” [, arg1, arg2, … ] ); Format String: Composed of literals and format specifiers. Arguments are required only if there are format specifiers in the format string. Format specifiers include: flags, width, precision, and conversion characters in the following sequence: % [flags] [width] [.precision] conversion-character ( square brackets…

How to have a hello world in Scala to run within an IDE

Java style main method: object Hello {   def main(args: Array[String]) {       println("Hello, World!")    } } Or Instead of providing a main method, you can extend the App trait and place the program code into the constructor body:  object Hello extends App…

Scala Exceptions

Exceptions Scala exceptions work the same way as in Java or C++. When you throw an exception, for example throw new IllegalArgumentException("x should not be negative") Then the current computation is aborted, and the runtime system looks for an exception handler that can accept an IllegalArgumentException. Control resumes with…

Break && Continue in Scala

Scala has no break or continue statements To break out of a loop. What to do if you need a break? Here are a few options: Use a Boolean control variable instead. Use nested functions—you can return from the middle of a function. Use the break method in the…

How to install JDK8 on Ubuntu

sudo apt-get install python-software-properties sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java8-installer …

Closures in Scala

A closure is a function, whose return value depends on the value of one or more variables declared outside this function. Consider the following piece of code with anonymous function: val multiplier = (i:Int) => i * 10 Here the only variable used in the function body, i * 0, is i, which…

Will Spark take over Hadoop

Matei Zaharia, CTO @ Databricks It depends a bit on what you mean by "Hadoop". Some people take Hadoop to mean a whole ecosystem (HDFS, Hive, MapReduce, etc), in which case Spark is designed to fit well within the ecosystem (reading from any input source that MapReduce supports through the InputFormat…

Variance Basics in Java and Scala

Variance Terminology If you’re not familiar with the term “variance”, here’s what it means with respect to Java. Java arrays are covariant. That means that an array of B is a subtype of an array of A, provided that B is a subtype of A. The type-subtype relationship…

introduction to SBT

Let's start by creating a project directory with source code A valid sbt project can be a directory containing a single source file. Try creating a directory hello with a file hw.scala, containing the following: object Hi {       def main(args: Array[String]) = println("Hi!") } Now from…

Java8 Lambda Expressions

Lambda expression - Functional interface Lambda syntax (parameters) -> expression (parameters) -> statement (parameters) -> { statements } Lambda expression examples (int x, int y) -> x + y () -> System.out.println("hi " + s); (String s) -> { int n = s.length(); return n; } Run a Runnable Runnable r = () -> System.out.println…

Let's Play

Anatomy of a Play application The standard application layout The layout of a Play application is standardized to keep things as simple as possible. After a first successful compile, a standard Play application looks like this: There are three standard packages in the app directory, one for each component of…

Git tutorial

Setting Up a Git Repository git init The git init command initializes a new Git repository. If you want to place a project under revision control, this is the first command you need to learn. git init Command Tutorial The git init command creates a new Git repository. It can…

Cassandra MongoDB CouchDB Redis Riak HBase Couchbase Neo4j Hypertable ElasticSearch Accumulo VoltDB Scalaris

Redis (V2.8) Written in: C Main point: Blazing fast License: BSD Protocol: Telnet-like, binary safe Disk-backed in-memory database, Dataset size limited to computer RAM (but can span multiple machines' RAM with clustering) Master-slave replication, automatic failover Simple values or data structures by keys but complex operations like ZREVRANGEBYSCORE. INCR…

Play Framework for Java developers

Welcome to the Play2torial for Java! This tutorial will help teach you how to build Java web applications with Play Framework 2. https://github.com/jamesward/play2torial/blob/master/JAVA.md Before you get started you will need to install git and Play 2. Test that the play command works…

Functional Programming with Scala

Functional Programming (FP) is programming through building blocks of functions. Object-Oriented Programming(OOP) however is programming building blocks of objects. In Scala, functions are first class bulding blocks of objects. Unlike many other FPs Programs in Scala can be constructed through both the objects and/or functions. In Scala functions…

Static vs Dynamic Types

Static Typing Static typing is that variables need to be defined before they’re used. This implies that static typing has to do with the explicit declaration (or initialization) of variables before they’re employed. C#, Java,C, C++ are all static typed languages. /* Java code */ int i; .. i=10…