Mindmap
Pages 75-84
Inhalt der Mindmap
Pages 75-84
Class Members in UML Class Diagrams
- UML allows you to include field types and method signatures
- Field and its type is separated by a colon
- A methods argument list is presented in parentheses and its return comes after a colon
- UML allows you to include field types and method signatures
Creating Objects
- Object = instance
- Construct = create
- Instantiating a class = creating an instance of the class
- Construct = create
- Create an Object
- Use keyword new followed by the constructor of the class to be instantiated
- new Employee(); is how to make a new Employee object
- Manipulating the object later
- Assign the object to an object variable (reference variable)
- Declare an object reference with the same type as the object
- Employee employee = new Employee()
- Declare an object reference with the same type as the object
- Once an object is made you can call its methods and access its fields
- Use the object reference that was assigned to the object using a .
- ObjectReference.methodName
- Employee employee = new Employee(); Employee.age = 24; Employee.salary = 50000
- ObjectReference.methodName
- Use the object reference that was assigned to the object using a .
- Assign the object to an object variable (reference variable)
- Manipulating the object later
- new Employee(); is how to make a new Employee object
- Use keyword new followed by the constructor of the class to be instantiated
- Object = instance
The Null Keyword
- Reference variable refer to an object but those objects may not have variables = null
- Class level reference variables are initialized upon instance creation and do not need to have null assigned. But local references do need null assigned
- Accessing the field or method of a null value raises an error. You can test this by using ==
- if (book == null) { book = new Book();}
- Accessing the field or method of a null value raises an error. You can test this by using ==
- Class level reference variables are initialized upon instance creation and do not need to have null assigned. But local references do need null assigned
- Reference variable refer to an object but those objects may not have variables = null
Objects in Memory
- When variables are declared in the class or method level memory space is used for them
- declaring an int costs 4 bytes while declaring a long uses 8 bytes. These are primitive values
- Stored in Javas stack
- Objects data is stored in Javas heap
- Reference variable have data stored in Javas stack but the data stored is only the address of the object in the heap
- declaring an int costs 4 bytes while declaring a long uses 8 bytes. These are primitive values
- Stack data holds reference points that request data while Heap data holds the information
- When variables are declared in the class or method level memory space is used for them
Java Packages
- Allow you to group related classes or classes with similar functionality
- Java.io package = classes for performing input and output operations
- Java packages that start with JAVA are reserved for the core libraries
- Packages starting with javax are meant for extension libraries
- Classes with the same name can be used if they belong to different packages
- To group a class to a package use the keyword package followed by the package name. package com.brainysoftware.common
- fully qualified name = class name that carries with it its package name
- Allow you to group related classes or classes with similar functionality
Encapsulation and Access Control
- This is a mechanism that protects parts of an object that need to be secure. It also only exposes the parts that are safe to be exposed.
- 4 access control modifiers in Java: PUBLIC, PROTECTED, PRIVATE, and DEFAULT ACCESS LEVEL
- CLASS ACCESS CONTROL MODIFIERS
- Access control modifier at the beginning of the class declaration allows you to control from which packages your class can be seen
- Make a class public by using the public access control modifier
- A class whose declaration bears no access control modifier has default access
- Access control modifier at the beginning of the class declaration allows you to control from which packages your class can be seen
- CLASS ACCESS CONTROL MODIFIERS
- 4 access control modifiers in Java: PUBLIC, PROTECTED, PRIVATE, and DEFAULT ACCESS LEVEL
- This is a mechanism that protects parts of an object that need to be secure. It also only exposes the parts that are safe to be exposed.
Informationen
- Beschreibung
- Mindmap am Pages 75-84, erstellt von Gary Jones am 19/05/2019.
- Erstellt von
- Gary Jones
- Aufrufe
- 0
- Bewertung