38
Introduction to Computer Science I Introduction to Programming Janyl Jumadinova 22-24 January, 2018

Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

  • Upload
    others

  • View
    20

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Introduction to Computer Science I

Introduction to Programming

Janyl Jumadinova22-24 January, 2018

Page 2: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

What is Computer Science?

I A computation is a sequence of well-defined operations thatlead from an initial starting point to a desired final outcome

Computer science is the study of computation

2/23

Page 3: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

What is Computer Science?

I A computation is a sequence of well-defined operations thatlead from an initial starting point to a desired final outcome

Computer science is the study of computation

2/23

Page 4: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Computer science is the study of computation

I investigating problems that can be solved computationally

I programming languages used to describe computations

I machines that carry out computations

I theoretical limits of computation (what is or is not computable)

I computational solutions to problems in math, science,medicine, business, education, journalism, ...

Computers play a key role

3/23

Page 5: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Computer science is the study of computation

I investigating problems that can be solved computationally

I programming languages used to describe computations

I machines that carry out computations

I theoretical limits of computation (what is or is not computable)

I computational solutions to problems in math, science,medicine, business, education, journalism, ...

Computers play a key role

3/23

Page 6: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Computer science is the study of computation

I investigating problems that can be solved computationally

I programming languages used to describe computations

I machines that carry out computations

I theoretical limits of computation (what is or is not computable)

I computational solutions to problems in math, science,medicine, business, education, journalism, ...

Computers play a key role

3/23

Page 7: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Computer science is the study of computation

I investigating problems that can be solved computationally

I programming languages used to describe computations

I machines that carry out computations

I theoretical limits of computation (what is or is not computable)

I computational solutions to problems in math, science,medicine, business, education, journalism, ...

Computers play a key role

3/23

Page 8: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Computer science is the study of computation

I investigating problems that can be solved computationally

I programming languages used to describe computations

I machines that carry out computations

I theoretical limits of computation (what is or is not computable)

I computational solutions to problems in math, science,medicine, business, education, journalism, ...

Computers play a key role

3/23

Page 9: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Computer science is the study of computation

I investigating problems that can be solved computationally

I programming languages used to describe computations

I machines that carry out computations

I theoretical limits of computation (what is or is not computable)

I computational solutions to problems in math, science,medicine, business, education, journalism, ...

Computers play a key role

3/23

Page 10: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Computer science is the study of computation

I investigating problems that can be solved computationally

I programming languages used to describe computations

I machines that carry out computations

I theoretical limits of computation (what is or is not computable)

I computational solutions to problems in math, science,medicine, business, education, journalism, ...

Computers play a key role

3/23

Page 11: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Applications of Computer ScienceMotion Analysis

4/23

Page 12: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Applications of Computer Science

Animated Movies ...

5/23

Page 13: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Applications of Computer Science

... are made by Computer Scientists

6/23

Page 14: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Applications of Computer Science

I Think about your interests ...

I You can bet computer scientists are working in these areas!7/23

Page 15: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

What is a computer?

8/23

Page 16: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Hardware/Software

I Software/hardware relationship:I Hardware is controlled by softwareI Software is the collection of instructions that you issue to the

computer to perform actions and make decisions

9/23

Page 17: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Simple Structure

10/23

Page 18: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

What is Computer Programming?

I Programming is the act of writing usable and useful software

I A program is a set of instructions

11/23

Page 19: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

What is Computer Programming?

I Programming is the act of writing usable and useful software

I A program is a set of instructions

11/23

Page 20: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Programming Language

I We will use Java programming language in this class

I Java is a programming language originally developed by SunMicrosystems and released in 1995 as a core component ofSun’s Java platform

12/23

Page 21: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

HISTORY OF JAVA

I Started development in 1991 at Sun

I Originally called Oak

I Intended for smart consumer-electronic devices

I Derives much syntax/concepts from C++

I BCPL → B → C → C++ → Java

I Development almost halted, but 1993 saw introduction of web;Java was revamped to be able to easily add dynamic content toweb pages

I Formally announced and released in May 1995

I Released under GPL to the public in May 200713/23

Page 22: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Programming in Java

I Java is an object-oriented programming language

I Objects are fundamental elements that make up a program

I Java has a library of software, called Java API, that is availablefor your use

14/23

Page 23: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Programming in Java

I Java is an object-oriented programming language

I Objects are fundamental elements that make up a program

I Java has a library of software, called Java API, that is availablefor your use

14/23

Page 24: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Programming in Java

I Java is an object-oriented programming language

I Objects are fundamental elements that make up a program

I Java has a library of software, called Java API, that is availablefor your use

14/23

Page 25: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Java program development process

15/23

Page 26: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Simple first Java Program: “Hello World”

// This is the first program people write in a new language,

// the "Hello World!". In Java, this file must be named

// Welcome.java, with the first part of the name, Welcome, being

// the same as the name of the class. The filename itself

// (not the class name) must always end in .java to indicate

// to the operating system that it’s a java source file.

public class Welcome

{

public static void main ( String args[] )

{

System.out.println ( "Hello World!" );

}

}

16/23

Page 27: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Comments

Comments in Java can be one of three styles:

I Single line: starts at // anywhere on a line, ends at the end ofthat line

I Multi-line: starts with character sequence /* anywhere, endswith character sequence */ anywhere after that can spanmultiple lines

I javadoc: starts with character sequence /** anywhere, endswith character sequence */ anywhere, after that uses javadocutility to create HTML documentation from code

17/23

Page 28: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

I public class Welcome:I public means that something is available across packages

(reserved word)I Name of the class has to be the same as the name of the .java

file

I public static void main ( String identifier[] ):

I The particular form of main is required by Java.I JVM starts executing here!I main is a static method, it is part of its class and not part of

objects.I Strings in Java are sequence of characters

I Braces { } are used to collect statements into a ”block”

I Statements in Java end with semicolons.

18/23

Page 29: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

I public class Welcome:I public means that something is available across packages

(reserved word)I Name of the class has to be the same as the name of the .java

file

I public static void main ( String identifier[] ):

I The particular form of main is required by Java.I JVM starts executing here!I main is a static method, it is part of its class and not part of

objects.I Strings in Java are sequence of characters

I Braces { } are used to collect statements into a ”block”

I Statements in Java end with semicolons.

18/23

Page 30: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

I public class Welcome:I public means that something is available across packages

(reserved word)I Name of the class has to be the same as the name of the .java

file

I public static void main ( String identifier[] ):

I The particular form of main is required by Java.I JVM starts executing here!I main is a static method, it is part of its class and not part of

objects.I Strings in Java are sequence of characters

I Braces { } are used to collect statements into a ”block”

I Statements in Java end with semicolons.

18/23

Page 31: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

I public class Welcome:I public means that something is available across packages

(reserved word)I Name of the class has to be the same as the name of the .java

file

I public static void main ( String identifier[] ):

I The particular form of main is required by Java.I JVM starts executing here!I main is a static method, it is part of its class and not part of

objects.I Strings in Java are sequence of characters

I Braces { } are used to collect statements into a ”block”

I Statements in Java end with semicolons.

18/23

Page 32: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Printing

I println: New line after printing

I print: No new line

I printf: Can specify format - may learn this later

19/23

Page 33: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Character Strings

string literal in class String

“ABC”“This is interesting”“ ”“91”

I Use print or println methods to print a character string to theterminal

I System.out.println(“CMPSC 111”);

I the string “CMPSC 111” is a parameter: data sent to a method

20/23

Page 34: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Character Strings

string literal in class String

“ABC”“This is interesting”“ ”“91”

I Use print or println methods to print a character string to theterminal

I System.out.println(“CMPSC 111”);

I the string “CMPSC 111” is a parameter: data sent to a method

20/23

Page 35: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

String Concatenation

appending one string to the end of another: use + operator

“This is ”+ “interesting”“Your grade is ”+ “91”

I + is also used for arithmetic addition

I System.out.println(”Adding ”+ 12 + 23); is not the same asSystem.out.println(”Adding ”+ (12 + 23));

21/23

Page 36: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

String Concatenation

appending one string to the end of another: use + operator

“This is ”+ “interesting”“Your grade is ”+ “91”

I + is also used for arithmetic addition

I System.out.println(”Adding ”+ 12 + 23); is not the same asSystem.out.println(”Adding ”+ (12 + 23));

21/23

Page 37: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Escape Sequences

I Escape sequences, or escape characters, begin with a slash andare immediately followed by another character.

I This two-character sequence, inside “ ” allows you to controlyour output (\n, \t, \b) or output characters you wouldn’totherwise be able to (\\, \”) inside a string.

22/23

Page 38: Introduction to Computer Science I - Introduction to ... · Computer science is the study of computation I investigating problems that can be solved computationally I programming

Escape Sequences

Seq Meaning Example Code

\n New line System.out.println(”Hi\nThere”);\t Horizontal tab System.out.println(”What’s\tup?”);\b Backspace System.out.println(”Hi\b Hey”);\\ Backslash System.out.println(”Back\\Slash”);\” Double quote System.out.println(”Dbl\”Quote”);

23/23