CP122 CS I Chapter 1: Introduction
Introductions
Webpage and Syllabus cs.coloradocollege.edu/~mwhitehead
Hacker's Tip of the Day Hacker A person interested in how things work. A critical thinker, an endless tinkerer, a knowledge investigator, a bright engineer.
Hacker's Tip of the Day Hacker A person interested in how things work. A critical thinker, an endless tinkerer, a knowledge investigator, a bright engineer. Cracker A person who breaks into computer systems for malicious purposes.
Goals for the Class Learn about programming. Work with algorithms and computational thinking. Figure out what computer science means. Take over the world.
Chapter 1: Introduction What kinds of problems do computer scientists work on? What are the components of a modern computer? What exactly is programming and how is it done?
What do Computer Scientists do? Programming :)
What do Computer Scientists do? Databases How can we efficiently store massive amount of data?
What do Computer Scientists do? Artificial Intelligence Can we make machines smart? Can we make machines smarter than humans?
What do Computer Scientists do? Graphics How can we make beautiful computer games and computergenerated movies?
What do Computer Scientists do? Theory of Computation What is mathematically possible to compute?
What do Computer Scientists do? Programming Languages What kinds of languages can we use to program computers? AlephLanguage println "Hello World!" AppleScript on helloworld() display dialog "Hello World!" buttons {"OK"} end helloworld Awk echo "Hello World" awk '{print $0}' Basic 10 PRINT "HELLO WORLD"
What do Computer Scientists do? Security How can we prevent unwanted access to computer systems?
What do Computer Scientists do? Scientific Computing How can we use computers to solve difficult/large problems in science?
What do Computer Scientists do? Networking and Communication How can we effectively connect computer systems together?
Why Study Computer Science? Do you like solving problems? There are almost endless interesting problems in CS
Why Study Computer Science? Do you like solving problems? There are almost endless interesting problems in CS Do you have varied interests? You can use CS knowledge to write music software, run giant physics simulations, predict the stock market, develop medical software, etc.
Why Study Computer Science?
CNNMoney
Wall Street Journal Best Jobs 2010
Why Study Computer Science? It's an exciting time! Think how different technology is today vs. 10 years ago What will things be like in 20 years? 50 years? 100 years?
Why Study Computer Science? It's an exciting time! Think how different technology is today vs. 10 years ago What will things be like in 20 years? 50 years? 100 years? In 10-20 years, a $2000 computer will be equivalent in processing power to a human brain
Why Study Computer Science? It's an exciting time! Think how different technology is today vs. 10 years ago What will things be like in 20 years? 50 years? 100 years? In 10-20 years, a $2000 computer will be equivalent in processing power to a human brain In 30-40 years, a $2000 computer will be equivalent in processing power to ALL human brains
Computer Hardware Overview
Central Processing Unit (CPU) Execute basic instructions Registers hold the data for calculations Registers get data from memory (RAM) using the LOAD operation High-speed CPU cache speeds up memory data access
Main Memory (Random Access Memory: RAM) Volatile storage of program instructions and data An array of words Address Value 0xde88ca9c 15 0xde88ca9d 0xde88ca9e hi! LOAD......
Secondary Storage (Harddrive) Long-term storage of programs and data Contains a file system for organization of files and directories Solid-state drives are becoming more popular
Other I/O Devices (Keyboard, Monitor, etc.) Interface with the user Provide data input/output
System Bus Connector that links CPU and RAM Built in to the motherboard I/O buses also connect to the System Bus
Cost/Speed of Storage Device Relative Cost Access Time (estimate in ns) CPU Register $$$$ 0.5 CPU Cache $$$ 0.5-1 RAM $$ 100 Harddrive $ 5,000,000
What is a computer program?
How are Computers Programmed? Step 1: Write a.java file in plain text
How are Computers Programmed? Compilation Step 2: Compile the program into a special low-level language that can be executed
How are Computers Programmed? JVM Step 3: Execute the program by loading it with the Java Virtual Machine and launching it on the CPU
How are Computers Programmed in Java? Step 1: Write Java code in a plaintext file (.java file) Step 2: Compile the Java code into a bytecode file (.class file) Step 3: Execute the byte-code in the Java Virtual Machine (JVM)
What Does a Java Program Look Like? public class MyFirstProgram { } public static void main(string[] args) { System.out.println( This is my first program! ); }
What Does a Java Program Look program (chosen by Like? public class MyFirstProgram { This is the name of our us!) } public static void main(string[] args) { System.out.println( This is my first program! ); }
Our program is a class. A What Does a Java Program Look class is a blueprint for Like? creating an object. public class MyFirstProgram { } public static void main(string[] args) { System.out.println( This is my first program! ); }
What Does main is a the Java name Program of a method Look in our class. A Like? method is a block of code that performs a task. public class MyFirstProgram { } public static void main(string[] args) { System.out.println( This is my first program! ); }
What Does Whenever a Java a program Program starts Look running, it always Like? begins executing code in its main method. public class MyFirstProgram { } public static void main(string[] args) { System.out.println( This is my first program! ); }
What Does The body a Java of the main Program method is Look defined inside Like? of these curly braces. public class MyFirstProgram { } public static void main(string[] args) { System.out.println( This is my first program! ); }
What Does Each line a of Java code Program is called a Look statement. Like? This statement prints out some text to the screen. public class MyFirstProgram { } public static void main(string[] args) { System.out.println( This is my first program! ); }
What Does a Java Program Look println stands for Print Like? Line. println is just another method like our main method. public class MyFirstProgram { } public static void main(string[] args) { System.out.println( This is my first program! ); }
What System Does refers to a another Java Program class that Look implements low-level Like? system tasks (like displaying text on the screen) public class MyFirstProgram { } public static void main(string[] args) { System.out.println( This is my first program! ); }
What Does a Java Program Look Like? public class MyFirstProgram { public static void main(string[] args) { System.out.println( This is my first program! ); } } The text This is my first program! is called a String and will be displayed when this programs runs. It is inside quotation marks so it can be distinguished from regular Java instructions.
What Does a Java Program Look Like? public class MyFirstProgram { public static void main(string[] args) { System.out.println( This is my first program! ); } } This String is a parameter being passed to the println method. println has to know what to print, right? The parameter provides that value.
What Does What a do Java public, Program static, and Look void stand for? Like? We'll cover these very soon. public class MyFirstProgram { } public static void main(string[] args) { System.out.println( This is my first program! ); }
Installing Java
Let's Write It and Run It!
Documenting Our Program // This is my first program ever public class MyFirstProgram { } public static void main(string[] args) { /* This is a multiline comment Display a message to the screen */ System.out.println( This is my first program! ); }
When Things Go Horribly Wrong Compiler error: a syntactical problem with a program (the program doesn't obey the syntax rules of the programming language)
When Things Go Horribly Wrong Compiler error: a syntactical problem with a program (the program doesn't obey the syntax rules of the programming language) Run-time error: the program generates an error (called an exception) E.g. Division by zero
When Things Go Horribly Wrong Compiler error: a syntactical problem with a program (the program doesn't obey the syntax rules of the programming language) Run-time error: the program generates an error (called an exception) E.g. Division by zero Logical error: the program doesn't do the right thing
Algorithm Informal definition: a series of steps to solve a problem
No-Knead Bread Recipe Combine 3 cups flour, 1.5 cups water, 0.25 tsps yeast, and 2 tsps salt in a bowl Mix the ingredients Wait for the bread to rise Dump the dough into a bread pan Bake for 56 minutes at 400 degrees (if you live at 6500') Let bread cool for 1 hour before eating
Algorithm Formal definition: a sequence of steps that is unambiguous, executable, and terminating
No-Knead Bread Algorithm? Combine 3 cups flour, 1.5 cups water, 0.25 tsps yeast, and 2 tsps salt in a bowl Mix the ingredients Wait for the bread to rise Dump the dough into a bread pan Bake for 56 minutes at 400 degrees (if you live at 6500') Let bread cool for 1 hour before eating
Break!