Lecture 2, CS 302-7 and 8, January 25

  1. Reminders
    1. Labs start Tuesday, January 31 (next week)
    2. Exam conflicts – online form (lab)
    3. Office hours
    4. Codelab
  2. Review
    1. For the new people – we went over syllabus, talked about computer science, and introduced the idea of an algorithm
  3. Brief intro to what is Computer science
    1. 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.”

    1. Edsger Dijkstra:

                                                               i.      "Computer science is no more about computers than astronomy is about telescopes."

    1. 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

  1. What is an algorithm?  Sequence of steps for doing something.  Basically, a recipe
    1. All algorithms must meet three criteria

                                                               i.      Unambiguous

1.      Precise Instructions

                                                             ii.      Executable

1.      Can be done

                                                            iii.      Terminating

1.      Ends

    1. 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
  1. What is a program?
    1. Sequence of instructions and decisions.

                                                               i.      Tells a computer exactly how to perform a task

    1. You can think of a program as a concrete implementation of an algorithm in a form that a computer understands
    2. 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

  1. Intro to Java
    1. Java is a more formal way of telling a computer how to do something
    2. Java is one example of a programming language
    3. Java is a language that a computer can understand…kind of.  It is what is called a high level language.
    4. 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
  2. Machine code
    1. The computer still doesn’t understand java directly
    2. What does a computer understand?  Machine Code.  These are very low-level instructions – basically, just patterns of bits.
    3. The processor of the computer is wired so that it understands these commands via its circuits
    4. What is a bit?  0 or 1.
  3. Compiled Languages/Compilers
    1. Many programming languages are compiled directly into machine code.  This is done by a compiler.
    2. 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.
    3. 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.
    4. C is an example of a compiled language
    5. Example – growing up, remember how you needed different CDs for Macs and Windows?
  4. Interpreted Languages
    1. So, I mentioned that Java is not an example of the above.  Why?  Java is what is called an interpreted language.
    2. 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.
    3. When you download a java program, this is what you download - __.class file
    4. 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.
    5. This means that the same java program can run across platforms – Mac, Windows, etc.  You just need to have the correct JVM installed
    6. Note – this means that interpreted languages are Slower
  5. So, why do we use Java for this course?
    1. Important/useful language
    2. Portability (see above – also means it’s slow)
    3. Ease of programming
    4. Error Reporting
    5. Java class library
  6. Programming environments
    1. 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

    1. Terminal window/text editor

                                                               i.      Compile via console, edit in text editor

                                                             ii.      Not as many bells and whistles as Eclipse

    1. You’ll be using Eclipse in labs/for homework, so I’ll use that throughout the course
  1. Java files
    1. Source.java
    2. Source.class
    3. .java is java code (the program you write), .class is java byte code
  2. Our first program - Hello World
    1. HelloWorld.java
  3. HW:
    1. Finish reading ch. 1 in the textbook