0% found this document useful (0 votes)
60 views

Lesson 1

The document provides an introduction to programming and the Java programming language. It discusses computer basics and software, how programming creates software through source code, and how different programming languages are converted to machine code. It then focuses on Java, describing its creation and key concepts like being object-oriented, simple, platform independent, robust and secure.

Uploaded by

Vusani Neguyuni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Lesson 1

The document provides an introduction to programming and the Java programming language. It discusses computer basics and software, how programming creates software through source code, and how different programming languages are converted to machine code. It then focuses on Java, describing its creation and key concepts like being object-oriented, simple, platform independent, robust and secure.

Uploaded by

Vusani Neguyuni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Fundamentals of the Java Programming Language

Lesson I

Property of Airos Education


Copyright 2018 Airos Education
www.airos.co.za
Lesson 1: Introduction to Programming and Java

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

❖ To understand computer basics such as software


❖ To understand the role that computer programming has in software creation
❖ To describe the relationship between high level and low level languages
❖ To explain the sequential flow of control in programming
❖ To describe the relationship between Java and the World Wide Web
❖ To compare and contrast the features and components of Java such as: platform
independence, object orientation, encapsulation, etc.

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.

Property of Airos Education


Copyright 2018 Airos Education
www.airos.co.za
1
Figure 2: Categorising the level of programming languages

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.

Property of Airos Education


Copyright 2018 Airos Education
www.airos.co.za
2
Figure 3: How Java code is compiled

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

1. Differentiate between the following and give an example of each:


a. High-level and low-level programming languages
b. Software and programming

Section A: Introducing the Java Programming Language

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.

Property of Airos Education


Copyright 2018 Airos Education
www.airos.co.za
3
Figure 4: Computer processor

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.

Property of Airos Education


Copyright 2018 Airos Education
www.airos.co.za
4
Figure 5: The object-oriented programming paradigm

2. Simple​: The language was intended to be simple in comparison to other languages


that preceded it, such as C or C++. Java eliminated the use of pointers and operator
overloading.

3. Encapsulation​: Java comes equipped with access modifiers (such as public,


protected, and private) to secure your data from unintended access and modification.

Property of Airos Education


Copyright 2018 Airos Education
www.airos.co.za
5
Figure 6: The level of protection provided by the different types of modifiers in Java

4. Platform-independent​: Perhaps one of the most important concepts to note about


Java, which arguably sparked the birth of the language, is that it is cross-platform in
the sense that a ​compiled Java program can run on all platforms, if a Java Virtual
Machine is present. These platforms include Windows, Linux, and MAC OS, among
others.

Property of Airos Education


Copyright 2018 Airos Education
www.airos.co.za
6
Figure 7: Compiled Java code can run on any operating system

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.

Explaining Object-Oriented Programming

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.

Property of Airos Education


Copyright 2018 Airos Education
www.airos.co.za
7
From any blueprint, any number of objects can be created, however, they all will be of the
same type since they are constructed from the same blueprint. And obviously, by altering the
blueprint, we can create different objects.

Section B: Java Technology Product Groups

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:

❖ Java Standard Edition (Java SE)


❖ Java Enterprise Edition (Java EE)
❖ Java Micro Edition (Java ME)

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.

Property of Airos Education


Copyright 2018 Airos Education
www.airos.co.za
8
The Java EE is the standard in community-driven enterprise software. In other words, as the
name suggests, it is designed for businesses to build scalable business services that feed
dynamic web and mobile applications, such as, multi-tier enterprise applications,
eCommerce, web services support etc.

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

Property of Airos Education


Copyright 2018 Airos Education
www.airos.co.za
9
Formative Assessment

To progress to the next lesson, please complete the following questions:

1. Differentiate between high-level and low-level programming languages and mention


whether Java is a high level or low level language.
2. What is the name of the code that is passed to the Java Virtual Machine?
3. What is a compiler used for?
4. Explain the function of the Java Virtual Machine.
5. Mention and describe two key features that make Java the most widely used
programming language.
6. Differentiate between the three Java technology product groups discussed in this
lesson.

Property of Airos Education


Copyright 2018 Airos Education
www.airos.co.za
10

You might also like