Topic: Java in the Computer World 7/12/2016 Week 1 Lecture notes 1

advertisement
Topic: Java in the Computer World
7/12/2016
Week 1 Lecture notes
1
Computer Software vs. Hardware
Hardware
software
Book
Cover, paper, ink,
binding
Content,
idea, language
Computer
Various devices,
such as the
keyboard, screen,
disks, memory and
processing units.
Computer
programs that run
on a computer.
Computer
language.
compare
(E.g.
7/12/2016
Week 1 Lecture notes
)
2
Programming languages
• High-level languages:
– single statements could
be written to accomplish
substantial tasks.
High-level language
• Assembly languages:
– English-like abbreviations;
– elementary operations
• Machine languages:
Assembly language
Machine language : 0111010
– 1's and 0's;
– machine-dependent
7/12/2016
Week 1 Lecture notes
3
Example (Programming languages)
• Machine languages:
+1300042774
+1400493419
+1200274027
• Assembly languages:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
• High-level languages:
grossPay = basePay +overTimePay
7/12/2016
Week 1 Lecture notes
4
Java Software Development Environment
• You can have 4 separate parts:
–
–
–
–
Editor
Compiler
Interpreter
Debugger
• Or you can combine some of these parts
7/12/2016
Week 1 Lecture notes
5
7/12/2016
Week 1 Lecture notes
6
Integrated Development Environment (IDE)
• IDE combins
– editor, compiler, interpreter and debugger
• IDE is a tool for developing software
• This course is not about IDE
• This course is about designing software
Tool
Book
Content
Pen, ink, paper Plot, story,
English language
Software CodeWarrior (IDE) Class, method, Java language
7/12/2016
Week 1 Lecture notes
7
Where is Java in the compter world?
-- section summary
Hardware
software
Book
Cover, paper, ink,
binding
Content,
idea, language
Computer
Various devices,
such as the
keyboard, screen,
disks, memory and
processing units.
Computer
programs that run
on a computer.
Computer
language.
compare
(E.g.
High-level language
Assembly language
Machine language : 0111010
)
Tool
Book
Content
Pen, ink, paper Plot, story,
English language
Software CodeWarrior (IDE) Class, method, Java language
7/12/2016
Week 1 Lecture notes
8
Topic: Object Oriented Design
• Classes
• Methods
7/12/2016
Week 1 Lecture notes
9
Classes
Section I: Classes
•
•
•
•
= Classification
= The classification process
Classification is good
Classification takes places in everyday life
7/12/2016
Week 1 Lecture notes
10
Classes
Classes -- How to classify
• Example
• object group ==>classes
–
–
–
–
–
–
class monitor (output device)
class printer (output device)
class speaker (output device)
class computer tower (computing device)
class keyboard (input device)
class mouse (input device)
7/12/2016
Week 1 Lecture notes
11
Classes
Class and Object Relation
• An object is an instance of a class
• A class represents a category of objects
obj
obj
Class monitor
obj
7/12/2016
Class printer
obj
Week 1 Lecture notes
12
Classes
Class and method relation
7/12/2016
Week 1 Lecture notes
13
Classes
Why Different Classes?
• Good thing about such modular design:
– Independent objects ==>local problem only
• Example
– bad keyboard, but everything else is still working fine
– Easy to find problems
– try a new keyboard --> find out the old keyboard is bad
– Easy to fix problems
– buy a new keyboard for $15
– If the system does not have such modular design
we’d be in trouble.
7/12/2016
Week 1 Lecture notes
14
Classes
Sub-class
• A big class might have sub-classes
• Good vs. bad classification
• Example: make sub-classes for books in a bookstore
– Good classification:
• literature, arts, science, religion, sports, home, map…
– Bad classification:
• alphabetically order books: section A,B,C...
7/12/2016
Week 1 Lecture notes
15
Classes
About Classes: section summary
• We have learned
– Classification is good
• classification = categorization
– (motivated why we want to split things into classes
– Good classification vs. bad classification
– Sometimes, a class has sub-classes
7/12/2016
Week 1 Lecture notes
16
Classes
About Classes: section summary (continue…)
• Also, we have learned...
obj
– An object is an instance of a class
– A method is inside of a class
Class monitor
obj
7/12/2016
Week 1 Lecture notes
17
Methods
Section II: Methods
• Each method belongs to a class
• A class can have many methods
7/12/2016
Week 1 Lecture notes
18
Methods
Make Methods (Example)
• Example: make up some methods for the printer class
• What does a printer do?
– Let’s draw a flow chart...
7/12/2016
Week 1 Lecture notes
19
Methods
7/12/2016
Week 1 Lecture notes
20
Flow chart --> Methods
methods
• Flow chart
– help us to think through
– breaks big task to smaller sub-tasks
– small sub-tasks ==> methods
• Each method is an action
• Now, we are ready to write the skeleton of
“class printer”...
7/12/2016
Week 1 Lecture notes
21
//-----------------------------------// class Printer
//-----------------------------------class Printer
{
//--------------------------// define variables
//--------------------------boolean double_sided;
// The variable "double_sided"
// as type "boolean", so it can
// take only values "true" or "false".
int maximum_memory_size;
methods
// The maximum size of the memory
// is an integer. Type "int"=integer.
//------------------------------------// Method: receive_file
// DOES: Receive files to be printed.
//-------------------------------------void receive_file()
{
// ...
// We don't know how to program the method yet.
}
7/12/2016
Week 1 Lecture notes
22
methods
About Methods: section summary
• In this section, we learned that
– A class consists of many/some methods
– A class might have methods to handle some
tasks
– Break a big task into small sub-tasks
– method = sub-tasks (manageable sub-tasks)
– often, mehtods ==> an action
7/12/2016
Week 1 Lecture notes
23
Topic Summary: Class and method
•
•
•
•
•
Class <==> classification
class <==> modular design
class = (method) + (method) +…
big task = (small sub-task) + (small sub-task) + ...
Methods <==> small sub-task
• We are happy -- that we designed a nice
schematic Printer class.
7/12/2016
Week 1 Lecture notes
24
Programming process
ideas
Program in
Java byte code,
in the file
Test.class
Work done at
the keyboard
with a text
editor
Program text,
on paper or in
head
Compiler-a program for
translating
programs
Program text,
in a file such
as Test.java
Java Virtual
Machine JVM,
executes the
program Test.class
7/12/2016
Week 1 Lecture notes
25
Download