Java Flashcards

Learn Theory (61 cards)

1
Q

What is encapsulation?

A

The idea of wrapping variables and methods together into a single unit. It makes use of the “protected” access modifier.

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

What does protected mean?

A

Like private, it will not be accessible to other classes but now with the exception of inherited classes. i.e classes that extend from a superclass. Subtypes will have access to any protected and public methods.

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

If the constructor has been given to a superclass does the subclass need to define one?

A

No! By default the subclass object will refer to the superclass’s constructor!

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

How does a subclass constructor invoke a superclass constructor?

A

With the “Super” keyword. This allows the constructor of the subclass to have its own traits as well as the traits from the parent class.

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

What are the two types of relationships you can have when it comes to inheritance?

A

Is-a relationship (Extension)

Has-a relationship (Composition)

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

What is “#” mean in UML design?

A

“protected”

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

How many classes can you inherit from?

A

1

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

Can you use subclass properties through a superclass binding?

A

No

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

List (the) seven Primitive types.

A

Int, float, double, boolean, char, short, Byte, Long Boolean.

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

What is the memory allocation and the range for Boolean?

A

Range: True, False

1 byte

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

What is the memory allocation and the range for byte?

A

[-128, 127]

1 byte

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

What is the memory allocation and the range for short?

A

[-32768, 32767]

2 bytes

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

What is the memory allocation and the range for int?

A

big

4 bytes

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

What is the memory allocation and the range for long?

A

massive.

8 bytes

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

What is the memory allocation and the range for float?

A

big.

4 Bytes

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

What is the memory allocation and the range for double?

A

Massive.

8 bytes

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

What is the memory allocation and the range for char?

A

[0, 65535]

2 Bytes

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

What is the memory allocation and the range for String?

A

Very Long

Variable memory.

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

Why do we have types?

A

To confirm what we are dealing with and to sort memory allocation.

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

What does a stack based language mean?

A

When a method is executed it is put into the call stack. The method being executed at the top of the stack is the most recently called method..

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

What will be returned when you first initialise an array then call it ?

A

The memory address!

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

What type is an array?

A

Reference type.

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

True or False. Strings are mutable?

A

False, Strings are immutable.

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

What does UML stand for?

A

Unified Modelling Language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What do you use to write a text file?
PrintWriter. Don't forget to import it! :)
26
What does the "garbage collector" do?
The garbage collector will free any allocation that no longer has a reference during execution.
27
What does ADT stand for?
Abstract Data Type
28
True or False. Arrays are a fixed length?
True.
29
What is overloading?
Using the same method name but with a different method signature. We can't apply overloading if the two methods have different return types.
30
True or False. Overloading cannot be applied to constructors.
False. It can!
31
What is a checked exception?
A checked exception is one where the programmer must handle it using a try-catch block. Exception and any subclasses is a checked exception.
32
What is an unchecked exception?
An unchecked Exception is an exception that a programmer does not need to handle but can catch if they want to. This includes RuntimeException.
33
True or False. Abstract classes cannot be instantiated?
True! But you can specify methods, constructors, attributes and access modifiers.
34
How are abstract classes illustrated within a UML diagram?
Abstract class names are and polymorphic methods are Italicised.
35
True or False. Unlike abstract classes, we can implement interfaces as many times as we want.
True!
36
True a False. An interface is a class.
False. An interface defines a group of methods for implementers to define.
37
Can interfaces have variables?
Yes but the are static (they eblong to the interface) and constant (have the final modifier applied to them). Therefore we cannot us these variables for instances.
38
How do we represent an interface using UML?
<> InterfaceName +_______(xxxxx: int): void NOTE :the above is italicised to show it is a polymorphic method. Additionally: The relationship link is dotted ("- - - - -") and establishes a realisation deck between implementer and the interface. etc.
39
What is a default method?
Interface method that is fully filled out and does not have to be specified in the class that implements it.
40
What is Polymorphism?
Polymorphism allows us to assert the use of methods specified in an inherited type through other types.
41
Name the advantages of using generics:
- Faster compile time from stronger type checks. - Elimination of Casts (i.e changing variables) - Enables you to implement generic algorithms.
42
True or False. Exceptions and errors should be thrown when the precondition of the method has been violated?
True.
43
What is a precondition?
A precondition is input that must be within its bounds for it to execute correctly.
44
What does the Assert Keyword do?
It evaluates an expression and will throw an AssertionError if the statement is false.
45
What is a post-condition?
A post condition is where any mutation or output from a method is considered to adhere to the requirements of the method. Simply -- What the method promises to do.
46
What is the difference between White Box and Black Box testing?
White Box Testing - Where we employ some unit testing software, to help analyse the internals of the system. Black Box Testing - User centric, Testing, without knowledge of the internals, input is given and compared to match the output of the program.
47
What is regression testing?
When the system has been modified and the changes may result in a failure of a previous successful test case.
48
What is Integration Testing?
Integrating individual components into the whole system to see if it works.
49
A recursive function is made of two things, what are they?
A base case - Where the function terminates. Recursive Case - which will converge to a base case.
50
Negatives of recursion?
- Java programming does not allow for infinite recursion. - inefficient with memory. - potentially more computationally demanding due to the overhead caused by method calls.
51
What is Memoization (or caching)?
It is a technique for storing the results of computation. We keep the results in the event that we may want to use them later....
52
What is an anonymous class?
An anonymous class is instantly constructed and an instance returned to the caller.
53
True or False. Lambda methods require an interface that declares only one method.
True.!
54
True or False. Lambdas cannot have multiple lines.
FALSE!
55
What are gotchas?
Help Alex pls.
56
Given a collection that specifies an upperbound we....
...specifically use the collection for reading only.
57
Given a collection that specifies a lower bound we...
... have only writing performed on it.
58
Lets go over wildcards!
Yes pls. Exam Question.
59
Why use wildcards?
They allow methods to accept multiple different collections(or types that contain a type parameter) with an inherited type.
60
What are inner classes?
They are classes that are defined within a class. They are referred to by their identifier within the class.
61
Difference between an idiom and a pattern?
For software development an idiom is a pattern that is afforded by the language and is typically language specifice