Java Programming Features Flashcards

Help me to become familiar with what to include in the IA

1
Q

What is OOP?

A

Object-Orientated Programming. This is a way of programming based on the concept of a collection of objects containing both data and methods (functions) coming together to make a program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do objects interact in OOP?

A

Objects interact with each other by accessing data and calling methods from each other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why do we have OOP?

A

To avoid “spaghetti code”. The opposite of OOP is procedural programming which basically uses a single class to write the whole programming meaning the repetitive copy pasting of functions/methods and too much interdependency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Components of an object

A

Data - called “properties”
Functions - called “methods”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Objects are _______ of classes

A

instances

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are classes and why are they important to OOP?

A

A class is essentially a blueprint for creating objects. Objects are instances of classes that have specific attributes and behaviors. A class defines the properties and methods common to all objects of that type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Difference between variable, parameter and property?

A

Variable:
A container that is used to temporarily hold a data value. They are declared with a specific data type and can hold different values throughout the execution of the program. (e.g. int age = 7)

Parameter:
That shit within the brackets of a method. It represents the new value that is going to be assigned to a property in that class.
(e.g. public void setName(String newName))

Property:
Properties are attributes or characteristics of objects within a class. Usually they are represented using private instance variables. (e.g. private String name;)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what does static mean when you are making a method?

A

It means that you do not have to make an object* when you’re calling it.

*Making the object means for example Student s = new Student();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is encapsulation?

A

This is when we use private instances and getters and setters in order to make sensitive data hidden from users and increase the amount of abstraction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is polymorphism?

A

Polymorphism literally means “many forms”

Essentially, this is when we can have multiple methods with the same name (hence, many forms) but they must have different parameters.

Additionally, another important form of polymorphism is when we can extend classes with another class allowing one class to inherit properties and methods from another class this is called inheritance by the way and is also another Java feature).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are inner classes?

A

This is when we next classes. The purpose of this is to group classes that belong together which makes our code more readable and maintainable. To do this in our main method, we create an object of the outer class, and then create another object of the inner class (the inner class would be declared within the outer class by the way)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are constructors and why do we have them?

A

Constructors are essentially the method which creates the object for us. They will have the same name as the name of the class. We can use constructors to set the initial values for object attributes which helps us to avoid repetitive code thus increasing the elegance.

There is a basic, hidden constructor in each class that does the actual creation but we can multiple constructors in a class. For example,
they can take parameters which is used to create the attributes we want for that object.

Constructors cannot have return types like void.

Example of constructor:

public class Main {
int x; // Create a class attribute

// Create a class constructor for the Main class
public Main() {
x = 5; // Set the initial value for the class attribute x
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly