Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Modern Introduction to Object Oriented Programming for Prospective Developers
Modern Introduction to Object Oriented Programming for Prospective Developers
Modern Introduction to Object Oriented Programming for Prospective Developers
Ebook114 pages2 hours

Modern Introduction to Object Oriented Programming for Prospective Developers

Rating: 0 out of 5 stars

()

Read preview

About this ebook

This guide is intended to introduce modern programming by means of examples. The first section gives an introduction to the theoretical background of computing. In the following one, two programming problems are discussed and a solution to them is being developed. The third section deals with the techniques that are required for implementing the examples from section two. Finally, the fourth section provides the prospective developer with hint about debugging and gives some advice about common problems that usually occur in the first programming sessions.
LanguageEnglish
PublisherLulu.com
Release dateApr 6, 2011
ISBN9781447610342
Modern Introduction to Object Oriented Programming for Prospective Developers

Related to Modern Introduction to Object Oriented Programming for Prospective Developers

Related ebooks

Computers For You

View More

Related articles

Reviews for Modern Introduction to Object Oriented Programming for Prospective Developers

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Modern Introduction to Object Oriented Programming for Prospective Developers - Fabian Gebert

    Epilogue

    1 Introduction to the Theoretical Background

    Software basically transforms data. Functions compute calculations and store the results into the memory. Various hardware items such as the keyboard or the mouse generate a huge amount of data that needs to be processed. Output devices like screens and printers allow to react to the user input.

    In this section, we introduce and discuss important ideas involved with object oriented programming.

    Learning Goals After reading this section, you will be able to:

    Describe the way the computer saves information

    Explain what functions and variables are

    Discuss the advantages of programming with classes

    Describe the way the execution of programme code works

    1.1 Memory

    One of the most basic things about a computer is its memory. It contains the data necessary to display a picture on the screen, to print out something or to send an email. At a higher level of abstraction, the memory is just an array¹ of bits. A bit is 1 sequence or ordered set that is the smallest memory unit in the computer and has the states 0 and 1. All data is being represented by bits, usually in packets of eight bits, that is one byte. When we want to represent a decimal number, e.g. n = 120 we can decompose that number into powers of 2:

    e9781447610342_i001.jpg

    This number will usually be represented ² by eight bits with the states 0, 1, 1, 1, 1, 0, 0, 0.

    Instead of numbering the bits, we group the memory into bytes and number them. We simply start at 0 and count up till the end of the available memory. To access data, we just need the number of the starting byte in memory and the number of bytes we want to read. On a x86-computer (ordinary desktop computer), the common integer number consists of 32 bits and therefore refers to an integer between 0 and 2³² − 1. If we need negative numbers, we just³ interpret the number as its ordinary value minus 2³¹ . The range of the variable then is [2³¹; 2³¹ − 1].

    Exercise 1.1: Ways of saving strings in memory⁴ A string is an array of characters. Sentences, phrases and single letters can be represented by strings. What would be the most memory saving way to represent a string in memory allowing to determine the length of it? What do we have to consider when we have a large string with several parts we want to access quickly?

    1.2 Execution

    Basically, the processor starts reading the memory at a particular position and executes commands according to the data it is provided with⁵. One very basic command understood by the processor is moving parts of the memory into the processor’s register⁶ and vice versa. Different commands then allow to perform operations with the data in the register. For instance addition or multiplication of numbers. The data can be written back into the main memory afterwards. When a command is executed, the processor jumps to the next order and so on. It is also possible to jump within the command list using the go to command⁷.

    1.3 Functions

    When the tasks are getting more complex than simple calculations, we should work with the computer in a more abstract way. It is not usual to programme the computer using punch cards or assembly language any longer, the computer nowadays understands a more human language. This is the step where source code and compiler⁸ appear. The code is a listing of human readable language statements structured in specific parts. The compiler translates the source into the language the processor understands, i.e. sequences of machine code commands.

    We structure the code in functions. That makes it easier to read the code and allows to reuse specific parts of the code at other places in the code by referring to the function. We can simply call a function which then performs a calculation and returns a result which can be used at the position of the function call. The code execution begins at the main function from which all operations are performed. When having done all operations, the execution reaches the end of the main function and stops⁹.

    Similar to the mathematical definition, a function maps from one set of variables into another. In computing, a function usually takes zero, one or multiple arguments of different kinds and returns a result. We could for example define the function sine, which takes the argument angle and returns the sine value corresponding to the angle, whereas angle and the return value are just numbers.

    Even though at the end of the day, the computer speaks a language consisting of numbers, using modern programming languages we use variable types that match the idea of what they naturally refer to. For instance, when we are calculating a birthday, we can use the variable type date. If we want to listen to a audio file, we could pass the play function a string describing the resource where it is to find the music file using an URL or file path. Also we might define a function that directly takes the data as an array of bytes¹⁰.

    When we call a function, the runtime has to find the way back to the caller when the function returns. Therefore, the runtime provides a call stack. As soon as a function is called, it adds the code line¹¹ of the caller. When the called function returns, the runtime can find the way back to the caller by popping the last added address from the stack. Also, the stack is commonly used to store

    Enjoying the preview?
    Page 1 of 1