Programming Practice and Applications Flashcards

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
Q

What does null mean?

A

null means nothing has been assigned to the variable. Any primitive data type can be assigned to null.

26
Q

What are the primitive data types?

A

integer, boolean, floating point

27
Q

What is an external method call?

A

An object calling a method from a different class

28
Q

How do classes define types?

A

A class name can be used as a type for a variable. Objects can hold other objects or store references to them

29
Q

What is an object type?

A

Types defined by classes and strings, created manually

30
Q

What does 9+3+”cat” return?

A

“12cat”

31
Q

What does “cat”+9+3 return?

A

cat93

32
Q

What is a debugger?

A

Software that helps examine how an application executes and helps finds bugs.

33
Q

How to set a field with the same name as the parameter?

A

this.fieldName=parameter

34
Q

What Java Class libraries can we use for array?

A

import java.until.Arraylist

35
Q

What is a generic class type?

A

A collection that has one element type for all its elements

36
Q

How to declare an array list?

A

private ArrayList files;

37
Q

What is the diamond notation

A

If collection type is stated in the field declaration, you can leave it out in the constructor.

38
Q

Features of a collection

A

Increases its capacity as necessary, keeps a count, keeps elements in order

39
Q

what does filename.countains(“hi”) do?

A

Gives a partial match of the filename

40
Q

What are the ArrayList methods?

A

.add, .get, .remove, .size

41
Q

What types of loop is a for-each loop?

A

It is a definite loop because it goes through every element in a collection

42
Q

What type of loop is a while loop?

A

An indefinite loop because the amount of times it loops is unpredictable and dependent on whether the condition is met

43
Q

What are the benefits of a for-each loop?

A

It is easier to write, its safe because it is guaranteed to stop

44
Q

What are the benefits of a while loop?

A

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
Q

How to check if two string are the same?

A

stringName.equals(“hi”) because String is a class in java and each string variable is a different object

46
Q

How to use the iterator object?

A

Iterator it = files.iterator();
while(it.hasNext()) {
ElementType tk= it.next();
.println(tk.getDetails());}

47
Q

How to use the iterator object to remove an element?

A

it.remove()

48
Q

When do we use iterator objects?

A

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