Week 1-6 Flashcards

1
Q

What is machine code?

A

Low level hexadecimal instructions

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

What is assembly language?

A

Low-level programming language with symbols for instructions.

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

What is high level programming language?

A

Easier to understand. Translated to machine code by compiler.

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

Explain life-cycle of a C-file?

A

Starts as basic text file.
Compiler takes C file and produces an executable.
When we execute loaded into memory.
CPU executes.

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

What are the problems with machine code?

A

Computer systems are different.
OS provide different libraries
Different CPUs cannot execute the same program and have different instructions
Programs must be compiled again for the different CPU types.

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

Why do we download different versions of software for each OS?

A

Cause each OS has different libraries and code must be compiled differently for each.

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

What is the advantage of JVM?

A

Write code once, run on any OS?

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

What is a java program compiled to?

A

bytecode

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

Why do we not need dynamic memory allocation?

A

JVM garbage collector frees memory automatically.

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

What does IDE stand for?

A

Integrated Development Environment

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

When we perform calculations with different typing in java, what type does the result take?

A

The longest type.

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

What is autoboxing and unboxing?

A

A: Primitive type converted to wrapper object. E.g. Integer i = 4;
U: Wrapper object converted to primitive type. int i = intObj;

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

Syntax for array declaration in java.

A

int[] numbers = new int[size];

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

Syntax to get length of array test.

A

test.length

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

Syntax for ArrayList.

A

ArrayList<TYPE> array = new ArrayList<TYPE>();</TYPE></TYPE>

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

What is OOP?

A

Is based on the concept of objects which can encapsulate both data and behavior. Designed to model real-world entities and their interactions.

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

What is cohesion?

A

Programs are broke up into classes. Classes contain related functionalities. The more related the higher the cohesion.

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

Difference between object and class.

A

Class is an idea. E.g. idea of a ‘chair’
Object is an instance of idea, real thing.

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

What is a default constructor?

A

Constructor with no parameters, that initializes instance variables to their default values.

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

T or F. We can have more than one constructor.

A

True.

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

What does a constructor implicitly return?

A

A reference to where the object is in memory.

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

How does copying a primitive differ from copying an object in java?

A

If I copy a primitive, a whole new copy is made in memory, so changing the copy won’t affect original.

If I copy an object, a reference is all that is copied, so if I edit the copy, the original will also be affected.

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

Syntax for default constructor.

A

public Name() {

}

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

Main syntax.

A

public static void main(String[] args) {
}

25
What does a constructor explicitly return?
A constructor does not return any value, not even void
26
What does API stand for?
Application Programmer Interface
27
Syntax for enums.
enum type {Coffee, Biscuits, Milk}; private type t; Object o = new Object(type.Milk);
28
Define encapsulation.
The process of hiding implementation details inside a class, but allowing methods to be accessed.
29
Explain visibility access levels.
Same class (public, protected, default, private) Same package (public, protected, default) A subclass (public, protected) Anywhere else (public)
30
Give the visibility things in order of decreasing security.
private default protected public
31
What is an immutable class?
A class without a mutator (setter) method.
32
What is a class variable? Syntax for a class variable.
A variable shared among all instances of a class. static int name = 1;
33
Syntax for constant.
public static final int CONSTANT = 0;
34
Why would a static method be used? What are their features?
For a utility role. Cannot use instance variables and not connected to objects but still call with class name.
35
What are the only variables that can be used by static methods?
static variables.
36
Explain static imports using Math as an example.
import static java.lang.Math.*; means that we can call sqrt() without doing Math.sqrt();
37
What are singleton variables?
Special case of static class variables. Is an object that we need only one instance of.
38
Syntax for interface.
public interface InterfaceName { }
39
T or F. An interface can also provide method implementation without any extra syntax.
False.
40
T or F. A class that implements an interface must override all abstract methods of the interface.
True.
41
T or F. All methods in an interface are public.
True
42
What is polymorphism?
Means classes can implement the same methods differently even if part of the same interface.
43
What are default methods in java?
Allow method implementation within an interface in java by placing keyword default in front.
44
T or F. You can override the visibility of a method being overwritten from implemented interface.
False.
45
T or F. You can instantiate an interface.
False.
46
How is inheritance defined?
extends keyword
47
If a subclass inherits a private variable what happens?
The variable exists but cannot be accessed or changed.
48
What is the default superclass?
Object
49
T or F. If A extends B and we cast A to B. What methods can be accessed?
Only the methods of B
50
Syntax for calling superclass constructor.
super(parameters);
51
Syntax for running superclass function.
super.functionName(parameters);
52
Overriding equals syntax.
public boolean equals (Object obj){ if (obj instanceof BankAccount){ BankAccount b = (BankAccount) obj; return b.accountNumber == this.accountNumber; } else { return false; } }
53
How does inheritance work with interfaces?
Simply adds more requirements for class that implements subclass.
54
What is the difference between an abstract class and an interface?
Abstract classes can contain instance variables. Abstract classes are implemented with extends
55
Syntax for abstract class.
public abstract class AbstractShape { }
56
What is a final class?
A class that cannot be extended.
57
What is a final method?
A method which cannot be ovverriden.
58
What must be done to a method called it within a constructor?
It must be declared as final.