95-712 Object Oriented Programming Java - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

95-712 Object Oriented Programming Java

Description:

Look for updates to reading list on schedule. 95-712 Lecture 1: Introduction. 4. Grading ... Some problems require us to iterate or loop over a series of ... – PowerPoint PPT presentation

Number of Views:188
Avg rating:3.0/5.0
Slides: 35
Provided by: Office20041655
Category:

less

Transcript and Presenter's Notes

Title: 95-712 Object Oriented Programming Java


1
95-712 Object Oriented
Programming Java
  • Lecture 1 Introduction

2
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

3
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

4
Grading
  • Programming (5-7) 40
  • Three quizzes (low score dropped) 15
  • Midterm
    20
  • Final Exam 25
  • I will assign exactly one A per section.

5
Teaching Assistant Yubao
Office hours will be announced soon.
6
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/lib
    rary/769.html

7
Prerequisites to OOP Logic
  • Logical And Logical Or

8
Prerequisites to OOP Logic
  • Examples of Logical Negation

9
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,

10
Prerequisites to OOPTypes
  • Expressions have types as well as
  • values
  • Expression Type Value
  • 42 integer 6
  • 4lt2 boolean false
  • 4gt2 boolean true
  • 4.02.0 real 6.0

11
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
12
Prerequisites to OOPProtocol
  • Definition
  • Informally, a protocol is a set of rules
    governing the exchange or transmission of data
    electronically between devices2.

2. Oxford American Dictionary
13
Prerequisites to OOPASCII
  • 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
14
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 may vary in size.

4. Unicode.org
15
Prerequisites to OOPBinary 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.
6510010000012. 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.
16
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. Its 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 all binary files.
17
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
  • the machine code runs on the processor.

18
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.

19
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.

20
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.

21
Prerequisite to OOPVariables
  • 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.

22
Prerequisite to OOPModulo Arithmetic
  • Modulo arithmetic is often a convenient tool to
    have handy. Informally, it is clock arithmetic.

0
1 5 0 (mod 6) 12 0 (mod 6) 5 4 3 (mod
6) 2 5 4 (mod 6) 23 5 (mod 6)
1
5
2
4
3
  • Without using a clock, divide 23 by
  • 6 and take the remainder. So,
  • 23 mod 6 5.

23
Prerequisite to OOPInstruction 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
24
Prerequisite to OOPiteration
Some problems require us to iterate or loop over
a series of instructions while some condition
holds true. while(someConditionHolds)
instruction1 instruction2
instruction3
25
Prerequisite to OOPSelection
Some problems require us to select which group of
instructions to execute based upon some
criteria. If(someConditionHolds)
instruction1 instruction2
instruction3 else instruction4
instruction5
26
Prerequisite to OOPApplication 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 users computer
    that is
  • communicating with another machine. These may
    be console
  • or GUI applications.
  • Server side applications typically wait for
    client generated
  • requests.

27
Prerequisite to OOPDocumenting 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.

28
Prerequisite to OOPMaking Assertions
  • Programmers are expensive.
  • Programs are complex.
  • The liberal use of assertions helps in debugging.
  • Make good use of assertions.

29
Prerequisite to OOPIntegrated Debugging
Environments(IDEs)
  • Many high quality Java IDEs exist.
  • These include Apache Eclipse, Suns 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.

30
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
Fahrenheitgt")
31
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)

32
From the command line
javac TemperatureConverter.java java
TemperatureConverter
33
With Eclipse
Create a workspace. Create a Java
project. Create a Java class. Switch between the
Java and Debug perspectives.
34
Problems with the code above
  • No comments.
  • No JavaDoc.
  • Makes no attempt to handle invalid input.
  • Not object oriented.
Write a Comment
User Comments (0)
About PowerShow.com