Chapter 1: Introduction to Computers, Programs, and Java - Vocabulary Flashcards

Introduction to Computers, Programming, and Hardware

  • The fundamental goal of computer programming is to solve problems by creating software.

  • Programming (also termed software development) is the process of creating software.

  • Software (or a program) consists of instructions that tell a computer or a computerized device what actions to perform.

  • Software is ubiquitous in modern society, powering personal computers as well as embedded systems in devices such as airplanes, automobiles, cell phones, and household appliances like toasters.

  • Common personal computer software applications include:

    • Word processors (used to create and format written documents).

    • Web browsers (used to navigate and explore the Internet).

    • E-mail clients (used to send and receive electronic messages).

  • Programming Languages: Software developers create software using tools known as programming languages. There is no single "best" programming language; each language has distinct strengths, weaknesses, and intended use cases. Experienced software developers master multiple languages to expand their arsenal of development tools.

  • Learning a first programming language establishes core problem-solving methodology, making it straightforward to learn subsequent programming languages.

Computer Systems and Hardware Architecture

  • A computer is an electronic device that stores and processes data.

  • A computer system is comprised of two primary components:

    • Hardware: The physical, tangible, visible components of a computer.

    • Software: The intangible, invisible set of instructions that direct the hardware to perform tasks.

  • Computer components are interconnected via a subsystem called a bus.

    • A bus functions as a network of internal roads carrying data and power between system components.

    • In personal computers, the bus is integrated into the computer's motherboard, which is a circuit board connecting all internal components.

A computer consists of a CPU, memory, storage devices, input devices, output devices, and communication devices.

Major Hardware Components

Central Processing Unit (CPU)

  • The Central Processing Unit (CPU) is the operational brain of the computer. It retrieves instructions from memory and executes them.

  • The CPU typically consists of two main internal components:

    • Control Unit: Controls and coordinates the actions and timing of all other computer components.

    • Arithmetic/Logic Unit (ALU): Performs mathematical operations (addition, subtraction, multiplication, division) and logical comparisons.

  • CPUs are fabricated on small silicon semiconductor chips containing millions of tiny electronic switches called transistors.

  • Clock Speed:

    • Every computer contains an internal clock that emits electronic pulses at a constant rate to synchronize operations.

    • Higher clock speeds allow a processor to execute more instructions in a given unit of time.

    • Measured in Hertz (Hz), where 1 Hz=1 pulse per second1\text{ Hz} = 1\text{ pulse per second}.

    • In the 1990s, CPU speeds were measured in Megahertz (MHz) (1 MHz=1,000,000 Hz1\text{ MHz} = 1,000,000\text{ Hz}).

    • Modern CPU speeds are measured in Gigahertz (GHz) (1 GHz=1,000,000,000 Hz1\text{ GHz} = 1,000,000,000\text{ Hz}). Modern Intel processors run at speeds around 3 GHz3\text{ GHz}.

  • Cores:

    • A core is the portion of the processor that reads and executes instructions.

    • Early CPUs contained only a single core. Contemporary CPUs are multicore processors, combining two or more independent cores on a single component (e.g., dual-core, tri-core, quad-core) to enhance performance.

Bits, Bytes, and Data Representation

  • Computers store data using electronic switches that exist in two stable states: on (11) or off (00).

  • Bit: Short for binary digit. The basic unit of data in computing, taking a value of either 00 or 11 in the binary number system.

  • Byte: The minimum storage unit in a computer system, consisting of 8 bits8\text{ bits}.

  • Encoding Schemes: Rules that define how characters, numbers, and symbols are converted into unique binary bit patterns.

    • Example: In the ASCII encoding scheme, the uppercase character 'C' is represented by the 8-bit byte 01000011.

    • The number 33 is represented as 00000011.

  • Units of Storage Capacity:

    • Kilobyte (KB): Approximately 1,000 bytes1,000\text{ bytes} (1,024 bytes1,024\text{ bytes} or 210 bytes2^{10}\text{ bytes}).

    • Megabyte (MB): Approximately 1 million bytes1\text{ million bytes} (1,000 KB1,000\text{ KB} or 1,048,576 bytes1,048,576\text{ bytes}).

    • Gigabyte (GB): Approximately 1 billion bytes1\text{ billion bytes} (1,000 MB1,000\text{ MB}).

    • Terabyte (TB): Approximately 1 trillion bytes1\text{ trillion bytes} (1,000 GB1,000\text{ GB}).

  • Concrete Capacity Examples:

    • A typical 1-page word processing document occupies about 20 KB20\text{ KB}.

    • 1 MB1\text{ MB} can store approximately 50 pages50\text{ pages} of text documents.

    • 1 GB1\text{ GB} can store approximately 50,000 pages50,000\text{ pages} of text documents.

    • A 2-hour high-resolution movie occupies about 8 GB8\text{ GB}; storing 20 such movies20\text{ such movies} requires 160 GB160\text{ GB} of storage.

Memory (Random-Access Memory - RAM)

  • Memory consists of an ordered sequence of bytes used as the workspace for running programs and active data.

  • Every program and its associated data must be loaded into memory before the CPU can execute it.

  • Unique Addresses: Each byte in memory has a unique numeric address used to locate and access data.

  • Random-Access Memory (RAM): Bytes in memory can be accessed directly in any random sequence.

  • Typical RAM Capacity: Modern personal computers typically contain at least 4 GB4\text{ GB} of RAM, commonly ranging between 6 GB6\text{ GB} and 8 GB8\text{ GB}.

  • Key Memory Characteristics:

    • Volatility: RAM is volatile storage. All stored information is lost when system power is switched off.

    • Non-emptiness: Memory bytes are never empty; their initial contents may be meaningless leftover bits.

    • Overwriting: Placing new data into a memory byte completely overwrites and erases its previous content.

    • Physical Fabrication: Built on silicon semiconductor chips containing millions of transistors. Compared to CPUs, memory chips are simpler, slower, and less expensive.

Storage Devices

  • Permanent (non-volatile) storage where programs and data are preserved even when system power is turned off.

  • Data is transferred from permanent storage devices into RAM when the computer executes programs or manipulates data.

  • Drives and Media: A storage drive is an operating mechanism that reads data from and writes data onto a physical storage medium.

  • Major Storage Device Types:

    1. Magnetic Disk Drives (Hard Disks): Primary internal non-volatile storage. Capacities in modern computers range from 500 GB500\text{ GB} to 1 TB1\text{ TB}. External removable hard drives are also available.

    2. Optical Disc Drives:

    • Compact Disc (CD): Holds up to 700 MB700\text{ MB} of data. Types include CD-R (Compact Disc-Recordable, read-only permanent storage) and CD-RW (Compact Disc-ReWritable, acts like a hard drive where data can be overwritten).

    • Digital Versatile Disc / Digital Video Disc (DVD): Holds significantly more data than a CD, with a standard single-layer capacity of 4.7 GB4.7\text{ GB}. Types include DVD-R (read-only) and DVD-RW (rewritable).

    1. USB Flash Drives:

    • Connects via Universal Serial Bus (USB) ports, which allow connecting peripherals (printers, cameras, mice, external drives).

    • Small, portable solid-state storage devices with capacities available up to 256 GB256\text{ GB}.

Input and Output Devices

  • Input Devices: Enable users to feed data and commands into the computer.

    • Keyboard: Primary text/command entry device. Contains:

    • Function Keys: Located along the top edge, prefaced with letter FF (F1F1-F12F12). Functions depend on active software.

    • Modifier Keys: Keys such as ShiftShift, AltAlt, and CtrlCtrl that modify another key's behavior when pressed concurrently.

    • Numeric Keypad: Calculator-style cluster on the right side for rapid numerical input.

    • Arrow Keys: Positioned between main keyboard and numeric keypad for screen navigation.

    • Editing Keys: InsertInsert, DeleteDelete, Page UpPage\ Up, and Page DownPage\ Down keys used for text/object insertion, deletion, and scrolling.

    • Mouse: Pointing device used to move an on-screen graphical arrow called a cursor and click buttons or interface controls.

  • Output Devices: Display or present information produced by the computer.

    • Monitor: Displays visual output (text and graphics). Quality is determined by:

    • Screen Resolution: The number of horizontal and vertical pixels ("picture elements"). Example: 1024×7681024 \times 768 resolution on a 17-inch screen means 1,024 pixels wide by 768 pixels high. Higher resolution delivers sharper image clarity.

    • Dot Pitch: The physical distance between individual pixels measured in millimeters (mm\text{mm}). Smaller dot pitch values produce sharper displays.

    • Printer: Produces hard-copy output on paper.

Communication Devices

  • Enable computers to connect and communicate over local networks or the Internet.

  • Dial-up Modem: Uses standard telephone lines; maximum data transfer speed is 56,000 bps56,000\text{ bps} (bits per second).

  • Digital Subscriber Line (DSL): Uses standard phone lines but transfers data up to 20×20\times faster than standard dial-up modems.

  • Cable Modem: Uses cable television lines provided by cable operators; generally faster than DSL.

  • Network Interface Card (NIC): Hardware device connecting a computer to a Local Area Network (LAN) (commonly deployed in universities, businesses, and government agencies). High-speed 1000BaseT cards transfer data at speeds up to 1,000 Mbps1,000\text{ Mbps} (million bits per second).

  • Wireless Adapter: Enables cable-free connection to local wireless networks and the Internet.

Programming Languages

  • Computer programs are written in programming languages. Hundreds of programming languages exist, created to streamline software creation for human developers. All code must ultimately be converted into machine instructions that the computer's CPU can execute.

Machine Language

  • A computer's native, built-in primitive language consisting of binary code instructions (00s and 11s).

  • Differs across different computer hardware architectures.

  • Example addition instruction in machine binary code: 1101101010011010.

  • Programming in machine language is extremely tedious, highly error-prone, and virtually unreadable for humans.

Assembly Language

  • Developed as a low-level alternative to raw binary machine code in the early days of computing.

  • Replaces binary codes with short descriptive symbolic words called mnemonics.

    • Examples: Mnemonic add represents addition; sub represents subtraction.

    • Example assembly statement: add 2, 3, result.

  • Assembler: A translation program that converts assembly language code into binary machine code.

  • Assembly language is classified as a low-level language because its instructions map directly to underlying machine instructions, requiring intimate knowledge of CPU hardware architecture.

High-Level Languages

  • Developed beginning in the 1950s to make programming English-like, intuitive, and platform-independent.

  • Program instructions in high-level languages are called statements.

  • Example high-level language statement computing a circle's area (radius=5radius = 5):   area = 5 * 5 * 3.14159;

  • Platform Independence: High-level language code can run on diverse CPU architectures without modification.

  • High-Level Languages Overview:

    • Ada: Named for Ada Lovelace; developed for the U.S. Department of Defense; heavily used in defense software.

    • BASIC: Beginner's All-purpose Symbolic Instruction Code; designed for easy learning by novices.

    • C: Developed at Bell Laboratories; combines low-level hardware control of assembly with high-level language portability.

    • C++: Object-oriented expansion of C.

    • C#: Developed by Microsoft; object-oriented hybrid combining features of Java and C++.

    • COBOL: Common Business Oriented Language; designed specifically for business applications.

    • FORTRAN: FORmula TRANslation; popular for scientific, engineering, and mathematical computing.

    • Java: Originally created by Sun Microsystems (now Oracle); widely used for platform-independent web, desktop, server, and mobile software.

    • Pascal: Named for Blaise Pascal; simple, structured language created primarily for teaching programming principles.

    • Python: Simple, general-purpose scripting language popular for rapid program development.

    • Visual Basic: Developed by Microsoft for rapid development of Graphical User Interface (GUI) applications.

Translation: Interpreters vs. Compilers

  • Source Program / Source Code: A program written in a high-level language.

  • Because CPUs cannot directly execute high-level source code, it must be translated into binary machine code using either an interpreter or a compiler.

  • Interpreter:

    • Reads one statement from source code, translates it into machine code or virtual machine code, and executes it immediately.

    • A single high-level statement may translate into multiple low-level machine instructions.

  • Compiler:

    • Translates the entire source code file at once into a machine-code output file.

    • The generated machine-code file is subsequently executed independently.

Operating Systems

  • The Operating System (OS) is the most crucial system program running on a computer.

  • It manages and controls all hardware operations, system resources, and software activities.

  • Application software (word processors, web browsers) cannot run without an active underlying OS.

  • Major general-purpose operating systems: Microsoft Windows, Mac OS, Linux.

  • System Layering: User ↔\leftrightarrow Application Programs ↔\leftrightarrow Operating System ↔\leftrightarrow Hardware.

Key OS Responsibilities

  1. Controlling and Monitoring System Activities:

    • Handles basic tasks: recognizing keyboard input, directing output to display monitors, tracking files/folders on storage media, controlling peripherals (printers, disk drives).

    • Prevents concurrent programs and users from interfering with one another.

    • Maintains system security by restricting access to authorized users and programs.

  2. Allocating and Assigning System Resources:

    • Identifies resource requirements of programs (CPU time, RAM space, disk storage, I/O devices) and dynamically assigns them during execution.

  3. Scheduling Operations:

    • Schedules program execution to maximize resource utilization efficiency through advanced execution techniques:

      • Multiprogramming: Allows multiple applications to share a single CPU concurrently. Because the CPU operates vastly faster than I/O devices, it remains idle while awaiting disk transfers; multiprogramming uses this idle CPU time to execute statements from other applications (e.g., editing a document while downloading a web file).

      • Multithreading: Allows a single application to execute multiple concurrent subtasks (e.g., editing text while saving a document to disk simultaneously within the same word processor).

      • Multiprocessing (Parallel Processing): Uses two or more physical CPUs working in parallel to perform program subtasks concurrently, joining their results to solve the primary task.

Java, the World Wide Web, and Beyond

  • Origins and History:

    • Created by a team led by James Gosling at Sun Microsystems.

    • Initiated in 1991 under the name Oak, designed for embedded microchips in consumer electronic appliances.

    • Redesigned in 1995 and renamed Java, targeting Web application development.

    • Sun Microsystems was acquired by Oracle in 2010.

  • Design Goals and Core Characteristics:

    • Primary Philosophy: Write Once, Run Anywhere (WORA).

    • Defined characteristics: Simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high-performance, multithreaded, dynamic.

  • Web and Software Ecosystem:

    • Applets: Java programs embedded inside HTML web pages that execute within web browsers, offering graphical user interfaces (buttons, text fields, radio buttons) to make web pages interactive.

    • HTML (Hypertext Markup Language): Simple markup language for laying out documents and multimedia on the Web.

    • Rich Internet Applications (RIAs): Web applications delivering complex features and performance equivalent to desktop software.

    • Server-Side Applications: Backend web applications processing business logic, computing data, and serving dynamic web content.

    • Android Platform: Software applications for Android cellular phones are built using Java.

    • Space Exploration: Java code was utilized to control and communicate with the robotic Mars rover.

Java Standards and Tools: Language Specification, API, JDK, and IDE

  • Java Language Specification: Technical definition detailing Java syntax and semantics.

  • Application Programming Interface (API) / Library: Predefined collection of Java classes and interfaces available for developing software.

  • Java Editions:

    1. Java Standard Edition (Java SE): Core foundation for developing client-side desktop applications and applets.

    2. Java Enterprise Edition (Java EE): Platform for server-side enterprise applications (Java servlets, JavaServer Pages/JSP, JavaServer Faces/JSF).

    3. Java Micro Edition (Java ME): Platform for mobile and embedded devices (cell phones).

  • Version Naming:

    • Java SE 8 utilizes the Java Development Toolkit (JDK) named JDK 1.8 (also referred to as Java 8 or JDK 8).

  • Development Tools:

    • JDK: A bundle of command-line tools for compiling, testing, and executing Java programs.

    • Integrated Development Environment (IDE): Software providing an all-in-one Graphical User Interface (GUI) combining text editing, compiling, building, debugging, and execution (e.g., NetBeans, Eclipse, TextPad).

    • IDEs are development tools; they are NOT distinct dialects or language extensions of Java.

Anatomy of a Simple Java Program

  • Console Terminology:

    • Console: Historical computer term referring to text entry and display hardware.

    • Console Input: Receiving user input typed via the keyboard.

    • Console Output: Displaying text output on the monitor screen.

Listing 1.1: Welcome.java

public class Welcome {
  public static void main(String[] args) {
    // Display message Welcome to Java! on the console
    System.out.println("Welcome to Java!");
  }
}

Program Components Breakdown

  • Class Definition (public class Welcome):

    • Every Java program must contain at least one class.

    • Class names begin with an uppercase letter by convention (e.g., Welcome).

    • File naming rule: The source file name MUST match the public class name exactly, appending .java (Welcome.java).

  • Main Method (public static void main(String[] args)):

    • Program execution starts at the main method entry point.

    • main resides inside a class block and contains executable program statements.

  • Console Output Statement (System.out.println("Welcome to Java!");):

    • Displays the specified text string on the console screen.

    • String: A literal sequence of characters enclosed in double quotation marks ("...").

    • Statement Terminator: Every statement in Java ends with a semicolon (;).

  • Reserved Words (Keywords):

    • Words reserved by the Java compiler with predefined meanings (e.g., public, class, static, void). Cannot be reused as variable or class names.

  • Comments:

    • Explanatory notes ignored by the compiler.

    • Line Comment: Preceded by // on a single line.

    • Block Comment: Enclosed between /* and */ across one or multiple lines.

    • Javadoc Comment: Enclosed between /** and */; extracted into HTML reference files using the JDK javadoc command.

  • Blocks and Braces:

    • A block is formed by curly braces ({ ... }) grouping class or method statements.

    • Every opening brace { must have a matching closing brace }.

  • Case Sensitivity: Java is strictly case-sensitive (main is valid; Main causes compile/runtime errors).

Special Characters Reference

  • {} (Opening and closing braces): Denote a code block enclosing statements.

  • () (Opening and closing parentheses): Used with methods.

  • [] (Opening and closing brackets): Denote an array.

  • // (Double slashes): Precede a line comment.

  • "" (Double quotation marks): Enclose literal character strings.

  • ; (Semicolon): Marks the end of a statement (statement terminator).

Creating, Compiling, and Executing a Java Program

  • Program Development Cycle:

    1. Write Source Code: Create code in a .java file using a text editor (e.g., Notepad) or an IDE.

    2. Compile Source Code: Run compiler command javac ClassName.java. Translates source code into Java Bytecode saved in a .class file.

    3. Execute Bytecode: Run interpreter command java ClassName. Invokes the Java Virtual Machine (JVM) to interpret bytecode into target machine code step-by-step.

Java Virtual Machine (JVM)

  • Java bytecode is a low-level, architecture-neutral code that can execute on any computer platform containing a JVM.

  • Class Loader: Program within JVM that dynamically loads needed .class bytecode files into memory.

  • Bytecode Verifier: Checks bytecode validity and verifies security rules to prevent host machine damage.

Common Command-Line Execution Errors

  • Executing command java ClassName.class raises an error because the system attempts to open ClassName.class.class.

  • NoClassDefFoundError: Raised when executing a .class file that does not exist in the working directory.

  • NoSuchMethodError: Raised when executing a class file that lacks a valid main method (or where main is misspelled as Main).

Programming Style and Documentation

  • Proper programming style and documentation prevent bugs and make programs readable and maintainable.

  • Document Summary: Include a summary block at the beginning of files explaining purpose, features, and key techniques.

  • Javadoc Comments (/** ... */): Place directly before class or method headers to enable automated HTML documentation generation.

  • Indentation and Spacing:

    • Indent nested statements at least 2 spaces deeper than their enclosing block.

    • Place single spaces on both sides of binary operators (e.g., 3 + 4 * 4 instead of 3+4*4).

  • Block Styles:

    • Next-Line Style: Aligns opening brace { on a new line aligned vertically with the header.

    • End-Of-Line Style: Places opening brace { at the end of the header line (standard Java API style, saves vertical screen space).

Programming Errors

Categories of Errors

  1. Syntax Errors (Compile Errors):

    • Violations of language structure rules (e.g., missing semicolons, missing quotation marks, mismatched braces, misspelled keywords).

    • Detected and reported by the compiler before program execution.

    • Best practice: Fix reported syntax errors starting from the top error message downwards.

  2. Runtime Errors:

    • Causes abnormal program termination while running.

    • Occurs when the environment detects impossible operational requests (e.g., integer division by zero 1 / 0, invalid data input types).

  3. Logic Errors:

    • Program compiles and runs to completion without crashing, but yields incorrect results due to flawed logic.

    • Example: Computing integer division (9 / 5) * 35 + 32 yields 67 instead of 95.0 because integer 9 / 5 truncates the fraction to 1. Using floating-point literal (9.0 / 5) * 35 + 32 corrects the error.

Common Beginner Errors

  1. Missing closing braces }.

  2. Missing semicolons ; (statement terminators).

  3. Missing closing quotation marks " in strings.

  4. Misspelling names/keywords (e.g., writing Main instead of main, or string instead of String).

IDE Development Workflows

NetBeans Workflow

  1. Create Project: File →\rightarrow New Project →\rightarrow Categories: Java, Projects: Java Application →\rightarrow Next →\rightarrow Specify Project Name and Location →\rightarrow Finish.

  2. Create Class: Right-click project node →\rightarrow New →\rightarrow Java Class →\rightarrow Specify Class Name (e.g., Welcome) →\rightarrow Finish.

  3. Compile and Run: Right-click file →\rightarrow Run File (or press Shift + F6). NetBeans compiles modified files automatically before execution.

Eclipse Workflow

  1. Create Project: File →\rightarrow New →\rightarrow Java Project →\rightarrow Enter Project Name (e.g., demo) →\rightarrow Select "Use project folder as root for sources and class files" →\rightarrow Finish.

  2. Create Class: File →\rightarrow New →\rightarrow Class →\rightarrow Type Name (e.g., Welcome) →\rightarrow Check public static void main(String[] args) →\rightarrow Finish.

  3. Compile and Run: Right-click class file →\rightarrow Run As →\rightarrow Java Application. Output displays in the Console window.

Review Checkpoint Questions and Answers

  • 1.1 What are hardware and software?

    • Hardware is the physical, tangible computer components; software consists of the invisible instructions controlling hardware.

  • 1.2 List five major hardware components of a computer.

    • CPU, memory (RAM), storage devices, input devices, output devices, communication devices.

  • 1.3 What does the acronym "CPU" stand for?

    • Central Processing Unit.

  • 1.4 What unit is used to measure CPU speed?

    • Hertz (Hz), Megahertz (MHz), and Gigahertz (GHz).

  • 1.5 What is a bit? What is a byte?

    • A bit is a binary digit (00 or 11). A byte is a binary storage unit consisting of 8 bits8\text{ bits}.

  • 1.6 What is memory for? What does RAM stand for? Why is memory called RAM?

    • Memory holds data and instructions for CPU execution. RAM stands for Random-Access Memory. It is called RAM because bytes can be accessed in any random order.

  • 1.7 What unit is used to measure memory size?

    • Bytes, kilobytes (KB), megabytes (MB), gigabytes (GB), terabytes (TB).

  • 1.8 What unit is used to measure disk size?

    • Gigabytes (GB) and terabytes (TB).

  • 1.9 What is the primary difference between memory and a storage device?

    • Memory is volatile (temporary, fast workspace lost on power-off); storage devices are non-volatile (permanent, slower storage).

  • 1.10 What language does the CPU understand?

    • Machine language (binary code).

  • 1.11 What is an assembly language?

    • A low-level programming language using symbolic mnemonics to represent binary machine instructions.

  • 1.12 What is an assembler?

    • A utility program that translates assembly language code into binary machine code.

  • 1.13 What is a high-level programming language?

    • An English-like, platform-independent programming language whose statements compute tasks.

  • 1.14 What is a source program?

    • A program written in a high-level language.

  • 1.15 What is an interpreter?

    • A translator that reads, converts, and executes source code statements line-by-line.

  • 1.16 What is a compiler?

    • A program that translates an entire high-level source code file into a machine-code file.

  • 1.17 What is the difference between an interpreted language and a compiled language?

    • Interpreted languages execute source statements immediately line-by-line; compiled languages generate a separate machine-code file for execution.

  • 1.18 What is an operating system? List some popular operating systems.

    • The master system program controlling computer hardware and software. Popular systems: Microsoft Windows, Mac OS, Linux.

  • 1.19 What are the major responsibilities of an operating system?

    • Controlling/monitoring system activities, allocating/assigning resources, and scheduling operations.

  • 1.20 What are multiprogramming, multithreading, and multiprocessing?

    • Multiprogramming shares one CPU across multiple programs. Multithreading runs concurrent tasks within a single program. Multiprocessing executes subtasks across multiple physical processors in parallel.

  • 1.21 Who invented Java? Which company owns Java now?

    • Created by James Gosling's team at Sun Microsystems; currently owned by Oracle.

  • 1.22 What is a Java applet?

    • A Java program embedded in HTML pages designed to run inside web browsers.

  • 1.23 What programming language does Android use?

    • Java.

  • 1.24 What is the Java language specification?

    • The formal technical document defining Java syntax and semantics.

  • 1.25 What does JDK stand for?

    • Java Development Toolkit.

  • 1.26 What does IDE stand for?

    • Integrated Development Environment.

  • 1.27 Are tools like NetBeans and Eclipse different languages from Java, or are they dialects or extensions of Java?

    • They are IDE tools for software development, not dialects or extensions of Java.

  • 1.28 What is a keyword? List some Java keywords.

    • Words reserved by the compiler with fixed meanings (class, public, static, void).

  • 1.29 Is Java case sensitive? What is the case for Java keywords?

    • Yes, Java is strictly case-sensitive. All Java keywords are lowercase.

  • 1.30 What is a comment? Is the comment ignored by the compiler? How do you denote a comment line and a comment paragraph?

    • Explanatory program notes ignored by the compiler. Line comment: //. Block comment paragraph: /* ... */.

  • 1.31 What is the statement to display a string on the console?

    • System.out.println("...");

  • 1.32 Show the output of the following code:

  public class Test {
    public static void main(String[] args) {
      System.out.println("3.5 * 4 / 2 2.5 is ");
      System.out.println(3.5 * 4 / 2 - 2.5);
    }
  }
  ```
  - Output:
    `3.5 * 4 / 2 2.5 is `
    `4.5` (Computed as 3.5×42−2.5=7.0−2.5=4.5\frac{3.5 \times 4}{2} - 2.5 = 7.0 - 2.5 = 4.5).
- **1.33 What is the Java source filename extension, and what is the Java bytecode filename extension?**
  - Source extension: `.java`. Bytecode extension: `.class`.
- **1.34 What are the input and output of a Java compiler?**
  - Input: `.java` source file. Output: `.class` bytecode file.
- **1.35 What is the command to compile a Java program?**
  - `javac ClassName.java`
- **1.36 What is the command to run a Java program?**
  - `java ClassName`
- **1.37 What is the JVM?**
  - Java Virtual Machine (software interpreter executing Java bytecode).
- **1.38 Can Java run on any machine? What is needed to run Java on a computer?**
  - Yes, provided a JVM compatible with the machine platform is installed.
- **1.39 If a `NoClassDefFoundError` occurs when you run a program, what is the cause of the error?**
  - The specified class file cannot be located.
- **1.40 If a `NoSuchMethodError` occurs when you run a program, what is the cause of the error?**
  - The class file lacks a properly declared `main` method.
- **1.41 Reformat the following program according to style guidelines using end-of-line brace style:**

java public class Test { // Main method public static void main(String[] args) { /** Display output */ System.out.println("Welcome to Java"); } }   ```

  • 1.42 What are syntax errors, runtime errors, and logic errors?

    • Syntax: Language structure rule violations (e.g., missing semicolon).

    • Runtime: Environment execution errors causing abnormal crash (e.g., division by zero).

    • Logic: Flawed logic leading to wrong results without crashing.

  • 1.43 If you forget to put a closing quotation mark on a string, what kind of error will be raised?

    • Syntax error (compile error).

  • 1.44 If your program needs to read integers, but the user entered strings, what kind of error occurs?

    • Runtime error.

  • 1.45 Suppose you write a program for computing the perimeter of a rectangle and mistakenly compute the area. What kind of error is this?

    • Logic error.

  • 1.46 Identify and fix errors in:java public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }   

    • Errors fixed: Added static and return type void to main; changed single quotes ' to double quotes " around the string.

Chapter Programming Exercises Summary and Mathematical Equations

  • Exercise 1.1 (Display three messages): Program displaying Welcome to Java, Welcome to Computer Science, and Programming is fun.

  • Exercise 1.2 (Display five messages): Program displaying Welcome to Java five times.

  • Exercise 1.3 (Display a pattern): Program displaying pattern spelling JAVA using letter combinations.

  • Exercise 1.4 (Print a table): Program outputting a grid of numbers aa, a2a^2, and a3a^3 for a∈1,2,3,4a \in {1, 2, 3, 4}.

  • Exercise 1.5 (Compute expressions): Program computing:   9.5×4.5−2.5×345.5−3.5\frac{9.5 \times 4.5 - 2.5 \times 3}{45.5 - 3.5}

  • Exercise 1.6 (Summation of a series): Program computing:   1+2+3+4+5+6+7+8+91 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9

  • Exercise 1.7 (Approximate π\pi): Program calculating:   π=4×(1−13+15−17+19−111+… )\pi = 4 \times \left(1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \frac{1}{11} + \dots\right)

  • Exercise 1.8 (Area and perimeter of a circle): Program computing circle values (radius=5.5radius = 5.5):   perimeter=2×radius×πperimeter = 2 \times radius \times \pi   area=radius×radius×πarea = radius \times radius \times \pi

  • Exercise 1.9 (Area and perimeter of a rectangle): Program computing rectangle values (width=4.5width = 4.5, height=7.9height = 7.9):   area=width×heightarea = width \times height   perimeter=2×(width+height)perimeter = 2 \times (width + height)

  • Exercise 1.10 (Average speed in miles): Program calculating average speed in miles per hour (14 km14\text{ km} run in 45 min 30 sec45\text{ min } 30\text{ sec}; 1 mile=1.6 km1\text{ mile} = 1.6\text{ km}).

  • Exercise 1.11 (Population projection): Program computing 5-year population projections starting from current population 312,032,486312,032,486 (365 days/year365\text{ days/year}) given:

    • 1 birth every 7 seconds7\text{ seconds}.

    • 1 death every 13 seconds13\text{ seconds}.

    • 1 new immigrant every 45 seconds45\text{ seconds}.

  • Exercise 1.12 (Average speed in kilometers): Program computing average speed in kilometers per hour (24 miles24\text{ miles} run in 1 hr 40 min 35 sec1\text{ hr } 40\text{ min } 35\text{ sec}).

  • Exercise 1.13 (Algebra: solve 2×22 \times 2 linear equations): Using Cramer's rule to solve:   ax+by=eax + by = e   cx+dy=fcx + dy = f   x=ed−bfad−bcx = \frac{ed - bf}{ad - bc}   y=af−ecad−bcy = \frac{af - ec}{ad - bc}   Applied to equation system: 3.4x+50.2y=44.53.4x + 50.2y = 44.5 and 2.1x+0.55y=5.92.1x + 0.55y = 5.9.