# Object Oriented with Java/Object-oriented programming with java

This unit introduces:
* Fundamental hardware and software concepts
* Programming approaches: procedural programming and object oriented programming
* Speculation about Objects
* Sending messages to objects and grouping objects into classes

## Fundamental hardware and software concepts

A computer is a device that accepts input, processes data, stores data, and produces output. These are the main basic tasks of a computer. Simply, any computer system is composed of computer hardware and software:
* The hardware components of a computer system are the electronic and mechanical parts.
* The software components of a computer system are the intangible parts: it is a general term of all the applications, programs, and systems that run on your computer. Software consists of sets of instructions that tell a computer how to perform a particular task.

## Computer Hardware

The main hardware devices are classified as:
* Essential parts of a computer : Central Processing Unit (CPU) & main memory;
* Peripheral devices, which is any component of the computer that is not part of essential devices, such as: Input/Output devices, secondary storage (Storage devices). Some peripherals are mounted in the same case as processor such as hard disks, others such as printers are physically outside the computer.
An input device gathers and translates input into a form that the computer can process, these are devices such as: keyboard, mouse, scanner, microphone, card-reader, and bar reader.
CPU Processing data is done in a device called central processing unit (CPU). A processor is, (the brain of a computer), an electronic device about one inch square covered in plastic, in which a processor manipulates data in many ways by applying a series of actions.
Output device, produces results using devices such as: printers, screens, plotters, and loud speaker.
Storing data, a computer must store data so that it will be available for processing. There are two places to store data: • Maim memory (MM), which holds the programs temporarily during execution. • Secondary storage, which holds data and programs permanently such as hard-disk, floppy disks, CD's

## Computer Software

Software (SW) is a general terminology; for all programs, applications and systems. The SW makes a computer useful. SW is kept on some hardware device such as the hard disk.:
Usually any software is written using a programming language which is called as the source code. Then this code is compiled (translated) into zeros and ones (binary digits, low-level) or bits, which make up the instructions and data that the hardware can execute.
Software could be classified into: System, Program, and Application.
System The term system has different meanings depending on how it is used as listed below:
* An operating system: is essentially the master controller for all of the activities that take place within a computer. It sets the standards for all application SW that a computer runs. (i.e. how do I configure my system to allow me using my new scanner?)
* A computer system: a combination of hardware and software. (i.e. my system crashed 4 times last night, and I can’t figure out whether it is a hardware problem or that I game I picked up cause the problem).
* A software system: a large piece of software which is essentially meant to run forever (no start point or end point), and has to respond to a variety of events that may occur in an unpredictable order. The system usually is composed of smaller units of SW called applications or programs which communicate with each other.
* System Software: is categorized as software that helps the computer carry out its basic operating tasks. It is required to support the production or execution of applications but which is not specific to any particular application. System Software includes:
       a. Operating systems, that controls the execution of the programs;
       b. User interface software such as graphical windows and menus interpreters
       c. Development tools such as compilers
       d. Utility programs involved in sending data, printing or communicating with peripheral devices.
Program A computer program is a set of detailed, step by step instructions that tells a computer how to solve a problem or carry out a task. The notion of a program assumes a pattern: input data-processing data-output data. Any program has a starting point which takes some input, then performs needed computations, and then it has an end point at which output is given and software stop running (in contrast to systems that run for ever).
Applications These are programs which users choose to work with such as word processing & Excel, web browser. You can liken applications to virtual computers each with a special operating system. Applications differ from systems in that:
    • They are not designed to run for ever;
    • Run on a single computer;
    • And perform a single task for a single user.

## The operating system

An operating system (OS) is the software responsible for the control and management of hardware and basic system operations (such as data input and output), as well as running application software such as word-processing programs and web browsers.
The operating system is always present when the computer is running, and it acts as an intermediary between the user and the computer hardware. Common operating systems for personal computers include Linux, Mac OS (for the Apple Macintosh) and the various versions of Windows, e.g. Windows 2000 and Windows XP.
Note that: not all computers have OS, if computer runs a single program all the time, which can configured directly on the hardware, then OS is unnecessary. (i.e. fuel-injection system in a car)

#### Operating System main services are:

* :Management of Memory: To run a program, this program should be moved from secondary storage to main memory. It is the job of OS to:
      * Allocate appropriate sized area of memory to each program,
      * To ensure that program data and instructions do not interfere with each other or with other programs and applications.
* Coordination and control of peripheral devices: OS coordinates the communication with peripheral devices such as input/output devices, to accept data from user, produce output on screen or printer, connect to a network etc.
* Scheduling of access to the processor: The operating system manages access to the processor, by prioritising jobs to be run and ensuring that the processor is used efficiently. (i.e. if current running program is waiting data from hard disk, the OS will ensure to run another program so processor will not be idle and that it used efficiently).
* Provision of basic utilities: Operating systems also provide basic utilities such as disk formatting facilities, file management systems and software installation wizards.
* Provision of an interface between applications/programs and hardware: :OS provides a stable, consistent way for software communicate with the computer’s hardware without having to access that hardware directly, or know details of it. This is achieved through application programming interface (API) which is a set of instructions (a protocol) in which an application can ask OS to do a services such as printing a file. By this way you can guarantee that your program will run on different computers without bothering of printer type connected to these PCs.
* Provision of a user interface: OS provides a graphical user interface that enables user to communicate with computer. Early OS were text based such as Dos. New OS are graphical user interface (GUI) based which has icons, menus and it is more user friendly such as Microsoft Windows.
* Booting your computer: When you switch on a computer, the first thing it needs to do is to load an operating system (which is usually stored on the hard disk).

## How a program executes on a computer?

The general process of executing a program is:
* The source code is written in high level language such as Java, C++, etc.
* The source code is translated into machine code (low level language that the computer understood) using compilers or interpreters.
* A compiler is a program that translates the program written in high-level language into low-level instructions (machine code or byte code) then executes it as a whole.
* An Interpreter, do the same job as a compiler, but it translates each instruction then executes it.

## Object Oriented Programming (OOP)

In OOP, the software objects is used to model real-life ones such as car, employee, DVD, etc. The software objects simulate the part of the real world (Application domain, problem domain) with which we are concerned. For example if we need to develop a system to manage patients in a hospital then the domain is hospital, and objects are patients, doctors, nurses, etc.

### Important issues about objects:

* Each object has attributes and its own behavior.
* An attribute is some property or characteristic of an object. It describes the kinds of information that an object needs in order to provide the required behaviours. So a student object might have attributes such as student number, student name, registered module and so on. The attribute value of ‘studetn number’ might be ‘2012105’ and the attribute value of ‘student name’ might be ‘Anderson Robert’.
* The behaviour of an object is the collection of actions an object knows how to carry out.
* The values of all an object’s attribute together determine the object’s state.
* Users can not directly interact with objects, they can do so by using user interface to send messages to these objects. Actions such as clicking the mouse, or pressing a key on the keyboard, will cause messages to be sent to the appropriate objects.
* In its basic definition, an object is an entity that contains both data (in the form of attribute values) and behaviour (the actions it takes on receiving messages).
* Each object is represented by a rectangle. To get an object to do something, it must be sent a message (call method); messages are depicted as the arrows between the objects.

## Grouping objects into classes

If two ro more objects have the same attributes, the same methods, and behave in the same way in response to those methods, then these objects belong to the same class.
In Object Oriented an object is defined as an instance of a class. A class is used to group related variables and functions. A class is like a blueprint or template for the creation of objects and ensures that all its instances:
* have the same attributes,
* and respond to the same set of messages in an identical manner.
A protocol is known as the list of messages to which any instance of the class can respond.