O GoConqr está de visual novo! Conte para nós o que você achou.

Mapa mental

Objects

Andre Luck Computer Science Inglês

Objects

Conteúdo do mapa

Objects

  1. How are they represented in life?

    • Any thing you can think of: abstract or concrete
    • Ex: people, animals, streets, houses, apples, love, trees, laws
  2. What features do they have?

    • Attributes and actions they can perform
      • Attributes are descriptors
        • Ex for a car: color, # of tires, plate number, # of valves
      • Actions they can perform
        • Ex for a car: run, brake
  3. How are they represented in Java?

    • actions are called methods
      • Both are optional. Object may have one, both, or neither of a method or field.
    • attributes are called fields
  4. How do you create Objects in Java?

    • Classes!
      • "A class is a blueprint or a template to create objects of identical type"
        • To create "Employee" objects, you must first create an "Employee" class
          • Ex: Creating an "Employee" class that has fields for age and position, then all "Employee" objects created out of this class will have those fields
      • Classes are the abstraction of a problem, with the objects being representative of real life objects
        • All program elements must reside in a class in Java
      • 3 things to consider when writing a class
        • the class name
        • The Fields
          • Fields are variables
            • Can be primitives or references to objects
              • Ex of reference to another object: Address address;
                • in which an "Employee" class has an "address" field of type "Address"
          • initial of each word after the first is capitalized
            • Ex: validAddress, numberOfRows
        • The Methods
          • Define actions that a class's objects (instances) can do
          • syntax
            • a method has a declaration part and a body
              • declaration part consists of: a return value, method name, and a list of arguments.
                • AKA "signature"
              • the body contains code to perform the action
              • Ex of a getSalary method that returns a double:
                • double getSalary ( )
                  • "the getSalary method does not accept arguments" (I am confused)
              • Ex of a method that returns an Address object"
                • Address getAddress ( )
              • Ex of a method that accepts an argument:
                • int negate (int ~an actual number~)
              • Ex of a method that takes more than one argument (separate them by a comma):
                • int add (int a, int b)
                  • this "add" method will take 2 "ints" and return an "int:
          • the return type of a method can be primitive, an object, or void
            • return type "void" means that the method returns nothing
          • The Method main
            • provides an entry point to an application. An application only needs one class to have a main method
            • the signature goes:
              • public static void main (String [ ] ~args~)
            • can pass arguments to "main" when using "java" to run a class by typing them after the class name and separating them with a space
              • java ~className~ ~arg1~ ~arg2~ ~arg3~ ...
                • Ex passing two arguments "1" and "safeMode" when running Test class:
                  • java Test 1 safeMode
      • the syntax
          • Example for an employee
        • class names capitalize the initial of each word
          • Ex: DateUtility
        • class definitions saved in a file with the same name as the class name
          • Ex: Employee.java
              • "age" and "salary" are fields
      • Constructors
        • Used to construct an object and looks like a method
        • Every class needs at least one constructor
        • does not have a return value
        • a constructor must have the same name as the class
        • syntax
        • Ex adding two constructors to Listing 4.1:
            • second constructor passes the values at the same time you create the object
              • instead of:
    • Creating Objects AKA constructing/instantiating instances (wow!)
      • using the "new" keyword, followed by a constructor of the class to be instantiated
        • Ex to create an "Employee" object
          • new Employee ( ) ;
        • Usually want to assign the new object to an object/reference variable
          • Ex:
            • Employee employee = new Employee ( ) ;
              • where employee is an object reference of type Employee
          • once you have object, can call its methods and access its fields through the assigned object reference. Use a period to call a method or field
              • Ex creating an "Employee" object and assigning values to its "age" and "salary" fields
          • Reference variables can also not contain values AKA not reference an object
            • Ex of type "Book" not assigned a value
              • Book book; // Book is null
            • Ex of local reference variable within a method without an assigned object:
              • Book book = null
            • Can’t access the field or method of a null variable, leads to error.
  5. Notes

    • can not italicize individual words on here
      • ~'s surrounding a word means to italicize it
    • white colored node contains code
  6. AKA instances

Imagens e arquivos do mapa

  • Objects
  • Objects
  • Objects
  • Objects
  • Objects
  • Objects
  • Objects
  • Objects
  • Objects

Informações

Descrição
Computer Science Mapa Mental sobre Objects, criado por Andre Luck em 30-05-2020.
Criado por
Andre Luck
Visualizações
0
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?