Java Classes & Object Oriented Programming, Schemes and Mind Maps of Object Oriented Programming

Class: Object Types. • Java uses classes and structures to define objects. • A Java class is an object type. • When you create the definition of a.

Typology: Schemes and Mind Maps

2022/2023

Uploaded on 03/01/2023

nicoth
nicoth 🇺🇸

4.3

(20)

262 documents

1 / 24

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Object Oriented Programming 1
Java Classes
&
Object Oriented Programming
Introduction
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

Download Java Classes & Object Oriented Programming and more Schemes and Mind Maps Object Oriented Programming in PDF only on Docsity!

Java Classes

Object Oriented Programming

Introduction

Object Oriented Programming

  • One of the first applications of modern computing was modeling and simulation.
  • Scientists soon realized that functions alone were insufficient to model systems intuitively
  • If we are going to model a planet we would like to actually create a virtual planet, define how it behaves in our simulated universe, and then just observe it.

Object Oriented Programming

  • Even engineers are social animals - we evolved to think about the world in terms of agents and objects (not recursion).
  • In many situations we solve large problems by delegation. That is we have workers who specialize in solving a particular problem.
  • Those specialists have specific skills that they can apply to a specific class of problems.

Object Oriented Programming

  • We can pattern software after a group of specialists at a company working on a problem.
  • For example, there are two objects we have used – System.out and System.in.
  • System.in is the name of an object who knows all about reading data from the keyboard and putting it into a variable.
  • It is easier to ask System.out to do the work than write a program to do it ourselves.

Object Oriented Programming

  • When we mail a letter all we have to worry about is following the correct protocol to ensure our letter gets to the right place.
  • We have to know where to go, how to pay, the format expected for the destination address and return address, etc.
  • In software this protocol is called the interface.
  • All objects have to have an interface that clearly defines how we can interact with the object.

Object Oriented Programming

• Almost any problem can be broken up

into objects.

• Objects are defined by three things:

– Their state – this is the information

they contain.

– Their behavior or capabilities – these

are the functions they have access to.

– Their interface – the rules describing

how they interact with other objects in

the system.

Reasons for OOP

Abstraction Encapsulation Information hiding Inheritance Software Engineering Issues

Class: Object Types

• Java uses classes and structures to

define objects

• A Java class is an object type.

• When you create the definition of a

class you are defining the attributes and

behavior of a new type.

  • Attributes are data members.
  • Behavior is defined by methods.

Information Hiding

  • The interface to a class is the list of public data members and methods.
  • The interface defines the behavior of the class to the outside world (to other classes and functions that may access variables of your class type).
  • The implementation (the code that makes the class work) doesn't matter outside the class.

Information Hiding (cont.)

  • This is good because it allows us to change the underlying code without forcing everyone who uses our objects to change their code.
  • You can change the implementation and nobody cares! (as long as the interface is the same).

Special Member Functions

  • Constructors: called when a new object

is created (instantiated).

  • can be many constructors, each can take different arguments
  • Garbage Collection. This is why Java is

so popular.

Anatomy of a Class

public class Dog { Dog( String dog_name ){ name = dog_name; } public void bark(){ System.out.println(“woof”); } public string getName() { return name } private String name; }

Put all this in

Dog.java

Accessing Data Members

  • Data members are available within each method (as if they were local variables).
  • Public data members can be accessed by other functions using the member access operator ".".

Accessing class methods

  • Within other class methods, a method can be called just like a function.
  • Outside the class, public methods can be called only when referencing an object of the class.