A computer can be described as an electronic machine that processes data. At a fundamental level a computer simply accepts input, performs some processing, and produces output. As an example, consider how a computer is used to perform the payroll functions for a small business.
The processing that takes place is the calculation of the pay due each employee. The input to this process is the number of hours worked and rate of pay for each employee, and the output is the employee checks.
The following diagram illustrates this model.
Components of a Computer
The components of a computer are shown in the following diagram.
In the context of structured programming, the primary components of a computer and their relevance are as follows:
Central Processing Unit (CPU): The CPU is the brain of the computer where most calculations take place. It is crucial in structured programming for executing program instructions and logical operations.
RAM (Random Access Memory): This is the primary working memory used by a computer, where data and programs in use are temporarily stored. In structured programming, RAM is vital for storing the state and variables of a program during execution.
ROM (Read-Only Memory): Contains the instructions for booting up the computer and basic operations. It’s less directly involved in structured programming but essential for the overall operation of the system.
Hard Drives/Solid State Drives (HDD/SSD): These are used for long-term data storage, including the storage of program files and related data in structured programming.
Input Devices (Keyboard, Mouse): These are used to input data and commands into the computer. In structured programming, they are essential for user interaction.
Output Devices (Monitor, Printer): These display or output the results of a computer’s processes, including the outcomes of structured programs.
Motherboard: The motherboard connects all of the computer's components and allows them to communicate with each other. It's critical for integrating the CPU, memory, and other components necessary for running structured programs.
Power Supply Unit (PSU): Provides the necessary power to all the computer components. While not directly involved in programming, it is essential for the functioning of the computer.
In structured programming, these components work in unison to execute programs efficiently and reliably, adhering to structured paradigms like sequence, selection, and iteration.
Input and Output on a Computer
When we talk about input and output in computing, we describe all forms of communication between a program on the computer and the outside world, which includes human end users, other programs on the same machine, or other programs running on other computers. Input includes all the data and signals received by the running program. For instance, input can be sent to a program using input devices such as a keyboard or mouse, or can come from other computers, such as when you use your web browser to load in a specific web page. Output on the other hand includes all the signals and data sent from a program. Monitors and printers are prime examples of output devices, but again, output can involve pure data, such as when your web browser sends a request to a web server to receive a web page. The latter immediately illustrates that the same program (a web browser) can involve a series of input and output operations. The same holds for hardware devices, such as a network card or a modem. A particular form of I/O we will be taking a closer look at in this chapter is file I/O, meaning input and output operations that read and write data to files stored on your computer. We can skip the details until we are ready to start dealing with files in Java, but two aspects are worth mentioning:
file modes and
the difference between text and binary files as they apply to programming languages other than Java.
Input and Output
Interaction in programming is described as input/output (I/O). Of course, this communication flows in two directions, one in the form of output, which is information the program provides to outside parties, and the other in the form of input, which is information users provide to the program or information the program reads in from the outside world. It is easy to imagine a multitude of cases where such functionality could be useful. Imagine a program asking the user's name, for instance, or a program asking if it should terminate or ignore an error when something unexpected happens. These aspects are all covered in this chapter. Interaction can happen not only between a program and a human end user, but can also involve other sources of information. Consider, for example, the fact that so far, whenever you closed and restarted a program, all its previous data values were lost. When writing a budget tracking application, you cannot expect your users to leave the program running indefinitely (what if the power goes out?) or expect them to re-enter all the information once they reopen the program. As such, you will also deal with ways of handling I/O between your program and data sources. This chapter covers the most basic of data sources, namely that of a file.
You are now familiar with the various components of a computer.
The next lesson will explain the role of an operating system.