Mapa mental
Objects and Classes
Contenido del mapa
Objects and Classes
Class
- "A blueprint or template to create objects of identical type"
- "Fundamental building blocks of a Java program"
- class className { [class body] }
- Class names use the Pascal naming system - capitalize the first initial of each word.
- UML Class Diagram
- Top: Class name, Middle: list of fields, Bottom: list of methods
- Fields and types are separated by a colon.
- A method's arguments are presented in parentheses and its return value is written after a colon.
- Provides a summary of all fields and methods
- Top: Class name, Middle: list of fields, Bottom: list of methods
- Object
- Fields
- Variables - can be primitives or references to objects
- Methods
- Defines actions that objects or instances can do
- Declaration Part
- Return Value
- Can be a primitive, object, or void
- return type void means method returns nothing
- Can be a primitive, object, or void
- Method Name
- List of Arguments
- If a method takes more than one argument, separate arguments with a comma.
- Also known as the signature of the method
- Return Value
- Body
- Contains code that performs the action
- returnType methodName (list of arguments)
- Method main
- Provides the entry point to an application
- public static void main (String [ ] args)
- Can pass arguments to main when using Java to run a class
- To pass arguments, type after the class name
- java className arg1 arg2 arg3 ...
- To pass arguments, type after the class name
- Method and field names use the camel naming system - capitalize the first initial of each word except the first word.
- Also known as an instance
- A new keyword can be used to create an object.
- new is followed by the constructor of the class that is being created.
- Assign the created object to an object or reference variable with the same type as the object to manipulate the object.
- Once an object is created, methods can be called and fields can be accessed.
- Use a period (.) to call a method or field.
- When an object is created, the JVM performs initialization to assign default values to fields.
- Null keyword
- Reference variable has no value.
- When declaring a local reference variable within a method without assigning an object, assign null to satisfy computer.
- Null does not need to be assigned to class-level reference variables as they will be initialized when an instance will be created.
- Trying to access the field or method of a null variable reference will raise an error.
- Test to see if a reference variable is null by using the == operator.
- Fields
- Constructor
- Every class must have a constructor.
- If a class does not explicitly define a constructor, the compiler will automatically add one.
- no-arg constructor
- Constructors with zero argument
- Addition will be implicit and not displayed in source file.
- no-arg constructor
- Must have same name as the class
- If a class does not explicitly define a constructor, the compiler will automatically add one.
- Used to construct an object
- Also known as constructor method; looks like a method
- Unlike methods, constructors do not have a return value.
- constructorName (listOfArguments) { [constructor body] }
- Every class must have a constructor.
Object-Oriented Programming (OOP)
- Models application on real-world objects
Información
- Descripción
- Mapa Mental sobre Objects and Classes, creado por Hae Won Kim el 05/09/2019.
- Creado por
- Hae Won Kim
- Visitas
- 0
- Valoración