Cover
Aloita nyt ilmaiseksi Introduction To Programming-Goodnotes.pdf
Summary
# Introduction to computer science and programming concepts
This section introduces the foundational concepts of computer science, differentiating between coding and programming, tracing historical computing milestones, and exploring theoretical underpinnings like Turing machines and complexity theory.
## 1. Introduction to computer science and programming concepts
### 1.1 Coding vs. programming
Understanding the distinction between coding and programming is crucial for grasping the broader scope of computer science [2](#page=2).
* **Coding:** This refers to the practical ability to utilize a programming language to construct software programs, such as applications, games, or websites [2](#page=2).
* **Programming:** This encompasses coding as a foundational skill, but extends beyond it. Programming involves defining requirements, writing pseudocode, conceptualizing algorithms, optimizing code, testing, creating executables, and maintaining software [2](#page=2).
### 1.2 Historical milestones in computing
The evolution of computing can be traced through several key historical developments.
#### 1.2.1 Charles Babbage and the Analytical Engine
Charles Babbage (1791-1871) is credited with creating the first mechanical computers [2](#page=2).
* **The Analytical Engine:** This conceptual machine was designed to be programmable using punched cards. Although it never physically materialized, its design principles were remarkably similar to modern computers [2](#page=2).
#### 1.2.2 The ENIAC
The ENIAC (Electronic Numerical Integrator & Computer), completed in 1946, was the first electronic digital programmable computer [2](#page=2).
* **Architecture:** It was modular, composed of individual panels designed for different functions [2](#page=2).
* **Programming Method:** Initial programming involved physically switching cables, a complex task that could take weeks to map a problem onto the machine [2](#page=2).
* **Purpose:** ENIAC was developed for the U.S. Navy to compute trajectory tables, which required numerical solutions to differential equations for tasks like estimating missile trajectories based on wind, initial speed, and weather conditions [2](#page=2).
* **Human Computers:** Before ENIAC, these computations were performed by humans known as "computers," a role in which women's contributions were significant [3](#page=3).
### 1.3 Theoretical foundations of computer science
The theoretical underpinnings of computer science were significantly shaped by mathematicians and logicians in the early 20th century.
#### 1.3.1 The decision problem and undecidability
In the late 1800s, mathematicians began exploring the foundations of mathematics itself. David Hilbert proposed 23 foundational mathematical problems to be solved during the 20th century [3](#page=3).
* **Hilbert's Decision Problem:** This problem asked whether there exists a method to definitively determine if a given statement logically follows from other statements [3](#page=3).
* **Turing and Church's Contribution:** Around 1936, Alan Turing and Alonzo Church demonstrated that such a universal deciding procedure does not exist, proving that some statements are "undecidable" [3](#page=3).
#### 1.3.2 Algorithms and the Turing Machine
In their work on decidability, Turing and Church introduced the concept of an algorithm [3](#page=3).
* **Algorithm Definition:** An algorithm is defined as a finite sequence of mathematically rigorous instructions, typically used to solve a class of specific problems or perform a computation [3](#page=3) [5](#page=5).
* **The Turing Machine:** This is a theoretical model of computation [3](#page=3).
* **Components:** It consists of a tape, a read/write head, and a control unit that manages states and transitions [3](#page=3).
* **Functionality:** A Turing machine operates by reading symbols on the tape, changing its internal state, and writing new symbols or moving the tape [3](#page=3).
* **Universality:** It is considered a universal machine capable of computing any computable function. A computable function is one for which an algorithm exists to produce an output given an input [3](#page=3) [4](#page=4) [5](#page=5).
#### 1.3.3 Complexity theory
Turing and Church are also credited with establishing complexity theory [4](#page=4).
* **Core Concept:** Complexity theory categorizes algorithms into different complexity classes based on the time required to compute them [4](#page=4).
* **Practical Implications:** This means some algorithms, while theoretically computable, may require an impractical amount of time to execute in practice, potentially billions of years [4](#page=4).
### 1.4 Core concepts in computer science
Computer science is fundamentally concerned with the study of computation and computational systems [4](#page=4).
#### 1.4.1 What is a computer?
A computer is a versatile tool with several key functions [4](#page=4).
* **Data Storage:** It can store data, including numbers, words, images, and sounds [4](#page=4).
* **Device Interaction:** It interacts with various devices such as monitors, keyboards, and mice [4](#page=4).
* **Program Execution:** It runs programs, each designed to perform a specific function, from editing text to playing games or editing video [4](#page=4).
* **Versatility:** This ability to run diverse programs makes computers extremely versatile and flexible [4](#page=4).
#### 1.4.2 What is a program?
A program is a set of instructions executed by a computer to perform a specific activity or achieve a particular outcome [5](#page=5).
* **Execution:** Programs are sequences of instructions that are executed by a computer, involving decisions made by the machine [5](#page=5).
* **Complexity:** While programs can be highly sophisticated and perform complex functions, their primitive instructions are very basic [5](#page=5).
#### 1.4.3 What is programming?
Programming is the activity of designing, realizing, testing, and maintaining programs [5](#page=5).
* **Program Description:** A program describes the precise sequence of steps a computer must follow to accomplish a given task or solve a problem [5](#page=5).
#### 1.4.4 What is an algorithm?
As previously defined, an algorithm is a finite sequence of mathematically rigorous instructions used to solve a specific problem or perform a computation. A problem can only be solved algorithmically if an algorithm exists for it [3](#page=3) [5](#page=5).
> **Tip:** Remember that while "coding" is about writing instructions in a specific language, "programming" involves the entire lifecycle of problem-solving and software development, from conception to maintenance.
> **Tip:** The Turing machine, though theoretical, serves as a fundamental model for understanding the limits and capabilities of computation.
> **Tip:** Complexity theory helps us understand not just if a problem *can* be solved, but *how efficiently* it can be solved.
---
# Computer hardware and software components
A computer system is composed of interconnected hardware and software components, each playing a critical role in its functionality [6](#page=6).
### 2.1 Hardware components
Hardware refers to the physical, tangible parts of a computer system. These include essential elements such as the Central Processing Unit (CPU), main memory, secondary storage devices, and input/output (I/O) devices [6](#page=6) [7](#page=7).
#### 2.1.1 Central Processing Unit (CPU)
The CPU, also known as the processor or microprocessor, is the chip that executes program commands. It operates through a continuous fetch-decode-execute cycle [14](#page=14) [6](#page=6):
1. **Fetch:** Retrieve an instruction from main memory [14](#page=14).
2. **Decode:** Determine what the instruction is [14](#page=14).
3. **Execute:** Carry out the instruction [14](#page=14).
The CPU is comprised of several key units:
* **Arithmetic/Logic Unit (ALU):** Performs calculations and makes decisions [15](#page=15).
* **Control Unit:** Coordinates processing steps [15](#page=15).
* **Registers:** Small storage areas within the CPU [15](#page=15).
The speed of a CPU is governed by the system clock, which generates regular electronic pulses to coordinate CPU activities. CPU speed is typically measured in gigahertz (GHz) [15](#page=15).
#### 2.1.2 Main Memory (RAM)
Main memory, also known as Random Access Memory (RAM), serves as the primary storage area for programs and data that are in active use. It is a volatile form of storage, meaning its contents are lost when electric power is removed. Each cell in RAM stores a bit (0 or 1) and is composed of transistors and capacitors. RAM is a direct access device, allowing information to be reached directly. The terms RAM and main memory are often used interchangeably [13](#page=13) [14](#page=14) [6](#page=6) [7](#page=7).
> **Tip:** RAM is essentially a Read-Write Memory, contrasting with ROM.
#### 2.1.3 Secondary Storage Devices
Secondary storage devices provide long-term, non-volatile storage for data and programs. Unlike main memory, the information stored here is retained even when power is off. Examples include Hard Disk Drives (HDD) and Solid State Drives (SSD) . Information is moved between main memory and secondary storage as needed [13](#page=13) [7](#page=7).
Both main memory and disks are classified as direct access devices. This means data can be accessed directly, and the terms "direct access" and "random access" are often used interchangeably. In contrast, a magnetic tape is a sequential access device, requiring access to intervening data to reach specific information [13](#page=13).
##### 2.1.3.1 Storage Capacity
Storage capacity quantifies the number of bytes a memory device can hold and is expressed in various units [13](#page=13):
* **Kilobyte (KB):** $2^{10}$ = 1024 bytes.
* **Megabyte (MB):** $2^{20}$ (over 1 million) bytes.
* **Gigabyte (GB):** $2^{30}$ (over 1 billion) bytes.
* **Terabyte (TB):** $2^{40}$ (over 1 trillion) bytes.
* **Petabyte (PB):** $2^{50}$ (a very large amount) bytes.
#### 2.1.4 Input/Output (I/O) Devices
Input/Output (I/O) devices facilitate user interaction with the computer. They allow data to enter the system (input) and allow the system to present information to the user (output) [7](#page=7).
Common I/O devices include:
* **Input:** Keyboard, Mouse, Touch Screen.
* **Output:** Monitor Screen.
The size of a monitor is measured diagonally (e.g., 17 inches) . Monitors also have a maximum resolution, which indicates the number of picture elements (pixels) they can display, such as 1280 by 1024. A higher resolution results in sharper images [15](#page=15).
#### 2.1.5 Analog vs. Digital Data Storage
Computers primarily store and manage data in digital form, but understanding analog data is also important [8](#page=8).
* **Analog:** Data is continuous and directly proportional to the information it represents, like the grooves on a record album directly corresponding to voltage signals sent to a speaker [8](#page=8).
* **Digital:** Information is broken down into discrete pieces, with each piece represented separately. This often involves sampling the analog representation to record specific voltage levels at particular times, as seen in Compact Discs storing numbers representing these sampled levels [8](#page=8).
### 2.2 Software Components
Software is a set of instructions or programs that tell hardware what to do. It is essential for hardware to function and is categorized into operating systems and application programs [6](#page=6).
#### 2.2.1 Operating Systems (OS)
Operating systems are fundamental software that control all machine activities. They provide the user interface and manage system resources like the CPU and memory. Examples of operating systems include Windows, Mac OS, Unix, and Linux [8](#page=8).
#### 2.2.2 Application Programs
Application programs are a generic term for any other type of software that is not an operating system. These programs perform specific tasks for the user and can range from word processors and games to complex systems like missile control systems [8](#page=8).
> **Tip:** Many operating systems and application programs feature a Graphical User Interface (GUI), which provides a visual way for users to interact with the computer [8](#page=8).
---
# Data representation and binary systems
This section explains how computers store and process information using the binary number system [8](#page=8).
### 3.1 Analog vs. Digital Data Storage
There are two fundamental methods for storing and managing data: analog and digital [8](#page=8).
* **Analog:** This method stores information that is continuous and directly proportional to the data being represented. An example is music on a record album, where the needle's movement across grooves directly corresponds to the voltage sent to the speaker [8](#page=8).
* **Digital:** This method breaks information down into discrete pieces, with each piece represented separately. Digital music on a Compact Disc, for instance, stores numbers that represent specific voltage levels sampled at particular times [8](#page=8).
### 3.2 Digital Information Representation
Computers store all types of information digitally, including numbers, text, graphics, images, audio, video, and program instructions. Essentially, all information is digitized by being broken into pieces and represented numerically [9](#page=9).
#### 3.2.1 Representing text digitally
Every character, including spaces, digits, and punctuation, is stored as a specific number. Uppercase and lowercase letters are treated as distinct characters [9](#page=9).
### 3.3 Binary Numbers
Once information is digitized, it is represented and stored in memory using the binary number system [9](#page=9).
* **Bit:** A single binary digit (0 or 1) is called a bit. Its unit symbol is 'b' [9](#page=9).
* **Byte:** A byte consists of 8 bits. Its unit symbol is 'B' [9](#page=9).
A single bit can represent two possible states, akin to a light bulb being either on or off [1](#page=1) [9](#page=9).
#### 3.3.1 Bit permutations
The different permutations or combinations of bits are used to store values. The number of items that can be represented by a certain number of bits follows the formula $2^n$, where $n$ is the number of bits [10](#page=10).
* 1 bit can represent $2^1 = 2$ items [10](#page=10).
* 2 bits can represent $2^2 = 4$ items [10](#page=10).
* 3 bits can represent $2^3 = 8$ items [10](#page=10).
* 4 bits can represent $2^4 = 16$ items [10](#page=10).
* 5 bits can represent $2^5 = 32$ items [10](#page=10).
Each additional bit doubles the number of possible permutations [10](#page=10).
#### 3.3.2 Place value
* **Decimal numbers:** These are base-10 numbers and use ten digits (0-9). For example, the decimal number 8427 can be expressed as $8 \times 10^3 + 4 \times 10^2 + 2 \times 10^1 + 7 \times 10^0$ [10](#page=10).
* **Binary numbers:** These are base-2 numbers and use two digits (0-1). The binary number 1101 can be converted to decimal as $1 \times 2^3 + 1 \times 2^2 + 0 \times 2^1 + 1 \times 2^0 = 8 + 4 + 0 + 1 = 13$ [10](#page=10).
### 3.4 Converting Decimal to Binary
The process of converting a decimal number to its binary equivalent involves repeatedly dividing the decimal number by 2 and recording the remainders. The binary number is formed by reading these remainders from bottom to top [11](#page=11).
> **Example:** Converting the decimal number 180 to binary:
>
> * 180 ÷ 2 = 90 remainder 0
> * 90 ÷ 2 = 45 remainder 0
> * 45 ÷ 2 = 22 remainder 1
> * 22 ÷ 2 = 11 remainder 0
> * 11 ÷ 2 = 5 remainder 1
> * 5 ÷ 2 = 2 remainder 1
> * 2 ÷ 2 = 1 remainder 0
> * 1 ÷ 2 = 0 remainder 1
>
> Reading the remainders from bottom to top gives the binary representation: 10110100 [11](#page=11).
### 3.5 Storage Capacity
Every memory device has a storage capacity, which indicates the number of bytes it can hold. These capacities are expressed in various units [13](#page=13):
* **Kilobyte (KB):** $2^{10} = 1024$ bytes [13](#page=13).
* **Megabyte (MB):** $2^{20}$ (over 1 million) bytes [13](#page=13).
* **Gigabyte (GB):** $2^{30}$ (over 1 billion) bytes [13](#page=13).
* **Terabyte (TB):** $2^{40}$ (over 1 trillion) bytes [13](#page=13).
* **Petabyte (PB):** $2^{50}$ (a whole bunch) bytes. One Petabyte (1 PB) is one billion Megabytes [11](#page=11) [13](#page=13).
* **Exabyte (EB):** 1000 Petabytes [11](#page=11).
#### 3.5.1 Types of Memory and Access
* **Main memory:** This is volatile, meaning stored information is lost when electric power is removed. Main memory and disks are direct access devices, allowing information to be reached immediately. The terms "direct access" and "random access" are often used interchangeably [13](#page=13).
* **Second memory devices:** These are non-volatile [13](#page=13).
* **Magnetic tape:** This is a sequential access device, as data is arranged linearly, requiring access to intervening data to reach specific information [13](#page=13).
Common storage devices include Hard Disk Drives (HDD) and Solid State Drives (SSD) [13](#page=13).
---
# Java programming language fundamentals
This section introduces the fundamental concepts of the Java programming language, covering its creation, syntax, compilation and execution process, standard libraries, and basic program structure, including classes, methods, and comments.
### 4.1 Introduction to Java
Java is a programming language created by Sun Microsystems and introduced in 1995. A programming language uses a set of rules to define how words and symbols can be combined to form valid program statements. Java offers the advantage of writing code once and executing it on any computer that has a Java interpreter. It also provides a wide, operating system-independent standard library with numerous functionalities [16](#page=16).
The general process of programming involves three steps:
1. Writing the code (source code) [16](#page=16).
2. Compiling the source code to create executable code [16](#page=16).
3. Executing the code [16](#page=16).
Tools like the Java Development Kit (JDK) and Integrated Development Environments (IDEs) such as IntelliJ are used for Java development [16](#page=16).
### 4.2 Compilation and Execution
#### 4.2.1 Bytecode and the Java Virtual Machine (JVM)
Compiling Java source code produces executable code known as **bytecode**. Bytecode is the code intended for the Java Virtual Machine (JVM) [17](#page=17).
The process can be visualized as follows:
* **Source File:** `javac HelloTester.java` [17](#page=17).
* **Compiler:** Generates `HelloTester.class` (Java Class File) [17](#page=17).
To execute a program, a Java interpreter is used, which acts as a virtual CPU (JVM) on the user's machine. The JVM translates bytecode into machine code that the real CPU can understand [17](#page=17).
> **Tip:** The JVM is crucial for Java's platform independence, allowing the same bytecode to run on different hardware and operating systems.
#### 4.2.2 Interpreter vs. Compiler
Most high-level programming languages use either an interpreter or a compiler exclusively. Java, however, uses both a compiler and an interpreter [18](#page=18).
The process of programming involves taking source code and libraries, passing them through a compiler, and then an interpreter to run the program. This combination influences portability and execution speed [19](#page=19).
* **Interpreted Languages:** Programs are very portable but generally less efficient because translation to machine code happens each time the program runs [20](#page=20).
* **Compiled Languages:** Programs are highly efficient as translation occurs only once before execution, but executable files are not portable across different CPUs and require a specific compiler for each architecture [20](#page=20).
* **Java:** Offers a good compromise between portability and efficiency. Source files are compiled into bytecode, which is then interpreted on different CPUs [20](#page=20).
> **Tip:** If portability is the primary goal, interpreted languages are preferred. If efficiency is paramount, compiled languages are the choice. Java aims for a balance between the two.
### 4.3 Standard Libraries
Java's standard libraries are collections of classes that provide readily available functionalities. These libraries allow Java to interact with the operating system for tasks like writing to the standard output without requiring low-level, OS-specific knowledge [18](#page=18).
Some key packages and classes include:
* `java.lang`: Contains fundamental classes like `System` and `Math` [18](#page=18).
* `java.util`: Provides utility classes such as `Scanner` [18](#page=18).
* `java.net`: Includes classes for networking like `URL` and `Socket` [18](#page=18).
The `System` class from the standard library contains objects and methods for using system resources. The `out` object within `System` represents the standard output stream [22](#page=22).
### 4.4 Basic Java Program Structure
#### 4.4.1 Classes and Objects
A Java program is made up of one or more classes. Classes are fundamental to Java as they act as "producers of objects". For now, objects can be considered as manipulable elements within a Java program [21](#page=21) [24](#page=24).
* **Class Definition:** Starts with the reserved word `class` [21](#page=21).
* **Access Modifier:** The keyword `public` indicates that a class can be used by anyone [21](#page=21).
* **File Naming:** Each source file can contain only one public class, and its name must match the file name [21](#page=21).
#### 4.4.2 Methods
A method defines a sequence of instructions to perform a specific task. Methods must be defined within a class [21](#page=21).
* **`main` Method:** Every Java application must have exactly one `main` method, declared as `public static void main(String[] args)` [21](#page=21).
* `static`: Indicates that the `main` method does not interact with or modify objects of the class it belongs to [21](#page=21).
* `void`: Means the method does not return any value [21](#page=21).
* **Method Body:** Enclosed in curly braces `{}` and contains program statements that are executed sequentially [22](#page=22).
#### 4.4.3 Statements and Instructions
Program statements are the instructions within a method's body. Each instruction typically terminates with a semicolon `;` [22](#page=22) [24](#page=24).
An example of a single instruction is `System.out.println("Hello World!");`, which visualizes or writes a line of text to the standard output [22](#page=22).
> **Example:**
> `System.out.println;` prints the number 7 [7](#page=7).
> `System.out.println(3+4);` prints the result of the sum, which is 7.
> `System.out.println("3+4");` prints the literal string "3+4" [23](#page=23).
#### 4.4.4 Comments
Comments are used to explain code and are ignored by the compiler [22](#page=22).
* **Single-line comments:** Start with `//` [22](#page=22).
* **Multi-line comments:** Start with `/*` and end with `*/` [22](#page=22).
Comments can be placed almost anywhere in the code [24](#page=24).
### 4.5 Identifiers and Reserved Words
#### 4.5.1 Identifiers
Identifiers are the "words" used in a program [24](#page=24).
* **Composition:** Java identifiers can consist of letters, digits, and the underscore `_` or dollar sign `USD` characters [24](#page=24).
* **Restrictions:** Identifiers cannot begin with a digit [24](#page=24).
* **Case Sensitivity:** Java is case-sensitive, meaning `Total`, `total`, and `TOTAL` are distinct identifiers [24](#page=24).
Programmers often use different casing styles for various types of identifiers:
* Title case (e.g., `Lincoln`) for class names [24](#page=24).
* Uppercase (e.g., `MAXIMUM`) for constants [24](#page=24).
#### 4.5.2 Reserved Words
Reserved words, also known as keywords, have predefined meanings in Java and cannot be used for other purposes [24](#page=24).
Some common reserved words include: `abstract`, `boolean`, `break`, `byte`, `case`, `catch`, `char`, `class`, `continue`, `default`, `do`, `double`, `else`, `extends`, `final`, `finally`, `float`, `for`, `if`, `implements`, `import`, `instanceof`, `int`, `interface`, `long`, `native`, `new`, `null`, `package`, `private`, `protected`, `public`, `return`, `short`, `static`, `strictfp`, `super`, `switch`, `synchronized`, `this`, `throw`, `throws`, `transient`, `true`, `try`, `void`, `volatile`, `while`. Words marked with an asterisk (*) are reserved but not currently used [25](#page=25).
### 4.6 White Space
Spaces, blank lines, and tabs are collectively referred to as white space. White space is used to separate words and symbols in a program, and extra white space is ignored by the compiler [25](#page=25).
### 4.7 Programming Errors
Programming errors can be broadly categorized into:
* **Syntax Errors:** Violations of the language's grammatical rules, such as a missing semicolon or incorrect keyword usage [23](#page=23).
* **Logical Errors:** Errors in the program's logic that cause it to produce incorrect results, even if the syntax is valid [23](#page=23).
---
# Problem solving and algorithm design in Java
This topic explores the systematic approach to problem-solving through algorithm design, their translation into Java code, and the fundamental Java constructs of variables, data types, expressions, and data conversions.
### 5.1 The process of problem solving and algorithm design
An algorithm is a precise, executable, and terminating sequence of steps designed to solve a specific problem. This involves understanding the problem, developing and describing an algorithm, testing it with simple inputs, translating it into a programming language, and finally compiling and testing the resulting program [26](#page=26) [27](#page=27).
#### 5.1.1 Developing an algorithm
Algorithms can be described using pseudocode, which is an informal description of steps that is more detailed than natural language but less formal than a programming language. Pseudocode uses indentation to indicate control structures like selections and repetitions and clearly indicates how results are reported [27](#page=27).
**Example:** An algorithm to determine how many years it takes for an investment to double at a 5 percent annual interest rate:
1. Start with a year value of 0, an initial balance of USD 10,000, and a column for interest.
2. Repeat the following steps while the balance is less than USD 20,000:
* Increment the year value by 1.
* Calculate the interest as `balance * 0.05`.
* Add the calculated interest to the balance.
3. Report the final year value as the answer [26](#page=26).
#### 5.1.2 Testing algorithms
Algorithms should be tested with simple inputs to verify their correctness. For instance, if the interest rate changes to 20 percent, one can trace the algorithm's steps to find the new doubling time [28](#page=28).
#### 5.1.3 Example: Cell phone carrier charges
An algorithm can be designed for more complex scenarios, such as calculating monthly cell phone charges. This involves a base fee for a certain number of minutes and an additional charge for minutes exceeding that limit, plus taxes and fees [28](#page=28).
### 5.2 Fundamental Java programming constructs
#### 5.2.1 Character strings
A string literal in Java is represented by enclosing text within double quotes. Examples include `"This is a string literal!"` and `"123 Main Street"`. Every string literal is an object defined by the `String` class [29](#page=29).
##### 5.2.1.1 String concatenation
The `+` operator is used for string concatenation, appending one string to another. When used with strings, it performs concatenation; if both operands are numbers, it performs addition; if one operand is a string and the other is a number, it performs string concatenation [29](#page=29).
> **Tip:** A string literal cannot span multiple lines directly in code; this will result in a compiler error [29](#page=29).
##### 5.2.1.2 Escape sequences
Escape sequences are used to represent special characters within strings, beginning with a backslash (`\`). Common escape sequences include `\t` for tab, `\n` for newline, `\"` for a double quote, and `\\` for a backslash [30](#page=30).
**Example:** To print `"Thank you all for coming to my home tonight," he said mysteriously.`, the following `println` statement can be used:
`System.out.println ("\"Thank you all for " + "coming to my home\ntonight, \" he said " + "mysteriously. ");` [30](#page=30).
#### 5.2.2 Variables and assignment
A variable is a named memory location that stores a value. A variable declaration specifies its name and data type. After declaration, a variable's type cannot be changed, and it must be declared only once [30](#page=30) [31](#page=31).
##### 5.2.2.1 Variable initialization
Variables can be given an initial value during declaration. For example, `int sum = 0;`. When a variable is referenced, its current value is used [31](#page=31).
**Example:** The `PianoKeys.java` program demonstrates declaring and initializing an integer variable to store the number of piano keys:
```java
public class PianoKeys {
public static void main(String[] args) {
int keys = 88;
System.out.println("A piano has " + keys + " keys.");
}
}
```
This program outputs: `A piano has 88 keys.` [31](#page=31).
##### 5.2.2.2 Assignment
An assignment statement uses the `=` operator to change the value of a variable. The assigned value must be consistent with the variable's declared type [31](#page=31).
**Example:** The `Geometry.java` program illustrates how assignment statements can change the value stored in a variable:
```java
public class Geometry {
public static void main(String[] args) {
int sides = 7; // declaration with initialization
System.out.println("A heptagon has " + sides + " sides.");
sides = 10; // assignment statement
System.out.println("A decagon has " + sides + " sides.");
sides = 12;
System.out.println("A dodecagon has " + sides + " sides.");
}
}
```
This program outputs:
```
A heptagon has 7 sides.
A decagon has 10 sides.
A dodecagon has 12 sides.
```
[32](#page=32).
> **Tip:** The right and left sides of an assignment statement can contain the same variable, as in `count = count + 1;`, which increments the variable's value [36](#page=36).
#### 5.2.3 Constants
A constant is an identifier similar to a variable but holds a fixed value throughout its existence. In Java, constants are declared using the `final` modifier [32](#page=32).
**Example:** `final int MIN_HEIGHT = 69;` [32](#page=32).
Constants are beneficial for:
1. Giving meaning to literal values (e.g., `MAX_LOAD` is more descriptive than `250`) [32](#page=32).
2. Facilitating program maintenance, as a constant's value only needs to be updated in one place [32](#page=32).
3. Formally establishing that a value should not change, preventing inadvertent errors [32](#page=32).
#### 5.2.4 Primitive data types
Java has eight primitive data types:
* **Integers:** `byte`, `short`, `int`, `long` [32](#page=32).
* **Floating-point numbers:** `float`, `double` [32](#page=32).
* **Characters:** `char` [32](#page=32).
* **Boolean values:** `boolean` [32](#page=32).
##### 5.2.4.1 Numeric primitive data
The difference between numeric primitive types lies in their storage size and the range of values they can hold [33](#page=33).
| Type | Storage | Min Value | Max Value |
| :------ | :------ | :-------------------- | :------------------ |
| `byte` | 8 bits | -128 | 127 |
| `short` | 16 bits | -32,768 | 32,767 |
| `int` | 32 bits | -2,147,483,648 | 2,147,483,647 |
| `long` | 64 bits | \~ -9 x 1018 | \~ 9 x 1018 |
| `float` | 32 bits | +/- 3.4 x 1038 | +/- 3.4 x 1038 |
| `double`| 64 bits | +/- 1.7 x 10308| +/- 1.7 x 10308|
*Note: `float` has approximately 7 significant digits, while `double` has approximately 15 significant digits.* [33](#page=33).
##### 5.2.4.2 Characters
A `char` variable stores a single character, delimited by single quotes (e.g., `'a'`, `'X'`, `'7'`). Character literals are distinct from string literals [33](#page=33).
* **Character sets:** Character sets are ordered lists where each character corresponds to a unique number. Java's `char` type uses the Unicode character set, which uses 16 bits per character and supports 65,536 unique characters, accommodating international symbols and characters from various languages [33](#page=33).
* **ASCII:** The older ASCII character set is a subset of Unicode and includes uppercase and lowercase letters, digits, punctuation, special symbols, and control characters [34](#page=34).
* **Character literals:** Characters can be represented using Unicode escape sequences (e.g., `\u005B`) or directly as character literals (e.g., `'9'`) [34](#page=34).
**Example:**
`char c = '\u005B';`
`System.out.println(c);` // Prints the character corresponding to the Unicode value.
`char d = '9';`
`System.out.println(d);` // Prints the character '9'. [34](#page=34).
##### 5.2.4.3 Boolean
A `boolean` value represents a true or false condition. The reserved words `true` and `false` are the only valid values for this type. Boolean variables can also represent states like a light bulb being on or off [34](#page=34).
**Example:** `boolean clone = false;` [34](#page=34).
#### 5.2.5 Expressions
An expression is a combination of operators and operands that produces a result [35](#page=35).
##### 5.2.5.1 Arithmetic expressions
Arithmetic expressions compute numeric results using operators like addition (`+`), subtraction (`-`), multiplication (`*`), division (`/`), and remainder (`%`). If any operand is a floating-point value, the result will be a floating-point value [35](#page=35).
##### 5.2.5.2 Division and remainder
* When both operands of the division operator (`/`) are integers, the result is an integer, with the fractional part discarded. For example, `14 / 3` equals `4`, and `8 / 12` equals `0` [35](#page=35).
* The remainder operator (`%`) returns the remainder after division. For example, `14 % 3` equals `2` (since 14 = 3 * 4 + 2), and `8 % 12` equals `8` [35](#page=35).
##### 5.2.5.3 Operator precedence
Operators have a defined precedence that determines the order of evaluation in complex expressions. Multiplication, division, and remainder are evaluated before addition, subtraction, and string concatenation. Parentheses (`()`) have higher precedence than other operators and can be used to enforce a specific evaluation order [36](#page=36).
**Example:** In `result = total + count / max - offset;`, the division `count / max` is performed first, followed by addition and subtraction based on their left-to-right evaluation [36](#page=36).
##### 5.2.5.4 Expression trees
Expression trees can visually represent the evaluation order of expressions, where operators lower in the tree have higher precedence within that expression [36](#page=36).
##### 5.2.5.5 Increment and decrement operators
The increment (`++`) and decrement (`--`) operators are unary operators that add or subtract 1 from their operand [37](#page=37).
* **Postfix form (`count++`):** The expression evaluates to the original value of `count` before the increment [37](#page=37).
* **Prefix form (`++count`):** The expression evaluates to the value of `count` after the increment [37](#page=37).
**Example:**
`int count = 3;`
`int value = count++;`
`System.out.println(value);` // Prints 3 (original value of count)
`System.out.println(count);` // Prints 4 (incremented value)
`int count = 3;`
`int value = ++count;`
`System.out.println(value);` // Prints 4 (incremented value)
`System.out.println(count);` // Prints 4 (incremented value)
[37](#page=37).
#### 5.2.6 Assignment operators
Assignment operators provide a shorthand for common assignment operations [38](#page=38).
| Operator | Example | Equivalent to |
| :------- | :----------- | :---------------- |
| `+=` | `x += y` | `x = x + y` |
| `-=` | `x -= y` | `x = x - y` |
| `*=` | `x *= y` | `x = x * y` |
| `/=` | `x /= y` | `x = x / y` |
| `%=` | `x %= y` | `x = x % y` |
If the operands are strings, `+=` performs string concatenation [38](#page=38).
#### 5.2.7 Data conversion
Data conversion, or casting, allows converting a value from one data type to another. These conversions do not change the variable's type but convert a value for a specific computation [38](#page=38).
##### 5.2.7.1 Widening and narrowing conversions
* **Widening conversions:** These are generally safer as they convert from a smaller data type to a larger one (e.g., `short` to `int`). Information is typically not lost [39](#page=39).
* **Narrowing conversions:** These can lose information as they convert from a larger data type to a smaller one (e.g., `int` to `short`) [39](#page=39).
| From | To | Type of Conversion |
| :------ | :---------------------------------------- | :----------------- |
| `byte` | `short`, `int`, `long`, `float`, `double` | Widening |
| `short` | `int`, `long`, `float`, `double` | Widening |
| `char` | `int`, `long`, `float`, `double` | Widening |
| `int` | `long`, `float`, `double` | Widening |
| `long` | `float`, `double` | Widening |
| `float` | `double` | Widening |
| `byte` | `char` | Narrowing |
| `short` | `byte`, `char` | Narrowing |
| `char` | `byte`, `short` | Narrowing |
| `int` | `byte`, `short`, `char` | Narrowing |
| `long` | `byte`, `short`, `char`, `int` | Narrowing |
| `float` | `byte`, `short`, `char`, `int`, `long` | Narrowing |
| `double`| `byte`, `short`, `char`, `int`, `long`, `float` | Narrowing |
*Note: `char` uses 16 bits and ranges from 0 to 65,535.* [39](#page=39).
##### 5.2.7.2 Types of data conversions in Java
1. **Assignment conversion:** Occurs when a value of one type is assigned to a variable of another type. Only widening conversions can happen via assignment. If a narrowing conversion is attempted, the compiler will issue an error, requiring an explicit cast [40](#page=40).
* **Example (Widening):**
```java
int dollars = 20;
double money = dollars; // Widening conversion: int to double
```
* **Example (Narrowing - requires cast):**
```java
double money = 20.7;
int dollars = (int) money; // Narrowing conversion: double to int
```
2. **Promotion:** Happens automatically when operators in expressions convert their operands. This is also only widening [40](#page=40).
* **Example:**
```java
int count = 12;
double sum = 490.27;
double result = sum / count; // count is promoted to double for division
```
The value of `count` is converted to a `double` to perform the division calculation [40](#page=40).
3. **Casting:** The most powerful, and potentially dangerous, technique for conversion, allowing both widening and narrowing conversions. The type to convert to is placed in parentheses before the value [41](#page=41).
* **Example:**
```java
int total = 50;
float result = (float) total / 6; // Explicit cast to float
```
Without the cast, the fractional part of the answer would be lost due to integer division [41](#page=41).
**Quiz:**
`double d = 5.0;`
`int i = d / 3;`
`System.out.println(i);`
**Answer:** This code has a syntax error. Automatic narrowing is not performed. You must cast: `int i = (int) d / 3;` [41](#page=41).
**Quiz:**
`char c = 65;`
`System.out.println(c);`
`int i = (char) -65;`
`System.out.println(i);`
**Answer:** The ASCII/Unicode decimal number for 'A' is 65, so the first `println` prints `A`. For the second part, `(char) -65` results in the character with decimal value 65471 (due to 16-bit representation wrapping around), so the second `println` prints `65471` [41](#page=41).
---
# Interactive programming and object-oriented concepts
This section covers how to create interactive programs by reading user input and introduces fundamental object-oriented programming (OOP) concepts in Java.
### 6.1 Interactive programming with the Scanner class
Interactive programs require input from the user to operate. The `Scanner` class, found in the `java.util` library, provides convenient methods for reading input values of various data types [42](#page=42).
#### 6.1.1 Reading user input
To read input from the keyboard, a `Scanner` object must be created, associated with the `System.in` object [42](#page=42).
**Creating a Scanner object:**
```java
Scanner scan = new Scanner(System.in);
```
The `new` operator instantiates the `Scanner` object. This object can then be used to invoke various input methods [42](#page=42).
**Input methods:**
* `nextLine()`: Reads all input until the end of the line is found and returns it as a `String` [42](#page=42).
* `next()`: Reads the next input token, separated by whitespace, and returns it as a `String`. Whitespace includes spaces, tabs, and new line characters [43](#page=43).
* `nextInt()`: Reads an integer value from the input [43](#page=43).
* `nextDouble()`: Reads a double-precision floating-point value from the input [43](#page=43).
> **Tip:** The `Scanner` class must be imported into a program using `import java.util.Scanner;` before it can be used [42](#page=42) [43](#page=43).
> **Example:** The `Echo.java` program demonstrates reading a line of text from the user using `nextLine()` and printing it back. The `GasMileage.java` program shows how to use `nextInt()` and `nextDouble()` to calculate fuel efficiency [43](#page=43).
### 6.2 Object-oriented concepts
Object-oriented programming (OOP) builds programs around "objects," which are entities manipulated by calling their methods [45](#page=45).
#### 6.2.1 Objects and methods
An **object** is an entity in a program that has behaviors and data. A **method** is a sequence of instructions that can access an object's data and define its behaviors. You interact with objects by calling their methods [45](#page=45) [49](#page=49).
> **Example:** `System.out` is an object of the `PrintStream` class that has methods like `println()` and `print()`. `String` objects, such as `"Hello World"`, also have associated methods like `toUpperCase()` [45](#page=45) [46](#page=46) [49](#page=49).
#### 6.2.2 Classes
A **class** describes a set of objects that share the same behavior. It acts as a blueprint for creating objects. All objects of a given class share a common set of methods [46](#page=46) [49](#page=49).
* The `PrintStream` class defines methods for its objects, like `println()` and `print()`, to write to different destinations [46](#page=46).
* The `String` class provides methods applicable to all `String` objects [46](#page=46).
The collection of methods available for an object forms its **public interface**, specifying what actions can be performed with it. The internal implementation details of how these actions are carried out are hidden [49](#page=49).
> **Example:** A `String` object knows about its letters, but it doesn't know how to send itself to a console window or a file. This functionality is provided by methods defined in other classes, like `PrintStream` [46](#page=46).
#### 6.2.3 Variables
Variables are used to store values that can be used later in a program [46](#page=46).
* **Declaration:** A variable is declared with its type and name, optionally followed by an initial value [46](#page=46) [47](#page=47).
* Syntax: `typeName variableName = value;` or `typeName variableName;` [46](#page=46).
* **Types:**
* `int`: Used for whole numbers without fractional parts [47](#page=47).
* `double`: Used for floating-point numbers [47](#page=47).
* `String`: Used for sequences of characters [47](#page=47).
* **Naming Rules:**
* Must start with a letter or underscore (`_`).
* Remaining characters can be letters, numbers, or underscores.
* Cannot use symbols like `USD%` or spaces.
* Use uppercase letters to denote word boundaries (e.g., `milesPerGallon`), a convention called camel case [48](#page=48).
* Cannot use reserved Java keywords (e.g., `double`, `class`) [48](#page=48).
* Java convention: variable names start with a lowercase letter, and class names start with an uppercase letter [48](#page=48).
* **Assignment:** The assignment operator (`=`) is used to change the value of a variable. The right-hand side of the assignment can be a mathematical expression [48](#page=48).
* Syntax: `variableName = value;` [49](#page=49).
* A variable can appear on both sides of the assignment operator, allowing its value to be updated based on its current value [48](#page=48) [49](#page=49).
> **Tip:** Always use descriptive variable names that indicate their purpose. Supplying an initial value when declaring a variable is generally good practice [46](#page=46) [48](#page=48).
> **Common Error:** It is an error to use a variable that has not been assigned a value [47](#page=47) [48](#page=48).
#### 6.2.4 Method arguments and return values
* **Arguments (Parameters):** Most methods require values to provide details about the task they need to perform. These input values are called arguments or parameters [50](#page=50).
* `System.out.println("greeting");` - Here, the string `"greeting"` is an argument passed to the `println` method [50](#page=50).
* **Return Values:** Methods can return a computed value back to the caller.
* The `toUpperCase()` method, when called on a `String` object, returns a new `String` object with all characters converted to uppercase [50](#page=50).
> **Example:**
> ```java
> String river = "Mississippi";
> String bigRiver = river.toUpperCase(); // bigRiver will be "MISSISSIPPI"
> ```
> In this example, `toUpperCase()` is a method called on the `river` object, and it returns a new `String` object which is then assigned to `bigRiver` [50](#page=50).
### 6.3 Mathematical operations
Java's `Math` class provides methods for mathematical computations [45](#page=45).
* `Math.sqrt(x)`: Computes the square root of a number `x` [45](#page=45).
* `Math.pow(x, n)`: Computes `x` raised to the power of `n` ($x^n$) [45](#page=45).
* Compound interest calculation often uses `Math.pow`:
$$ \text{Amount} = P \times (1 + r/100)^n $$
This can be represented in Java as `principal * Math.pow(1 + rate / 100, numberOfYears)` [45](#page=45).
### 6.4 Project example: Tic Tac Toe Runner
The Tic Tac Toe Runner game project utilizes the `Scanner` class to read user commands and input for playing the game. This includes reading game mode choices (P, Q, I), row numbers (1-3), and column numbers (1-3). The program is designed to run, allow a full game, display the board, detect wins/draws, and accept specific commands. A welcome message is also an output of the program [51](#page=51) [52](#page=52).
---
## Common mistakes to avoid
- Review all topics thoroughly before exams
- Pay attention to formulas and key definitions
- Practice with examples provided in each section
- Don't memorize without understanding the underlying concepts
Glossary
| Term | Definition |
|------|------------|
| Coding | The act of using a programming language to create a software program, such as an application, game, or website. |
| Programming | The broader discipline that encompasses coding, along with defining requirements, writing pseudocode, thinking of algorithms, optimizing code, testing code, creating executables, and maintaining code. |
| Babbage Analytical Engine | A mechanical computer designed by Charles Babbage in the 19th century, featuring programmability via punched cards and a structure similar to modern computers, though it was never fully built. |
| ENIAC | The first electronic digital programmable computer, completed in 1946. It was modular, composed of individual panels, and programming involved switching cables, a complex and time-consuming task. |
| Algorithm | A finite sequence of mathematically rigorous instructions designed to solve a specific class of problems or perform a computation. |
| Turing Machine | A theoretical model of computation proposed by Alan Turing, representing a universal machine capable of computing any computable function. It consists of a tape, a head, and a set of states and instructions. |
| Complexity Theory | A field within computer science that studies the resources (such as time and memory) required to solve computational problems, categorizing algorithms into different complexity classes. |
| Computer | A tool that stores data, interacts with devices, and runs programs to perform specific functions, characterized by its versatility and flexibility due to the many programs it can execute. |
| Program | A sequence of instructions that are executed by a computer to perform a specific activity or function, often very sophisticated yet built from basic primitive instructions. |
| Hardware | The physical, tangible parts of a computer system, including components like the keyboard, monitor, wires, and chips. |
| Software | A program or set of programs that instructs a computer on what to do and how to do it. |
| CPU (Central Processing Unit) | The primary chip in a computer responsible for executing program commands and performing calculations. |
| Main Memory (RAM) | The primary storage area within a computer where programs and data in active use are held for quick access by the CPU. It is volatile, meaning its contents are lost when power is removed. |
| RAM (Random Access Memory) | A synonym for main memory, characterized by its ability to directly access any memory location. |
| ROM (Read-Only Memory) | A type of memory that can be read from but not written to, often containing essential system instructions or firmware. |
| Volatile Memory | Memory that loses its stored information when the power supply is interrupted. RAM is a prime example. |
| Non-volatile Memory | Memory that retains its stored information even when the power supply is interrupted. Secondary storage devices like hard drives are non-volatile. |
| Direct Access | A method of accessing data where any piece of information can be reached directly, without having to go through intermediate data. RAM and disk drives are direct access devices. |
| Sequential Access | A method of accessing data where information is arranged in a linear order, and access to a particular piece of data requires passing through all preceding data. Magnetic tapes are sequential access devices. |
| Microprocessor | A small chip that contains the CPU and its associated circuitry. |
| Fetch-Decode-Execute Cycle | The fundamental cycle performed by the CPU: fetching an instruction from memory, decoding it to understand its purpose, and executing the instruction. |
| System Clock | A component that generates electronic pulses at regular intervals, coordinating the activities of the CPU and controlling its speed. |
| Pixel | A single picture element, representing the smallest controllable element of a picture represented on a screen. Resolution is often measured by the number of pixels. |
| Java | A high-level, object-oriented programming language introduced in 1995, known for its "write once, run anywhere" capability and extensive standard libraries. |
| Source Code | The human-readable code written by programmers in a programming language before it is compiled or interpreted. |
| Bytecode | An intermediate code generated by a Java compiler that is platform-independent. It is executed by the Java Virtual Machine (JVM). |
| JVM (Java Virtual Machine) | A virtual CPU that interprets Java bytecode, allowing Java programs to run on any platform that has a compatible JVM installed. |
| Compiler | A program that translates source code written in a high-level programming language into machine code or an intermediate code (like bytecode) that a computer can execute. |
| Interpreter | A program that directly executes instructions written in a programming language, typically line by line or statement by statement, without a separate compilation step. |
| Portability | The ability of a program to be executed on different types of computer systems or hardware without modification. Interpreted languages are generally more portable than compiled languages. |
| Efficiency | The measure of how effectively a program uses resources, particularly execution speed and memory usage. Compiled languages are typically more efficient than interpreted languages. |
| Class | In object-oriented programming, a blueprint or template for creating objects. It defines the properties (attributes) and behaviors (methods) that objects of that class will have. |
| Object | An instance of a class, representing a specific entity in a program with its own data and behaviors. |
| Method | A sequence of instructions within a class that performs a specific task or behavior. Methods are invoked on objects to make them perform actions. |
| `main` method | The entry point of a Java application. A Java program must have exactly one `main` method, which is the first method to be executed when the program runs. |
| `public static void main(String[] args)` | The standard signature for the main method in Java. `public` means it's accessible from anywhere, `static` means it can be called without creating an object of the class, `void` means it doesn't return a value, and `String[] args` represents command-line arguments. |
| Comments | Text within a program that is ignored by the compiler or interpreter but provides explanations for human readers. In Java, comments can be single-line (`//`) or multi-line (`/* ... */`). |
| Reserved Words | Words that have a predefined meaning in a programming language and cannot be used as identifiers (e.g., `class`, `public`, `int`). |
| White Space | Spaces, tabs, and blank lines used in a program to improve readability by separating words and symbols. Extra white space is typically ignored by the compiler. |
| Pseudocode | An informal, high-level description of the steps of an algorithm or program, using natural language mixed with programming-like constructs. It is used for planning before writing actual code. |
| String Literal | A sequence of characters enclosed in double quotes (`"`) that represents a text value in a program. |
| `System.out.println()` | A Java method used to print output to the console, followed by a newline character. |
| `System.out.print()` | A Java method used to print output to the console without advancing to the next line. |
| String Concatenation | The process of joining two or more strings together to form a single string, typically using the `+` operator. |
| Escape Sequence | A sequence of characters starting with a backslash (`\`) that represents a special character, such as a newline (`\n`) or a tab (`\t`). |
| Variable | A named storage location in memory that holds a value of a specific data type. The value stored in a variable can be changed during program execution. |
| Variable Declaration | The process of specifying a variable's name and the type of data it will hold. |
| Variable Initialization | The process of assigning an initial value to a variable when it is declared. |
| Assignment Statement | A statement that changes the value of a variable by assigning a new value to it using the assignment operator (`=`). |
| Constant | An identifier whose value cannot be changed after it has been assigned. In Java, constants are declared using the `final` modifier. |
| Primitive Data Types | Basic data types in Java that directly store values, such as integers (`byte`, `short`, `int`, `long`), floating-point numbers (`float`, `double`), characters (`char`), and boolean values (`boolean`). |
| `char` | A primitive data type in Java used to store a single character. Character literals are enclosed in single quotes (e.g., `'A'`). |
| Unicode | A character encoding standard that supports a vast number of characters from various languages and symbols, using 16 bits per character. |
| ASCII | An older and smaller character encoding standard that is a subset of Unicode, commonly used for English characters, numbers, and symbols. |
| `boolean` | A primitive data type in Java that can hold one of two values: `true` or `false`. |
| Expression | A combination of operators, operands, and values that produces a result when evaluated. |
| Operator Precedence | A set of rules that determines the order in which operators are evaluated in an expression. Parentheses have the highest precedence. |
| Increment Operator (`++`) | An operator that increases the value of a variable by 1. It can be used in postfix (`variable++`) or prefix (`++variable`) form. |
| Decrement Operator (`--`) | An operator that decreases the value of a variable by 1. It can be used in postfix (`variable--`) or prefix (`--variable`) form. |
| Assignment Operators | A set of operators that combine an arithmetic or bitwise operation with assignment (e.g., `+=`, `-=`, `*=`, `/=`, `%=`). |
| Data Conversion | The process of changing a value from one data type to another. This can be widening (safe, e.g., `int` to `double`) or narrowing (can lose information, e.g., `double` to `int`). |
| Widening Conversion | A data conversion where a value is converted from a smaller data type to a larger one, typically without loss of information. |
| Narrowing Conversion | A data conversion where a value is converted from a larger data type to a smaller one, which may result in a loss of information. |
| Casting | An explicit technique used to perform data conversions, especially narrowing conversions, by placing the target data type in parentheses before the value. |
| `Scanner` Class | A Java utility class used for reading input from various sources, including user input from the keyboard via `System.in`. |
| Token | An element of input separated by whitespace. The `Scanner` class can read input as individual tokens. |
| `Math.sqrt()` | A Java method in the `Math` class that calculates the square root of a number. |
| `Math.pow()` | A Java method in the `Math` class that calculates a number raised to a specified power. |
| Arguments (Parameters) | Values passed to a method when it is called, providing the method with the necessary information to perform its task. |
| Public Interface | The set of methods and behaviors that a class makes available for external use, defining how other parts of a program can interact with its objects. |
| Implementation | The internal details of how a class's methods perform their tasks. This is hidden from external users and can be changed without affecting the public interface. |