Programming Practice and Applications Flashcards

(48 cards)

1
Q

Class

A

a category or type of ‘thing’. Like a template or a blueprint.

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

Object

A

Represents ‘things’ from the real world, or from some problem domain

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

Methods

A

Methods can have parameters to pass additional information needed to execute. Can also return values

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

Attributes

A

Characteristics of an object that is stored in a field

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

A method signature

A

Made up of the method name and its parameters

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

The state of an object

A

The set of values of all attributes defining an object

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

Fields

A

Attributes, they store data persistently and define the state of an object. They are instance variables

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

Structuring of a field

A

Always private, starts with a lowercase letter

Private datatype variable_name

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

Constructor

A

Initialises an object

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

Structure of a constructor

A

Always public, initial values stored in fields, can use parameters, same name as class

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

Why are constructors public?

A

So they can be called by anyone who wants to use the class

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

What are the two types of variables?

A

Instance variables and parameter variables which only exits while the parameter is being called, then gets called into a field

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

What does a method do and what is it made up of

A

Methods implement the behaviour of an object. They are made up of a header and a body

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

What is a mutator method?

A

They receive a parameter and they change an object. They have a void return type.

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

What is an accessor method?

A

They have a non-void return value and they return a statement about the object.

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

What is string concatenation?

A

Merging two or more strings

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

What is a scope?

A

A scope is a textual block{ } in Java, which defines where the variable can be accessed

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

What is a local variable?

A

A variable that only exists and are accessible within a specific scope. e.g when the method is called

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

What is the scope and lifetime of a field?

A

It’s scope is the whole class and its lifetime is the lifetime of its object

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

What is a lifetime?

A

Lifetime describes how long the variable can be used until it is destroyed

21
Q

What is abstraction?

A

The ability to ignore details of parts and focus on more important fundamental aspects

22
Q

What is modularisation?

A

The process of dividing a whole into well-defined parts which can be build and examined separately

23
Q

What is Constructor overloading?

A

Having more than one constructor

24
Q

What does the modulo operator do?

A

Returns the remainder of an integer divison

25
What does null mean?
null means nothing has been assigned to the variable. Any primitive data type can be assigned to null.
26
What are the primitive data types?
integer, boolean, floating point
27
What is an external method call?
An object calling a method from a different class
28
How do classes define types?
A class name can be used as a type for a variable. Objects can hold other objects or store references to them
29
What is an object type?
Types defined by classes and strings, created manually
30
What does 9+3+"cat" return?
"12cat"
31
What does "cat"+9+3 return?
cat93
32
What is a debugger?
Software that helps examine how an application executes and helps finds bugs.
33
How to set a field with the same name as the parameter?
this.fieldName=parameter
34
What Java Class libraries can we use for array?
import java.until.Arraylist
35
What is a generic class type?
A collection that has one element type for all its elements
36
How to declare an array list?
private ArrayList files;
37
What is the diamond notation
If collection type is stated in the field declaration, you can leave it out in the constructor.
38
Features of a collection
Increases its capacity as necessary, keeps a count, keeps elements in order
39
what does filename.countains("hi") do?
Gives a partial match of the filename
40
What are the ArrayList methods?
.add, .get, .remove, .size
41
What types of loop is a for-each loop?
It is a definite loop because it goes through every element in a collection
42
What type of loop is a while loop?
An indefinite loop because the amount of times it loops is unpredictable and dependent on whether the condition is met
43
What are the benefits of a for-each loop?
It is easier to write, its safe because it is guaranteed to stop
44
What are the benefits of a while loop?
We don't have to process the whole collection doesn't have to be used with a collection. Sadly it can cause an infinite loop
45
How to check if two string are the same?
stringName.equals("hi") because String is a class in java and each string variable is a different object
46
How to use the iterator object?
Iterator it = files.iterator(); while(it.hasNext()) { ElementType tk= it.next(); .println(tk.getDetails());}
47
How to use the iterator object to remove an element?
it.remove()
48
When do we use iterator objects?
If we want to stop part way through a loop, it might be inefficient to go through indexed, when we want to remove an object from a collection