Chapter 1 Introduction to Object Oriented Programming (1)
Chapter 1 Introduction to Object Oriented Programming (1)
1. Programming Paradigms
Programming is a creative process carried out by programmers to instruct a computer on how to do
a task. A program is a set of instructions that tells a computer what to do in order to come up with a
solution to a particular problem. There are a number of alternative approaches to the programming
process, referred to as programming paradigms. Different paradigms represent fundamentally
different approaches to building solutions to specific types of problems using programming. Most
programming languages fall under one paradigm. Two of the most important programming
paradigms are
The procedural paradigm and
The object-oriented paradigm.
1.1.Procedural Programming
Procedural programming uses a list of instructions to tell the computer what to do step-by-step. A
procedure contains a series of computational steps to be carried out. Procedural programming is also
referred to as imperative programming. Procedural programming languages are also known as top-
down languages Examples of procedural languages include Fortran, COBOL and C, which have
been around since the 1960s and 70s.
1.2.Object-Oriented Programming
OOP is an approach to problem-solving where all computations are carried out using objects.
An object is a component of a program that knows how to perform certain actions and how to
interact with other elements of the program. A method in object-oriented programming is like a
procedure in procedural programming. The key difference here is that the method is part of an
object. In object-oriented programming, you organize your code by creating objects, and then you
can give those objects properties and you can make them do certain things. A key aspect of object-
oriented programming is the use of classes. A class is a blueprint of an object. You can think of a
class as a concept, and the object as the embodiment of that concept.
Example of OOP language Java, C#, C++, Visual Basic etc…
Injibara University, Object Oriented Programming Material Course Material Page 1|5
2.2. Object Oriented Programming paradigm
Emphasis is on data rather than procedure.
Data is hidden and cannot be accessed by external function.
The problem is divided into objects.
5. Features of Java
Java is a powerful object-oriented programming language introduced by Sun Microsystems in
1995.There is many features of java. These are:
Simple: According to Sun, Java language is simple because: syntax is based on C++ (so easier for
programmers to learn it after C++). No need to remove unreferenced objects because there is
Automatic Garbage Collection in java.
Object-oriented: Object-oriented means we organize our software as a combination of different types
of objects that incorporates both data and behavior. Object-oriented programming (OOPs) is a
methodology that simplifies software development and maintenance by providing some rules.
Injibara University, Object Oriented Programming Material Course Material Page 2|5
Platform Independent: A platform is the hardware or software environment in which a program runs.
There are two types of platforms software-based and hardware-based. Java provides software-based
platform. The Java platform differs from most other platforms in the sense that it's a software-based
platform that runs on top of other hardware-based platforms. Java code can be run on multiple
platforms e.g.Windows,Linux,Sun Solaris,Mac/OS etc. Java code is compiled by the compiler and
converted into byte code. This bytecode is a platform independent code because it can be run on
multiple platforms i.e. Write Once and Run Anywhere (WORA).
Secured: Java is secured because:
No explicit pointer
Programs run inside virtual machine sandbox.
Classloader- adds security by separating the package for the classes of the local file
system from those that are imported from network sources.
Bytecode Verifier- checks the code fragments for illegal code that can violate access
right to objects.
Security Manager- determines what resources a class can access such as reading and
writing to the local diskRobust: Robust simply means strong. Java uses strong memory
management. There is lack of pointers that avoids security problem. There is automatic garbage
collection in java. There is exception handling and type checking mechanism in java. All these points
make java robust.
Portable: We may carry the java byte code to any platform
Multi-threaded: A thread is like a separate program, executing concurrently. We can write Java
programs that deal with many tasks at once by defining multiple threads. The main advantage of multi-
threading is that it shares the same memory. Threads are important for multi-media, Web applications
etc.
class name should start with uppercase letter and be a noun e.g. String, Color,
Button, System, Thread etc.
interface name should start with uppercase letter and be an adjective e.g. Runnable,
Remote, ActionListener etc.
Injibara University, Object Oriented Programming Material Course Material Page 3|5
method name should start with lowercase letter and be a verb e.g. actionPerformed(),
main(), print(), println() etc.
variable name should start with lowercase letter e.g. firstName, orderNumber etc.
package name should be in lowercase letter e.g. java, lang, sql, util etc.
The various terms used in the above program have some specific purpose. These terms are:
Public – public is an access modifier used to define access restrictions. In this case, public
implies that the class “Main” is publicly available and its function main() can be accessed by
Class – the keyword class begins the class definition for a newly created class, say Main.
Static – this keyword states that the function main() is a class function which can be called
without instantiating the class.
Void – the term void refers to the return type and shows that the function main() doesn’t
return any value.
main() – is the main starting point of execution in every Java program.
String args[] – this is the parameter list of function main(). It says that the main() function
can accept an array of String object that represent the command – line arguments passed by
the user at the time of execution. String is the name of predefined class.
System – is a predefined class used to access the keyboard and monitor. It is used directly
because it is found in the package java.lang in which it is automatically included in any Java
program.
Out – refers to the console/monitor. It defines an output stream used to output something on
the monitor.
Injibara University, Object Oriented Programming Material Course Material Page 4|5
Println/print – is used to print different types of variables and text.
{} - these braces are used to define class body and method body.
The class names should be the same as with the file name where the class lives.eg class named
Main has to be saved in the file called Main.java.
Note: Java is case – sensitive.
7. Java Development Environment
Java development kit is the tools that are used to develop and execute Java programs.
Basic tools: these tools are the foundation of the Java 2 SDK (Software Development System). They
are the tools used to create and build applications.
1. Javac – is the Java language compiler, which convert Java source code into byte file
(byte code). (Javac className.java)
2. Java – the Java language interpreter, which is used to run Java application program.
(java classname)
3. Javadoc – creates documentation in HTML format from the java source code.(javadoc
className.java)
4. Appletviewer – run and debug applets without a web browser.
Injibara University, Object Oriented Programming Material Course Material Page 5|5