CSC 122 Final Exam

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

3 Benefits of generics

1) Allow you to re-use same code with different inputs 2) Elimination of casts 3) Eliminate overloaded methods

Advantages of LinkedList

1) Dynamic structure (memory allocated as needed). 2) Add and remove doesn't require re-shuffling 3) Stacks and queues are easily implemented

Disadvantages of LinkedList

1) Extra storage required for pointers 2) Sequential access obscured

3 benefits of encapsulation

1) Improved maintainibility/flexibility, 2) fields can be made read or write only, 3) makes it easy to model real-world entities

5 Concepts of Proper Encapsulation

1) Restrict access- declare all instance variables private 2) Know the limits- All values should be limited to the range of legal values. Any change made should be checked 3) Initialize all data using constructor. Even if 0! 4) Validate all input: Assume user is an idiot (all user input is EVIL) 5) Maintain valid objects. Your object might be empty, small, or negative, but it should always be valid.

What three things should a developer do inside their constructors?

1) Validate values of parameters (if applicable), 2) initialize all instance variables, 3) set the value of any constants.

Two benefits of generics

1)Provide compile-time type safety (you can catch invalid types at compile time); 2) eliminates the need for casting

constructor

A method within a class that is where all instance variables should be initialized. Providing no parameters and no method body will invoke the default constructor of the superclass. IT CREATES THE OBJECTS.

static

A reserved word that serves as a modifier for methods and variables. Static method is also called a class method and can be referenced without an instance of the class. Static variable (AKA class variable) is common to all instances of the class.

Encapsulation

AKA "data/information hiding" the technique of making the fields in a class private and providing access to the fields via public methods. Prevents data from being accessed by code defined outside the class.

stacks

Abstract data structure that manages data last in, first out (LIFO). Linear.

queues

Abstract data type that manages information in first in, first out manner (FIFO). Linear.

In a LinkedList, insertions and deletions are performed in ___ time.

Constant

Benefits of testing

Determines quality of program, if problems detected earlier, cheaper/easier to to fix program

coupling

Elements are coupled if a change in one forces a change in the other. coupling refers to the degree to which different modules/classes depend on each other (think "among"). Loose coupling is what you want, because it yields lower interdependency

Generics

Enable types (classes and interfaces) to be parameters when defining classes, interfaces, and methods.

Array-Based time complexity

Find nth element, implement a HashTable

LinkedList time complexity

Good for: "Add to Front, Insert in Middle"

streams

Handles all input and output in Java

Efficiency of using a HashTable to implement a "set" class

HashTables perform "find" and"add" operations in almost constant time. This is similar to set operations, which include adding members (disallowing duplicates), removing members, and testing if a member is present

Call stack

Indicates where exception occurred. First trace line indicates the method that produced the error.

Checked Exceptions

Invalid conditions that are outside the program's control, e.g. file does not exist, network failure, computer virus

Benefits of constants

Less inadvertent coding erros, and you need to change the value only once if you use it multiple times throughout program.

Access modifier

Modifier that defines the scope in which a construct can be accessed

Can (or should) a HashTable be used as a stack?

No! This is a BAD idea, because HashTables have no ordering scheme at all, whereas stack relies on FILO pattern.

When to throw an exception?

Only to be used if method throws a checked exception! Use when fundamental assumption of current code block is found to be false

Benefits of inheritance

Organizes information well, groups similar classes, models similarity between classes, easier to navigate program

Polymorphism

Polymorphism is the ability of an object to take on many form, or accessed more than one way

scanner

Provides convenient methods for reading input values of various types

Inheritance

The ability to derive a new class from an existing one. IS-A RELATIONSHIP

Main benefit of encapsulation

The ability to modify implemented code without breaking the code of others who use our code

Overriding

The process of modifying the definition of an inherited method to suit the purposes of the subclass. Specific implementation of a method, but same parameters as superclass version

constants

These link an unchanging value to a variable name. ALL_SHOULD_BE_CAPS. Used to make code more robust and human-readable.

static-- use?

Used to refer the common property of all objects.

static

Variable is shared between all objects. Think of "club" example

4 Goals of implementation

Well documented, flexible, reliable, correct

recursion

a method where the solution to a problem depends on the solutions to small instances of the same problem (see "base cases"). Compare recursion to iteration.

Explicitly required to throw or catch ___ exceptions

checked

In an array, random access is performed in ___ time.

constant

When an object is created, Java will call the ___ first.

constructor

unchecked exceptions

defects in the program; conditions that effect errors in the program's logic. These can be avoided by better programming. ("Not checked" at compile time)

Four fundamental OOP principles

encapsulation, inheritance, polymorphism, abstraction

Major operations performed on a dictionary besides equals and toString:

get (just looking at it), put, remove

abstraction

hiding the bowels of your program, showing only implementation details

cohesion

high cohesion is desired. This is when you have a class that does a well-defined job. Low cohesion (bad) is when a class does a lot of jobs that don't have much in common (think washing machine that cleans both dishes and clothes. You want high cohesion to avoid this!).

The Dictionary data structure maps ___ to ___.

keys; values

What specifically is created when the following line of code is created? House [] d = new House [20];

only the array is created

Re-running all tests after finishing a bug is called ____.

regression testing

toString

returns a string representation of the object that textually represents the object. Result should be concise. Helpful for debugging classes during development.

In addition to being declared final, constants need to be declared ___.

static

Error

system malfunction, unanticipatable and unrecoverable

"final" keyword

tells Java that you will not be allowing the variables "pointer" to the value to be changed to another value

regression testing

the process of testing changes to computer programs to make sure older programming still works with the new changes

True or false: a static variable is showed among all instances of a class

true

public

visibile to everyone

private

visible to class only

protected

visible to package AND all subclasses in the inheritance

default (more provided)

visible to the package


Kaugnay na mga set ng pag-aaral

Psych Ch. 16: Methods of Therapy

View Set

Partnership Law - Multiple Choice

View Set