Lesson 1
Lesson 1
Lesson I
Computers are capable of performing extraordinary tasks that most of us take for granted.
We use computers everyday to watch movies, listen to music, create art, and to assist us in
our work environment. But, have you ever wondered how computers are able to successfully
execute our requests? Well, computers achieve this by utilising a component known as
software, which is defined as the collection of instructions that enable the user to interact
with a computer and its hardware, in order to perform tasks. As you’re probably aware, there
are many different types of software for different purposes. For example, Microsoft Word for
writing documents, Internet browsers for surfing the web, Microsoft Excel for creating
spreadsheets etc. However, perhaps the most important piece of software is your Operating
System which provides the foundation to run these different types of programs.
Objectives of Lesson I
With that being said, you’re probably wondering how we create these different types of
programs to make our lives easier. Well, this is where programming comes in. Programming
is the process of creating software by composing instructions that your computer can
understand. These instructions are defined as source code, which is a set of written
instructions that a computer can understand. Unfortunately for us, the languages we use
everyday to communicate to one another are somewhat ambiguous and cannot be used for
programming, as machines require precise and accurate instructions, since they take every
instruction literally. For this reason, we must create programs with the use of programming
languages such as Java so that computers are capable of processing our instructions.
Figure 2 shows how computers understand the various programming languages (high level
languages, low level and machine code) we use. However, it should be noted that
programming in machine code has become redundant because low-level languages, such
as assembly, are still widely used in programming hardware (micro-controllers).
Nevertheless, as you can see, it is not a straightforward process for computers to
understand programming languages. Since computers can only understand machine code,
both high level and low level languages must be converted into machine code before a
computer can understand what the programmers want and execute an appropriate output.
This is done with the aid of a compiler. A compiler is a special type of program that
translates programming language code into code that a computer can understand and
execute. Computers, at their most basic level, only react to electronic signals, therefore,
seeing functions, such as the Java println( ) function (which is a simple function to display
some text to the user), doesn’t mean anything to them. The code that we write needs to be
translated into machine code that computer circuitry can interpret and act accordingly.
As indicated by figure 3, our Java code is passed to the Java compiler, which translates our
Java program into to bytecode. This in turn is passed to the Java Virtual Machine which
does the translation of bytecode to machine code. Machine code is the code that your
computer understands, hence, your computer can now execute your code and display the
output (if any) to your computer screen.
Exercise 1
The genesis of Java can be attributed to James Gosling and his team at Sun Microsystems
in 1991. The intention was to devise a language capable of bridging the communication gap
between many consumer devices, such as TV sets, toasters, and various other home
appliances. This, of course, was no mean feat because these appliances are managed by a
wide variety of computer processing chips. But, Gosling and his team wanted provide a
language that would function on all of these different processors.
The initial concept failed as several (appliance) manufacturers weren’t willing to invest time
and money into developing compilers capable of translating the appliance language into a
language the processor could understand and execute. However, Gosling and his team
designed a piece of software that would translate an appliance language program into a
program in an intermediate language, nowadays referred to as bytecode, that would be the
same for all processors. Subsequently, a program would then translate the bytecode into
machine code for a particular appliance and/or computer.
Much to the dismay of Gosling and his team, the language did not appease the appliance
manufacturers. Hence, the language was not used by the manufacturers . However, Gosling
and his team realized that the language could be used to design web applications. This lead
to a few changes to the language, and we now refer to it as Java.
Before we delve into the coding and the development of programs, you will need to
understand a few theoretical concepts. This will ensure you have a holistic understanding of
the language. Let’s begin with the concepts Gosling and his team had in mind when devising
the language:
1. Object-oriented: Gosling and his team ensured the language was object-oriented.
This means that all code is placed inside classes and most of those classes can be
used to create real-world objects. Many of Java’s predecessors were procedural,
which means there were routines or methods, but no classes.
5. Robust: One of the major advantages of Java over C++ is that it takes care of some
of the hassles posed by C++, such as, memory hassles, which Java is able to
allocate and deallocate internally, ultimately freeing up time for the programmer and
allowing for speedy development. Memory management is a huge source of errors in
C++ programs.
6. Secure: The concept of security is central to Java. For this reason, Java comes
equipped with a Java Virtual Machine (JVM). This means that your code runs inside
the JVM, and the code cannot pose a threat to the computer it is running on. Hence,
the JVM can potentially protect your computer from malicious code that may
manipulate your computer memory, or allow an applet to read/write from your hard
disk etc.
In the previous section, we briefly mentioned the concept of classes. But, what does this
mean? Well, essentially, classes are blueprints. For elaboration, consider the process of
building a house. Initially, the architect will have a blueprint, which is not the house itself, but
just a plan to construct one. A class is a similar entity, which is basically a blueprint or plan
for an object. Once we have a blueprint in place, we can construct as many objects of that
blueprint as we desire. This is what we mean when we say that Java is object-oriented i.e. it
is comprised of classes, which can be used to create objects.
Java is divided into many different product groups. In total, there are more than five product
groups, however, there are three major ones, which will be discussed briefly here. Each
product group allows you to build a different range of applications. Hence, it is important to
learn the differences, so you know which Java technology product group to download and
install. The three major product groups are:
Figure 8: The three major Java technology product groups and some of their uses
As stated by Oracle, the Java SE is for developing and deploying Java applications on
desktops and servers, as well as in embedded environments. It offers a rich user interface,
performance, versatility, portability, and security, that applications require. This course uses
the Java Standard Edition product.
The Java ME is used to write to devices with a small memory footprint. It provides a robust,
flexible environment for applications running on embedded and mobile devices, such as,
micro-controllers, sensors, cellphones, tablets etc. Applications based on Java ME are
portable across many devices, yet leverage each device’s native capabilities.
Lesson Summary
❖ Computer programs, known as software, are the invisible instructions that control the
hardware and make it perform tasks.
❖ Computer programming is the writing of instructions for computers to perform.
❖ Computers use zeros and ones as their most basic language.
❖ The machine language is a set of primitive instructions built into every computer.
❖ Assembly language is a low-level programming language in used to represent each
machine-language instruction.
❖ High-level languages are English-like and are used by humans to program.
❖ A compiler is a software program that translates the source program (high level
language) into a machine language program.
❖ Java is platform independent, meaning that you can write a program once and run it
on any computer.
❖ Java is object-oriented, meaning that all code is placed within classes