Lecture 2, CS 302-6, September 7

  1. Review
    1. Last time - we went over syllabus, talked about computer science, and what an algorithm is
    2. What is an algorithm?  Sequence of steps for doing something.  Basically, a recipe

                                                               i.      Unambiguous

                                                             ii.      Executable

                                                            iii.      Terminating

    1. Pseudocode – language for writing algorithms
    2. What is a program?  Sequence of instructions and decisions.
    3. Steps to writing a 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 instructing computers how to do something
    2. Java is one example of a programming language
    3. As stated before, computers only do exactly what you tell them too
    4. Java is a language that a computer can understand…kind of.  It is what is called a high level language.
    5. History of Java:

                                                               i.      Started in 1991, released 1995

                                                             ii.      Released by sun Microsystems

                                                            iii.      Current stable release – version seven

                                                           iv.      Very often used in web applets

                                                             v.      Open source

    1. 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
  1. Machine Code
    1. The above is kind of a misnomer – the computer still doesn’t understand java.
    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 – circuits
    4. What is a bit?  0 or 1.
    5. So, 32 bit - this is what it means when you hear about 32 bit, 64 bit Windows.  Each instruction consists of 32 0’s and 1’s.  This is directly readable by the computer’s processor.

                                                               i.      Machine code has instructions like add, subtract, binary operators (AND, OR)

    1. Want to know more?  Take a computer architecture course.
  1. 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.
  2. Interpreted Languages
    1. 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 turns 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.
    4. Your computer has a program installed on it called the Java Virtual Machine.  When you run a java program, this converts the Byte Code into Machine Code at runtime, to make it readable by the computer. 
    5. This means that the same java program can run across platforms – Mac, Windows, etc.  They just need the correct JVM.
    6. Want to know more?  Take a programming languages class
  3. So, why Java?
    1. Error Reporting
    2. Portability - - trade off!  This makes Java slower than a compiled language
    3. Ease of programming
    4. Important/useful language
    5. Java class library
  4. Programming environments
    1. Eclipse

                                                               i.      This is an IDE – Integrated Development Environment

                                                             ii.      Features – in the same screen, you can write code, display results, compile, see tree structure, etc.  Also annotates code for correctness, kind of like spell check

    1. Console/text editor

                                                               i.      Compile via console, edit in text editor

    1. You’ll be using Eclipse in labs, so I’ll demonstrate with that
  1. Java files
    1. Source.java
    2. Source.class
    3. .java is java code, .class is java byte code
  2. Hello World 
    1. Class – fundamental building blocks of java programs, more details later
    2. Main method – starting point for program.  When you execute a program, it begins executing instructions here.  Introduce the idea of a thread
    3. Other methods – can do other things.  More later
    4. Statement;
    5. Some hand-waving here – public static void main(String[] args)

                                                               i.      Main is where the program starts

    1. Note – semi colons, curly brackets, etc
    2. Strings - text
  1. HW:
    1. R1.11, R1.12, R1.18, R1.16
    2. R1.6, R1.7, R1.8