Programming Practice and Applications Flashcards
Class
a category or type of ‘thing’. Like a template or a blueprint.
Object
Represents ‘things’ from the real world, or from some problem domain
Methods
Methods can have parameters to pass additional information needed to execute. Can also return values
Attributes
Characteristics of an object that is stored in a field
A method signature
Made up of the method name and its parameters
The state of an object
The set of values of all attributes defining an object
Fields
Attributes, they store data persistently and define the state of an object. They are instance variables
Structuring of a field
Always private, starts with a lowercase letter
Private datatype variable_name
Constructor
Initialises an object
Structure of a constructor
Always public, initial values stored in fields, can use parameters, same name as class
Why are constructors public?
So they can be called by anyone who wants to use the class
What are the two types of variables?
Instance variables and parameter variables which only exits while the parameter is being called, then gets called into a field
What does a method do and what is it made up of
Methods implement the behaviour of an object. They are made up of a header and a body
What is a mutator method?
They receive a parameter and they change an object. They have a void return type.
What is an accessor method?
They have a non-void return value and they return a statement about the object.
What is string concatenation?
Merging two or more strings
What is a scope?
A scope is a textual block{ } in Java, which defines where the variable can be accessed
What is a local variable?
A variable that only exists and are accessible within a specific scope. e.g when the method is called
What is the scope and lifetime of a field?
It’s scope is the whole class and its lifetime is the lifetime of its object
What is a lifetime?
Lifetime describes how long the variable can be used until it is destroyed
What is abstraction?
The ability to ignore details of parts and focus on more important fundamental aspects
What is modularisation?
The process of dividing a whole into well-defined parts which can be build and examined separately
What is Constructor overloading?
Having more than one constructor
What does the modulo operator do?
Returns the remainder of an integer divison
What does null mean?
null means nothing has been assigned to the variable. Any primitive data type can be assigned to null.
What are the primitive data types?
integer, boolean, floating point
What is an external method call?
An object calling a method from a different class
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
What is an object type?
Types defined by classes and strings, created manually
What does 9+3+”cat” return?
“12cat”
What does “cat”+9+3 return?
cat93
What is a debugger?
Software that helps examine how an application executes and helps finds bugs.
How to set a field with the same name as the parameter?
this.fieldName=parameter
What Java Class libraries can we use for array?
import java.until.Arraylist
What is a generic class type?
A collection that has one element type for all its elements
How to declare an array list?
private ArrayList files;
What is the diamond notation
If collection type is stated in the field declaration, you can leave it out in the constructor.
Features of a collection
Increases its capacity as necessary, keeps a count, keeps elements in order
what does filename.countains(“hi”) do?
Gives a partial match of the filename
What are the ArrayList methods?
.add, .get, .remove, .size
What types of loop is a for-each loop?
It is a definite loop because it goes through every element in a collection
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
What are the benefits of a for-each loop?
It is easier to write, its safe because it is guaranteed to stop
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
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
How to use the iterator object?
Iterator it = files.iterator();
while(it.hasNext()) {
ElementType tk= it.next();
.println(tk.getDetails());}
How to use the iterator object to remove an element?
it.remove()
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