CS101 · Chapter 1 · Annotated SlidesIntroduction to Computers, Programs, and Java
Original
Overview

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.

How to read this page

Every original slide is shown unchanged. Yellow marks on a slide point to a numbered note: hover or tap a mark to jump to its note, and hover a note to see its marks. Questions tagged Past exam appeared on a real paper; Prediction questions are likely angles, not confirmed. Pick an answer to each question: a wrong pick tells you why it is wrong, so you can try again.

All 67 slides
  1. 1 Introduction to Computers, Programs, and Java
  2. 2 Objectives
  3. 3 What is a Computer?
  4. 4 CPU
  5. 5 Memory
  6. 6 How Data is Stored?
  7. 7 Storage Devices
  8. 8 Output Devices: Monitor
  9. 9 Monitor Resolution and Dot Pitch
  10. 10 Communication Devices
  11. 11 Programs / Softwares
  12. 12 Types of software
  13. 13 Types of software
  14. 14 Operating Systems
  15. 15 Programming Languages
  16. 16 Programming Languages
  17. 17 Programming Languages
  18. 18 Popular High-Level Languages
  19. 19 Interpreting/Compiling Source Code
  20. 20 Interpreting Source Code
  21. 21 Compiling Source Code
  22. 22 Why Java?
  23. 23 Java, Web, and Beyond
  24. 24 Java’s History
  25. 25 Companion
  26. 26 Companion
  27. 27 Companion
  28. 28 Companion
  29. 29 Companion
  30. 30 Companion
  31. 31 Companion
  32. 32 Companion
  33. 33 Companion
  34. 34 Companion
  35. 35 Companion
  36. 36 Companion
  37. 37 Popular Java IDEs
  38. 38 A Simple Java Program
  39. 39 Creating, Compiling, and Running Programs
  40. 40 Compiling Java Source Code
  41. 41 animation
  42. 42 animation
  43. 43 animation
  44. 44 Anatomy of a Java Program
  45. 45 Class Name
  46. 46 Main Method
  47. 47 Statement
  48. 48 Statement Terminator
  49. 49 Reserved words
  50. 50 Blocks
  51. 51 Special Symbols
  52. 52 { ... }
  53. 53 ( ... )
  54. 54 ;
  55. 55 // ...
  56. 56 " ... "
  57. 57 WelcomeWithThreeMessages
  58. 58 ComputeExpression
  59. 59 Programming Style and Documentation
  60. 60 Appropriate Comments
  61. 61 Naming Conventions
  62. 62 Proper Indentation and Spacing
  63. 63 Block Styles
  64. 64 Programming Errors
  65. 65 Syntax Errors
  66. 66 Runtime Errors
  67. 67 Logic Errors
Slide 1 / 67

Introduction to Computers, Programs, and Java

Slide 1: Introduction to Computers, Programs, and Java

Notes

  1. Tip Three 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 / 67

Objectives

Slide 2: Objectives
Slide 3 / 67

What is a Computer?

Slide 3: What is a Computer?

Notes

  1. A computer = CPU, memory, storage devices, input and output devices, communication devices, connected by the bus.

Slide 4 / 67

CPU

Slide 4: CPU

Notes

  1. CPU: fetches instructions from memory and executes them. Two parts: control unit and arithmetic/logic unit. Speed in hertz (GHz).

Exam angle

PredictionQ1

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

Slide 5 / 67

Memory

Slide 5: Memory

Notes

  1. Memory (RAM): ordered bytes holding data and program instructions; a byte = 8 bits; each byte has an address.

Exam angle

PredictionQ1

One byte is:

Slide 6 / 67

How Data is Stored?

Slide 6: How Data is Stored?

Notes

  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 / 67

Storage Devices

Slide 7: Storage Devices

Notes

  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.

Exam angle

PredictionQ1

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

Slide 8 / 67

Output Devices: Monitor

Slide 8: Output Devices: Monitor
Slide 9 / 67

Monitor Resolution and Dot Pitch

Slide 9: Monitor Resolution and Dot Pitch
Slide 10 / 67

Communication Devices

Slide 10: Communication Devices
Slide 11 / 67

Programs / Softwares

Slide 11: Programs / Softwares
Slide 12 / 67

Types of software

Slide 12: Types of software

Notes

  1. Two kinds of software: system software (OS, utilities) and application software (word processors, games).

Slide 13 / 67

Types of software

Slide 13: Types of software

Notes

  1. Same slide continued.

Slide 14 / 67

Operating Systems

Slide 14: Operating Systems

Notes

  1. The OS manages and controls the computer’s activities: allocates resources, schedules operations, controls hardware.

Exam angle

PredictionQ1

Which program manages and controls a computer’s activities?

Slide 15 / 67

Programming Languages

Slide 15: Programming Languages
Slide 16 / 67

Programming Languages

Slide 16: Programming Languages

Notes

  1. Assembly language: mnemonics (ADDF3 R1, R2, R3) translated by an ASSEMBLER into machine code; still machine-dependent.

Slide 17 / 67

Programming Languages

Slide 17: Programming Languages

Exam angle

PredictionQ1

Which language is machine-independent and English-like?

Slide 18 / 67

Popular High-Level Languages

Slide 18: Popular High-Level Languages

Notes

  1. Popular high-level languages: Ada, BASIC, C, C++, C#, COBOL, Fortran, Java, Pascal, Python, Visual Basic.

Slide 19 / 67

Interpreting/Compiling Source Code

Slide 19: Interpreting/Compiling Source Code
Slide 20 / 67

Interpreting Source Code

Slide 20: Interpreting Source Code
Slide 21 / 67

Compiling Source Code

Slide 21: Compiling Source Code

Notes

  1. Compiler: translates the WHOLE program into machine code first, then it runs.

  2. Memory trick Interpreter = live translator, line by line. Compiler = translates the whole book first.

Exam angle

PredictionQ1

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

Slide 22 / 67

Why Java?

Slide 22: Why Java?

Notes

  1. Java: general-purpose, runs on servers, desktops and mobile; “write once, run anywhere”.

Slide 23 / 67

Java, Web, and Beyond

Slide 23: Java, Web, and Beyond

Notes

  1. Java can build standalone apps, applets, servlets, Android apps.

Slide 24 / 67

Java’s History

Slide 24: Java’s History

Notes

  1. James Gosling at Sun Microsystems; originally Oak (1991), renamed Java (1995).

Slide 25 / 67

Companion

Slide 25: Companion
Slide 26 / 67

Companion

Slide 26: Companion

Notes

  1. Characteristics, continued.

Slide 27 / 67

Companion

Slide 27: Companion

Notes

  1. Characteristics, continued.

Slide 28 / 67

Companion

Slide 28: Companion

Notes

  1. Characteristics, continued.

Slide 29 / 67

Companion

Slide 29: Companion

Notes

  1. Characteristics, continued.

Slide 30 / 67

Companion

Slide 30: Companion

Notes

  1. Characteristics, continued.

Slide 31 / 67

Companion

Slide 31: Companion

Notes

  1. Characteristics, continued.

Slide 32 / 67

Companion

Slide 32: Companion

Notes

  1. Characteristics, continued.

Slide 33 / 67

Companion

Slide 33: Companion

Notes

  1. Characteristics, continued.

Slide 34 / 67

Companion

Slide 34: Companion

Notes

  1. Characteristics, continued.

Slide 35 / 67

Companion

Slide 35: Companion

Notes

  1. Characteristics, continued.

Slide 36 / 67

Companion

Slide 36: Companion

Notes

  1. Characteristics, continued.

Slide 37 / 67

Popular Java IDEs

Slide 37: Popular Java IDEs
Slide 38 / 67

A Simple Java Program

Slide 38: A Simple Java Program
Slide 39 / 67

Creating, Compiling, and Running Programs

Slide 39: Creating, Compiling, and Running Programs

Exam angle

PredictionQ1

Compiling Welcome.java produces:

PredictionQ2

Java bytecode is executed by the:

Slide 40 / 67

Compiling Java Source Code

Slide 40: Compiling Java Source Code
Slide 41 / 67

animation

Slide 41: animation
Slide 42 / 67

animation

Slide 42: animation
Slide 43 / 67

animation

Slide 43: animation

Notes

  1. Trace: output appears.

Slide 44 / 67

Anatomy of a Java Program

Slide 44: Anatomy of a Java Program
Slide 45 / 67

Class Name

Slide 45: Class Name
Slide 46 / 67

Main Method

Slide 46: Main Method
Slide 47 / 67

Statement

Slide 47: Statement
Slide 48 / 67

Statement Terminator

Slide 48: Statement Terminator
Slide 49 / 67

Reserved words

Slide 49: Reserved words

Exam angle

PredictionQ1

Which is a Java reserved word?

Slide 50 / 67

Blocks

Slide 50: Blocks
Slide 51 / 67

Special Symbols

Slide 51: Special Symbols
Slide 52 / 67

{ ... }

Slide 52: { ... }

Notes

  1. { } — denotes a block.

Slide 53 / 67

( ... )

Slide 53: ( ... )

Notes

  1. ( ) — used with methods.

Slide 54 / 67

;

Slide 54: ;

Notes

  1. ; — ends a statement.

Slide 55 / 67

// ...

Slide 55: // ...

Notes

  1. // — line comment (/* */ block comment).

Slide 56 / 67

" ... "

Slide 56: " ... "

Notes

  1. " " — encloses a string.

Slide 57 / 67

WelcomeWithThreeMessages

Slide 57: WelcomeWithThreeMessages

Notes

  1. Program with three println messages.

Slide 58 / 67

ComputeExpression

Slide 58: ComputeExpression

Notes

  1. Printing the result of an expression: (10.5 + 2 * 3) / (45 - 3.5).

Slide 59 / 67

Programming Style and Documentation

Slide 59: Programming Style and Documentation
Slide 60 / 67

Appropriate Comments

Slide 60: Appropriate Comments
Slide 61 / 67

Naming Conventions

Slide 61: Naming Conventions
Slide 62 / 67

Proper Indentation and Spacing

Slide 62: Proper Indentation and Spacing

Notes

  1. Indent each nested level (two spaces); spaces around operators.

Slide 63 / 67

Block Styles

Slide 63: Block Styles
Slide 64 / 67

Programming Errors

Slide 64: Programming Errors

Notes

  1. Three kinds of errors.

  2. Tip Three 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 / 67

Syntax Errors

Slide 65: Syntax Errors

Notes

  1. Syntax (compile) errors: detected by the compiler.

Exam angle

PredictionQ1

A missing semicolon is a:

Slide 66 / 67

Runtime Errors

Slide 66: Runtime Errors

Notes

  1. Runtime errors: the program aborts while running (e.g., dividing an int by zero).

Exam angle

PredictionQ1

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

Slide 67 / 67

Logic Errors

Slide 67: Logic Errors

Notes

  1. Logic errors: the program runs but gives wrong results (e.g., Celsius conversion with integer 5 / 9 = 0).

Exam angle

PredictionQ1

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