Lecture 2, CS 302-7 and 8, January 25
- Reminders
- Labs
start Tuesday, January 31 (next week)
- Exam
conflicts – online form (lab)
- Office
hours
- Codelab
- Review
- For
the new people – we went over syllabus, talked about computer science,
and introduced the idea of an algorithm
- Brief
intro to what is Computer science
- Wikipedia:
i.
“Computer science [] is the study of the theoretical
foundations of information and computation
and of practical techniques for their implementation and application in computer
systems.[1][2] Computer scientists invent algorithmic
processes that create, describe, and transform information and formulate
suitable abstractions to model complex
systems.”
- Edsger Dijkstra:
i.
"Computer science is
no more about computers than astronomy is about telescopes."
- Richard
Feynman:
i.
Computer
science also differs from physics in that it is not actually a science. It does
not study natural objects. Neither is it, as you might think, mathematics;
although it does use mathematical reasoning pretty extensively. Rather,
computer science is like engineering; it is all about getting something to do
something, rather than just dealing with abstractions
- What
is an algorithm? Sequence of steps
for doing something. Basically, a
recipe
- All
algorithms must meet three criteria
i.
Unambiguous
1.
Precise Instructions
ii.
Executable
1.
Can be done
iii.
Terminating
1.
Ends
- Pseudocode
is a language for writing algorithms – it is somewhere between
programming and English. It is
not a formal language – it is just a term used to describe the way that
programmers often describe their algorithms
- What
is a program?
- Sequence
of instructions and decisions.
i.
Tells a computer exactly how to perform a task
- You
can think of a program as a concrete implementation of an algorithm in a
form that a computer understands
- Steps
to writing a java program (textbook):
i.
Understand the problem
ii.
Develop and describe an algorithm
iii.
Test the algorithm with simple inputs
iv.
Translate the algorithm into java
v.
Compile and test your program
- Intro
to Java
- Java
is a more formal way of telling a computer how to do something
- Java
is one example of a programming language
- Java
is a language that a computer can understand…kind of. It is what is called a high level
language.
- Note
– if you want to use java on your home computer, you will need to
download the Java Software Development Kit (SDK) – JRE (Java Runtime
Environment) is not enough – MORE ON THIS NEXT WEEK
- Machine
code
- The
computer still doesn’t understand java directly
- What
does a computer understand?
Machine Code. These are
very low-level instructions – basically, just patterns of bits.
- The
processor of the computer is wired so that it understands these commands
via its circuits
- What
is a bit? 0 or 1.
- Compiled
Languages/Compilers
- Many
programming languages are compiled directly into machine code. This is done by a compiler.
- Basically,
a compiler is a computer program that converts a high level language into
machine code. Note – I will not
use Java as an example here.
Instead, I will use C.
- Say
you write a C program. You’ll
have to run a command to compile it.
If you want to run it on a Windows computer, you’ll have to use
one Compiler to compile it. If
you want to run it on a Mac, you’ll need to use a different Compiler to
compile it.
- C is
an example of a compiled language
- Example
– growing up, remember how you needed different CDs for Macs and Windows?
- Interpreted
Languages
- So,
I mentioned that Java is not an example of the above. Why?
Java is what is called an interpreted language.
- The
Java compiler does not turn the java program into machine code. Instead, it translates it into java
byte code. Byte code is an
intermediate form of computer code – it is lower level than Java, but
higher level than machine code.
- When
you download a java program, this is what you download - __.class file
- Then,
your computer has a program called the Java Virtual Machine installed on
it. When you run a java program,
this converts the Byte Code into Machine Code at runtime, to make it
directly readable by the computer.
- This
means that the same java program can run across platforms – Mac, Windows,
etc. You just need to have the
correct JVM installed
- Note
– this means that interpreted languages are Slower
- So,
why do we use Java for this course?
- Important/useful
language
- Portability
(see above – also means it’s slow)
- Ease
of programming
- Error
Reporting
- Java
class library
- Programming
environments
- Eclipse
i.
We’ll be using Eclipse for our class
ii.
Eclipse is an IDE – Integrated Development Environment
iii.
Features – in the same screen, you can write code, display
results, compile, see code tree structure, etc.
iv.
Also annotates code for correctness, kind of like spell check
- Terminal
window/text editor
i.
Compile via
console, edit in text editor
ii.
Not as many bells and whistles as Eclipse
- You’ll
be using Eclipse in labs/for homework, so I’ll use that throughout the
course
- Java files
- Source.java
- Source.class
- .java
is java code (the program you write), .class is java byte code
- Our
first program - Hello World
- HelloWorld.java
- HW:
- Finish
reading ch. 1 in the textbook