¡GoConqr estrena diseño! Cuéntanos qué te parece.

Mapa mental

Mental Map:chp 4

Brianna Harris Inglés

Mental Map:chp 4

Contenido del mapa

Mental Map:chp 4

  1. Introduction

    • To develop an application in an OOP one must create a model which resembles a situation to solve the problem.
    • What is an Object?
      • Objects can be living, nonliving, concrete, or abstract. Objects have attributes (called fields) and perform actions (called methods). Objects don't always have both fields and methods; but they can have both, they can also have neither. To create objects, Java's "blueprint" are called classes.
      • Classes
        •  Classes are capitalized and are a tool used to create the abstraction of a problem. A class is a template to create objects of said type and determines the kind of objects you get. For example; if you create an Employee class with fields: age and position, all Employee objects created out of this Employee class will have age and position fields as well. When writing a class consider ·     Class name ·     The fields ·     The methods Declaring a class requires the keyword class followed by a class name. then a class has a body within braces class Employee  {   int age;   double salary; } A class definition must be saved in a file that has the same name as the class name as well as the java extension,“.java”
        • Examples UML Class Diagram
        • Fields
          • Are variables which can be primitives or references to objects. Example for the latter; Employee class may have an address field of type Address; which is another class that represents a street address. In other words an object can contain other objects.
        • Methods
          • Define actions that a class’s objects or instances can do. They have a declaration part, and a body. The declaration consists of a return value, the method name, and a list of arguments. The body contains code that perform the action. The syntax for declaring a method: returnType methodName (listOfArguments) Return type can be primitive, an object, or void. The declaration part is also called the signature of the method. The following are 4 examples ·     getSalary method that returns a double        o  double getSalary()        o  observe this method does not accept      arguments ·     method that returns Address object        o  Address getAddress() ·     Method that accepts argument        o  Int negate(int number) ·     if methods have x>1 arguments, separate them w/ commas.        o  Int add(int a, int b)        o  An add method takes 2 ints and returns 1 int
          • The Method main
            •  A method called main is an entry point to an application. Apps can have many classes but only one class needs to have a main method which allows this single class to be invoked. Its signature is public static void main(String[] args) You can pass arguments to main when using java to run a class. Do this by typing them after the class name. Multiple arguments are separated by a space and must be passed as strings. Example ·    To pass 2 arguments “1” and “safeMode” while running the Test class,      o  Java Test 1 safeMode
        • Constructors
          •  This creates objects out of the class, it constructs an object. Every class must have at least 1 constructor. It looks like a method but does not have a return value, and must have the same name as the class. Here is the syntax: constructorName (listOfArguments)  {     [constructor body] }   It doesn’t need arguments, called no-arg. But constructor arguments can be used to initialize the fields in the object. Example: The Employee class with 2 Constructors Public class Employee             {             Public int age;             Public double salary;             Public Employee ( )       { }    Public Employee(int ageValue, double salaryValue )  {           Age = ageValue;          Salary = salaryValue;      } } Constructor #2 is useful. It assigns values to age and salary. You can pass the values at the same time you create an object (new is also a keyword) new Employee (20, 90000.00);
      • Creating Objects
        • Create an object, also called an instance, from a class. The most common way is by using new keyword. new is followed by the constructor of the class to be created. Ex, creating Employee new Employee ( ) ; Usually you will want to assign the created object to an object variable, or reference variable. This way you can manipulate an object later. Do this by declaring an object reference with the same type as the object. Employee employee =  new Employee  ( ) ; Here, employee is an object reference of type Employee, observe the capital letter and when it was used.
        • Calling an object
          • Once you have an object you can call its methods and access its fields with the object reference that was assigned to the object. Use a period (.) to call a method or a field objectReference .methodName objectReference . fieldname Another example code which creates Employee object and assigns values to its age and salary fields  Employee employee = new Empoyee ( ) ; employee . age  = 24; employee . salary = 5000;
      • Null
        • A reference variable refers to an object, but if this variable has no value thus is not referencing an object, it is called null. You will need to assign a local reference variable within a method -null-  if you do not assign an object to it, observe; Book book = null; When an instance is created you do not need to assign them null. An error occurs if one tries to access the field/method of null variable reference; observe Book book = null; System.out.printIn(book.title); // error because book is null Test if a reference variable is null with == if (book == null)           {             book = new Book ( ) ; } System.out.printIn(book.title) 
      • Objects in Memory
        • Declaring a variable allocates memory space for data. Data space is divided into the stack and the heap. Java objects lay in the heap. Primitive data is standard in memory taken and are allocated to the stack, but reference variables are a bit different. Here, some bytes go to the stack, but the memory which it contains is the address of the object in the heap. A reference variable accesses object. Example, if the Book class has the public review method use syntax: book.review( ) ; Objects can be referenced by multiple reference variables.

Imágenes y archivos del mapa

  • Mental Map:chp 4
  • Mental Map:chp 4

Información

Descripción
Mapa Mental sobre Mental Map:chp 4, creado por Brianna Harris el 02/06/2020.
Creado por
Brianna Harris
Visitas
2
Etiquetas
cop2800
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?