Final Gaddis Chap 3 Flashcards
package
a group of related classes
the classes in the Java API are organized into
packages
the Scanner class is in…
the java.util package
Before they can be used, many API classes must be
imported
import the Scanner class
import java.util.Scanner;
explicit import statements
specify a single class ex: import java.util.Scanner;
wildcard import statements
imports all of the classes in a package
ex:
import java.util.*;
the java.lang package
- automatically imported into every Java program
- contains general classes such as String and System
- does not need an import statement (automatically imported)
Write a call to get an integer from the keyboard and store it in an integer variable num
Scanner scan=new Scanner (System.in);
num=scan.nextint();
finding the classes
1) get written description of the problem domain
2) identify all nouns, each is a potential class
3) redefine list to include only classes relevant to the problem
identify the responsibilities
1) things a class is responsible for knowing
2) things a class is responsible for doing
3) refine list to include only classes relevant to the problem
encapsulation
enclosing the proper attributes and methods inside a single class. All that is necessary for the class to operate
encapsulation ensures that
the class is self-contained
data hiding
an aspect of encapsulation that uses the private access modifier on fields to hide them from other classes with the idea that classes should not only be self-contained but also self-governing. Methods are needed to allow access and modification of the class’ data
Decisions that must be made when designing a class: (5)
1) what data must be accounted for
2) what actions need to be performed
3) what data can be modified
4) what data needs to be accessible
5) any rules as to how data should be modified
Class design is typically done with the aid of
a Unified Modeling Language (UML) diagram
UML class diagram
a graphical tool that can aid in the design of a class
3 main sections for UML diagrams
class name, attributes, methods
the data elements of a class
define the object to be instantiated from the class
Attributes must be
specific to the class and define it completely ex: a rectangle is defined by: length and width
Attributes are then
accessed by methods in the class
instance
kind of like each use. For example, each instance of the Rectangle class shares the same design, but each instance contains different data.
Each instance has
all of the attributes and methods that were defined in the class
Classes are defined to represent
a single concept or service