-
-
Notifications
You must be signed in to change notification settings - Fork 2
Java OOP and Programming Concepts Wiki
Welcome to this comprehensive wiki based on the provided documents, code snippets, PPTs, and UML diagrams. This covers key concepts from your NSCC PROG1400/2595 course materials on Object-Oriented Programming (OOP) in Java. I've structured it like a wiki for easy navigation: sections with explanations in simple terms, examples from your files, and cross-references. Focus is on "structs" (classes/structures), "conts" (constructors), "lets" (variables/fields, like 'let' in other languages but here Java fields or locals), "i and j" (loop counters), loops, arrays, inheritance, GUI, UML, refactoring, and more.
Use the table of contents to jump around. Explanations are kept clean, to-the-point, and tied together (e.g., how loops use i/j to process arrays in code).
- Introduction to OOP
- Classes and Objects (Structs)
- Constructors (Conts)
- Variables and Fields (Lets)
- Loops and Counters (i and j)
- Arrays
- Inheritance
- Abstract Classes and Methods
- Encapsulation, Aggregation, and Composition
- Method Overloading and Overriding
- GUI with Swing
- UML Diagrams
- Refactoring Concepts
- Code Examples and Integration
- Glossary of Terms
OOP is a way to structure code like real-world things (objects) with traits (properties) and actions (methods). From "1_IntroToOODesign.pptx": Key principles are A PIE – Abstraction (general ideas), Polymorphism (same action, different ways), Inheritance (sharing traits), Encapsulation (hiding details).
- Simple Terms: Think of a "Car" as an object. It has color (property) and can drive (method). Classes are blueprints for objects.
- Tie-In: Loops (with i/j) process groups of objects (arrays). Constructors build objects. UML shows how classes connect.
Classes are blueprints (like structs in other languages) defining properties and methods. Objects are instances of classes.
-
From Docs: In "3_ClassesAndConstructors.ppt", a Car class has properties like color, make, model. Create objects like
Car myCar = new Car();. - Simple Terms: Class = template. Object = real thing made from template. Fields (variables) store data; methods do actions.
-
Example: In "Main.java" variants,
Car yousefsCar = new Car();creates an object. Access fields likeyousefsCar.carsMake. -
Tie-In: Use constructors to set initial values. Loops iterate over object arrays (e.g.,
Car[] myGarage).
Constructors are special methods that run when creating an object (new). They set initial values.
-
From Docs: In "3_ClassesAndConstructors.ppt", default constructor (no params) vs. overloaded ones (with params). E.g.,
public Car(String make, String color) { this.make = make; }. - Simple Terms: Like building a house – constructor lays the foundation with starting values. Overload for flexibility (different param counts/types).
-
Example: In "Main (20).java",
Circle c1 = new Circle();(default),Circle c3 = new Circle(3.5, "Blue");(params). - Tie-In: Super() calls parent constructor in inheritance. Variables (lets) get set here.
Variables store data. "Lets" might refer to declarations (like 'let' in JS, but Java uses types like int, String). Fields are class-level variables; locals are method-level.
-
From Docs: In UML Cheat Sheet, instance variables (properties) like
-radius: double. Access: private (-), public (+), protected (#). -
Simple Terms: Fields = object's traits (e.g.,
private String name;). Locals = temp storage in methods (e.g.,int i = 0;). Constants = final (unchanging). -
Example: In "Two Dimensional Arrays.txt",
int[][] my2Array = {{1,2,3}, {4,2,1}};– array variable. In Main files,String carsMake = sc.nextLine();. - Tie-In: Loops use locals like i/j as counters. Encapsulation hides fields with getters/setters.
Loops repeat code. i and j are common counters (indices) – i for outer loops, j for inner (nested).
-
From Docs: In "2_JavaArrays.ppt", for-loop:
for (int i=0; i<myArray.length; i++) { System.out.println(myArray[i]); }. Nested for 2D arrays. -
Simple Terms: For-loop:
for (init; condition; increment) { code }. Init:int i=0;(start). Condition:i<length;(when to stop). Increment:i++(add 1). i/j track position. -
Example: In "maximum number with Arrays.txt",
for (int i=0; i<myArray.length; i++) { if (max <= myArray[i]) max = myArray[i]; }– finds max, i = index. - Tie-In: Loops process arrays (e.g., fill with scanner input). In GUI, loop to add radios (e.g., for colors list).
Arrays store fixed-size collections of same-type items. Like lists, but can't resize.
-
From Docs: In "2_JavaArrays.ppt", declare:
int[] myArray = new int[5];. 2D:int[][] my2D = new int[3][4];. Parallel arrays for related data (e.g., names and grades). -
Simple Terms: Fixed "boxes" for data. Index starts at 0. Access:
array[i]. Length:array.length. -
Example: In "Two Dimensional Arrays.txt",
for (int i=0; i<3; i++) { for (int j=0; j<3; j++) { System.out.print(my2Array[i][j]); } }– prints 2D grid, i=row, j=column. -
Tie-In: Loops with i/j iterate. Objects in arrays:
Car[] myGarage = new Car[3];. From Main files, scanner fills arrays.
Subclasses inherit from superclasses, reusing code.
-
From Docs: In "3_Inheritance_Pt1_extends-super.pptx",
public class Car extends Vehicle { super(speed); }. Keywords: extends, super(). - Simple Terms: Child class gets parent's traits/methods. Override for custom behavior.
-
Example: In Shapetastic UML, Circle/Rectangle/Triangle extend Shape.
getArea()overridden (e.g., Circle: π*r²). - Tie-In: Abstract methods force overrides. Constructors call super(). Loops over inherited objects.
Abstract = blueprint only, can't instantiate. Forces subclasses to implement.
-
From Docs: In "3_Inheritance_Pt2_abstract-overrides.pptx",
public abstract class Vehicle { public abstract void move(); }. @Override for custom. - Simple Terms: Abstract class: general (e.g., Shape). Abstract method: declare but no code – kids must fill in.
-
Example: Shape has abstract
getArea(). Triangle implements: 0.5baseheight. - Tie-In: Inheritance uses this. UML: italic class/method names.
Hide details (encapsulation). "Has a" relationships: aggregation (weak, parts independent), composition (strong, parts die with whole).
- From Docs: UML Cheat Sheet and Refactoring doc. Encapsulation: private fields + getters/setters. Aggregation: hollow diamond.
- Simple Terms: Encapsulation: lock data, use methods to access. Aggregation: loose link (e.g., Shape has ShapeColor). Composition: tight (e.g., GUI panels own components).
- Example: In Shapetastic, Shape aggregates ShapeColor (can reuse color). MainFrame composes shapes (static fields).
-
Tie-In: In code,
private String name;withpublic String getName().
Overload: same name, different params. Override: redefine inherited method.
- From Docs: In "1_MethodOverloading.ppt", overload constructors. In inheritance PPT, @Override for move().
- Simple Terms: Overload: flexible calls (e.g., add(int a) vs. add(int a, int b)). Override: customize parent method.
- Example: In "Main (11).java", Adder has multiple add() overloads. toString() often overridden.
- Tie-In: Loops call overloaded methods on array items.
Swing builds windows/apps with components like buttons, labels.
- From Docs: In "1_GUIwithSwing.pptx" and "2_Swing.pptx", extend JFrame. Add JButton, JLabel, etc. ActionListeners for events.
- Simple Terms: JFrame = window. JPanel = section. Radios/buttons: user choices. setBounds() positions.
- Example: In Shapetastic, ChoosePanel adds radios (loop over colors: for i=0; i<colors.size(); i++ add radio). DisplayPanel shows area/image.
- Tie-In: Inheritance: panels extend JPanel. Loops add components.
Visual blueprints showing classes, relationships.
- From Docs: UML Cheat Sheet and Shapetastic PDF. Boxes: class name, fields, methods. Arrows: inheritance (solid triangle), aggregation (hollow diamond).
- Simple Terms: Top: name. Middle: fields (-private). Bottom: methods (+public). Abstract: italic.
- Example: Shape -> Circle (inheritance). Shape has ShapeColor (aggregation).
- Tie-In: Refactoring: move common fields "up" to superclass.
Improve code without changing behavior. From "Refactoring Concepts_Fall2025.docx".
- Simple Terms: Abstract: group similar (e.g., Bird/Fish -> Animal). Factor up: move shared to superclass. Justify subclasses: unique methods/fields/overrides.
- Example: Verify aggregation vs. composition by business rules (e.g., color independent? Aggregate).
- Tie-In: Applies to inheritance/UML. Loops unchanged.
- Arrays + Loops: "maximum number with Arrays.txt" – loop finds max with i as index.
- OOP Integration: Main files create objects, fill arrays via scanner (loops), call methods (overrides).
- GUI + Inheritance: Shapetastic – loop adds radios, createShape() uses if/else on selection, display calls overridden getArea().
- Full Tie-In: Start with class (struct), constructor (cont) sets fields (lets). Loop (i/j) processes array. Inherit/override for shapes. GUI loops add UI, shows results.
- Structs: Classes/objects.
- Conts: Constructors.
- Lets: Variables/fields.
- i/j: Loop counters (index vars).
- Loops: Repeaters (for, while).
- More: Scanner (input), toString() (string rep), super() (parent call), abstract (must implement).