Lecture 0 CSIS10A Overview
Welcome to CSIS10A (5 mins) – Typical format for class meetings New material first (monitors off, notebooks out) Practice new material (like a lab) – Syllabus – Aim of this course (learning Java) – Course assumes no prior knowledge of programming. – What is a program? A set of step-by-step instructions that directs a computer to solve some problem. – Pretty much anything you can do with a computer, you can do by programming in Java
Do introductions (15 mins) class website: Click on "Tell me about yourself" – Name – Major and what year – Why taking the course – Something unique about yourself then we go around and tell each other
Do administrative stuff (10 mins) – Few if any handouts will be printed. They will be posted on the web instead. – No late work (model solutions, quick turnaround) – For conflicts with class meetings: let me know now! – We will use the online textbook JavaNotes by EckJavaNotes Textbook does not always line up with class, but is a great reference – I will provide notes for each lab. – We will use online labs by Michael Kowalczk, used with permission. We will thank him at the end of class!Michael Kowalczk – Academic dishonesty – Office hours, and by appointment – Computer science tutor will be available – Steve Bruemmer our instructional tech, 9-5 most days
Do PB & J demonstration (20 mins) – Get into groups and write up instructions (10 mins) – Present the results and have me follow those directions (10 mins)
PBJ Debrief – Talk about observations; similarities to programming Explicitness Sequence, selection, repetition Dependencies - when does order matter? Closing open files and stuff What is a basic command? Unexpected uses of software Infinite loops
– Course will be challenging, fun, painful at times - much like making a sandwich But, you will make yourself more marketable or may get sold on computer science!
Basic computer anatomy
What the parts do CPU – ``The brain''; performs relatively basic operations – It only executes machine language – The machine language varies from CPU to CPU Storage – Primary storage/random-access memory/RAM/``memory'' Fast, but volatile and expensive – Secondary storage/hard drive/hard disk Cheap and non-volatile, but slow Input devices (the ``I'' in ``I/O'') – Mouse, keyboard Output devices (the ``O'' in ``I/O'') – Monitor, speakers, printer
How hardware relates to programming – Your.java program files are files, therefore found on the hard drive (typically) – Programs need to run fast, so the computer uses primary memory for programs that are currently running. – There are ways to communicate with I/O devices in Java.
Communicating instructions to the computer Problem: We want to give instructions to the CPU, but the CPU's language is hard for humans to read, write, and understand. How do we handle this? One (painful) solution: Just program in machine code – Why is this so painful? Just note this C code: main() { printf("hello, world"); } – does the same thing as the machine code on the next slide. – Since machine code depends on the CPU, the program would only work on a limited number of machines anyway
"Hello World" program in machine code
One (bad) solution: Try to make a system where we can just type in instructions with natural language, and have the computer translate that into machine code. – Extremely difficult – Very ambiguous; for example, in ``I called the guy with the cell phone'' - who is carrying the cell phone?
One (better) solution: Use an intermediate language that is somewhat easy for humans to use (i.e. Pascal, C++, etc.), and have the computer translate that into machine code. This translator is called a compiler. – Compiled languages such as C work in this way.
Running programs the Java way In Java, the computer simulates an imaginary CPU with very particular specifications. – This imaginary CPU is called the Java virtual machine (or JVM). – Java simulates the JVM much like an emulator simulates a Super-Nintendo Main advantage: The same code can be made to run on any machine without modification (see previous slide). – Example: Good for Java applets on the web Another advantage: Much better security can be implemented when running code in a virtual machine. – Example: again, crucial for Java applets on the web One disadvantage: Simulating the JVM makes the program run slower One caveat: There can actually be variations in your program from machine to machine, for a number of reasons – Different I/O devices – Different library implementations (or bugs) – Bugs in a JVM implementation (yes, it happens)
Source file compiler bytecode The JVM's language is bytecode, which is found inside.class files. – The compiler converts java files into class files – Class files are not human readable See the bytecode for the HelloWorld.java program
Java source file public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }
Java Bytecode for previous slide
A source file contains source code and is really just a simple text file. It contains (among other things) instructions for the computer to execute. – A ``.java'' ending is used to distinguish it as a Java source file – Java files have special structure so that the computer can translate it into machine code. – Use a text editor or an IDE (in this class we use BlueJ but you can also use Eclipse) to create source and make changes to it. – We'll make a simple "Hello World" program now!