Java

5.0(1)
Studied by 1 person
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/33

encourage image

There's no tags or description

Looks like no tags are added yet.

34 Terms

1
New cards

Class

A blueprint that defines what fields and methods its objects will have (ex: public class Dog)

2
New cards

Object

One actual instance made from a class using new (ex: Dog d = new Dog();)

3
New cards

Instance

Another word for an object made from a class

4
New cards

Constructor

Special code that runs when an object is created; same name as the class and NO return type, not even void

5
New cards

Overloaded Constructor

A second constructor in the same class with a different parameter list (ex: Dog() and Dog(String name))

6
New cards

Instance Variable / Field

A variable declared in the class but outside any method; each object gets its own separate copy

7
New cards

Parameter

A value passed into a method or constructor, listed inside the parentheses (ex: newName in setName(String newName))

8
New cards

Method

A block of code inside a class that performs an action (ex: public void bark())

9
New cards

Declaration

Stating a variable's type and name without giving it a value (ex: int age;)

10
New cards

Assignment

Giving a value to a variable that already exists, with no type in front (ex: age = 16;)

11
New cards

Declaration + Initialization

Declaring and assigning in one line (ex: int age = 16;)

12
New cards

Variable naming rules

No spaces, first letter lowercase, remaining words capitalized (camelCase) (ex: totalScore)

13
New cards

Method naming rules

No spaces, first letter lowercase, remaining words capitalized (camelCase) (ex: getAge)

14
New cards

Class naming rules

No spaces, first letter capitalized, remaining words capitalized (ex: BankAccount)

15
New cards

camelCase

Naming style where the first word is lowercase and each following word starts with a capital (ex: studentAge)

16
New cards

Getter

A public method that returns a private field's value; returns the field's type and takes no parameters (ex: public int getAge() { return age; })

17
New cards

Setter

A public void method that takes a parameter and assigns it to a private field (ex: public void setAge(int newAge) { age = newAge; })

18
New cards

Encapsulation

Keeping fields private and only allowing access through public methods (getters/setters) so the class protects its own data

19
New cards

OOP

Object-Oriented Programming: organizing code around classes and objects that bundle data (fields) with behavior (methods)

20
New cards

Abstraction

Using an object without needing to know how its code works inside (ex: calling str.length())

21
New cards

Inheritance

When one class builds on another using extends and gets its fields and methods (ex: class SavingsAccount extends BankAccount)

22
New cards

Polymorphism

Different classes responding to the same method call in their own way (ex: Dog and Cat both have speak())

23
New cards

private

Access keyword meaning only code inside the same class can use it; fields are usually private

24
New cards

public

Access keyword meaning any class can use it; getters, setters, and constructors are usually public

25
New cards

this

Refers to the current object; this.name means the field, plain name means the parameter when they share a name

26
New cards

new

Keyword that creates a new object and runs its constructor (ex: new Dog("Max"))

27
New cards

Return type

The type of value a method gives back (int, double, String, etc.), written before the method name

28
New cards

void

Return type meaning the method does not return anything

29
New cards

return

Keyword that sends a value back from a method

30
New cards

static

A field or method shared by the whole class; one copy for all objects, so changing it changes it for every object

31
New cards

Separate copies of fields

Each object has its own copy of instance variables, so changing one object's field does not affect other objects

32
New cards

Methods share fields

All methods in the same object use that object's fields, so a setter's change shows up in the getter

33
New cards

Reference

A variable that points to an object; b = a makes both point to the SAME object, only new makes a separate one

34
New cards

Cube method

public int cube(int n) { return n * n * n; }