COSC282 BIG DATA ANALYTICS FALL 2015 LECTURE 2 - SEP 9

Similar documents
Pemrograman Dasar. Basic Elements Of Java

Introduction to Java

Java Crash Course Part I

Introduction to Java. CS 3: Computer Programming in Java

Variables, Constants, and Data Types

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

CS 106 Introduction to Computer Science I

Analyse et Conception Formelle. Lesson 5. Crash Course on Scala

Example of a Java program

1001ICT Introduction To Programming Lecture Notes

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Java Programming Fundamentals

A Scala Tutorial for Java programmers

J a v a Quiz (Unit 3, Test 0 Practice)

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Introduction to Python

Java programming for C/C++ developers

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

Overview. java.math.biginteger, java.math.bigdecimal. Definition: objects are everything but primitives The eight primitive data type in Java

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example

Lecture 5: Java Fundamentals III

SparkLab May 2015 An Introduction to

Number Representation

Objective-C Tutorial

Introduction to Python

public static void main(string[] args) { System.out.println("hello, world"); } }

Chapter 7D The Java Virtual Machine

Crash Course in Java

Introduction to Java Lecture Notes. Ryan Dougherty

Sources: On the Web: Slides will be available on:

Computer Programming Tutorial

Introduction to Data Structures

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Java Types and Enums. Nathaniel Osgood MIT April 25, 2012

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

A list of data types appears at the bottom of this document. String datetimestamp = new java.sql.timestamp(system.currenttimemillis()).

How to Run Spark Application

Java Basics: Data Types, Variables, and Loops

Installing Java (Windows) and Writing your First Program

Chapter 1 Java Program Design and Development

Computational Mathematics with Python

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Introduction to Python for Text Analysis

Quick Introduction to Java

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

Java Interview Questions and Answers

CSC 551: Web Programming. Fall 2001

COSC 6397 Big Data Analytics. 2 nd homework assignment Pig and Hive. Edgar Gabriel Spring 2015

Object Oriented Software Design

Section 6 Spring 2013

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

An Overview of Java. overview-1

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Introduction to Object-Oriented Programming

CS170 Lab 11 Abstract Data Types & Objects

Creating a Java application using Perfect Developer and the Java Develo...

Computational Mathematics with Python

CS Unix Tools & Scripting Lecture 9 Shell Scripting

How to Install Java onto your system

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Sample CSE8A midterm Multiple Choice (circle one)

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June Dr.-Ing.

Beyond the Mouse A Short Course on Programming

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

MXwendler Javascript Interface Description Version 2.3

Spark ΕΡΓΑΣΤΗΡΙΟ 10. Prepared by George Nikolaides 4/19/2015 1

Shell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script

CS106A, Stanford Handout #38. Strings and Chars

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

Semester Review. CSC 301, Fall 2015

Lecture 22: C Programming 4 Embedded Systems

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Hadoop + Clojure. Hadoop World NYC Friday, October 2, Stuart Sierra, AltLaw.org

Informatica e Sistemi in Tempo Reale

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Building Java Programs

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

[1] Learned how to set up our computer for scripting with python et al. [3] Solved a simple data logistics problem using natural language/pseudocode.

Basic Programming and PC Skills: Basic Programming and PC Skills:

Outline Basic concepts of Python language

Programmierpraktikum

Installing Java. Table of contents

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Comp151. Definitions & Declarations

LAB 2 SPARK / D-STREAM PROGRAMMING SCIENTIFIC APPLICATIONS FOR IOT WORKSHOP

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

Getting t Ge o K tting t no o K w Scala no for fo r Da D t a a t a Sc S i c e i n e c n e

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Contents. 9-1 Copyright (c) N. Afshartous

Transcription:

COSC282 BIG DATA ANALYTICS FALL 2015 LECTURE 2 - SEP 9 1

HOW WAS YOUR WEEKEND? Image source: http://www.liverunsparkle.com/ its-a-long-weekend-up-in-here/ 1. Read and Post on Piazza 2. Installed JDK & Spark 3. Submit Your Assignment 1 (Due Today 11:59pm, Blackboard) 4. Office hours: Tue 1-2, 6-7:30, Wed 6-7:30PM 2

HTTPS://PIAZZA.COM/GEORGETOWN/FALL2015/COSC282/HOME PIAZZA 3

SCALA CRASH COURSE Stairs in Italian Why Scala? Spark is written in Scala originally Quite fun 4

WHAT DO YOU KNOW ABOUT SCALA? 5

THINGS ABOUT SCALA Object-Oriented classes can be extended every value is an object Functional every function is a value so, every function is an object Statically typed type inference saves us efforts to write explicit types Interoperates with Java can use any Java class and can be called by Java 6

WHAT DO YOU WANT TO LEARN ABOUT SCALA? 7

SCALA FOR TODAY Syntax define variables define functions closures collection control structures Compile using sbt A show-and-tell 8

LET S WORK IN SCALA SHELL 9

VARIABLES var x: Int = 5 var x = 5 // type inferred val mystate = free fall // read-only, final, value cannot be changed 10

DATA TYPES Byte 8 bit signed value. Range from -128 to 127 Short 16 bit signed value. Range -32768 to 32767 Int 32 bit signed value. Range -2147483648 to 2147483647 Long 64 bit signed value. -9223372036854775808 to 9223372036854775807 Float Double Char String Boolean 32 bit IEEE 754 single-precision float 64 bit IEEE 754 double-precision float 16 bit unsigned Unicode character. Range from U+0000 to U+FFFF A sequence of Chars Either the literal true or the literal false All the data types listed above are objects. There are no primitive types like in Java. This means that you can call methods on an Int, Long, etc. 11

FUNCTIONS 12

FUNCTIONS first letter in function name needs to be lower case def square(x: Int): Int = x*x def square(x: Int): Int = { x*x } def announce(text: String) = { println(text) } def addtwo(x: Int): Int = x + 2 13

CLOSURES a function, whose return value depends on the value of one or more variables declared outside this function var factor = 3 def multiplier = (i:int) => i * factor // factor is the variable outside this function we could also say var multiplier = (i:int) => i * factor What will be the output for multiplier(1) multiplier(2) 14

CLOSURES multiplier(1) // 3 multiplier(2) // 6 15

CONTROL STRUCTURES var x = 30; if (x<20) { println ( free fall ); } else{ Semicolon is optional println ( parachute ); } 16

CONTROL STRUCTURES var x = 30; var mystate = free fall ; while (x>0) { if (x< 15) { mystate = parachute } ; println (mystate); x = x - 1; } 17

CONTROL STRUCTURES As such there is no built-in break nor continue statements available in Scala well, for the later versions of Scala 2.8, there are objects defined for the purpose. 18

COLLECTIONS IN SCALA Scala collections have mutable and immutable collections. A mutable collection can be updated or extended in place. This means you can change, add, or remove elements of a collection Immutable collections, by contrast, never change. 19

COMMON COLLECTIONS Mutable Map, HashMap, ListMap, MutableList, LinkedList, Seq Immutable List, Array, Vector, Set, String, Seq 20

PROCESSING COLLECTIONS val list = List(1, 2, 3) list.foreach(x => println(x)) // prints 1, 2, 3 list.foreach(println) // same list.map(x => x + 2) // returns a new List(3, 4, 5) list.map(_ + 2) // same list.filter(x => x % 2 == 1)// returns a new List(1, 3) list.filter(_ % 2 == 1) // same 21

WHAT DO YOU GET? > import scala.collection.mutable > val map = mutable.map.empty[string, Int] > map("hello") = 1 > map("there") = 2 > map > map.foreach(println) > map("hello") > map.filter(map( hello")==1) > map.filter(_==pair( hello",1)) > map.filter(_==pair( there",2)) > map.filter(_==pair("there",1)) 23

> import scala.collection.mutable > val map = mutable.map.empty[string, Int] > map("hello") = 1 > map("there") = 2 > map > map.foreach(println) > map( hello") // res25: Int = 1 > map.filter(map( hello )==1) // <console>:14: error: type mismatch; // found : Boolean // required: ((String, Int)) => Boolean // map.filter(map("hello")==1) > map.filter(_==pair( hello,1)) // res27: scala.collection.mutable.map[string,int] = Map(hello -> 1) > map.filter(_==pair( there,2)) // res29: scala.collection.mutable.map[string,int] = Map(there -> 2) > map.filter(_==pair( there",1)) // res30: scala.collection.mutable.map[string,int] = Map() 24

PROCESSING COLLECTIONS map(f: T => U): Seq[U] // Each element is result of f flatmap(f: T => Seq[U]): Seq[U] // One to many map filter(f: T => Boolean): Seq[T] // Keep elements passing f exists(f: T => Boolean): Boolean // True if one element passes f forall(f: T => Boolean): Boolean // True if all elements pass 25

LET S WORK IN SCRIPTS - USING SBT TO COMPILE

STEP 1: SETUP SBT From the directory that you copy from the spark thumb drive Go to spark_disk/sbt NOT spark_disk/spark/sbt chmod a+x sbt mkdir -p src/main/scala 27

STEP 2: WRITE YOUR HELLOWORLD.SCALA Create a file called HelloWord.scala using your text editor in Mac, you could use emacs, vim or nano; You might want to open another Terminal window to work on the editor while keep the./sbt directory active in one Terminal in Windows, you could use NotePad or WordPad as the text editor Put the following line in your file object HelloWorld { def main(args: Array [String]) = println ("Hi, cosc 282!") } mv HelloWorld.scala src/main/scala/. Note: Make sure there is only one.scala file in src/main/scala/. We will talk about how to build a package later. As for now, just compile one file 28

STEP 3: COMPILE AND RUN go back to the sbt directory cd./spark_disk/sbt type./sbt from the sbt prompt, type run > run keep typing run, the program will be compiled and run again > run 29

YOU SHOULD GET SOMETHING LIKE THIS 30

FUN TIME

SHOW-AND-TELL val states = List ("blue sky", "crazy", "jump", "free fall", "parachute", "alive", "dead", "cloudy") var mystate = "" println ("I have a friend " ) println ("Sometimes she is " + states(1) ) print ("When it is ") val r = scala.util.random var chance = r.nextint(100) if (chance >=50) { mystate = states(7) println(mystate) println ("She is " + states(5) ) } else { mystate = states(0) println(mystate) println("she " + states(2)) } 32

THE STORY LOOKS LIKE:

ASSIGNMENT 2 - FINISH THE STORY Using control structures (Bonus) Using processes for collections What to submit: your codes screencapture of at least 4 random runs of results Due: Next Wed 9/16, 11:59pm 34

HERE COMES THE REAL SHOW-AND-TELL

COURSE VIDEOS a few videos are put on piazza. they are the demos and assignment related procedures that we have shown in class. Please check them out