Introduction to Computing and Programming

nutmegactΛογισμικό & κατασκευή λογ/κού

10 Νοε 2012 (πριν από 4 χρόνια και 9 μήνες)

285 εμφανίσεις


CSCI
-

1301

Introduction to Computing and
Programming


Anousha Mesbah

1
-
1

Overview



What is
CSCI 1301

?


Introductory

course

in

Object
-
Oriented

Programming

using

the

programming

language

Java
.



Primary Goal


Learning the basics of computer programming
using Java


byproduct


Enhancement of you problem solving and abstract
reasoning skill



1
-
2

CSCI 1301

How many of you play computer games ?








Would you like to implement your own computer
game ?




1
-
3

by Robert Kirkland


Introduction


Java is the language behind thousands of cool
software applications:


Internet
-
based and Desktop Applications


Airlines Ticketing and reservation systems


Bank Internet Payment System


Manufacturing


Airport Monitor


Computer Games


Mobile Phone


Games


Email


Chats


1
-
4

more at
http://www.java.com/en/javahistory/

Focus of the Course


Object
-
Oriented Software Development


problem solving


program design, implementation, and testing


object
-
oriented concepts


classes


objects


encapsulation


inheritance


the Java programming language



1
-
5

To get started



No prior programming experience


You will learn from scratch , step by step


Basic skills with using computers


Comfortable to work and access WebCT


On
-
line tutorials at:
https://webct.uga.edu/www/student/guide/


1
-
6

Course Materials


WebCT


Lab Assignments


Projects


Electronic Submission


Software


J2SE Development Kit (JDK) 6.0


NetBeans 6.1
®

(open
-
source)

1
-
7

Important Dates


Date






Thursday, Jan 8


Lectures begin


Monday, Jan 12


Labs begin (room 307A)


Thursday, Feb 26

Exam 1


Tuesday , Mar 24

Withdrawal deadline


Thursday Apr 9


Exam 2


Tuesday, Apr 28


Last lecture


Thursday ,




May 7 @12:00

Final Exam



1
-
8

Your To Do List:


Buy the textbook.



Check you have access to WebCT


Log in myUGA


Click on the WebCT Icon



1
-
9


Read the course syllabus in details on webCT.



Check course news and material periodically
in Class web page


Some Hints


Ask questions ASAP


Do not fall behind


“Cramming” won’t work


Start on projects early


Read Announcements on course webpage often


Take advantages of Office Hours


If you need help, ask for help


Instructor


Lab instructors


1
-
10

Lecture 1: Introduction to Java

1
-
11

Outline

1
-
12

Computer System

Hardware Components

Software

Programming languages

Programming languages level

Software Development


Computer System

Computer system is made up of hardware and software



Hardware


the physical, tangible parts of a computer


keyboard, monitor, disks, wires, chips, etc.


Software


programs and data


a
program

is a series of instructions



A computer requires both hardware and software


Each is essentially useless without the other

1
-
13


Regardless of differences in physical appearance,
virtually every computer may be envisioned into
six logical units or sections.


1.
Input units

2.
Output units

3.
Memory units

4.
Arithmetic and logic unit (ALU)

5.
Central processing unit (CPU)

6.
Secondary storage unit

1
-
14

Hardware Components

1
-
15

Central

Processing

Unit

Main

Memory

Floppy Disk

Hard Disk

Monitor

Keyboard

Flash Disk

Secondary memory

devices provide

long
-
term storage

Hard disks

Floppy disks

ZIP disks

Writable CDs

Writable
DVDs

Tapes

Hardware Components

1
-
16

Central

Processing

Unit

Main

Memory

Floppy Disk

Hard Disk

Monitor

Keyboard

Flash Disk

I/O Devices

Monitor

Keyboard

Printers

Scanners

Hardware Components

1
-
17

Central

Processing

Unit

Main

Memory

Floppy Disk

Hard Disk

Monitor

Keyboard

Flash Disk

Chip that executes
program instructions


Intel Pentium 4

Sun ultraSPARC III

Primary storage

area
for programs and
data that are in
active use


A
bit

is a digit with a
value of either 0 or 1.


A
byte

consists of 8 bits.


Each byte in main
memory resides at a
numbered location
called its
address
.






㌰㈱

11110000

3022

01110010

3023

10001101

3024

00101100

3025

00001000

3026

10110101

3027

10101011

3028

00001111





1
-
18


A
bit

is a digit with a
value of either 0 or 1.


A
byte

consists of 8
bits.


Each byte in main
memory resides at a
numbered location
called its
address.


When more than a
single byte is needed
to represent some
data, several adjacent
bytes are used.


The
address

of the first
byte is the address of the
unit of bytes.







㌰㈱

11110000

3022

01110010

3023

10001101

3024

00101100

3025

00001000

3026

10110101

3027

10101011

3028

00001111





1
-
19

2
-
byte memory location at
address
3021

1
-
byte memory location at
address
3023

3
-
byte memory location at
address
3024

1
-
byte memory location at
address
3027

1
-
byte memory location at
address
3028

Software


Software


programs and data


a
program

is a series of instructions



Programming

involves writing a set of instructions to
instruct the computer how to accomplish some
specific task:


Greeting the user


Computer Game


A Flight Simulator


Computer programming:”
Art of making a
computer do
what YOU want.”

“Computers are good at following instructions, but not at
reading your mind.”
-

D. Knuth


1
-
20

What is a programming language?


Why can’t we “Speak” to the computer in English
or in Greek or in Chinese?


Because natural language are prone to ambiguities.



Since computers do exactly what we tell them to,
we must be
VERY

precise what we tell them,
otherwise they will not respond since they have
NO intelligence.



Programming languages have been developed for
the purpose of communicating with computers

1
-
21

Programs


A
program

is a set of instructions that is
understandable by the computer and can
be executed.


To execute a program, you may need
some
input



The
data

needed by the program.


The
output

is the result(s) produced by
executing the instructions in the program.


1
-
22

Programming Languages


A program is written in a specific programming
language.



There are many programming languages


C


C++


Java


Smalltalk


Python



1
-
23

Programming Languages

A
programming language

specifies the words and
symbols and syntax rules that we can use to write a
program


Syntax rules

-

how to put together symbols, words to
make a valid program


Analogy


English Grammar


Semantics

-

what a statement of a program means (its
purpose or role in a program)


Analogy
-

meaning of an English statement


A program that is syntactically correct is not
necessarily logically (semantically) correct


Analogy


a grammatically correct sentence that does
not make any sense


1
-
24

Programming Language Levels


Programming
language levels:






Low Level

»
machine language

»
Each type of CPU has its own specific
machine
language


Assembly language



High
-
level language

1
-
25

Machine Language


Machine language is the basic set of instructions
that the CPU can executed.


Every CPU has its own machine language


Machine language instructions are sequence of 0

s
and 1

s.

1
-
26

010111010101

010101010101

010101001111

11101101110


A CPU

only executes

programs written in machine
language .


Programming in machine language is extremely
cumbersome.


Program written in machine language are very
difficult
for humans to understand.


A= B+C

Assembly Language








Assembly language

consists of simple
mnemonics for the
instruction set.


An
Assembler

is a
program that
translate a program
written in
Assembly
Language

into an
equivalent program
in machine language.


1
-
27

LOAD A, R1

NOP ;

LOAD B, R2

NOP

ADD R2 R1

NOP ;

STORE R2, C

HALT ;

RISC Assembly
program:

C= A+B

High
-
Level Programming Languages


Closer to
natural languages
.


syntax and words that resembles English
-
like phrases.



Usually, several machine instructions are combined
into one high
-
level instruction.

A=B+C


High
-
Level Programming Languages


Pascal


Modula


C




C++





Java
Matlab

1
-
28

High
-
Level Programming Languages


Each type of CPU executes only programs in a
particular
machine language
.


A program in a HLPL must be translated into
machine language before it can be executed.


A
compiler

is a software tool which translates
source code

into a specific target language.


The target language is often the machine language
for a particular CPU type




1
-
29

Program’s Source Code

Compiler

ML program

Syntax Errors


Java Translation


1
-
30

Java bytecode

is
not the machine
language


Java Translation is different …

1
-
30

Java source

code

Machine

code

Java

bytecode

Bytecode

Compiler (JVM)

Java

compiler

Java Advantage



Java is portable


Java bytecode is
machine
independent


It can be executed by
a Java VM ported to
a given platform


1
-
31

Mac OS X

Solaris


Unix

Windows XP

javac

Hello.class





Hello!

Hello!

Hello!

Java VM

Java VM

Java VM

Problem Solving


The purpose of writing a program is to solve a problem


Solving a problem consists of multiple activities:


Understand the problem


Design a algorithmic solution


An
algorithm

describes a means of performing a task


Consider alternatives and refine the solution


Implement the solution in a High Level Programming
Language


Java in our case


Test the solution


These activities are not purely linear


they overlap and
interact

1
-
32

Algorithm




An algorithm is a detailed sequence of simple
steps

that are needed to solve a problem


It is a
step
-
by
-
step

solution to a problem


Example:
What is the value of x in the following equation?




5x


10 = 30

Algorithm [ Solution ]:

Step 1:

5x = 30 + 10

Step 2:

5x = 40

Step 3:

x = 40/5

Step 4:

x = 8


In programming the steps are called
statements.


1
-
33

Basic Program Development

1
-
34

Syntax
errors

Run
-
time and logic errors

Edit and

save program


Compile program

Execute program and

evaluate results

Run
-
time and logic errors are
typically called
bugs

The process of eliminating
run
-
time and logic error is
called

debugging

What is a good program

1.
run correctly


run in accordance with the specifications.


2.
run efficiently


Small running time


Does not require too many resources


Memory


Storage space in hard disk

3.
be easy to read and understand

4.
be easy to modify.


1
-
35

Development Environments


There are Integrated Development Environments
(IDE) that support the development of Java
software:


Borland JBuilder


MetroWerks CodeWarrior


Monash BlueJ


JCreator


Eclipse


Crimson Editor

1
-
36

NetBeans


1
-
37

Java Language


An overview


A high
-
level programming language created by
Sun Microsystems, Inc.


It was introduced in 1995 and it's popularity has
grown quickly since then.


1
-
38

Types of Java Program



Application is just a regular program


run on your computer


Applets


Run on the internet.

1
-
39

Java Application Structure


A java application is made up of one or more
classes


A
class

contains data and one or more
methods


A
method

contains program
statements


Each java class

is stored in
its own file

with
extension java


Hello.java


1
-
40

Java Program Structure

1
-
41

public

class

HelloWorld

{










}

// comments about the class

class
header

class body

Comments can be placed almost anywhere

className

Java Program Structure

1
-
42

public

class

HelloWorld

{










}

// comments about the class

public static void

main (String[] args)

{



}

// comments about the method

method header

method body


In a stand
-
alone Java application at least one class has a
method called
main


Comments


Comments are
inline documentation


They should be included to explain the purpose of the
program and describe processing steps


They do not affect how a program works


Java comments can take three forms:

1
-
43

// this comment runs to the end of the line

/* this comment runs to the terminating


symbol, even across line breaks */

/** this is a
javadoc

comment */

Identifiers


Identifiers

are the words (names) a programmer uses in
a program


An
identifier

starts with a letter, a dollar sign or the
underscore character followed by a sequence of
letters, digits, the underscore character ( _ ), and the
dollar sign

Valid Identifiers


interestRate

my_salary2005



A_B_C


$AB_C


$$$



_A_B


Invalid Identifiers


2AB$

%rate

Hello!


1
-
44

Reserved Words


Reserved words are
words
\
that already have
a predefined meaning
in Java


A reserved word
cannot be used as
Identifier.

1
-
45

abstract

boolean

break

byte

case

catch

char

class

const

continue

default

do

double

else

enum

extends

false

final

finally

float

for

goto

if

implements

import

instanceof

int

interface

long

native

new

null

package

private

protected

public

return

short

static

strictfp

super

switch

synchronized

this

throw

throws

transient

true

try

void

volatile

while

Identifiers


Identifiers in Java are
case sensitive





Hello, hello,
and

HELLO
are different identifiers



By convention, programmers use different case
styles for different types of identifiers.


Class name starts with a capital letter


Example


MyFirstClass


1
-
46

Identifiers


Some guidelines to choose identifiers



Do not use abbreviations


Avoid long identifiers


Use mixed case to increase readability



For class identifiers, we will use
title case


HelloWorld


Oracle


Car


BankAccount




1
-
47

White Space


Spaces, blank lines, and tabs are called
white
space


White space is used to separate words and
symbols in a program


Extra white space is ignored


A valid Java program can be formatted many ways


Programs should be formatted to enhance
readability, using consistent indentation



1
-
48

Java Program Structure

1
-
49

public class

HelloWorld

{










}

// Hello World Application

public static void

main (
String
[] args)

{



}

// Java application to display the message

// Hello World on the screen

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


Save your program as

HelloWord.java

The filename of the program must be
identical

to
the name of the class.

Outline

1
-
50

Computer System

Hardware Components

Software

Programming languages

Java


An Overview


Reading Assignment


Chapter 1


Sections 1.1, 1.2,1.3
-

Testing and Debugging


For Next Lecture


Chapter 2: 2.1


2.4


1
-
51