in Informatica

Java programming course lesson 1 Introduction to programming

The Java programming course

lesson 1 – Introduction to programming

Before going into deep with Java programming we have to get familiar with some fundamental concepts.

Hardware and software

Maybe the difference is already clear, but to make everyone aware about the difference between these two words it is worth mentioning their definitions.  The functioning of a personal computer depends on the combination of some physical components (electronic, magnetic and optical stuff) referred to as hardware together with some logical components (programs and data) called software.

The main hardware components are:

  • CPU (Central Processing Unit) – is the central unit of elaboration, it is able to  fetch instructions from the memory and to execute them. Operations are executed on the data fetched from the memory and the results are stored back into the memory.
  • RAM (Random Access Memory) – it is a device capable of fetching and storing data; it is divided into cells which are identified by an address.
  • Input/output devices – they access the memory to store data on optical or magnetic disks, to show it on the screen, to play music or sounds, to send it via a network of calculators.
    • sensors (input): they measure the physical characteristics of the surrounding environment (e.g. temperature or luminosity).
    • actuators (output): they allow to operate on the surrounding environment. (e.g. a mechanical arms, electrically controlled motors…)

Now let’s talk about software. A fundamental definition:

A set of instructions having a specific task is called a program.

One of the most important program running on a computer is called the Operating System (OS); 

Software – The Operating System (OS)

The OS provides an abstraction layer between the hardware devices and the programs that are executed on it. All the interactions between the programs and the hardware are performed by the OS on the user’s behalf. When a program needs to store data on the disk, to play a sound or to read a text from the keyboard it asks this operation to the OS, then the OS executes the requested operation and eventually provides the result to the applicant.

Memory and CPU are totally managed by the OS;

the Operating Systems also manages:

  • How the access to the CPU is shared by the programs, in particular it interleaves their executions providing the user with the impression that their are being executed in the same time.
  • The loading of programs into memory (loading their source code from mass memory like optical disks, magnetic supports, or solid state disks)
  • How memory is shared by the programs being executed.

Software – Libraries

A library is a set of frequently used instructions (e.g. the instructions needed to compute some mathematical formulas). Libraries act like building blocks, the developer using a library avoids to rewrite some frequently used and well known routines.

Typically the software in a library is more stable and trustable if compared to the code that can be written by a single autonomous developer simply because many people have already tested it.

The other advantage in using libraries resides in reducing the size and complexity of the programs.

Software – API

The set of services provided by a software component (OS, library or program) it is often referred to as API (Application Programming Interface), which in other words, is the interface that a software components offers to other programs.

A software that uses API only have to care about its specific tasks, asking to software components already written by others all the routine tasks.

High level languages, interpreter or compiler?

Another way to reduce software complexity is using an high level programming language. An high level language has a strong expressive power that allows to execute very complex calculations if compared to the CPU instructions that are very limited (copy a value from a point of the memory to another one, sum, subtract, etc.).

There are two ways for executing an high level programming language:

  • A specifically crafted program called interpreter loads the program as input data, examines the instructions contained in the program and in the moment of running one of them it executes a piece of its own code obtaining the effect asked by the high-level instruction.
  • A specific program called compiler loads the program as input data, examines the instructions contained in the program and it translates each of the instructions into a sequence of CPU instructions. The obtained data (called the object code) is stored on the disk, loaded back as a program and directly executed from the CPU. This operation can be iterated as in the Java case: We start from Java source code (.java files), we compile it into Java ByteCode (.class files), then either the JVM (Java Virtual Machine) interprets the ByteCode or the code is further compiled in the CPU language. The second compilation can also be carried out for some frequently used parts of the code during the interpretation of the ByteCode; in this way some parts of the code will be interpreted while others will be compiled the first time and then directly executed by CPU every time it is needed. This technique is called JIT (Just-In-Time Compilation).

    Java code compilation and execution

    Java code compilation and execution