cmis 102a 1 introduction introduction of java introduction to programming course goals/objectives...
TRANSCRIPT
CMIS 102A 1
Introduction
Introduction of Java
Introduction to Programming
Course Goals/Objectives
Grading
CMIS 102A 2
Programming Languages
A programming language is a language used to write instructions for a computer to follow
Java is one of many programming languages
Features of JavaPlatform independentOOP= Object Oriented ProgrammingApplications and applets
CMIS 102A 3
Platform Independent
Platform independent: the same program can run on different computers with different operating systems or different hardware. (more later)Here are three different computers each with their own unique Hardware and Software.
X86 (IBM compatible with Windows)RISC (common in embedded systems)PowerPC (Built by Macintosh)
A program for X86 will not run on a PowerPC
CMIS 102A 4
Programming Languages
Machine languageLanguage that a computer can understand directlyConsists of only 0's and 1'sDifferent computers have different machine languages
Want to write a program in a machine language?Examples:
file size: 84KB
internet connection: 2Mbps
Measure of information:
bit (b): a 0 or 1byte (B): eight bits
5
Computer Thinks in Binary
Binary (base 2) - numbers use 2 digits: JUST 0 and 1
Decimal (base 10) - numbers use 10 digits:0 THROUGH 9
Converting numbers:0 0 5 101 101 1 6 110 112 10 7 123 11 8 134 100 9 14
6
Measure of Information
Bit (b; short for binary digit) either a 0 or 1
Byte (B) 1 byte = 8 bits
1 KB = 1024 bytes (2^10) 1 MB = 1,048,576 bytes (2^20) 1 GB = 2^30 ~ 10^9 1 TB = 2^40 ~ 10^12
CMIS 102A 7
Programming Languages
Assembly language (low level language)Using symbolic names for binary codesNeed an assembler to translate an assembly-language program to machine code
Example:Instruction Machine LanguageJMP 2010 00100010STO 617, 201 10001001JZ0 201 10010010
CMIS 102A 8
Programming Languages
High-level languagesCloser to a natural language; easy for human beings to read and write
Two categories:CompiledInterpreted
CMIS 102A 9
Programming Languages
Compiler (is a special SW program)A program that translates a program in a high-level language to machine codeSource program (code): program in high-level languageObject program (code): translated machine code versionCompiling a program and running a program are two different activities
Interpreter (is a special SW program)Translates and executes each instruction in the source program, one at a time
10
Programming Languages Compiled
Compile once then run many times (faster)
If something changes, the whole source must be Compiled again.
Distribution problems
Interpreted Since each
instruction is translated, it’s slower.
If something changes, just that code needs to be changed.
Distribution not as hard
CMIS 102A 11
How Does Java Achieve Platform-Independent?
First, a Java program is compiled into an intermediate code called byte-code
Byte-code is a common language that all computers should understandIn order to understand this byte code, a computer has to install a Java Virtual Machine (JVM)
Then, the byte code is translated into machine code and executed, one at a time, by Java byte-code interpreter
Byte-code is platform independent!
CMIS 102A 12
High Levellanguage
SOURCE CODE
COMPILER forWINDOWS X86
COMPILERRISC
COMPILERPowerPC
X86Needed
Object files
RISC NeededObject Files
PowerPCNeeded
Object Files
X86OBJECT FILE
RISCOBJECT FILE
PowerPCOBJECT FILE
X86 RISC PowerPC
CMIS 102A 13
JAVASource Code
JAVACOMPILER
WINDOWS X86
JAVACOMPILER
RISC
JAVACOMPILERPowerPC
X86JVM
RISCJVM
PowerPCJVM
X86 RISC PowerPC
JAVASource Code
JAVASource Code
JAVABYTECODE
CMIS 102A 15
Java – Applications and Applets
Java applicationStand-alone program
CUI: console User interfaceGUI: Graphical User Interface
Java appletRun within a web browserSent across the Internet and run on a local computer
Byte-code program is sentLocal computer has to have JVM
CMIS 102A 16
History of Java
Developed by James Gosling and his team at Sun Micro-system in 1991As James Gosling and Henry McGilton (1996) wrote in their white paper The Java Language Environment,
"The design requirements of Java are driven by the nature of the computing environment in which software must be deployed."
Computing environment means: World Wide Web, local area networks, intranets, embedded systems such as TV set-top boxes, PDAs, cell-phones, copy machines, and other interconnected devices. Based on C and C++
Still changing1.4.21.5.0
CMIS 102A 17
Working with JAVA and JCreator
You could write JAVA programs in a text program like notepad and compile them in the command line. But this is not convenient.JCreator is a program that lets you easily:
Type the JAVA programCompile the programRun the programDebug the program** It’s a program that helps you build JAVA programs
CMIS 102A 19
Programming
A computer program: a sequence of instructions for a computer to follow to solve a problem
Programming: the process of creating a computer program to solve a problem
A computer can do some basic operations well; it follows instructions wellBut it must be told what to doA human being comes up with the solutions
How to do programming?----next!
20
STEP 1: Understand the requirementsCompany Payroll Case Study (from [1])
A small company needs an interactive program to figure its weekly payroll. The payroll clerk will input data for each employee. The input data includes employee's pay rate, and the number of hours worked that week.
The program should display the weekly pay for that employee.
The weekly pay is calculated as follows: Regular pay equals the pay rate times the number of hours worked,
up to 40 hours. If the employee worked more than 40 hours, wage equals regular
pay for 40 hours plus over time pay for hours over 40 Over time pay equals 1.5 times the pay rate times the overtime hours
These are the requirements!
21
Do some examples to get a feel for the problem…note the logic you take to solve the problem
Example 1: If an employee's hourly pay rate is $30.00, and he worked 52 hours.…………………………………………Then he made ____Dollars
Example 2: If an employee's hourly pay is $10.00, and she worked 36 hours.…………………………………………Then he made ____Dollars
Example 3: If an employee's hourly pay is $20.00 and he worked 40 hours. …………………………………………Then he made ____Dollars
22
Analyzing the Problem by looking at INPUT and OUTPUT
INPUT DATA OUTPUTRESULTS
Hourly payRate
Hours workedWeekly pay
23
Step 2) Find an Algorithm for Calculating Weekly Pay
Repeat the following process for each employee:1. Get the employee’s hourly payRate2. Get the hours worked this week
3. Calculate Wage:If hours worked is more than 40
wage = (40.0 * payRate) + (hours - 40.0) * 1.5 *payRateElse
wage = hours * payRate
4. Display wage
24
An Algorithm A set of instructions for solving a problem
Step-by-step solution Precise (same input gives same output always) A computer program is, by definition, an algorithm.
But we usually use algorithm to mean instructions expressed in English or something like English
Algorithms we've seen: Recipe Direction Manual
CMIS 102A 25
Another Example (from [1])
Procedure to start your car
1. Insert the key.2. Make sure transmission is in Park (or Neutral).3. Depress the gas pedal.4. Turn the key to the start position.5. If the engine starts within six seconds, release the key to
the ignition position.6. If the engine doesn't start in six seconds, release the key
and gas peal, wait ten seconds, and repeat Steps 3 through 6, but not more than five times.
7. If the car doesn't start, call the garage
CMIS 102A 26
An Exercise
Write an algorithm that gets the price and quantity of an item bought, and displays the total amount paid for that item after tax. The tax rate is fixed to be 5%.
To get started, work these: a) 5 widgets at 12.00 each. How much do you pay?b) 15 widgets at 2.00 each. How much do you pay?c) W widgets at P dollars each. How much do you
pay?
27
How to Do Programming? 1) Analyzing the problem: Identifying the input data and
the output results
2) Developing the solution algorithm
3) Coding the algorithm using a specific programming language
4) Testing Running (executing) your program on the computer, to see if it produces correct results
If it does not, then you must find out what is wrong with your program or algorithm and fix (debugging)
CMIS 102A 28
Structured Programming
Top-down development
Any computer program can be written using only three basic control structures:
Sequence: a sequence of instructions executed in the order they're writtenSelection: executing different instructions based on certain conditionsLoop: repeating a set of instructions while certain conditions are met
CMIS 102A 30
Course Goals and Objectives
Describe the development of computer programming and the main characteristics of JavaGain an understanding of the fundamentals of object-oriented programming, including classes, objects, creating objects, and using methods
Apply top-down and other techniques for algorithmic problem-solving in designing and writing computer programsApply incremental development techniques in writing complex programs
CMIS 102A 31
Course Goals and Objectives
Understand and use fundamental programming constructs such as data types and declarations, assignment statements, variables, constants, and arithmetic and logical operators
Understand and apply sequence, selection, and loop control structures in writing programs to solve common computing problems
Understand and use pre-defined classes
Create, compile, and execute Java programs to do the following:
Get input data from the user and display results to the userPerform simple arithmetic calculations, and string manipulationsPerform different tasks based on user input or results of calculations (selection)Repeat tasks (loop)
CMIS 102A 32
Course Goals and Objectives
Document programs effectively Design and use test data for validating programs
CMIS 102A 33
Grading
Projects (3) 50%LABS should help complete the projects
Homework including labs (assigned but not graded)These are the ‘self-test questions’ in text
Quizzes (2) 20%Short 20 question mc t/f fill-in questions and 1 JAVA code question.
Final 30%I’ll give you a sample Final + Answers
Participation counts toward marginal casesIf your on the edge of a grade, I look at the participation
CMIS 102A 34
Miscellaneous
Extra Credit. Short ans: None. 1) I have no ‘extra’ time to manage extra credit work. 2) Not a good practice as a student. The intention is good but misdirected. All military related absences or late assignments are excusable. You are the one responsible for the learning the material.Planned absences should not exceed 25% of the course.
i.e. planned vacation or military exercises should not exceed 4 classes
Never disappear from class [email protected] when dropping a course!
CMIS 102A 35
Best Way to Learn Programming?
Quotes from Bill Gates:
the best way to prepare (to be a programmer) is to write programs, and to study great programs that other people have written. In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system. You've got to be willing to read other people's code, then write your own, then have other people review your code.
CMIS 102A 36
Best Way to do well in class
Do the HW. Don’t just look at answers Participate in class Memorize the basic coding structures Do the projects well (50% of grade!) Differentiate the ‘interesting’ from the ‘testable’ Time Management !?!
CMIS 102A 37
Review (1)
High-level programming language
machine language
interpreter
Java
source program
object program
byte-code program
compiler
platform independent
CMIS 102A 38
Review (2)
programming
computer program
algorithm
selection
loop
sequenceinput and output
CMIS 102A 39
References
[1] Programming and Problem Solving with C++, 3rd Ed., Nell Dale, Chip Weems, Mark Headington, pp 33-37.
[2] Structured programming, http://en.wikipedia.org/wiki/Structured_programming
[3] COMPILERS, INTERPRETERS AND VIRTUAL MACHINES, http://www.homepages.com.pk/kashman/jvm.htm#_computers