Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
61 Cards in this Set
- Front
- Back
What does a class do? |
Describes all objects of a specific type. |
|
What is an object? |
Instances of a class. |
|
What are methods? |
Operations for an object (declared by the class).
|
|
What are constructors? |
Methods that initialise an object when the object is first created, setting up any fields the object has. |
|
What does a user have to do to change the formal parameters of a method into actual parameters? |
When the method is invoked, the user has to input values for the formal parameters. These values, or actual parameters, are lost when the method finishes running. |
|
What are the three parts of a method header? |
Visibility modifier, return type and method name. |
|
What do fields define? |
The state of an object. |
|
What are the two main types of method? |
1. Mutator - "Set" method. 2. Accessor - "Get" method. |
|
What are local variables and where can they be accessed? |
They are variables initialised within a method & can only be accessed from within that method as they are only around when the method is running. |
|
What does changing the visibility modifier do? |
It changes whether or not other classes (and programmers) can see it (or call it). |
|
What is the structure of a conditional (if) statement? |
if(boolean condition) { body } |
|
What are the boolean operators? |
&& and || or ! not |
|
What is modularisation? |
Splitting a whole into well-defined parts (that can be built separately and interact in well-defined ways). |
|
What is abstraction? |
Ignoring details of parts to focus on a higher problem. |
|
What are 2 examples of primitive types? |
1. int 2. boolean |
|
What is an example (and a general rule) of object types? |
Example: String. Rule: Any class can be an object type. |
|
What must you do for an object type that you don't need to do for a primitive one? |
Inside the constructor you must assign the field a new ClassName (actual parameters for this class). |
|
What does the modulo operator do? |
It gives the remainder after the division of integers. |
|
How do you call a method of an object type? |
fieldName.methodName([method'sactual parameters]); |
|
What is a generic class? |
A class that gets parameterised with a second type (like ArrayList). |
|
Does the size of an ArrayList have to be specified at initialisation? |
No, the size of an ArrayList is fluid, and will grow or shrink to accommodate deletion & creation of items. |
|
What are the four types of loop (in Java)? |
- For-each loop - For loop - While loop - Do-while loop |
|
What is the syntax for a for-each loop? |
for(ElementTypeelement : collection) { loopbody statements; } |
|
What is the syntax for a while loop? |
while(boolean condition) { loopbody statements; } |
|
What is the syntax for a for loop? |
for(initialisation; condition; post-body action) { loop body statements; } Initialisation& post-body action are usually to do with an int variable that is beingiterated a set number of times (as set out in the condition). |
|
What two methods does the Iterator class have to iterate over a collection? |
public boolean hasNext(); public ElementType next(); |
|
When should you use an Array (over an ArrayList)? |
When you know the length of the collection of items.
|
|
How are Arrays similar to ArrayLists? |
- You define them as a class field. - You construct your array using the new keyword. - When defining your array, you specify what type the objects/primitive values will be (this time in square brackets). |
|
What does 'Interface not Implementation' mean? |
You don't need to know how the program/class works - you just need to know that it does and how to use certain important parts of it. |
|
What is shown in documentation for a class? |
Anything with the visibility modifier of 'public'. |
|
What does API stand for? |
ApplicationProgramming Interface. |
|
What is different about a .equals() method vs using ==? |
The .equals() method tests for equality, while == tests for identity. |
|
What are HashMaps? |
Collections that contain pairs of values, each pair consisting of one key and one value. |
|
How do you initialise and then fill a HashMap? |
- To initialise it you create a field of type HashMap<type, type>; and then initialise it in the constructor using the new keyword. - You use the .put(item, item); method to fill it. |
|
How do you lookup a value in a HashMap? |
You supply the key and the value is returned. |
|
What happens if you try to add the same pair into the HashMap? |
It does not add it, as HashMaps do not allow for duplicates. |
|
What is a HashSet? |
It is an ArrayList that does not allow for duplicates. |
|
How do you initialise and then fill a HashSet? |
- You initialise it as a field (written as HashSet<type>) and then use the new keyword to create it in the constructor. - You fill it using the method .add(item); |
|
What does it mean to make a variable or method static? |
It means that variable/method does not belong to the object, it belongs to the class. They exist (and can be accessed) as soon as they are defined.
|
|
What does it mean to make a variable final? |
It means once the variable has been assigned a value, that value cannot change. |
|
What happens to the written source code in order for it to be read and executed by the machine? |
It must be compiled into Java Virtual Machine Code, which is in turn interpreted by the VM interpreter that carries out the intended instructions in the code. |
|
What are 2 examples of compile-time errors? |
- Syntax errors (e.g. missing semicolon or curly bracket). - Type errors (e.g. an int where a String was expected). |
|
What are the 2 types of run-time errors? |
- Given because your program does something illegal (e.g. NullPointerException). - Not given but your program does not do what you want. |
|
What is encapsulation? |
It means to hide any unnecessary information from people using your code. It is useful when trying to prevent bugs. |
|
What two things help with the detection of bugs? |
Documentation and Modularisation. |
|
What does it mean to test a program? |
It means to search for the presence of errors. It is not easy to do well. |
|
What does debugging do? |
It searches for the source of errors, often far away from where the problem actually arose. |
|
What is unit testing? |
It means to test everything from single methods to entire packages. You should:
- Understand what the unit should do. - Test boundary cases (e.g. full arrays, etc.). - Look for violations (e.g. what happens if the input is negative?). |
|
What is the directory structure of a BlueJ project? |
- One bluej.pkg project file per project. - One bluej.pkh backup file per project. - One *.java source code file per class. - One *.class byte code file per class. - One *.ctxt context file per class. |
|
What does IDE stand for? |
Integrated Developing Environment. |
|
How do you compile at the command line? |
You type javac classname.java to compile the class ClassName and any classes dependent upon it. |
|
How do you execute at the command line? |
You type java ClassName followed by any arguments required by the main method to execute a class (as long as it has already been compiled). |
|
What is the header for a main method? |
publicstatic void main(String[] args) |
|
What is the difference between tight and loose coupling and which one do you want? |
Tight coupling is where one class relies heavily upon another, whereas loose coupling is where one class only passes parameters to another (and so they aren't dependant upon each other). - You want loose coupling. |
|
What is the difference between high and low cohesion and which one do you want? |
- High cohesion - a unit is responsible for one single task. - Low cohesion - a unit is responsible for many unrelated tasks. - You want high cohesion. |
|
What is the difference between Responsibility-Driven Design (RDD) and Object-Oriented Design (OOD)? |
- Object-orienteddesign focuses on the client-server model, where both parties exchangeinformation based on a contract they both commit to. - Responsibility-drivendesign on the other hand looks at the classes & says that the class thatstores the data should be responsible for manipulating it. |
|
What is refactoring? |
A class/method is looked at and restructured to eliminate redundancy and improvereadability. |
|
What are two types of recursive data structures? |
1. Simple list data structures 2. Tree data structures |
|
What do simple lists consist of? |
A HEAD (which is a list element) and a TAIL (which is a smaller list) |
|
What do trees consist of? |
A ROOT node and a number of SUB_TREEs (which are smaller trees). |
|
What are the two parts of a recursive definition? |
1. The base part. 2. The inductive part. |