Introduction to Computer Science I Introduction to Programming - - PowerPoint PPT Presentation

introduction to computer science i
SMART_READER_LITE
LIVE PREVIEW

Introduction to Computer Science I Introduction to Programming - - PowerPoint PPT Presentation

Introduction to Computer Science I Introduction to Programming Janyl Jumadinova 22-24 January, 2018 What is Computer Science? A computation is a sequence of well-defined operations that lead from an initial starting point to a desired final


slide-1
SLIDE 1

Introduction to Computer Science I

Introduction to Programming

Janyl Jumadinova 22-24 January, 2018

slide-2
SLIDE 2

What is Computer Science?

◮ A computation is a sequence of well-defined operations that

lead from an initial starting point to a desired final outcome

2/23

slide-3
SLIDE 3

What is Computer Science?

◮ A computation is a sequence of well-defined operations that

lead from an initial starting point to a desired final outcome

Computer science is the study of computation

2/23

slide-4
SLIDE 4

Computer science is the study of computation

3/23

slide-5
SLIDE 5

Computer science is the study of computation

◮ investigating problems that can be solved computationally 3/23

slide-6
SLIDE 6

Computer science is the study of computation

◮ investigating problems that can be solved computationally ◮ programming languages used to describe computations 3/23

slide-7
SLIDE 7

Computer science is the study of computation

◮ investigating problems that can be solved computationally ◮ programming languages used to describe computations ◮ machines that carry out computations 3/23

slide-8
SLIDE 8

Computer science is the study of computation

◮ investigating problems that can be solved computationally ◮ programming languages used to describe computations ◮ machines that carry out computations ◮ theoretical limits of computation (what is or is not computable) 3/23

slide-9
SLIDE 9

Computer science is the study of computation

◮ investigating problems that can be solved computationally ◮ programming languages used to describe computations ◮ machines that carry out computations ◮ theoretical limits of computation (what is or is not computable) ◮ computational solutions to problems in math, science,

medicine, business, education, journalism, ...

3/23

slide-10
SLIDE 10

Computer science is the study of computation

◮ investigating problems that can be solved computationally ◮ programming languages used to describe computations ◮ machines that carry out computations ◮ theoretical limits of computation (what is or is not computable) ◮ computational solutions to problems in math, science,

medicine, business, education, journalism, ... Computers play a key role

3/23

slide-11
SLIDE 11

Applications of Computer Science

Motion Analysis

4/23

slide-12
SLIDE 12

Applications of Computer Science

Animated Movies ...

5/23

slide-13
SLIDE 13

Applications of Computer Science

... are made by Computer Scientists

6/23

slide-14
SLIDE 14

Applications of Computer Science

◮ Think about your interests ... ◮ You can bet computer scientists are working in these areas! 7/23

slide-15
SLIDE 15

What is a computer?

8/23

slide-16
SLIDE 16

Hardware/Software

◮ Software/hardware relationship:

◮ Hardware is controlled by software ◮ Software is the collection of instructions that you issue to the

computer to perform actions and make decisions

9/23

slide-17
SLIDE 17

Simple Structure

10/23

slide-18
SLIDE 18

What is Computer Programming?

11/23

slide-19
SLIDE 19

What is Computer Programming?

◮ Programming is the act of writing usable and useful software ◮ A program is a set of instructions 11/23

slide-20
SLIDE 20

Programming Language

◮ We will use Java programming language in this class ◮ Java is a programming language originally developed by Sun

Microsystems and released in 1995 as a core component of Sun’s Java platform

12/23

slide-21
SLIDE 21

HISTORY OF JAVA

◮ Started development in 1991 at Sun ◮ Originally called Oak ◮ Intended for smart consumer-electronic devices ◮ Derives much syntax/concepts from C++ ◮ BCPL → B → C → C++ → Java ◮ Development almost halted, but 1993 saw introduction of web;

Java was revamped to be able to easily add dynamic content to web pages

◮ Formally announced and released in May 1995 ◮ Released under GPL to the public in May 2007 13/23

slide-22
SLIDE 22

Programming in Java

◮ Java is an object-oriented programming language 14/23

slide-23
SLIDE 23

Programming in Java

◮ Java is an object-oriented programming language ◮ Objects are fundamental elements that make up a program 14/23

slide-24
SLIDE 24

Programming in Java

◮ Java is an object-oriented programming language ◮ Objects are fundamental elements that make up a program ◮ Java has a library of software, called Java API, that is available

for your use

14/23

slide-25
SLIDE 25

Java program development process

15/23

slide-26
SLIDE 26

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

slide-27
SLIDE 27

Comments

Comments in Java can be one of three styles:

◮ Single line: starts at // anywhere on a line, ends at the end of

that line

◮ Multi-line: starts with character sequence /* anywhere, ends

with character sequence */ anywhere after that can span multiple lines

◮ javadoc: starts with character sequence /** anywhere, ends

with character sequence */ anywhere, after that uses javadoc utility to create HTML documentation from code

17/23

slide-28
SLIDE 28

◮ public class Welcome:

◮ public means that something is available across packages

(reserved word)

◮ Name of the class has to be the same as the name of the .java

file

18/23

slide-29
SLIDE 29

◮ public class Welcome:

◮ public means that something is available across packages

(reserved word)

◮ Name of the class has to be the same as the name of the .java

file

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

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

  • bjects.

◮ Strings in Java are sequence of characters

18/23

slide-30
SLIDE 30

◮ public class Welcome:

◮ public means that something is available across packages

(reserved word)

◮ Name of the class has to be the same as the name of the .java

file

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

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

  • bjects.

◮ Strings in Java are sequence of characters

◮ Braces { } are used to collect statements into a ”block” 18/23

slide-31
SLIDE 31

◮ public class Welcome:

◮ public means that something is available across packages

(reserved word)

◮ Name of the class has to be the same as the name of the .java

file

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

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

  • bjects.

◮ Strings in Java are sequence of characters

◮ Braces { } are used to collect statements into a ”block” ◮ Statements in Java end with semicolons. 18/23

slide-32
SLIDE 32

Printing

◮ println: New line after printing ◮ print: No new line ◮ printf: Can specify format - may learn this later 19/23

slide-33
SLIDE 33

Character Strings

string literal in class String

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

20/23

slide-34
SLIDE 34

Character Strings

string literal in class String

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

◮ Use print or println methods to print a character string to the

terminal

◮ System.out.println(“CMPSC 111”); ◮ the string “CMPSC 111” is a parameter: data sent to a method 20/23

slide-35
SLIDE 35

String Concatenation

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

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

21/23

slide-36
SLIDE 36

String Concatenation

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

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

◮ + is also used for arithmetic addition ◮ System.out.println(”Adding ”+ 12 + 23); is not the same as

System.out.println(”Adding ”+ (12 + 23));

21/23

slide-37
SLIDE 37

Escape Sequences

◮ Escape sequences, or escape characters, begin with a slash and

are immediately followed by another character.

◮ This two-character sequence, inside “ ” allows you to control

your output (\n, \t, \b) or output characters you wouldn’t

  • therwise be able to (\\, \”) inside a string.

22/23

slide-38
SLIDE 38

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