CS101 · Annotated SlidesChapter 1 — Introduction to Computers, Programs, and Java
Chapter 1 · Annotated slides

Introduction to Computers, Programs, and Java

Computer basics (CPU, memory, storage, I/O), software and operating systems, machine vs. assembly vs. high-level languages, compilers vs. interpreters, why Java and how a Java program is written, compiled to bytecode and run on the JVM, the anatomy of a program, style, and the three kinds of programming errors.

Slide text Study notes Highlight: key words Tips, tricks & traps Seen again elsewhere How it can come up

Introduction to Computers, Programs, and Java

CS101 · Chapter 1
1
TipThree error types: SYNTAX (compiler catches it: missing ;, misspelled keyword) · RUNTIME (program crashes while running: divide by zero, bad input) · LOGIC (runs but gives the wrong answer).
Slide 2: Objectives
Exam weight Low
  1. Computer basics → programs and languages → Java → first program → errors.
Slide 3: What is a Computer?
Exam weight Low
  1. A computer = CPU, memory, storage devices, input and output devices, communication devices, connected by the bus.
Slide 4: CPU
Exam weight Medium
  1. CPU: fetches instructions from memory and executes them. Two parts: control unit and arithmetic/logic unit. Speed in hertz (GHz).
🎯 How this can come up · 1 question
MCQ

The part of the computer that retrieves and executes instructions is the:

Slide 5: Memory
Exam weight Medium
  1. Memory (RAM): ordered bytes holding data and program instructions; a byte = 8 bits; each byte has an address.
🎯 How this can come up · 1 question
MCQ

One byte is:

Slide 6: How Data is Stored?
Exam weight Low
  1. Everything is stored as bits (0 and 1), because digital devices have two stable states (on/off). Encoding schemes map characters to bits.
Slide 7: Storage Devices
Exam weight Medium
  1. Memory is VOLATILE (lost when power is off); storage devices (disks, CDs/DVDs, USB flash) keep data permanently. Programs are loaded from storage into memory to run.
🎯 How this can come up · 1 question
True / False

Memory (RAM) keeps its data when the power is turned off.

Slide 8: Output Devices: Monitor
Exam weight Low
  1. Monitor quality depends on resolution and dot pitch.
Slide 9: Monitor Resolution and Dot Pitch
Exam weight Low
  1. Resolution = number of pixels; dot pitch = space between pixels (smaller is sharper).
Slide 10: Communication Devices
Exam weight Low
  1. Communication devices: modem, DSL, cable modem, NIC (LAN), wireless.
Slide 11: Programs / Softwares
Exam weight Low
  1. Software = programs = instructions to the computer, written in programming languages.
Slide 12: Types of software
Exam weight Low
  1. Two kinds of software: system software (OS, utilities) and application software (word processors, games).
Slide 13: Types of software
Exam weight Low
  1. Same slide continued.
Slide 14: Operating Systems
Exam weight Medium
  1. The OS manages and controls the computer’s activities: allocates resources, schedules operations, controls hardware.
🎯 How this can come up · 1 question
MCQ

Which program manages and controls a computer’s activities?

Slide 15: Programming Languages
Exam weight Low
  1. Machine language: the CPU’s native binary instructions. Hard to read and write.
Slide 16: Programming Languages
Exam weight Low
  1. Assembly language: mnemonics (ADDF3 R1, R2, R3) translated by an ASSEMBLER into machine code; still machine-dependent.
Slide 17: Programming Languages
Exam weight Medium
  1. High-level languages: English-like, portable (area = 5 * 5 * 3.1415;).
🎯 How this can come up · 1 question
MCQ

Which language is machine-independent and English-like?

Slide 18: Popular High-Level Languages
Exam weight Low
  1. Popular high-level languages: Ada, BASIC, C, C++, C#, COBOL, Fortran, Java, Pascal, Python, Visual Basic.
Slide 19: Interpreting/Compiling Source Code
Exam weight Low
  1. Source code must be translated: by an INTERPRETER or a COMPILER.
Slide 20: Interpreting Source Code
Exam weight Low
  1. Interpreter: translates and executes ONE statement at a time.
Slide 21: Compiling Source Code
Exam weight High
  1. Compiler: translates the WHOLE program into machine code first, then it runs.
Memory trickInterpreter = live translator, line by line. Compiler = translates the whole book first.
🎯 How this can come up · 1 question
MCQ

Which translator converts the entire source program into machine code before execution?

Slide 22: Why Java?
Exam weight Low
  1. Java: general-purpose, runs on servers, desktops and mobile; “write once, run anywhere”.
Slide 23: Java, Web, and Beyond
Exam weight Low
  1. Java can build standalone apps, applets, servlets, Android apps.
Slide 24: Java’s History
Exam weight Low
  1. James Gosling at Sun Microsystems; originally Oak (1991), renamed Java (1995).
Slide 25: Companion
Exam weight Low
  1. Java characteristics: simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high-performance, multithreaded, dynamic.
Slide 26: Companion
Exam weight Low
  1. Characteristics, continued.
Slide 27: Companion
Exam weight Low
  1. Characteristics, continued.
Slide 28: Companion
Exam weight Low
  1. Characteristics, continued.
Slide 29: Companion
Exam weight Low
  1. Characteristics, continued.
Slide 30: Companion
Exam weight Low
  1. Characteristics, continued.
Slide 31: Companion
Exam weight Low
  1. Characteristics, continued.
Slide 32: Companion
Exam weight Low
  1. Characteristics, continued.
Slide 33: Companion
Exam weight Low
  1. Characteristics, continued.
Slide 34: Companion
Exam weight Low
  1. Characteristics, continued.
Slide 35: Companion
Exam weight Low
  1. Characteristics, continued.
Slide 36: Companion
Exam weight Low
  1. Characteristics, continued.
Slide 37: Popular Java IDEs
Exam weight Low
  1. IDEs: NetBeans, Eclipse, IntelliJ.
Slide 38: A Simple Java Program
Exam weight Low
  1. First program: public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }
Slide 39: Creating, Compiling, and Running Programs
Exam weight High
  1. Create (editor) → compile (javac Welcome.java → Welcome.class bytecode) → run (java Welcome on the JVM).
🎯 How this can come up · 2 questions
MCQ

Compiling Welcome.java produces:

MCQ

Java bytecode is executed by the:

Slide 40: Compiling Java Source Code
Exam weight Medium
  1. Bytecode is platform-independent; any machine with a JVM can run it.
Slide 41: animation
Exam weight Low
  1. Trace: the program starts at main.
Slide 42: animation
Exam weight Low
  1. Trace: println executes.
Slide 43: animation
Exam weight Low
  1. Trace: output appears.
Slide 44: Anatomy of a Java Program
Exam weight Low
  1. Anatomy: class name, main method, statements, statement terminator, reserved words, comments, blocks.
Slide 45: Class Name
Exam weight Low
  1. Every program has at least one class; class names start with a capital letter (Welcome).
Slide 46: Main Method
Exam weight Low
  1. The program starts executing at main: public static void main(String[] args).
Slide 47: Statement
Exam weight Low
  1. A statement is an action; System.out.println displays a string.
Slide 48: Statement Terminator
Exam weight Low
  1. Every statement ends with a semicolon.
Slide 49: Reserved words
Exam weight Medium
  1. Reserved words (keywords) have special meaning and can’t be used as identifiers: class, public, static, void.
🎯 How this can come up · 1 question
MCQ

Which is a Java reserved word?

Slide 50: Blocks
Exam weight Low
  1. A pair of braces forms a block (class block, method block).
Slide 51: Special Symbols
Exam weight Low
  1. Special symbols: { } ( ) ; // " ".
Slide 52: { ... }
Exam weight Low
  1. { } — denotes a block.
Slide 53: ( ... )
Exam weight Low
  1. ( ) — used with methods.
Slide 54: ;
Exam weight Low
  1. ; — ends a statement.
Slide 55: // ...
Exam weight Low
  1. // — line comment (/* */ block comment).
Slide 56: " ... "
Exam weight Low
  1. " " — encloses a string.
Slide 57: WelcomeWithThreeMessages
Exam weight Low
  1. Program with three println messages.
Slide 58: ComputeExpression
Exam weight Low
  1. Printing the result of an expression: (10.5 + 2 * 3) / (45 - 3.5).
Slide 59: Programming Style and Documentation
Exam weight Low
  1. Style: comments, naming conventions, indentation, block style.
Slide 60: Appropriate Comments
Exam weight Low
  1. Comment the program’s purpose and key steps.
Slide 61: Naming Conventions
Exam weight Low
  1. Naming: meaningful names; classes Capitalized (ComputeArea).
Slide 62: Proper Indentation and Spacing
Exam weight Low
  1. Indent each nested level (two spaces); spaces around operators.
Slide 63: Block Styles
Exam weight Low
  1. Block styles: next-line vs. end-of-line braces; be consistent.
Slide 64: Programming Errors
Exam weight Low
  1. Three kinds of errors.
TipThree error types: SYNTAX (compiler catches it: missing ;, misspelled keyword) · RUNTIME (program crashes while running: divide by zero, bad input) · LOGIC (runs but gives the wrong answer).
Slide 65: Syntax Errors
Exam weight High
  1. Syntax (compile) errors: detected by the compiler.
🎯 How this can come up · 1 question
MCQ

A missing semicolon is a:

Slide 66: Runtime Errors
Exam weight High
  1. Runtime errors: the program aborts while running (e.g., dividing an int by zero).
🎯 How this can come up · 1 question
MCQ

int x = 1 / 0; compiles but crashes when run. This is a:

Slide 67: Logic Errors
Exam weight High
  1. Logic errors: the program runs but gives wrong results (e.g., Celsius conversion with integer 5 / 9 = 0).
🎯 How this can come up · 1 question
MCQ

A program converting temperatures prints the wrong value but does not crash. This is a: