Quiz 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

What does the +, -, #, and underline show in a UML Class diagram

+ Stands for public attribute or operation - Stands for private attributes or operation # Stands for protected attributes or operation (later this course) underline for static

what is the difference between accessors and mutators

A mutator method may modify ("mutate") a class' fields (including private). An accessor method accesses fields but may not modify a class' fields. a mutator for setting the value, and an accessor for getting the value, known as a setter and getter method, respectively, and typically with names starting with set or get.

What is a package?

A package is a grouping of related types, classes, interfaces, and subpackage. The types, classes, and interfaces in a package are called package members. The following table lists several built-in Java packages and sample package members.

What is the difference between primitive and reference type?

A primitive type variable directly stores the data for that variable type, such as int, double, or char. Ex: int numStudents = 20; declares an int that directly stores the data 20. Has a fixed size. A reference type variable can refer to an instance of a class, also known as an object. A reference to data (heap space)

Define reference

A reference is a variable type that refers to an object. A reference may be thought of as storing the memory address of an object. Variables of a class data type (and array types, discussed elsewhere) are reference variables.

What are static member methods and what are they used for?

A static member method is a class method that is independent of class objects. Static member methods are typically used to access and mutate private static fields from outside the class. Since static methods are independent of class objects, the this parameter is not passed to a static member method. So, a static member method can only access a class' static fields.

What does it mean when a wrapper class is immutable?

A wrapper class object (as well as a String object) is immutable, meaning a programmer cannot change the object via methods or variable assignments after object creation.

How do you know if something is a class variable?

It has static (shared piece of memory)

A static method is needed to access or mutate a _____ static field from outside of the class.

Private: A public static method can be used to access or mutate a private static field.

What is the purpose of method overloading?

Programmers often want to provide different initialization values when creating a new object. A class creator can overload a constructor by defining multiple constructors differing in parameter types. When an object is created with the new operator, arguments can be passed to the constructor. The constructor with matching parameters will be called.

What is UML?

Unified Modeling Language = controlled by the Object Management Group and is the industry standard for graphically describing object oriented softwares

What type of relationships does a UML Case diagram describe? UML Sequence diagram? collaboration?

case: describes relationships from actor point of view (shows how external entities participate in a use case or group of activities) sequence: show message exchange (method calls) between objects collaboration: show interactions occurring between objects participating in a specific situation state: show the different states of an object during its life and the actions that cause object to change state Entity: show the conceptual design of database applications

The _________ construct defines a new type that can group data and methods to form an object. A class' ____________ indicate all operations a class user can perform on the object.

class public member methods

A constructor that can be called without any arguments is called a _______________

default constructor - constructors do not have return types

The this parameter can be used in a static method to access an object's non-static fields.

false this refers to a specific class object, but static methods are independent of class objects. So, the this parameter is not passed to static methods, and a static method cannot access non-static fields.

The "." operator, known as the ____________, is used to invoke a method on an object.

member access operator

New classes are what types where are primitives stored? Strings are ________ to other memory locations (on the heap)

new classes are reference data types primitives are stored directly into memory other classes (including strings) are references to other memory locations

For reference variables of wrapper classes (e.g., Integer, Double, Boolean), you SHOULD use the equality operators == and != when comparing values,

FALSE Although a programmer should never compare two reference variables of wrapper classes using the equality operators, a programmer may use the equality operators when comparing a wrapper class object with a primitive variable or a literal constant. Reference variables of wrapper classes can also be compared using the equals() and compareTo() methods.

The value of an Integer passed to a method can be modified within the method. True False

False An Integer object is immutable, meaning the value cannot be modified after the object is created. Assignment to an Integer parameter within a method creates a new Integer object and assigns the new object's reference to the parameter.

All static fields can be accessed anywhere in a program. True or False

False A class' public static fields can be accessed outside the class because the fields are public. But, a private field can only be accessed by the class' methods.

Each constructed class object creates a new instance of a static field. True or False

False A field belongs to the class, not each class object. Memory is only allocated once for a field, not for each object.

Assigning a different value to a parameter variable of reference type within the method deletes the original object.

False Assigning a value to a reference variable only changes the object to which it refers.

The generated API documentation includes private class members by default. True or False

False By default, the API documentation only includes class members accessible by external classes (i.e., public and protected members). To document private class members, the programmer must execute the javadoc tool with the -private flag.

The @author block tag can be used to specify a method's author. True or False

False The @author block tag is only compatible with Doc comments for classes and interfaces.

A key advantage of javadoc comments is that a change to a comment in the java source automatically updates documentation on an HTML webpage.

False The javadoc tool must be run to create new HTML.

A class' private helper method can be called from main(), which is defined in another class. True or False

False. A class' private methods can only be called from the class' other methods

A private helper method cannot call another private helper method. True or False

False. No such restriction exists. A private helper can be called from any other method of the class, whether public or private.

What is the difference between autoboxing and unboxing

Autoboxing is the automatic conversion of primitive types to the corresponding wrapper classes. Unboxing is the automatic conversion of wrapper class objects to the corresponding primitive types.

What about Constructors?

Same name as class - No return type - Default constructor (no parameters) - "Standard" constructor: takes in instance variables - "Copy" constructor: takes in an object to copy

What are the different ways classes can relate?

Same name as class - No return type - Default constructor (no parameters) - "Standard" constructor: takes in instance variables -"Copy" constructor: takes in an object to copy

What is a Class Diagram made up of?

Show the different classes that make up a system and how they relate to each other. + Stands for public attribute - stands for private attributes # = protected underlined = static represented by rectangles

What does static mean

The keyword static indicates a variable is allocated in memory only once during a program's execution. Static variables reside in the program's static memory region and have a global scope. Thus, static variables can be accessed from anywhere in a program.

What is a block tag?

The overall description describes the items purpose and extends to the first @, which denotes the beginning of the tags section. A Javadoc comment tags section consists of block tags, each of the form @keyword plus text, each block tag on its own line.

The default constructor is called when an object is created of the class type. True or False

True

A key advantage of javadoc comments is that the documentation is close to the source code so it is easier to keep consistent with the source code. True or False

True Having information different places makes consistency hard to maintain.

The Javadoc tool generates API documentation for classes and their members. True or False

True Javadoc parses source code and Doc comments to produce documentation describing how to interface with said classes.

A parameter of reference type allows a method to access the class members of the object to which the parameter refers.

True The argument's reference is copied to the parameter so that both refer to the same object.

What are some of the functions wrapper classes allow?

Wrapper classes allow the program to create objects that store a single primitive type value, such as an integer or floating-point value. The wrapper classes also provide methods for converting between primitive types (e.g., int to double), between number systems (e.g., decimal to binary), and between a primitive type and a String representation.

What is a static field?

a static field is a field of the class instead of a field of each class object. Thus, static fields are independent of any class object, and can be accessed without creating a class object. Static fields are declared and initialized in the class definition. Within a class method, a static field is accessed using the field name. A public static field can be accessed outside the class using dot notation: ClassName.fieldName.

how do you make a number a long?

add l at the end

Can immutable objects return new objects?

yes, many of their methods return new objects


Conjuntos de estudio relacionados

Chapter 10 - Pay for Performance: Incentive Rewards DONE

View Set

Principles of Auditing Chapter 5

View Set