PowerPoint Presentation - Service Oriented Architecture
Download
Report
Transcript PowerPoint Presentation - Service Oriented Architecture
95-712 Object Oriented
Programming Java
Lecture 1: Introduction
95-712 Lecture 1: Introduction
1
Structure of the Course
• Lectures / class participation
• Homework (pencil and paper and
programming)
• Quizzes
• Midterm and Final examinations
• Use Blackboard for queries on course
material
• Send email to me regarding personal issues
95-712 Lecture 1: Introduction
2
Readings
• Readings from the required text are
assigned for each lecture -- read them
in advance. The first reading is due for
next week.
• Readings from the web also assigned
• Look for updates to reading list on
schedule
95-712 Lecture 1: Introduction
3
Grading
•
•
•
•
•
Programming (5-7)
40%
Three quizzes (low score dropped) 15%
Midterm
20%
Final Exam
25%
I will assign exactly one “A+” per section.
95-712 Lecture 1: Introduction
4
Teaching Assistant: Yubao
Office hours
will be
announced soon.
95-712 Lecture 1: Introduction
5
Important Web Sites
•
•
•
•
•
http://www.andrew.cmu.edu/~mm6
http://www.javasoft.com
http://java.sun.com/docs/books/tutorial/
http://www.eclipse.org/
http://www-128.ibm.com/developerworks/rational/library/769.html
95-712 Lecture 1: Introduction
6
Prerequisites to OOP
Logic
Logical And
Logical Or
P
Q
P^Q
P
Q
PVQ
T
T
T
T
T
T
T
F
F
T
F
T
F
T
F
F
T
T
F
F
F
F
F
F
95-712 Lecture 1: Introduction
7
Prerequisites to OOP
Logic
Examples of Logical Negation
P
Q
----P^Q
P
Q
_ _
PVQ
T
T
F
T
T
F
T
F
T
T
F
T
F
T
T
F
T
T
F
F
T
F
F
T
95-712 Lecture 1: Introduction
8
Prerequisites to OOP
Sets
Important Sets:
Denotes the empty set
Denotes the set of integers {…,-2, 1,0,1,2,…}
R Denotes the set of real numbers
{…,-2.9, 4.5, 5.2, …}
95-712 Lecture 1: Introduction
9
Prerequisites to OOP
Types
Expressions have types as well as
values:
Expression Type
Value
4+2
integer 6
4<2
boolean false
4>2
boolean true
4.0+2.0
real
6.0
95-712 Lecture 1: Introduction
10
Prerequisites to OOP
Algorithm
Definition:
Informally, an algorithm is a process or
set of steps to be followed in
calculations or other problem-solving
operations, esp. by a computer1.
1. Oxford American Dictionary
95-712 Lecture 1: Introduction
11
Prerequisites to OOP
Protocol
Definition:
Informally, a protocol is a set of rules
governing the exchange or transmission
of data electronically between devices2.
2. Oxford American Dictionary
95-712 Lecture 1: Introduction
12
Prerequisites to OOP
ASCII
Definition:
ASCII is an abbreviation for the American
Standard Code for Information Interchange, a
set of digital codes representing letters,
numerals, and other symbols, widely used as
a standard format in the transfer of text
between computers3. ASCII is a seven bit
code.
3. Oxford American Dictionary
95-712 Lecture 1: Introduction
13
Prerequisites to OOP
Unicode
Definition:
The Unicode Standard is a character coding system designed to
support the worldwide interchange, processing, and display of
the written texts of the diverse languages and technical
disciplines of the modern world. In addition, it supports classical
and historical texts of many written languages.4 Unicode
characters
4. Unicode.orgmay vary in size.
95-712 Lecture 1: Introduction
14
Prerequisites to OOP
Binary Data
The coding schemes mentioned above (ASCII and Unicode)
amount to agreements about how characters in various
alphabets may be represented as integers.
The character “A”, for example, is represented as 6510.
But how do we represent the integer 65 in a computer?
We usually use the Binary Numbering System.
6510=010000012.
So, suppose we encounter the binary value 010000012.
What does it mean? Does it mean 6510 or “A” or is it a
description of how eight switches are set?
We would need to know more about its context to answer
that question.
95-712 Lecture 1: Introduction
15
Prerequisites to OOP
Text Vs. Binary
Why is the binary numbering system used?
For much the same reason that we all use base 10
for arithmetic. The algorithms are easy to learn. Try
doing long division with Roman numerals.
It’s simple to build machines to add and multiply and
so on if the numbering system is base 2.
In general, character data is encoded into a series of bits
using ASCII or Unicode. This is called text data. XML files,
for example, are text files.
Everything else is binary data. Machine code
Files , JPEG files, Java class files, Excel files, etc…, are
95-712 Lecture 1: Introduction
16
all binary files.
Prerequisites to OOP
Assembly Language
A Programmer is given a problem to solve.
She writes a solution in assembly language.
Two things are on her mind:
1. The problem
2. The machine architecture (number and type of CPU
registers, size of memory, memory addresses,
instruction set, etc.)
Her solution might look something like this:
mul R1,R2,40
add R1,R1,R2
STR Pay,R1
CALL PrintPayCheck
An assembler tool converts this to machine code and
1: Introduction
the machine code95-712
runsLecture
on the
processor.
17
Prerequisites to OOP
Procedural Language
A Programmer is given a problem to solve.
She writes a solution in Pascal.
Two things are on her mind:
1. The problem and
2. Variables, instructions and procedures that
change the state of the variables.
Her solution looks something like this:
pay := hours * payRate;
pay := pay + bonus;
printPayCheck(pay);
A compiler converts this to machine code and the machine
code is run on the processor.
95-712 Lecture 1: Introduction
18
Prerequisites to OOP
Objects
A Programmer is given a problem to solve.
She writes a solution in Java.
Two things are on her mind:
1. The problem.
2. Classes and objects - how they relate
and interact
Her solution might look something like this:
Employee e = new Employee(hours,rate,bonus);
e.printCheck();
This gets compiled into byte code and the byte code
is executed by the Java Virtual Machine.
95-712 Lecture 1: Introduction
19
Object Oriented Programming:
is a different way to think about software
development.
reduces complexity.
promotes code reuse and flexibility.
promotes important concepts from software
engineering, e.g.,abstraction and information
hiding.
cannot do anything more than previous
paradigms. But can make our lives more
enjoyable, software
easier
to
write
and
reuse.
95-712 Lecture 1: Introduction
20
Prerequisite to OOP:
Variables
Variables are addressable areas of memory
that change as a program runs.
Variables may contain simple values such as
integers or reals.
Variables may contain addresses of other
memory locations. These are called pointers
or references.
Variable names should be chosen wisely.
95-712 Lecture 1: Introduction
21
Prerequisite to OOP:
Modulo Arithmetic
Modulo arithmetic is often a convenient tool
to have handy. Informally, it is clock
arithmetic.
0
1
5
2
4
1 + 5 = 0 (mod 6)
12 = 0 (mod 6)
5 + 4 = 3 (mod 6)
2 * 5 = 4 (mod 6)
23 = 5 (mod 6)
3
Without using a clock, divide 23 by
6 and take the remainder. So,
95-712 Lecture 1: Introduction
23 mod 6 = 5.
22
Prerequisite to OOP:
Instruction Execution
Some problems, or parts of problems, may be solved by
a simple series of instructions that when executed in sequence
(one after the other) yield the answer or establish a desired state.
instruction1;
instruction2;
instruction3;
95-712 Lecture 1: Introduction
23
Prerequisite to OOP:
iteration
Some problems require us to iterate or loop over a series of
instructions while some condition holds true.
while(someConditionHolds) {
instruction1;
instruction2;
instruction3;
}
95-712 Lecture 1: Introduction
24
Prerequisite to OOP:
Selection
Some problems require us to select which group of instructions
to execute based upon some criteria.
If(someConditionHolds) {
instruction1;
instruction2;
instruction3;
}
else {
instruction4;
instruction5;
}
95-712 Lecture 1: Introduction
25
Prerequisite to OOP:
Application Types
Console applications run within a console window or shell.
GUI (Graphical User Interface) applications control the windowing,
buttons and text boxes and are typically event driven.
Client side applications run on a user’s computer that is
communicating with another machine. These may be console
or GUI applications.
Server side applications typically wait for client generated
requests.
95-712 Lecture 1: Introduction
26
Prerequisite to OOP
Documenting Code
• Important code is examined by programmers.
• Programmers are expensive.
• Appropriate use of comments tends to
shorten the time required to understand code.
• Document clearly and succinctly.
• Use the Javadoc tool.
• Indent your programs carefully.
95-712 Lecture 1: Introduction
27
Prerequisite to OOP
Making Assertions
• Programmers are expensive.
• Programs are complex.
• The liberal use of assertions helps in
debugging.
• Make good use of assertions.
95-712 Lecture 1: Introduction
28
Prerequisite to OOP
Integrated Debugging
Environments(IDE”s)
• Many high quality Java IDE’s exist.
• These include Apache Eclipse, Sun’s
Netbeans, Oracles JDeveloper, etc.
• In this class we will use Eclipse.
• You must also know how to compile and run
Java from the DOS or Unix command lines.
95-712 Lecture 1: Introduction
29
Compiling and Running a
Simple Program
import java.io.*;
public class TemperatureConverter {
public static void main(String args[]) throws IOException
{
BufferedReader in =
new BufferedReader(
new InputStreamReader(System.in));
System.out.print("Enter temperature in Fahrenheit>");
95-712 Lecture 1: Introduction
30
String fahrenheit = in.readLine();
Double fObj = new Double(fahrenheit);
double f = fObj.doubleValue();
double c = ((f - 32.0)/9.0) * 5.0;
System.out.println("Celsius = " + c);
}
}
95-712 Lecture 1: Introduction
31
From the command line…
javac TemperatureConverter.java
java TemperatureConverter
95-712 Lecture 1: Introduction
32
With Eclipse…
Create a workspace.
Create a Java project.
Create a Java class.
Switch between the Java and Debug
perspectives.
95-712 Lecture 1: Introduction
33
Problems with the code
above:
•
•
•
•
No comments.
No JavaDoc.
Makes no attempt to handle invalid input.
Not object oriented.
95-712 Lecture 1: Introduction
34