Vous êtes sur la page 1sur 10

Object-Oriented Programming Language

 Object-oriented programming is an extension of procedural programming.


 When writing object-oriented programs, it involves both creating objects and
creating applications that use those objects.
 Object-oriented programming or approach is a new approach to develop
software, which can be widely used in business application.
 With this approach, data and the program (or procedure) can be packaged into a
single unit called an object. An object is an item that can contain both data, which
are known as attributes or variables, and procedures, which contains activities that
read or manipulate the data.
Object-Oriented Programming Principle
A program developed in an object-oriented approach is based on the three basic
concepts, which are encapsulation, inheritance, and polymorphism.

Encapsulation
is a mechanism that binds together attributes and methods into a single
object, and keeps both safe from interference or misuse, that is, the details of the
object are encapsulated or hidden, from the user. The user knows that the method
can be requested but does now know how the specifics of how the method is
performed. This can be called information hiding.
Inheritance
An object maybe part of a large category of objects called a class. Every
object in a class shares similar methods and attributes as the original objects. The
higher-level class is called “superclass” the lower level class is called “subclass”.
This concept of low levels inheriting attributes and methods of a superclass is
called inheritance.
Polymorphism
Benefits of Object-oriented Programming

 Java removes several features considered unsafe and also frees memory.
Hence, it cuts down on the chances of making mistakes in the program.
 A major benefit of object-oriented approach is the ability to reuse the
defined objects and modify existing objects. The object-oriented approach to
program development saves programming time.
 Java’s adaptability is also a benefit as it is able to fit in different
environment.
 The advantage of object-oriented approach is reliability as it is able to
operate correctly under all conditions.
Introduction to Java Programming
Java programming language is an object-oriented language that is used both for
general-purpose business programs and interactive World Wide Web (WWW)-
based Internet programs developed by Sun Microsystems. The first version of
Java was introduced in 1995 and the language was then called “Oak”.
The language is modeled after the C++ programming language and it has
eliminated some of the most difficult features to understand in C++.
Java can be used for developing applets, which resides in www servers
downloaded by a browser to a client’s system, and run by the browser.
Java is platform independent
Resources to create a Java Program

 a text editor .e.g notepad, wordpad, context, edit etc.


 Java Development Kit, which includes the executable files needed for compiling
and executing the program etc.
 Other Java Development Tools e.g Borland JBuilder
Structure of a Java Program
//import packages
public class classname{
//instance variable
access specifier data type variable1;
access specifier data type variable2;
……………………..
//methods
access specifier data type methodname(parameter list)
{ //function body 1}
Access specifier data type methodname2(parameter list)
{ //function body 2 }
}
First application

Access specifier

public class HelloWorld class defined a new class created


{ Direct access

public static void main( String[] args ) function


{ Does not return a value
//this function outputs Hello World a single comment
System.out.println( “Hello World” ); displays the string Hello World
} ← End of main
} ← End of class
Access Specifier

An access specifier defines the circumstances under which a class or class


members in programs can be accessed.

Examples of Access specifiers


public
private
protected
default
Programming Exercises
State and explain the concepts of Object-Oriented Programming.
List the resources need to write a Java program
Explain what is access specifier
State any 2 access specifiers and explain the difference between the two types of
access specifiers
Write a simple program that displays the following
Main Menu
1. Data Entry
2. Display
3. Exit
Enter a choice:
The output statement, System.out.println(); is always used to display output.
Given that System is a class, what kind of an object does out refer to?

Vous aimerez peut-être aussi