Intro to Computer Science & Programming. A Cranes Club Initiative

Similar documents
Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware

COMP 202 Java in one week

Program Fundamentals

Java Programming. Atul Prakash

CSC 1214: Object-Oriented Programming

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

3. Java - Language Constructs I

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

2 rd class Department of Programming. OOP with Java Programming

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

Course Outline. Introduction to java

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Introduction to Programming Using Java (98-388)

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

CompSci 125 Lecture 02

Chapter 2. Elementary Programming

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

An overview of Java, Data types and variables

Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of

Java: framework overview and in-the-small features

Java for Python Programmers. Comparison of Python and Java Constructs Reading: L&C, App B

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Language Fundamentals Summary

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Getting started with Java

DM550 Introduction to Programming part 2. Jan Baumbach.

Programming Lecture 3

CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

JAVA Ch. 4. Variables and Constants Lawrenceville Press

CS 231 Data Structures and Algorithms, Fall 2016

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

CS313D: ADVANCED PROGRAMMING LANGUAGE

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

CS111: PROGRAMMING LANGUAGE II

DM503 Programming B. Peter Schneider-Kamp.

Answer1. Features of Java

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M.

Index COPYRIGHTED MATERIAL

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

5/23/2015. Core Java Syllabus. VikRam ShaRma

Software Practice 1 Basic Grammar

Operators and Expressions

Object-oriented programming in...

3. Java - Language Constructs I

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

Building Java Programs. Introduction to Programming and Simple Java Programs

Games Course, summer Introduction to Java. Frédéric Haziza

c) And last but not least, there are javadoc comments. See Weiss.

Software Practice 1 - Basic Grammar Basic Syntax Data Type Loop Control Making Decision

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

CS 11 java track: lecture 1

Pace University. Fundamental Concepts of CS121 1

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Topics. Chapter 5. Equality Operators

COP 3330 Final Exam Review

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

ECE 122 Engineering Problem Solving with Java

Welcome to CSE 142! Zorah Fung University of Washington, Spring Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs

Preview from Notesale.co.uk Page 9 of 108

: Primitive data types Variables Operators if, if-else do-while, while, for. // // First Java Program. public class Hello {

Imports. Lexicon. Java/Lespérance 1. PROF. Y. LESPÉRANCE Dept. of Electrical Engineering & Computer Science

Modern Programming Languages. Lecture Java Programming Language. An Introduction

The Java Language The Java Language Reference (2 nd ed.) is the defining document for the Java language. Most beginning programming students expect

CS 61C: Great Ideas in Computer Architecture Introduction to C

Basic Concepts. Computer Science. Programming history Algorithms Pseudo code. Computer - Science Andrew Case 2

Welcome to CSE 142! Whitaker Brand. University of Washington, Winter 2018

Chapter 1. Introduction to Computers and Programming. M hiwa ahmad aziz

COMP 202 Java in one week

Programming with Java

-Alfred North Whitehead. Copyright Pearson Education, 2010 Based on slides by Marty Stepp and Stuart Reges from

Lecture Set 2: Starting Java

Language Features. 1. The primitive types int, double, and boolean are part of the AP

F1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept

boolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while

Chapter 2: Data and Expressions

Accelerating Information Technology Innovation

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Lecture Set 2: Starting Java

Computer Programming : C++

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

COMP 202. Java in one week

The keyword list thus far: The Random class. Generating "Random" Numbers. Topic 16

Language Reference Manual

About this exam review

Chapter 1 Introduction to Java

Topic 16. battle -they are strictly limited in number, they require fresh horses, and must only be made at decisive moments." -Alfred North Whitehead

PROGRAMMING FUNDAMENTALS

Java Basic Programming Constructs

Crash Course Review Only. Please use online Jasmit Singh 2

Introduction to. Android Saturday. Yanqiao ZHU Google Camp School of Software Engineering, Tongji University. In courtesy of The Java Tutorials

Introduction to Java

Transcription:

Intro to Computer Science & Programming A Cranes Club Initiative

Cranes Club To create opportunities for professionals of Unificationist background to network and apply their expertise to better serve their communities and the greater society.

First Half: Fundamentals of CS using Java What is computer science? Object-oriented programming input/output Data structures and algorithms multithreading and GUI network programming Android app

Computer Science The study of using computers to solve problems. How to solve problems bettermore and faster?

Computer A machine that can perform calculations and operations to accomplish various tasks. Fetch, decode, execute. Program A set of instructions that tell the computer what to do.

Programming Language A specific way to write instructions for the computer, with its own syntax and grammar. Compiled Interpreted Imperative Declarative

Compiled vs Interpreted Compiled: broken down into machine language before execution. Interpreted: executed by an interpreter, which itself is a running program.

Compiler Source Program Compiler Input Machine Code Output Pros: performs fast. Cons: hardware-specific, compile time.

Interpreter Source Program Input Interpreter Output Pros: dynamic, no compile time. Cons: lots of overhead, slow performance.

Pros: optimizations can be done on the fly. Cons: overall still slower than compiled. Just-In-Time Compiler Source Program Compiler Bytecode JIT Compiler Input Machine Code Output

Bytecode Source Program Compiler Bytecode Java Virtual Machine ARM machine code Intel machine code SPARC machine code AMD machine code

Breaking down a Program int a = 1; C++ MOV 1, %g2 ST %g2, [%a] SPARC Assembly BA 01 02 CF 02 A0 machine code hex 10111010 00000001 00000010 11001111 00000010 10100000 machine code binary

Declarative vs Imperative Declarative describes what: statements. Imperative tells how: control flow, state. Ex: get the min, max, and average price of a stock over the past week. //Declarative implementation //Imperative implementation double[] prices; prices = (results.selects(item => item.price).toarray()); double min = prices.min(); double max = prices.max(); double avg = prices.average(); double min = results[0].price; double max = results[0].price; double avg; double sum = 0; foreach (TradeRecord record in results) { if (record.price < min) min = record.price; if (record.price > max) max = record.price; sum += record.price; } avg = sum / results.count;

Why Java? it is used everywhere- Android, web servers, enterprise systems, desktop applications, etc. Most popular language for jobs. Will help you learn other languages more easily (C#, Python, etc.) But, it s quite verbose.

Why Java?

Developer Jobs per Language in NY Job market by Language Java C# C++ JavaScript Python Indeed.com 7964 3197 3573 6126 4711 Dice.com 1876 763 726 1245 921 CareerBuilder. com 273 136 84 199 138

Average Salary (source: Glassdoor) Associate Software Engineer Software Engineer Senior Software Engineer Staff Software Engineer Software Developer Senior Software Developer Embedded Software Engineer $69,305 $90,374 $106,575 $124,324 $86,226 $122,296 $82,739

Object Oriented Design living things objects classes behaviors interfaces inheritance encapsulation composition polymorphism plant animal mammal insect bird amphibian reptile primates hominidae human beings

Overview of Objects and Classes Class: blueprint defining a set of behaviors (functions, methods) and states (fields, properties). aka Type. Object: an instance of a class. All Java programs are made up of classes and objects. Furthermore, all classes descend from the Object class.

Object behaviors (methods): clone() equals(object obj) getclass() hashcode() notify() notifyall() tostring() wait() The Object Class

The Object Class The Progenitor Class (the God class!) All classes in Java past, present, and future can do anything the Object class can do.

Example: Let s Create a Dog Class What are some dog behaviors? Bark Growl Whine Eat Sleep Fetch What are some dog properties? Height Weight Coat Color Sex Temperament

Dog Class in Java public class Dog { int height; int weight; String coat; String color; Boolean sex; Enum temperament; } void bark(){} void growl(){} void whine(){} void eat(string meal){} void sleep(int hours){} void fetch(string object){}

A Dog Class Object Recall an object is an instance of a class. Fido, AirBud, Lassie, RinTinTin are all instances of the Dog class (i.e. they are all Dog objects): They are also Object Class objects. Dog Fido = new Dog(); Dog AirBud = new Dog(); Dog Lassie = new Dog(); Dog RinTinTin = new Dog(); Fido.bark(); AirBud.fetch("basketball"); Lassie.eat("dog food"); RinTinTin.color = "black"; Fido.toString();

Classic Hello World Example public class Main { } public static void main(string[] args) { // write your code here System.out.println("Hello Cheon Il Guk!"); } Hello Cheon Il Guk! Process finished with exit code 0

Syntax and Semantics Syntax: the grammatical rules of a language. Semantics: the meanings of a language. English syntax error: Bear honey the likes eat to. English semantic error:

Java Syntax Overview Reference Types vs Primitive Types Variables Arithmetic Operators Console I/O Control Statements Comments Keywords

Reference Type vs Primitive Type Reference Type: descendant of Object Primitive Type: Simple numerical types. Not descendant of Object.

Reference Type Reference: the object s name. The new keyword is required to actually create the object in memory (in the heap). Dog Fido; Fido.bark(); Fido = new Dog(); Fido.bark(); //object reference only. No Dog object yet. //this will not work! //Dog object is now created. //this will work!

Primitive Type The new keyword is not used. These objects go on the stack. Wrapper classes are Reference Types int x = 10; Integer x_wrapper = new Integer(x); x.tostring(); x_wrapper.tostring(); //primitive type int object value of 10 on stack //wrapper class for primitive type int in heap //this won't work! //this will work!

Java s Primitive Types Primitive type Size Minimum Maximum boolean char 16-bit Unicode 0 Unicode 2 16-1 byte 8-bit -128 +127 short 16-bit -2 15 +2 15 1 int 32-bit -2 31 +2 31 1 long 64-bit -2 63 +2 63 1 float 32-bit IEEE754 IEEE754 double 64-bit IEEE754 IEEE754 void

Variables Named value. Left side = name (identifier) Right side = value (literals, constants, expressions) int h = 13; int i = h * 2 / 4; h++; String word = "Hello"; Dog Pluto = new Dog(); Integer holla = new Integer(h);

Arithmetic Operators Operator Description Example Associativity []. () array access, method call Fido.bark(); dalmations[100] = Pongo ; Left to Right ++ -- -! increment, decrement, negative, NOT weight++; degrees--; degrees = -40; verdict =!GUILTY; Left to Right, Right to Left / % * divide, modulo, multiply gdppc = gdp / pop; odd = number % 2; e = m * c * c; Left to Right + - add, subtract sum = 1 + 1; diff = sum - 1; Left to Right < <= > >= LT, LTE, GT, GTE if (Fido.weight < RinTinTin.weight) Left to Right ==!= equality if (AirBud.height == Lassie.height) Left to Right && conditional AND, conditional OR if (Fido.weight < 10 && Fido.height > 20) { System.out.println( Fido is too skinny! ); } Right to Left? : ternary, conditional operator (a? b) result = true : result = false; Right to Left = += -= *= /= %= assignment a += 4; google_stock -= 34.0; Right to Left

Console I/O Output: use System.out object. Input: use Scanner object and System. in object. System.out.println("Hello Cheon Il Guk!"); final double PI = 22.0 / 7.0; System.out.println(PI); System.out.format("%.5f\n", PI); Scanner scanner = new Scanner(System.in); String sentence = scanner.nextline(); System.out.println(sentence); int number = scanner.nextint(); System.out.println(number); Hello Cheon Il Guk! 3.142857142857143 3.14286 welcome to Intro to Comp Sci and Programming welcome to Intro to Comp Sci and Programming 1234 1234 Process finished with exit code 0

Conditional Statements if/else conditional logic Can be nested Curly braces { } are important. if (5 > 6) System.out.println("5 is greater than 6"); else System.out.println("6 is greater than 5"); if (PI > 3) { if (PI < 2){ System.out.println("PI is greater than 3"); System.out.println("PI is less than 4"); } } 6 is greater than 5 4 is greater than 10 Process finished with exit code 0 if (10 > 3) if (4 > 10) System.out.println("10 is greater than 3"); System.out.println("4 is greater than 10");

Comments for documentation purposes // for single line comment /* */ for multi-line comment // this is a single line comment /* this is a multi-line comment! */

Java Keywords reserved by the Java language cannot be used for naming things Dog short = new Dog(); //can't do that!

Java Keywords abstract continue for new switch assert *** default goto * package synchronized boolean do if private this break double implements protected throw byte else import public throws case enum **** instanceof return transient catch extends int short try char final interface static void class finally long strictfp ** volatile const * float native super while

Homework 1 Tip Calculator Due by next week s class For more Java practice, go to http://codingbat. com/ Now it s quiz time!!!!!