Download presentation
Presentation is loading. Please wait.
Published byEgbert Sutton Modified over 9 years ago
1
95-712 Lecture 1: Introduction1 95-712 Object Oriented Programming Java Lecture 1: Introduction
2
95-712 Lecture 1: Introduction2 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
95-712 Lecture 1: Introduction3 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
95-712 Lecture 1: Introduction4 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
95-712 Lecture 1: Introduction5 Teaching Assistant: Yubao Office hours will be announced soon.
6
95-712 Lecture 1: Introduction6 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
7
95-712 Lecture 1: Introduction7 Prerequisites to OOP Logic Logical And Logical Or PQP^Q TTT TFF FTF FFF PQPVQ TTT TFT FTT FFF
8
95-712 Lecture 1: Introduction8 Prerequisites to OOP Logic Examples of Logical Negation PQ----- P^Q TTF TFT FTT FFT PQ_ PVQ TTF TFT FTT FFT
9
95-712 Lecture 1: Introduction9 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
95-712 Lecture 1: Introduction10 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
11
95-712 Lecture 1: Introduction11 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 computer 1. 1. Oxford American Dictionary
12
95-712 Lecture 1: Introduction12 Prerequisites to OOP Protocol Definition: Informally, a protocol is a set of rules governing the exchange or transmission of data electronically between devices 2. 2. Oxford American Dictionary
13
95-712 Lecture 1: Introduction13 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 computers 3. ASCII is a seven bit code. 3. Oxford American Dictionary
14
95-712 Lecture 1: Introduction14 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
95-712 Lecture 1: Introduction15 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 65 10. But how do we represent the integer 65 in a computer? We usually use the Binary Numbering System. 65 10 =01000001 2. So, suppose we encounter the binary value 01000001 2. What does it mean? Does it mean 65 10 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
95-712 Lecture 1: Introduction16 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 all binary files.
17
95-712 Lecture 1: Introduction17 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
95-712 Lecture 1: Introduction18 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
95-712 Lecture 1: Introduction19 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
95-712 Lecture 1: Introduction20 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
95-712 Lecture 1: Introduction21 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.
22
95-712 Lecture 1: Introduction22 Prerequisite to OOP: Modulo Arithmetic Modulo arithmetic is often a convenient tool to have handy. Informally, it is clock arithmetic. 0 1 2 3 4 5 1 + 5 = 0 (mod 6) 12 = 0 (mod 6) 5 + 4 = 3 (mod 6) 2 * 5 = 4 (mod 6) 23 = 5 (mod 6) Without using a clock, divide 23 by 6 and take the remainder. So, 23 mod 6 = 5.
23
95-712 Lecture 1: Introduction23 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. instruction 1 ; instruction 2 ; instruction 3 ;
24
95-712 Lecture 1: Introduction24 Prerequisite to OOP: iteration Some problems require us to iterate or loop over a series of instructions while some condition holds true. while(someConditionHolds) { instruction 1 ; instruction 2 ; instruction 3 ; }
25
95-712 Lecture 1: Introduction25 Prerequisite to OOP: Selection Some problems require us to select which group of instructions to execute based upon some criteria. If(someConditionHolds) { instruction 1 ; instruction 2 ; instruction 3 ; } else { instruction 4 ; instruction 5 ; }
26
95-712 Lecture 1: Introduction26 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.
27
95-712 Lecture 1: Introduction27 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.
28
95-712 Lecture 1: Introduction28 Prerequisite to OOP Making Assertions Programmers are expensive. Programs are complex. The liberal use of assertions helps in debugging. Make good use of assertions.
29
95-712 Lecture 1: Introduction29 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.
30
95-712 Lecture 1: Introduction30 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>");
31
95-712 Lecture 1: Introduction31 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
95-712 Lecture 1: Introduction32 From the command line… javac TemperatureConverter.java java TemperatureConverter
33
95-712 Lecture 1: Introduction33 With Eclipse… Create a workspace. Create a Java project. Create a Java class. Switch between the Java and Debug perspectives.
34
95-712 Lecture 1: Introduction34 Problems with the code above: No comments. No JavaDoc. Makes no attempt to handle invalid input. Not object oriented.
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.