- Computer basics → programs and languages → Java → first program → errors.
- A computer = CPU, memory, storage devices, input and output devices, communication devices, connected by the bus.
- 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
The part of the computer that retrieves and executes instructions is the:
Correct: CPU.
- 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
One byte is:
Correct: 8 bits.
- Everything is stored as bits (0 and 1), because digital devices have two stable states (on/off). Encoding schemes map characters to bits.
- 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
Memory (RAM) keeps its data when the power is turned off.
False. It is volatile.
- Monitor quality depends on resolution and dot pitch.
- Resolution = number of pixels; dot pitch = space between pixels (smaller is sharper).
- Communication devices: modem, DSL, cable modem, NIC (LAN), wireless.
- Software = programs = instructions to the computer, written in programming languages.
- Two kinds of software: system software (OS, utilities) and application software (word processors, games).
- Same slide continued.
- The OS manages and controls the computer’s activities: allocates resources, schedules operations, controls hardware.
🎯 How this can come up · 1 question
Which program manages and controls a computer’s activities?
Correct: The operating system.
- Machine language: the CPU’s native binary instructions. Hard to read and write.
- Assembly language: mnemonics (ADDF3 R1, R2, R3) translated by an ASSEMBLER into machine code; still machine-dependent.
- High-level languages: English-like, portable (area = 5 * 5 * 3.1415;).
🎯 How this can come up · 1 question
Which language is machine-independent and English-like?
Correct: High-level language.
- Popular high-level languages: Ada, BASIC, C, C++, C#, COBOL, Fortran, Java, Pascal, Python, Visual Basic.
- Source code must be translated: by an INTERPRETER or a COMPILER.
- Interpreter: translates and executes ONE statement at a time.
- Compiler: translates the WHOLE program into machine code first, then it runs.
🎯 How this can come up · 1 question
Which translator converts the entire source program into machine code before execution?
Correct: Compiler.
- Java: general-purpose, runs on servers, desktops and mobile; “write once, run anywhere”.
- Java can build standalone apps, applets, servlets, Android apps.
- James Gosling at Sun Microsystems; originally Oak (1991), renamed Java (1995).
- Java characteristics: simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high-performance, multithreaded, dynamic.
- Characteristics, continued.
- Characteristics, continued.
- Characteristics, continued.
- Characteristics, continued.
- Characteristics, continued.
- Characteristics, continued.
- Characteristics, continued.
- Characteristics, continued.
- Characteristics, continued.
- Characteristics, continued.
- Characteristics, continued.
- IDEs: NetBeans, Eclipse, IntelliJ.
- First program: public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }
- Create (editor) → compile (javac Welcome.java → Welcome.class bytecode) → run (java Welcome on the JVM).
🎯 How this can come up · 2 questions
Compiling Welcome.java produces:
Correct: Welcome.class (bytecode).
Java bytecode is executed by the:
Correct: Java Virtual Machine (JVM).
- Bytecode is platform-independent; any machine with a JVM can run it.
- Trace: the program starts at main.
- Trace: println executes.
- Trace: output appears.
- Anatomy: class name, main method, statements, statement terminator, reserved words, comments, blocks.
- Every program has at least one class; class names start with a capital letter (Welcome).
- The program starts executing at main: public static void main(String[] args).
- A statement is an action; System.out.println displays a string.
- Every statement ends with a semicolon.
- Reserved words (keywords) have special meaning and can’t be used as identifiers: class, public, static, void.
🎯 How this can come up · 1 question
Which is a Java reserved word?
Correct: static.
- A pair of braces forms a block (class block, method block).
- Special symbols: { } ( ) ; // " ".
- { } — denotes a block.
- ( ) — used with methods.
- ; — ends a statement.
- // — line comment (/* */ block comment).
- " " — encloses a string.
- Program with three println messages.
- Printing the result of an expression: (10.5 + 2 * 3) / (45 - 3.5).
- Style: comments, naming conventions, indentation, block style.
- Comment the program’s purpose and key steps.
- Naming: meaningful names; classes Capitalized (ComputeArea).
- Indent each nested level (two spaces); spaces around operators.
- Block styles: next-line vs. end-of-line braces; be consistent.
- Three kinds of errors.
- Syntax (compile) errors: detected by the compiler.
🎯 How this can come up · 1 question
A missing semicolon is a:
Correct: Syntax error.
- Runtime errors: the program aborts while running (e.g., dividing an int by zero).
🎯 How this can come up · 1 question
int x = 1 / 0; compiles but crashes when run. This is a:
Correct: Runtime error.
- 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
A program converting temperatures prints the wrong value but does not crash. This is a:
Correct: Logic error.
No slides match this filter.