comp 14: intro. to intro. to programming may 23, 2000 nick vallidis
Post on 22-Dec-2015
226 views
TRANSCRIPT
![Page 1: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/1.jpg)
COMP 14: Intro. to Intro. to Programming
May 23, 2000
Nick Vallidis
![Page 2: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/2.jpg)
What we’ll talk about today...
Brief overview of computers Hardware and Software What is programming? Java Algorithms
![Page 3: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/3.jpg)
Computers
Basically “information processors”– Take info, do something to it, spit it out again
Digital– Store the information as numbers (“digits”)
Use the binary number system
![Page 4: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/4.jpg)
Computers are made of 2 things
Hardware– The part you can see and touch– CPU, monitor, mouse, keyboard
Software– Information to tell the computer HOW to
process information– OS, compiler, word processor, games, etc.
![Page 5: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/5.jpg)
Hardware
CPU: Pentium (II/III), Alpha, Athlon Memory: RAM, floppy disk, hard drive, CD Input Devices: keyboard, mouse, data tablet Output Devices: monitor, printer
![Page 6: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/6.jpg)
Our view of the hardware
Monitor
Keyboard
MainMemory
CentralProcessing
Unit
Floppy Disk
Hard Disk
Secondary Memory
![Page 7: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/7.jpg)
CPU
“Central Processing Unit” Continuously does fetch-decode-execute
fetch
Retrieve an instruction from main memoryRetrieve an instruction from main memory
decode
Determine what theDetermine what theinstruction isinstruction is
execute
Carry out theCarry out theinstructioninstruction
![Page 8: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/8.jpg)
Memory
An address is the name of a specific location in memory
Main Memory– run programs from here– fast, volatile
Secondary Memory– slow– permanent
![Page 9: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/9.jpg)
This class is about Software
Operating System (OS)– Understands the hardware– Simplifies your interaction with the hardware– Controls starting/stopping applications
Applications– any software that isn’t the OS– what you will learn to write
![Page 10: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/10.jpg)
Computer Languages
Machine Language– the form the CPU understands– strings of 1’s and 0’s
Assembly Language– people-friendly version of machine language
High-level languages– Java, C++, FORTRAN, COBOL, BASIC
![Page 11: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/11.jpg)
Compilers and Interpreters
Both are ways to turn high-level languages into something the computer can execute
Compilers turn a source code file into an executable
Interpreters let you type the program into it and run it directly
![Page 12: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/12.jpg)
Java is compiled and interpreted
Java sourcecode
Machinecode
Javabytecode
Javainterpreter
Bytecodecompiler
Javacompiler
![Page 13: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/13.jpg)
So what is programming?
Programming IS problem solving Takes multiple steps:
– understand what the problem is– find a solution (algorithm) for the problem– determine if the solution is correct– implement the solution– test the solution implementation
![Page 14: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/14.jpg)
Implementation
Not any more important than other steps, but probably the one you know the least about
We are using Java
![Page 15: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/15.jpg)
Simple Java Program
public class Simple
{
public static void main(String[] args)
{
System.out.println(“Hello!”);
}
}
![Page 16: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/16.jpg)
Simple Java Program
public class Simple
{
public static void main(String[] args)
{
System.out.println(“Hello!”);
}
}
All programs have to be part of a class
![Page 17: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/17.jpg)
Simple Java Program
public class Simple
{
public static void main(String[] args)
{
System.out.println(“Hello!”);
}
}
Tells the computer where to start running the program
![Page 18: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/18.jpg)
Simple Java Program
public class Simple
{
public static void main(String[] args)
{
System.out.println(“Hello!”);
}
}Braces indicate where different sections of the program begin and end
![Page 19: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/19.jpg)
Simple Java Program
public class Simple
{
public static void main(String[] args)
{
System.out.println(“Hello!”);
}
} This tells the computer to print out “Hello!” (without quotes)
![Page 20: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/20.jpg)
Simple Java Program
public class Simple
{
public static void main(String[] args)
{
System.out.println(“Hello!”);
}
} This indicates the end of a statement (one “step” in the program)
![Page 21: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/21.jpg)
Simple Java Program
public class Simple
{
public static void main(String[] args)
{
System.out.println(“Hello!”);
}
}These are reserved words in Java. This means that Java uses them for a special purpose
![Page 22: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/22.jpg)
Java Reserved Words
abstractbooleanbreakbytebyvaluecasecastcatchcharclassconstcontinue
defaultdodoubleelseextendsfalsefinalfinallyfloatforfuturegeneric
gotoifimplementsimportinnerinstanceofintinterfacelongnativenewnull
operatorouterpackageprivateprotectedpublicrestreturnshortstaticsuperswitch
synchronizedthisthrowthrowstransienttruetryvarvoidvolatilewhile
![Page 23: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/23.jpg)
Simple Java Program
public class Simple
{
public static void main(String[] args)
{
System.out.println(“Hello!”);
}
}These are identifiers. These are words chosen by a programmer as names for things.
![Page 24: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/24.jpg)
Java Identifiers
Can include letters, digits, $, and _ Must not start with a digit They are case sensitive
![Page 25: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/25.jpg)
Simple Java Program
public class Simple
{
public static void main(String[] args)
{
System.out.println(“Hello!”);
}
}
Red identifiers were chosen by the author of this program
Blue identifiers were chosen by another programmer.
![Page 26: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/26.jpg)
Identifier guidelines
You want to choose descriptive identifiers– things like a, b, dm, tu are bad– things like lastValue, $cost are good
If multiple words, start each new word with a capital letter
![Page 27: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/27.jpg)
Comments
You can insert comments in the code that are completely ignored by the compiler
two styles:– /* everything in here is a comment */– // everything to the end of line is a comment
I was very bad and didn’t comment the program I showed before. Let’s fix that...
![Page 28: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/28.jpg)
Simple Java Program
/* a very simple Java program */
public class Simple
{
// prints a message to the user
public static void main(String[] args)
{
System.out.println(“Hello!”);
}
}
![Page 29: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/29.jpg)
Algorithms
A step-by-step description of a solution to a problem
In some sense the computer is stupid and needs very explicit instructions
![Page 30: COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis](https://reader035.vdocument.in/reader035/viewer/2022062715/56649d7a5503460f94a5da80/html5/thumbnails/30.jpg)
Homework
Read Ch. 1 (there are more specific instructions on the web page, but it’s ok if you just read the whole thing)
Write an algorithm for making a peanut butter and jelly sandwich