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

Object-Oriented Programming With Java

This document discusses object-oriented programming concepts in Java including: 1. Classes contain attributes like properties and methods for accessing attributes. Objects are instances of classes. 2. Object-oriented development includes analysis, design, and programming phases. 3. In Java, classes are defined with attributes and methods. The Java runtime executes compiled Java code.

Uploaded by

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

Object-Oriented Programming With Java

This document discusses object-oriented programming concepts in Java including: 1. Classes contain attributes like properties and methods for accessing attributes. Objects are instances of classes. 2. Object-oriented development includes analysis, design, and programming phases. 3. In Java, classes are defined with attributes and methods. The Java runtime executes compiled Java code.

Uploaded by

Naser Arab
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Object Oriented Programming with

JAVA
1.Introduction to Object-Oriented System
Development
 Object orientation is an approach to complex systems in which the system is
described as the interaction of cooperating objects.
 A program developed with object-oriented programming will consist almost
exclusively of objects.
 An object contains Methods, attributes and properties.

 Classes contain attributes. The attributes (also: property of classes) are static
elements of classes. Concrete values of the object can be saved in an attribute.
 An object is a self-contained entity that is capable of action.
 In an object, Attributes store values, while methods allow you to access, read,
modify, or update attributes or perform calculations.
 Attributes are used exclusively for saving values and can be understood as free
memory inside of an object.
 Good candidates for attributes are nouns that can be used for describing or adding
details to other nouns
 The values of all the attributes of an object describe the state of the object.

 The goal of a Software development process is to develop a functional system that


meets the requirements of the clients with respect to functionality, quality, and
development costs.
 An object-oriented development process consists of three different phases:
1. Object-oriented analysis (OOA)  determines what a system should do.
2. Object-oriented design (OOD)  forms a bridge between the analysis and
implementation.
3. Object-oriented programming (OOP) a system design is translated into functioning
program code.
 Objects can later be exchanged or extended through the clear encapsulation of
responsibilities and the clear definition of interfaces without influencing the
stability and functionality of the overall system. This in turn simplifies the process
of quality assurance, since the entire system does not have to be tested again but
just the affected parts of the system.

2 - Introduction to Object-Oriented Modeling


 A class in object-oriented programming provides the structure that is needed for
the creation of a digital object.
 Methods (also: functions, operations) are dynamic elements of classes. They
contain algorithms, statements, and processing specifications that can be used to
create, calculate, modify, and delete values.
 Elements of a method: Name, Parameters and return value.
 Two examples of structure diagrams and behaviour diagrams in UML are:
1 - Structure diagrams: e.g., class diagram, component diagram
2 - behaviour diagrams: e.g., use case diagram, sequence diagram
 Structure diagrams are used for diagramming structure, elements and composition,
as well as the interfaces of systems. In simple terms, structure diagrams are used
to model where a system comes from. Behaviour diagrams, on the other hand, are
used to model what happens in a system.

3 - Programming Classes in Java


 Programming consists of three main activities:
o Programming: writing the source code itself.
o Compiling: transforming the code to a form that can be executed by
computers.
o Running the program and see how it performs.
 The Java runtime environment (JRE) consists of the Java virtual machine (JVM)
and the Java class library.
 The Java SDK consists of a Java compiler, a Java virtual machine, the Java class
library, and other tools.
 A class in the programming language Java has a unique name and can contain
attributes and methods.
 To create a class, the following four elements at a minimum are required: the
visibility modifier, the class keyword, the name of the class, and a few curly
braces.
 An attribute in Java is described with the following elements at a minimum: the
visibility modifier, the data type, and the attribute name.
 The signature of a method consists of the name of the method and the parameter
list. The return data type is not a part of the signature
 Basic elements of a method:
o Visibility modifier
o Return data type of the method
o Method name
o Parameter list
o Method body
o Curly braces
 The statements in a method body are processed in sequence from the top down.
5 - Inheratance
 The “is a” relationship is an important concept in object orientation and is
classified as an inheritance relationship.
 The subclasses are a more specific type of superclass. They have all the attributes
of the superclass, but in addition define other attributes that are important for their
own description.
 Inheritance is what allows information to be conveyed about things either
generally or specifically while avoiding redundancy.
 The subclass inherits all the attributes and methods of the superclass. An
exception are attributes and methods that have been declared private in the
superclass.
 When overriding attributes and methods, the original implementation from the
superclass is overridden by the new implementation

 Rules for creating a constructor:

o The name should be the same with the class.


o It has no return type.
o The visibility modifier must always be public.
o And it can only exist once per class.
 The standard constructor has two main tasks:
o Adapting the default values for primitive data types.
o Creating non-primitive attributes (objects).

 Problems that might occur when using own error codes:


o - Mixing error signals and domain return values
o - Misinterpretation of error signals
o - Risk of inadequate error handling due to omission of error signals
o - Unmanageable program structure
o - Extra work for the definition and interpretation of error signals
 What must an explicit error handling mechanism do to support the programming
of more robust applications?
o Separate channel for exceptions
o - Central definition of error messages
o - Provide pre-completed exceptions including appropriate error messages
o - Identification of error-prone methods
o - Flexibility through the definition of user-defined exception cases
 Java offers several alternatives for handling the exception:
o The exception is caught within the method.
o The exception is passed to the calling program.
o The exception is caught and is then passed to the calling program with a
specific message.
 What has to be taken into consideration when you need to program a user-defined
exception?  Each user-defined exception must inherit from the superclass
Exception. If the standard constructor is used for creating it, a standard error
message should be defined.

You might also like