Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Chapter 1 Introduction to Object Oriented Programming (1)

The document introduces Object-Oriented Programming (OOP) and its comparison with Procedural Programming, highlighting key concepts such as objects, classes, data abstraction, encapsulation, inheritance, and polymorphism. It discusses the advantages of OOP over procedural paradigms, including easier development and maintenance, data hiding, and real-world simulation. Additionally, it covers Java's features, naming conventions, and the Java Development Environment, including tools for creating, compiling, and running Java programs.

Uploaded by

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

Chapter 1 Introduction to Object Oriented Programming (1)

The document introduces Object-Oriented Programming (OOP) and its comparison with Procedural Programming, highlighting key concepts such as objects, classes, data abstraction, encapsulation, inheritance, and polymorphism. It discusses the advantages of OOP over procedural paradigms, including easier development and maintenance, data hiding, and real-world simulation. Additionally, it covers Java's features, naming conventions, and the Java Development Environment, including tools for creating, compiling, and running Java programs.

Uploaded by

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

Chapter One

Introduction to Object Oriented Programming

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…

2. Object Oriented Programming vs. Procedural Programming

2.1. Procedural Programming Paradigm


 Emphasis on doing things (algorithm).
 Modules or functions are the physical building blocks.
 Data moves openly around the system from function to function.
 Most of the function share global data.

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.

3. Advantage of OOPs over Procedure-oriented programming language


1. OOPs make development and maintenance easier where as in Procedure-oriented
programming language it is not easy to manage if code grows as project size grows.
2. OOPs provide data hiding whereas in Procedure-oriented programming language a
global data can be accessed from anywhere.
3. OOPs provides ability to simulate real-world event much more effectively
4. OOP makes it easy to add new features.

4. Concepts of Object Oriented Programming


 Objects: Objects are the basic run-time entities in an object-oriented system. Programming problem is
analyzed in terms of objects and nature of communication between them. When a program is executed,
objects interact with each other by sending messages. Different objects can also interact with each
other without knowing the details of their data or code.
 Classes: A class is a collection of objects of similar type. Once a class is defined, any number of
objects can be created which belong to that class.
 Data Abstraction: Abstraction refers to the act of representing essential features without including the
background details or explanations. Classes use the concept of abstraction and are defined as a list of
abstract attributes.
 Encapsulation: Storing data and functions in a single unit (class) is encapsulation. Data cannot be
accessible to the outside world and only those functions which are stored in the class can access it.
 Inheritance: Inheritance is the process by which objects can acquire the properties of objects of other
class. In OOP, inheritance provides reusability, like, adding additional features to an existing class
without modifying it. This is achieved by deriving a new class from the existing one. The new class
will have combined features of both the classes.
 Polymorphism: Polymorphism means the ability to take more than one form. An operation may
exhibit different behaviors in different instances. The behavior depends on the data types used in the
operation. Polymorphism is extensively used in implementing Inheritance.

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.

6. Java Naming conventions


Java naming convention is a rule to follow as you decide what to name your identifiers such as class,
package, variable, constant, method etc. But, it is not forced to follow. So, it is known as convention
not rule. All the classes, interfaces, packages, methods and fields of java programming language
are given according to java naming convention.

6.1. Advantage of naming conventions in java


By using standard Java naming conventions, you make your code easier to read for yourself and for
other programmers. Readability of Java program is very important. It indicates that less time is spent
to figure out what the code does.
Name Convention

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.

constants name Should be in uppercase letter. e.g. RED, YELLOW, MAX_PRIORITY


etc.

6.2.Understanding CamelCase in java naming conventions


Java follows camelcase syntax for naming the class, interface, method and variable.
If name is combined with two words, second word will start with uppercase letter always e.g.
actionPerformed(), firstName, ActionEvent, ActionListener etc.
Simple Java Program

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.

7.1. Steps for Creating, Compiling and Running Java programs


1. Creating a source file – a source file contains text written in Java programming
language.
2. Compiling – the compiler, Javac, takes the source file and translates its text into
instruction that the Java Virtual Machine (JVM) can understand (byte code file).
Byte code is known as compiled code or byte code is highly optimized set of
instruction designed to be executed by JVM.
3. Run – the interpreter takes the byte code file and carries them into instruction that a
computer can understand.

Injibara University, Object Oriented Programming Material Course Material Page 5|5

You might also like