Download presentation
Presentation is loading. Please wait.
Published byCameron Johnston Modified over 9 years ago
1
CS 201: Introduction to Programming Tarik Booker Department of Computer Science California State University, Los Angeles
2
Topics Prologue Introduction Programming Languages Machine language Assembly Language High Level Language Operating Systems Java Java Language Specification, API, JDK, IDE Java Programming Programming Style Errors
3
Prologue: (A little history…)
4
A little history…
5
A little history… (2)
6
A little history…
7
From Cambridge University Digital Library (http://cudl.lib.cam.ac.uk/)
8
A little history… Charles Babbage (1791 – 1871) Mathematician Philosopher Inventor Mechanical Engineer Genius A bit eccentric! "Table of the Relative Frequency of the Causes of Breakage of Plate Glass Windows“ (Mechanics Magazine 1857)
9
A little history… A year ago, you swore, fond she ! "To love, to honour," and so forth: Such was the vow you pledged to me, And here's exactly what 'tis worth. Lord Byron (1788-1824) First “Rock Star” Anne Isabella Byron (1792-1860)
10
A little history… Ada (Byron) Lovelace (1815 – 1852) How to compensate for a crazy father? Math! Trained Mathematician Introduced to Babbage at 12 Issuing professional work by 17 years of age Died at 36
11
A little history… (3) Charles Babbage (1791 – 1871) Ada (Byron) Lovelace (1815 – 1852) The Difference Engine (Designed but never built) + + =
12
A little history… Difference Engine
13
A little history… Analytical Engine
14
A little history…
15
A little history… (5) += Alan Turing (1912 – 1954) Enigma Machine
16
A little history… Bombe
17
A little history… The Difference Engine (in motion) (created 2008) https://www.youtube.com/watch?v=jiRgdaknJCg The BOMBE (restored at Bletchley Park) https://www.youtube.com/watch?v=5nK_ft0Lf1s (Operation at 8:45)
18
A little history… Using an Astrolabe https://www.youtube.com/watch?v=7COCkxpEvzs https://www.youtube.com/watch?v=yioZhHe1i5M Using a back staff: https://www.youtube.com/watch?v=-gK87XVCaN8 https://www.youtube.com/watch?v=ZM0_hp4G0BY
19
A little history… Charles Babbage http://en.wikipedia.org/wiki/Charles_Babbage Ada (Byron) Lovelace http://en.wikipedia.org/wiki/Ada_Lovelace Lord Byron http://en.wikipedia.org/wiki/Lord_Byron
20
Introduction Programming? Create / Develop Software Instructions Devices Not just computers? Cell phones Cars Refrigerators? Programming Languages Used to create instructions Different ones have different strengths and weaknesses
21
Programming Languages Different languages have different strengths Java – sophisticated, portable Newer Languages Ruby Python Older Languages C/C++ Ancient Fortran, COBOL, LISP
22
What is a Computer? Both hardware and software Hardware Actual physical device Electronics Software Invisible Instructions “Electricity”
23
What is a Computer (2) Hardware – Major components: Central Processing Unit (CPU) Memory (Main Memory) Storage Devices Input devices Output devices Communication Devices All connected with a bus – connection between all components Think of a highway
24
The CPU Central Processing Unit “Brain” of the Computer Two different internal components Control Unit Arithmetic Logic Unit (ALU) Based on semiconductor chips All have tiny switches (transistors) Contains a clock Keeps synchronization (and control) MHz, GHz(Hz = 1/s) Cores Part that reads instructions Multi-core
25
Bits / Bytes Bit – result of one switch Switch off – 0 (zero/ low) Switch on – 1 (one / high) How many switches do you know of? (L) What else? Computer – many (millions/billions of) switches Digital / Analog Analog (natural) info is converted to switches (digital)
26
Bits / Bytes (2) Byte – 8 bits ( 8 switches) Bit – binary digit Byte is minimum storage unit in a computer Can store a number (ex: 3) in a byte How? Many things can be encoded into bytes (digitally encoded) Numbers Text Audio Video Data (biometrical, biological)
27
Bits / Bytes (3) DNA Computing Use DNA to execute instructions
28
Bits / Bytes (4) Encoding Scheme Set of rules that govern how a computer translates info into data Standardized Music MP3 Wav Text ASCII UNICODE Images Jpg GIF Many, many, many more
29
Bits/Bytes (5) Memory Storage Capacity In bytes: 1 Kilobyte (KB) = 1,000 bytes 1 Megabyte (MB) = 1,000,000 bytes (million) 1 Gigabyte (GB) = 1,000,000,000 bytes (billion) 1 Terabyte (TB) = 1,000,000,000,000 bytes (trillion) Typically: Word doc: 20KB 1MB = ~50p of documents 2 Hour High-Def Movie = 8GB 20 Movies: 160GB What are (look up)? 1 Petabyte? 1 Exabyte?
30
Memory An ordered sequence of bytes for storing programs and data Work area for CPU Program and data must be moved here before execution (running the instructions) Every byte has a (unique) address Locate the byte for storage and retrieval Can be accessed in any order Called Random Access Memory (RAM) Most PC’s have ~4gigabytes of RAM Typically, the more RAM, the faster the computer Note, memory can contain garbage Deletion doesn’t remove the info Removes address
31
Storage Devices Internal memory (RAM) is volatile! When power is removed, saved information is lost Programs should be permanently stored on the computer How? (Secondary) Storage devices When power is removed, information stays Called persistent Note: Storage devices are notably slower than (internal) memory Three main types Magnetic disk drives Optical Disk Drives (CD, DVD) USB Flash Drives
32
Storage Devices (2) Disks Computer typically contains a hard disk drive Hard disk permanently stores programs (and data) Typically encased within computer
33
Storage Devices (3) CD Compact Disc Two different types CD-R (Read only) CR-RW (Read-Write) Can be used like a hard disk CD can hold up to 700MB (Second movement of Beethoven’s Ninth Symphony)
34
Storage Devices (4) DVD Holds much more info 4.7 GB DVD-R, DVD-RW
35
Storage Devices (5) USB Flash Drives Universal Serial Bus (USB) Allows you to “hot swap” different devices to the computer Flash Drive Flash Memory Currently up to 256 GB
36
Storage Devices (6) Interesting example: http://www.extremete ch.com/extreme/1346 72-harvard-cracks-dna- storage-crams-700- terabytes-of-data-into- a-single-gram
37
Input / Output Devices Lets the user communicate with the computer Most common Keyboard Mouse Monitor Other Trackball Joystick Eye Scanner What else?
38
Communication Devices Devices that allow computers to communicate with other computers (or devices) Dial up modem Digital Subscriber Line (DSL) Cable Modem Network Interface Card (NIC) Wireless networking Bluetooth
39
Other Types of Devices Biometric Devices Scan information What else can you think of?
40
Programing Languages The computer is a machine, and therefore must communicate in a way that is preferrable to the machine Machine Language The computer’s “native” language Directly in binary code (1’s and 0’s) Typically the instruction, then the operands Ex:1101101010011010 Assembly (Language) The previous alternative to machine code (language) Used a word (mnemonic) to describe each machine instruction Computer can’t execute, so must be converted to machine language Uses an “assembler” Ex:add 2, 3, result
41
Programming Languages (2) High Level Language Platform independent Can run on different CPUs Easier to use Like English – easier to learn Instructions in this language are called statements Ex:area = 5 * 5 * 3.14159; Many different types of High level Languages Ada, BASIC, C, C++, C#, Ruby, Pascal, Python, etc. Java
42
Operating Systems Main program that runs on a computer Manages and controls a computer’s activities Every computer you use has an operating system Controls: Controlling and monitoring system activities Allocating and assigning system resources Scheduling operations Different types of Operating Systems Windows Jaguar (Mac) Linux
43
Operating Systems (2) Controlling and Monitoring System Activities Performing basic tasks Recognizing input (keyboard, mouse, etc.) Sending output (monitor, printer, etc.) Keeping track of files and folders on storage devices Controlling “peripheral” devices Disk drives Printers Making sure programs (and users) do not interfere with each other Security
44
Operating Systems (3) Allocating and Assigning System Resources Responsible for system resources CPU time Memory Space Disk allocation I/O device allocation
45
Operating Systems (4) Scheduling Multiprogramming Multithreading Multiprocessing Parallel Processing Oscar.calstatela.edu Operating System (OS) does much much more!
46
Java This class introduces programming in Java Developed at Sun Microsystems (1991) James Gosling (Bought by ORACLE in 2010) Designed for use in embedded chips in consumer electronic appliances Redesigned and Java for developing Web applications Applets (got better!) Became incredibly popular “Write once, run anywhere” General purpose, high-level programming language Used for robust, mission-critical applications
47
Java (2) Useful for many different applications Mission critical applications Used on Mars rover Web (internet applications) Applets Rich Internet Application (RIA) Same features as desktop software Google docs Servers Dynamic Pages JSP
48
Java Language Specification Computer languages have strict rules Combined in a specification Technical definition of language structure Java language specification Technical definition of Java http://docs.oracle.com/javase/specs/ Application Program Interface (API) Contains predefined classes and interfaces for developing java programs Still expanding!! http://download.java.net/jdk8/docs/api/
49
Java Specification (2) Three editions of Java: Java Standard Edition (Java SE) Develop Client-side applications Run standalone Run as an applet Java Enterprise Edition (Java EE) Develop server-side applications (web) Java Servlets Java Server Pages (JSP) Java Micro Edition (Java ME) Develop mobile-device applications Cell phones The material in this class uses Java SE!!!!!!
50
JDK Java Development Kit (Toolkit) Collection of Programs to program with Java Integrated Desktop Environment (IDE) Software development tool to write and edit Java programs Comes with a JDK IDE allows you write, compile, and run Java files JDK allows you to compile and run Java files
51
Basic Java Program This program displays “Welcome to Java” on console output Console – the (old) name for text input and output on a computer Input – receive information Output – display information public class Welcome { public Static void main(String[] args) { //Display message on the console System.out.println(“Welcome to Java!”); }
52
Java Program Structure Lets look at the program line by line: We need to define a class Every program is written inside of a class (with its own name) Start each class name with an uppercase letter (by convention) Define the main method Where the program is executed from Note: a class may contain several methods Every program begins in main A method is the area to write statements Write to the console System.out.println writes to the console Writes the string (text) Welcome to Java! Strings must be enclosed in double quotes (“”) End each statement with a semicolon (;) Called the statement terminator
53
Java Program Structure (2) Reserved words There are certain words that are specific to the compiler and can’t be used for other purposes (in your program) Only use these words for these specific purposes. Reserved words (keywords) Class Public Static Void Comments Used to insert info in the program that is specifically meant to not be seen by the compiler (Java) Ignored by
54
Java Program Structure (3) Curly braces Forms a block the groups the program’s components Open brace and closing brace Every programming group has a block Class block Method block Blocks can be nested One block in within another Let’s look at the other program now!
55
Java Program Structure (4) public class Welcome { public Static void main(String[] args) { //Display message on the console System.out.println(“Welcome to Java!”); }
56
Creating Compiling, and Executing a Java Program You have to create your own program Make sure it works If it doesn’t compile you will not be able to run it! You can compile and run from a command window!
57
Compiling and Running a File Write your program Save as.java Type javac filename.java Javac = java compile Compiles to a.class file(s) Run java classname.class Runs this within a JVM (Java Virtual Machine)
58
The Java Virtual Machine The Java Virtual Machine (JVM) is the runtime environment A virtual computer that runs your environment Runs “around” the CPU Creates a layer between the CPU and the Java Program Java is compiled down to bytecode Not machine language JVM is run between the CPU and the Program Slower than something run directly on the CPU This makes the program portable Different JVM’s for different computers (CPUs)
59
Programming Style Make sure you do the following: Appropriate Comments Proper Indentation and Spacing Space operators Block Styles Next-line style End of line style
60
Errors There are three possible errors in java Syntax Errors Problems with spelling Missing characters Runtime Errors Abnormal termination Logic Errors
61
Using an IDE Use Textpad or Netbeans Eclipse is a very powerful IDE we will cover later Good luck!
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.