Mindmap
Object-Oriented Programming (OOP)

Inhalt der Mindmap
Object-Oriented Programming (OOP)
Objects
- Has attribute(s) (fields) and can perform action(s) (methods)
- To create objects, you need classes
- Creating objects
- Instantiate: instantiating the Employee is the same as creating an instance of Employee
- Most common way to create an object is by using the "new" keyword
- Example: to create an Employee object
- Example: to create an Employee object
- Assign the created object to an object variable (or a reference variable) to manipulate the object later
- You can call an object's methods and access its fields by using the object reference that was assigned the object. You use a period (.).
Classes
- Determines what kind of objects you get
- Tool that enable programmers to create the abstraction of a problem
- Abstraction is the act of using programming objects to represent real-world objects
- Blueprint/template to create objects of identical type
- ALL program elements in Java must reside in a class
- Consider 3 things when writing a class:
- 1. the class name
- 2. the fields
- 3. the methods
- General Syntax
- Use Pascal naming convention (ex: Employee, DateUtility, RegularRateCalculator)
Fields
- Variables
- Can be primitive or references to objects
- Can refer to another object
- Example: an Employee class may have an address field of type Address, which is a class that represents a street address
- Example: an Employee class may have an address field of type Address, which is a class that represents a street address
- Follows the camel naming convention (ex: maxAge, age, numberOfRows)
Methods
- Define actions that a class's objects (or instances) can do
- Consists of a declaration part and a body
- Declaration part consists of a return value, the method name, and a list of arguments
- Body contains code that perform the action
- Declaring a method: syntax
- If a method takes more than one argument, two arguments are separated by a comma
- Example: the following add method takes two ints and return an int
- Example: the following add method takes two ints and return an int
The Method main
- Special method called main provides the entry point to an application
- An application normally has many classes; only one of the classes needs to have a main method
- The signature of the main method:
- You can pass arguments to main when using Java to run a class:
- All arguments MUST be passed as strings
Constructors
- Every class must have at least one constructor
- If your class does not explicitly define a constructor, the compiler adds one for you
- Used to construct an object
- Does not have a return value, not even void
- Must have the same name as the class
- Syntax
- no-argument (no-arg) constructors have zero argument
- Every class must have at least one constructor
Class Members in UML Class Diagrams
- A field and its type is separated by a colon
- A method's argument list is presented in parentheses and its return type is written after a colon
The null Keyword
- When a reference variable does not refer to an object, it has a null value
- If you declare a local reference variable within a method but do not assign an object to it, you will need to assign null to it to satisfy the compiler
- Class-level reference variables will be initialized when an instance is created, therefore you do not need to assign null to them
- Trying to access the field or method of a null variable reference raises an error
- You can test if a reference variable is null by using the == operator
- You can test if a reference variable is null by using the == operator
Bilder und Dateien der Mindmap
Informationen
- Beschreibung
- Mindmap am Object-Oriented Programming (OOP), erstellt von Madalyn Lueken am 19/05/2021.
- Erstellt von
- Madalyn Lueken
- Aufrufe
- 0
- Bewertung

