Overview of the Computer
-
Upload
ann-hopkins -
Category
Documents
-
view
46 -
download
0
description
Transcript of Overview of the Computer
![Page 1: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/1.jpg)
04/19/23 cosc236/intro 1
Overview of the Computer
• Definition: a programmable device that can store, retrieve, and process data.
• Hardware = physical components of a computer
• Software = computer programs (the set of all programs available on a computer). – application software and system software.
![Page 2: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/2.jpg)
04/19/23 cosc236/intro 2
Computer components:
![Page 3: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/3.jpg)
04/19/23 cosc236/intro 3
Programming Language
• Definition: languages with strict grammar rules, symbols, and special words used to construct a computer program
![Page 4: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/4.jpg)
04/19/23 cosc236/intro 4
Machine language
• the language that can be directly used and understood by the computer
• operations are very low-level, specific to the architecture (not portable)
• made up of binary-coded instructions (strings of 0s and 1s)
• exa: 110011 - add instruction
![Page 5: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/5.jpg)
04/19/23 cosc236/intro 5
Assembly Language
•A low-level programming language in which a mnemonic is used to represent each of the machine language instructions for a particular computer•Requires assembler
![Page 6: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/6.jpg)
04/19/23 cosc236/intro 6
COMP$PAY PROC PUBLIC;; COMP$PAY - procedure to compute gross pay ; (PAY = HOURS * RATE)MOV AX,HOURS ; multiplicandMUL RATE+2 ; X second word of multiplierMOV PAY+2,AX ; store the product in PAY;MOV AX,HOURS ; multiplicandMUL RATE ; times first word of multiplierADD PAY+2,AX ; add the product to PAYADD PAY,DX ; add the carry, if anyRET ; end procedure
![Page 7: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/7.jpg)
04/19/23 cosc236/intro 7
High-level languages
• Basic, C++, Pascal, Java, Ada, Modula-2, Cobol, Fortran…
• Similar to natural language (easier to use and debug)
• standardized description of the language exists
![Page 8: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/8.jpg)
04/19/23 cosc236/intro 8
High-level languages cont’d
• Not understood directly by a computer, must be converted to machine language: – Compilers: whole program is translated into
another language (machine language or bytecode) and then executed
– Interpreters: program is translated and executed one line at a time
• portable (machine-independent) – Program is written for any platform– compiler translates to each platform
![Page 9: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/9.jpg)
04/19/23 cosc236/intro 9
• C++ compiled to machine language– Requires translating to many different
machine languages
• Java compiled to Java bytecodes– One set of bytecodes can execute on many
different machines– intermediate level– machine language for theoretical computer:
Java Virtual Machine (JVM)
![Page 10: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/10.jpg)
04/19/23 cosc236/intro 10
Java
• Class– Unit of code that is the basic building block
of Java programs
• Java runtime– JRE– Executes compiled Java class files– Most computers have Java runtimes on
their computer
![Page 11: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/11.jpg)
04/19/23 cosc236/intro 11
Background
• Released by Sun in 1995
• Object-oriented
• Rich libraries – pre-written software
• Active programmer community
• API Specification– Application Programming Interface
• Extremely platform-independent
![Page 12: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/12.jpg)
3/28/2003 Columbia University JETT 12
Java Advantages
• Platform independence
• Reuse of code
• Security
• Automatic garbage collection
• Stronger typing of objects and variables
![Page 13: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/13.jpg)
04/19/23 cosc236/intro 13
Java Programming Environment
1. Type program as Java class =>.java2. Compile => .class (bytecode)3. Loader – connects bytecode from
various classes and loads bytecode into main memory
4. Interpreter – translate and run
![Page 14: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/14.jpg)
04/19/23 cosc236/intro 14
Sample program
public class Hello { public static void main(String[] args) { System.out.println("Hello World!“); }
}
![Page 15: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/15.jpg)
04/19/23 cosc236/intro 15
Java programs
• class Hello
• Class names begin with capital letter
• file Hello.java
• Class name and file name must match
![Page 16: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/16.jpg)
04/19/23 cosc236/intro 16
class• Unit of code that is the basic building block of
java programspublic class <name> //class header{ <method> <method> … <method>}main method is required public static void main(String[] args)
![Page 17: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/17.jpg)
04/19/23 cosc236/intro 17
methods• particular action or calculation
• main method is required
• Method header public static void main(String[] args)
{
statements
}
![Page 18: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/18.jpg)
statements
• Command
• Statements end with ;
04/19/23 cosc236/intro 18
![Page 19: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/19.jpg)
04/19/23 cosc236/intro 19
System.out.println
• Line of output sent to console window• System.out.println("Hello World!");• System.out.println();• System.out.print("Hello");• //does not move to next line of output
![Page 20: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/20.jpg)
04/19/23 cosc236/intro 20
Literal string
• Surrounded by quotes• One line• Escape sequences
\t tab
\n new line
\” quotation
\\ backslash• System.out.println(" \"Slick\" Willy"); "Slick" Willy
![Page 21: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/21.jpg)
04/19/23 cosc236/intro 21
Example
System.out.println("This\nyields three lines\nof output\n");
This
yields three lines
of output
![Page 22: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/22.jpg)
04/19/23 cosc236/intro 22
Identifiers • used to name variables, constants,
methods, classes, and data types • Rules:
– must start with letter or underscore or $– Composed of letters, digits, $, or
underscore (better to start with a letter)
• Using Meaningful, Readable Identifiers!• Java is case sensitive• Don't use reserved words
![Page 23: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/23.jpg)
04/19/23 cosc236/intro 23
Identifiers
• Legal:
firstName
conversion
lengthOfRoom
payRate
counter1
x
• Illegal
first name
Hello!
5th
one+two
![Page 24: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/24.jpg)
04/19/23 cosc236/intro 24
Identifiers - Style Class name
Begin with capital letter Method
Begin with lowercase Exa: calcPay,getInfo, sum
• Constants: all caps• PI, MAX_HOURS, UNIV_NAME
![Page 25: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/25.jpg)
04/19/23 cosc236/intro 25
Comments• Compiler ignores comments
• /* */ everything between pair is ignored
• // - everything after the two slashes to the end of line is ignored
• header comment:• //Project number• //Student's name Date project is due• //Course number• //Purpose of the program
![Page 26: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/26.jpg)
04/19/23 cosc236/intro 26
When to use comments
• Comment variable and constant declarations.
• Precede blocks of code with an explanatory comment.
• Explain statements that are not obvious.• Precede each class with a brief header
comment
![Page 27: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/27.jpg)
04/19/23 cosc236/intro 27
Readability
• Class and method headers on lines by themselves
• One statement per line• Indent• Use whitespace liberally in the form of
blank lines and spaces.• Include at least one blank line between
methods
![Page 28: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/28.jpg)
04/19/23 cosc236/intro 28
Syntax
• Syntax - formal set of rules governing how valid instructions are written in a programming language
![Page 29: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/29.jpg)
04/19/23 cosc236/intro 29
Program Errors
• Syntax error – error in using Java, indicated by compiler– Cannot execute– Exa: File name does not match class name
• Logic error (bug) – code doesn't perform the intended task– debugging
![Page 30: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/30.jpg)
04/19/23 cosc236/intro 30
Structured Programming
• Control structures1. sequence
2. selection
3. Loop
• Modularity/Top-Down Design
– Decomposition – separation into parts
– Functions, procedures => methods
![Page 31: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/31.jpg)
04/19/23 cosc236/intro 31
Static method
• A block of statements that is given a name• Static
– allows non object-oriented invocation– Use no instance variable of any object they are
declared in
• Method call– Transfers control
• Methods can call other methods
![Page 32: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/32.jpg)
04/19/23 cosc236/intro 32
public class Memo { public static void main(String[] args) { printLogo(); //method call System.out.println("Reminder:" ); System.out.println("Company Meeting"); System.out.println("Thursday at 9:00!!!!"); printLogo(); } /* end main */ public static void printLogo() // method header { System.out.println("*************************************"); System.out.println("**********YOUR COMPANY********"); System.out.println("*************************************"); }}
![Page 33: Overview of the Computer](https://reader035.fdocuments.net/reader035/viewer/2022062422/56812bdf550346895d905009/html5/thumbnails/33.jpg)
04/19/23 cosc236/intro 33
Design/Plan the solution
• Algorithm – a step by step procedure for solving a problem, ordered set of instructions such that:
• programs are implementations of algorithms, emphasis on writing algorithms.
• the computer is a fast and flexible tool for implementing algorithms.
• tools– flowcharts – Pseudocode– subtasks - hierarchy chart
• test solution for correctness - trace