Ictopia Programming and Databases L6 L7
Ictopia Programming and Databases L6 L7
and Databases
Introduction
• In this course, Basic Java concepts and principles
will be discussed, alongside with the explanation
of sample executable programs.
• The student will also be trained in the various
concepts and models necessary to store,
manipulate and handle data using MySQL.
• This will involve creating forms and reports from
queries based on data present in an existing
database.
Learning Goals
By the end of this courseware, the student is expected to:
1. Appreciate Java as a programming language.
2. Define commonly used terms in object-oriented
programming such as classes and objects.
3. Apply the different language elements and constructs
of Java to solve simple programming problems.
4. Create a database using MySQL through
phpMyAdmin.
Lesson 6
Loops and Exceptions
• What Are Loops?
• For Loop
• While Loop
• Do – While Loop
• Nested Loops
• What are Exceptions
• Error – Handling
• Try and Catch Statement
What are Loops?
Loops permit a set of instructions to be repeated
until a condition is reached. In Java, there are three
loop structures.
• For Loop
• While Loop
• Do – While Loop
For Loop
Syntax
Example
While Loop
Syntax while (boolean condition)
{
<statement/s>
}
Example
Do-While Loop
Syntax do
{
<statement/s>
}while (Boolean condition);
Example
Nested Loops
What are Exceptions?
In Java, there are also exceptions: scenarios or
events that might cause your program to produce
errors.
Error-Handling
Exception Classes are used to handle errors in java
programming.
Example 1
Line 11 try
• try is a Java keyword that tells the compiler that
an error might happen within the scope of the try
statement.
Example 2
Lesson 7
Creating Classes
• Classes
• Methods
• Inheritance
• Method Overloading
• Overriding
Classes
In Java, the blueprint of real-life object is a class. An
object is used to represent a class.
name
attributes
methods
Methods
These are groups of codes that do a particular task
when executed.
Syntax
Example
Method Overloading
Overloading means that you have methods with the
same method name but with different argument
lists or parameters.
Method Overriding
Changing inherited methods within the subclass is
called overriding.
Example