CS 111: Programming Fundamentals II - Object-Oriented Programming and Core Java Concepts

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/99

flashcard set

Earn XP

Description and Tags

Comprehensive practice flashcards covering static members, argument passing, object references, constructors, toString, object equality, aggregation, composition, copy constructors, shallow vs. deep copies, null references, this, enumerations, wrapper classes, autoboxing/unboxing, StringBuilder, tokenization, regular expressions, inheritance, overriding, super, protected access, polymorphism, dynamic binding, final methods, and the Object class.

100 Terms

1
New cards

Static Field

A class-level variable declared with the static keyword that belongs to the class itself rather than to any individual object instance; a single copy is shared across all instances of the class.

2
New cards

Instance Field

A non-static variable declared inside a class that belongs to a specific object instance, meaning every created object maintains its own independent copy and state.

3
New cards

Static Method

A method declared with the static keyword that belongs to the class rather than an object, meaning it can be invoked directly through the class name without instantiating an object.

4
New cards

Instance Method

A method that operates on the state of a specific object instance and requires an object to be instantiated before it can be invoked.

5
New cards
<p>Static Member UML Representation</p>

Static Member UML Representation

The standard notation in a UML class diagram where static fields and static methods are indicated by underlining their signatures.

6
New cards

Static Method Direct Access Rule

The Java language rule establishing that a static method can directly access static fields and other static methods, but cannot directly access instance fields or instance methods because no specific object instance exists in its context.

7
New cards

Pass-by-Value

Java's universal parameter-passing mechanism where the value stored in the argument variable is copied directly into the method's parameter variable, with zero exceptions.

8
New cards

Reference Variable

A variable whose stored value is a reference (an address-like value) that locates an object or array allocated on the heap, rather than holding the raw object data itself.

9
New cards

Passing an Array to a Method

An operation where a copy of an array's reference value is passed to a method, allowing the method to access and modify the elements of the caller's original array.

10
New cards

Array Parameter Reassignment

Assigning a newly instantiated array to an array parameter inside a method, which only updates the method's local copy of the reference and leaves the caller's original array untouched.

11
New cards

Returning an Object from a Method

A method mechanism where a reference value pointing to an object is returned to the caller, giving the caller access to the original object without copying the object itself.

12
New cards

Java Reference vs. C++ Pointer

A conceptual distinction where a Java reference identifies an object in memory without exposing actual physical addresses or permitting pointer arithmetic, unlike pointers in C/C++.

13
New cards

final static Field

A class constant loaded into class memory only once during execution whose assigned value cannot be altered or reassigned by any object or method.

<p>A class constant loaded into class memory only once during execution whose assigned value cannot be altered or reassigned by any object or method.</p>
14
New cards

Global State

A program condition created by excessive static variables where data is globally accessible and mutable across an entire runtime, making code difficult to test, reason about, and synchronize across threads.

15
New cards

Single Return Value Encapsulation

The technique of overcoming Java's single-return-value limitation by bundling multiple related values as fields within a single object and returning that object's reference.

16
New cards

Constructor

A special class member that has the exact same name as the class and no return type, automatically invoked when new creates an object to initialize instance fields into a valid starting state.

17
New cards

Default Constructor

A parameterless constructor provided automatically by the Java compiler only when a class contains no declared constructors, initializing fields to default values like zero, null, or false.

18
New cards

Parameterized Constructor

A constructor declared with parameters that accepts arguments during object creation to initialize instance fields with specific custom values.

19
New cards

Constructor Overloading

Declaring multiple constructors within the same class that share the class name but have different parameter lists, allowing objects to be initialized in different ways.

20
New cards

Constructor Return Type Mistake

The error of declaring a return type such as void on a constructor, which causes the Java compiler to interpret it as an ordinary method rather than a constructor.

21
New cards

== Operator with Objects

A relational operator that compares the reference values (memory addresses) of two object variables, evaluating to true only if both variables refer to the exact same object instance.

22
New cards

Default Object.equals() Method

The default equals implementation inherited from java.lang.Object that performs an identity comparison identical to the == operator by comparing object reference addresses.

23
New cards

Overriding equals(Object obj)

Writing a custom equals method in a class that compares the internal data fields of two objects of the same type to evaluate whether they represent identical information.

24
New cards

Logical Equality

The equivalence condition where two separate objects in memory are considered equal because their corresponding instance fields contain matching data.

25
New cards

Aliasing

The situation where two or more distinct reference variables hold identical reference values and therefore point to the exact same object on the heap.

26
New cards

Class-Specific copy() Method

An ordinary instance method written within a class that instantiates and returns a new object containing duplicate values of the calling object's instance fields.

27
New cards

Has-A Relationship

A design relationship where one class contains a reference to an object of another class as an instance field, commonly implemented via aggregation or composition.

28
New cards

Aggregation

A weaker has-a relationship where the contained object can exist independently of the containing object and may be shared among multiple containing instances.

29
New cards

Composition

A stronger has-a relationship representing whole-part ownership where the contained object is created and managed by the containing object and cannot exist independently of it.

30
New cards
<p>Aggregation UML Notation</p>

Aggregation UML Notation

A relationship represented in a UML class diagram by a line with a hollow (unfilled) diamond attached to the containing class.

31
New cards

Composition UML Notation

A relationship represented in a UML class diagram by a line with a filled (solid black) diamond attached to the owning class.

32
New cards

Copy Constructor

A constructor that receives an existing object of the same class as a parameter and initializes a new object with duplicated field values from the source object.

33
New cards

Copy Constructor Syntax

The standard declaration format for a copy constructor, written as public ClassName(ClassName source), with no return type.

34
New cards

Copy Constructor vs. clone()

An industry design choice where copy constructors are preferred over clone() because copy constructors are type-safe, simple to implement, and avoid interface casting and default shallow copying issues.

35
New cards

Security Issue in Aggregate Constructors

A software vulnerability where an aggregate class constructor directly assigns an external object reference parameter to a private field, allowing external code to modify the class's private state.

36
New cards

Security Issue in Getter Methods

A vulnerability where an accessor method returns a direct reference to a private mutable object field, granting outside code direct access to mutate that private object.

37
New cards

Defensive Copying

The programming practice of creating copies of mutable objects when accepting them in constructors or returning them from accessors to protect a class's internal state from unauthorized external mutation.

38
New cards

Shallow Copy

An object-copying operation that duplicates the outer containing object but copies only the reference values of internal objects, leaving nested objects shared between both instances.

39
New cards

Deep Copy

An object-copying operation that duplicates the outer containing object and recursively creates brand new copies of all nested objects, ensuring complete operational independence.

40
New cards

null Literal

A special Java literal value indicating that a reference variable does not currently point to or identify any object in memory.

41
New cards

NullPointerException

A runtime exception thrown when a program attempts to invoke an instance method, access an instance field, or index an array using a reference variable that evaluates to null.

42
New cards

Default Value of Reference Fields

The default starting value automatically assigned by the Java virtual machine to any uninitialized instance or static object reference field, which is always null.

43
New cards

Null Checking

A defensive coding check (e.g., if (ref != null)) performed before invoking methods or accessing fields on an object reference to ensure it is not null.

44
New cards

this Keyword

A built-in Java reference variable available inside any instance method or constructor that refers directly to the current executing object.

45
New cards

Variable Shadowing

A condition where a constructor parameter or local variable shares the same identifier as an instance field, requiring the this. prefix to explicitly target the instance field.

46
New cards

this(…) Constructor Call

A special syntax used within a constructor to explicitly call another overloaded constructor in the same class, which must appear as the very first statement.

47
New cards

Enumeration (enum)

A specialized Java reference type that restricts a variable to hold only one constant from a fixed, predefined list of named values.

48
New cards

Enum Constant

An individual named identifier declared inside an enum type, written in uppercase letters by convention, that represents a distinct, immutable object instance.

49
New cards

values() Enum Method

A static method automatically provided for every enum that returns an array containing all declared constants of that enum type in the order of declaration.

50
New cards

ordinal() Enum Method

An enum instance method that returns the zero-based integer position of a constant within its enum declaration list.

51
New cards
<p>Wrapper Class</p>

Wrapper Class

A class that encapsulates a primitive data type into an object, providing utility methods and allowing primitives to be stored in object-only data structures.

52
New cards

compareTo() Enum Method

An enum method that compares the ordinal values of two constants of the same enum type, returning a negative integer, zero, or a positive integer.

53
New cards

Enum Equality with ==

The standard and safe practice of comparing enum constants using the == operator because Java guarantees that only one instance of each enum constant exists in memory.

54
New cards

Enum in switch Statements

The use of an enum variable as the control expression in a switch structure, where case labels specify bare constant identifiers without their enum class prefix.

55
New cards

Type Safety of Enums

A compile-time guarantee ensuring that an enum variable cannot be assigned misspelled strings, invalid integers, or out-of-range values.

56
New cards

Autoboxing

The automatic conversion performed by the Java compiler from a primitive data value into an instance of its corresponding wrapper class (e.g., int to Integer).

57
New cards

Unboxing

The automatic conversion performed by the Java compiler from an instance of a wrapper class back to its corresponding primitive value (e.g., Integer to int).

58
New cards

Wrapper Types in Generic Collections

The architectural requirement to use wrapper objects such as ArrayList rather than raw primitives, since Java generic collection classes only store object references.

59
New cards

Character.isDigit(char ch)

A static method in the Character class that returns true if the specified char parameter represents a numeric digit ('0' through '9'), and false otherwise.

60
New cards

Character.isLetter(char ch)

A static method in the Character class that returns true if the specified char parameter represents an alphabetic letter, and false otherwise.

61
New cards

Character.isLetterOrDigit(char ch)

A static method in the Character class that returns true if the specified char parameter is an alphanumeric letter or digit, and false otherwise.

62
New cards

Character.isLowerCase(char ch)

A static method in the Character class that returns true if the specified char parameter is a lowercase letter, and false otherwise.

63
New cards

Character.isUpperCase(char ch)

A static method in the Character class that returns true if the specified char parameter is an uppercase letter, and false otherwise.

64
New cards

Character.isSpaceChar(char ch)

A static method in the Character class that returns true if the specified char parameter represents a space or whitespace character, and false otherwise.

65
New cards

String Immutability

The property of Java String objects stating that their contents cannot be modified after creation; any apparent modification creates an entirely new String object in memory.

66
New cards

StringBuilder Class

A standard Java library class representing a mutable sequence of characters that can be modified, appended, or altered in place without creating new objects.

67
New cards

Default StringBuilder Capacity

The initial character buffer capacity allocated by the no-argument constructor new StringBuilder(), which provides storage for 16 characters before needing automatic expansion.

68
New cards

StringBuilder.append()

An overloaded method that converts its argument to text and attaches it directly to the end of the calling StringBuilder sequence in place.

69
New cards

StringBuilder.insert()

An overloaded method that inserts data representations into a StringBuilder object at a specified zero-based index.

70
New cards

StringBuilder.deleteCharAt(int index)

A method that removes the single character located at the specified zero-based index from the StringBuilder object.

71
New cards

StringBuilder.setCharAt(int index, char ch)

A method that replaces the character at the specified zero-based index in a StringBuilder with the character ch.

72
New cards

StringBuilder.reverse()

A method that reverses the character sequence of a StringBuilder in place.

73
New cards

Tokenizing

The process of breaking a single string of delimited text into smaller, meaningful constituent parts known as tokens.

74
New cards

String.split(String regex, int limit)

A method that partitions a string around matches of a regular expression delimiter, returning a String[] array whose maximum element count is governed by the integer limit.

75
New cards

Regular Expression (RegEx)

A formatted string pattern that defines search criteria used for pattern matching, validation, and tokenizing in text.

76
New cards

RegEx Dot Metacharacter (.)

A regular expression metacharacter that matches any single character.

77
New cards

RegEx Anchors (^ and $)

Boundary metacharacters in regular expressions where ^ specifies a match at the beginning of a line and $ specifies a match at the end of a line.

78
New cards

RegEx Character Class ([abc])

A bracketed regular expression pattern that matches any single character appearing in the specified set ('a', 'b', or 'c').

79
New cards

RegEx Negated Character Class ([^abc])

A bracketed regular expression pattern starting with a caret that matches any character except those explicitly listed within the set.

80
New cards

RegEx Whitespace Pattern (\s+)

A regular expression pattern that matches one or more consecutive whitespace characters (spaces, tabs, newlines).

81
New cards

Inheritance

An object-oriented programming mechanism where a new class (subclass) automatically acquires fields and methods from an existing class (superclass), promoting code reuse.

82
New cards

Superclass

A general parent class that defines common fields and methods to be inherited and extended by specialized subclasses.

83
New cards

Subclass

A specialized child class that extends a superclass, inheriting its accessible members and adding or overriding fields and methods.

84
New cards

extends Keyword

The Java keyword placed in a class header to establish that the class inherits from and specializes a specified superclass.

85
New cards

Is-A Relationship

The core relationship modeled by inheritance, indicating that an instance of a subclass is a specialized kind of its superclass (e.g., a Dog is an Animal).

86
New cards

Code Duplication Elimination

A primary benefit of inheritance that centralizes shared attributes and behaviors in a superclass to eliminate repeated code across related subclasses.

87
New cards

Subclass Access to Superclass Private Fields

The rule that private members of a superclass are inherited in memory but cannot be accessed directly by name within subclass code, requiring public or protected accessors.

88
New cards

Generalization UML Arrow

The visual connector in UML class diagrams consisting of a solid line with an open (unfilled) triangular arrowhead pointing from the subclass to the superclass.

89
New cards

Method Overriding

The practice where a subclass defines an instance method with the exact same name, return type, and parameter list as an inherited superclass method to provide specialized behavior.

90
New cards

Method Overloading vs. Overriding

Overloading involves methods with the same name but different parameter signatures in a class; overriding involves a subclass rewriting an inherited method using the exact same signature.

91
New cards

@Override Annotation

A compiler directive placed above an overriding method instructing the Java compiler to verify that the method correctly overrides an existing method in a superclass.

92
New cards

super() Constructor Call

An explicit statement in a subclass constructor that invokes a constructor of its immediate superclass, which must appear as the very first line of code.

93
New cards

super.method() Invocation

Using the super keyword as a prefix within a subclass method to explicitly invoke the superclass's version of an overridden method.

94
New cards

protected Access Modifier

An access specifier declared with protected (represented by # in UML) that allows a class member to be accessed by subclasses and classes within the same package, but not by unrelated outside classes.

95
New cards

Polymorphism

The capability of a superclass reference variable to refer to objects of any derived subclass and automatically execute the appropriate subclass behavior at runtime.

96
New cards

Dynamic Binding

The runtime mechanism by which the Java Virtual Machine decides which overridden version of a method to execute based on the actual object type residing on the heap.

97
New cards

Polymorphism Rule #1 (Reference Type)

The rule dictating that the declared reference type determines which method names and member variables a program is permitted to call at compile time.

98
New cards

Polymorphism Rule #2 (Actual Object Type)

The rule dictating that at runtime, the actual object type instantiated on the heap determines which overridden implementation of a method is executed.

99
New cards

final Method

A method declared with the final keyword in a superclass that prevents any subclass from overriding it, guaranteeing that the superclass implementation remains unchanged.

100
New cards
<p>Inheritance Hierarchy</p>

Inheritance Hierarchy

A branching tree-like structure of classes linked by inheritance, tracing from general ancestor classes down to specific descendant subclasses.