Knowledge Questions Flashcards Preview

CS1002 > Knowledge Questions > Flashcards

Flashcards in Knowledge Questions Deck (157)
Loading flashcards...
1
Q

What is computer science?

A

Understanding how computers and information technology work and applying that knowledge

2
Q

Why is CS important?

A

Fundamental to the management of existing systems and development of new systems

3
Q

Give examples of application domains

A
Logistics
Health care
Government
Finance
Critical Systems
Education
Entertainment
4
Q

Define Hardware

A

Physical part of a computer system

5
Q

Define software

A

Instructions that tell the computer what to do

6
Q

Give some desired qualities of software

A

Correct
Well designed
Well documented
Easy to understand and integrate

7
Q

What is a program?

A

A set of instructions to the computer

8
Q

What is the name of the method that a Java program executes first

A

Main

9
Q

What is object orientation?

A

A style of programming based on objects, which represent things of relevance to the problem

10
Q

What does documentation tell us in regards to OO programming?

A

The purpose of the objects

What methods are avaliable, what they do, what parameters they need if any

11
Q

What does JVM stand for?

A

Java Virtual Machine

12
Q

What is the difference between a class and an object?

A

Class is a blueprint for an object and an object is a specific instance of a class

13
Q

What does the this keyword refer to?

A

The current object

14
Q

Give examples of primitive types

A

Numbers, boolean values

15
Q

What is the default value for reference types?

A

Null

16
Q

What are the default values for

a) numbers
b) boolean

A

a) 0

b) false

17
Q

What is abstraction?

A

In programming this means a solution can be expressed at various different levels

18
Q

Give examples of different levels of abstraction

A

Binary, low level, high level

19
Q

What is the software development process

A

A scheme for producing a piece of software from an initial specification

20
Q

What is java bytecode executed by?

A

Java Virtual Machine

21
Q

What is a variable?

A

A piece of information with a name

22
Q

What do variable declarations consist of?

A

Type
Name
Optionally initial value

23
Q

What is used to represent assignment in java?

A

=

24
Q

What is a type in Java?

A

A type is a description of the kind of thing a value is

25
Q

What are the two kinds of type in Java?

A

Primitive

Reference

26
Q

What is a key difference between primitive and reference types?

A

How they are stored

27
Q

Describe byte

A

Signed Integer
8 bits
-128 and 127

28
Q

Describe char

A

Unicode Character

16 bits

29
Q

Describe short

A

Signed Integer
16 bits
-32,768 to 32,767

30
Q

Describe int

A

Signed Integer

32 bits

31
Q

Describe long

A

Signed Integer

64 bits

32
Q

Describe float

A

Floating Point number

32 bits

33
Q

Describe double

A

Floating Point number

64 bits

34
Q

What is a literal?

A

Representation in a Java Program of a fixed value

35
Q

How many decimal values of precision does float have?

A

7

36
Q

How many decimal values of precision does double have?

A

14

37
Q

What are the 2 parts that reference types are held in?

A

Reference

Object

38
Q

What is an identifier?

A

An unlimited series of letters, numbers and underscores

MUST BEGIN WITH A LETTER

39
Q

Give a few examples of keywords

A

Abstract
Class
Finally
Throws

40
Q

What is scope?

A

The certain restricted part of the program that an identifier is only valid within

41
Q

Describe the scope of a variable

A

From the end of its declaration to the nearest enclosing brace

42
Q

Give the order of operator precedence

A

()
* / %
+ -
=

(High to low)

43
Q

What is

x = 2 - 3 * 7

A

-19

44
Q

What is 1 + 12 / 8 + 1

A

3

45
Q

What is -2 + 4.1 * -2

A

-10.2

46
Q

What is (2-3) * 7

A

-7

47
Q

What is (1+12)/ 8 + 1

A

2

48
Q

What is -(2+4.1) * -2

A

12.2

49
Q

What is n+= 300 the same as?

A

n = n + 300

50
Q

What is n*=20 the same as?

A

n = n*20

51
Q

What does the flow of control refer to?

A

Which methods get executed, and in which order

52
Q

What is abstraction?

A

The process of extracting the general structure to allow the inessential details to be ignored.

53
Q

What is parameterisation?

A

Process of writing generic code to which specific parameters may be supplied to perform a specific task

54
Q

What are modifiers?

A

Used to control how the method can be used and it’s visibility

55
Q

What is the difference between formal and actual parameters?

A

Formal - Identifiers used to stand for the values passed into the method by a caller
Actual - arguments passed into the method when method is invoked

56
Q

What defines the method signature?

A

Name and parameters

57
Q

What happens when a method is invoked?

A

Actual arguments are copied to formal arguments
Control passes to the method
Method executes
Control and value return to the caller

58
Q

What is pass by value?

A

Actual arguments are copied onto the formal arguments of the method invoked
They then behave like variables within the method invoked

59
Q

What are the boolean operators for not, or and and

A

!, ||, &&

60
Q

Which boolean operators are short circuiting?

A

&&, ||

61
Q

What are the non short circuiting equivalents of and and or?

A

& and |

62
Q

Give the generic method definition

A

(){

}

63
Q

Iteration

A

Repeating actions more than once

64
Q

Where does the condition come in a while loop

A

At the start

65
Q

Write a general format of a for loop

A

for ( statement; boolean expression; statement){

}

66
Q

What are the 4 parts of the for loop

A

Declaration of a counting variable
Test whether loop should continue
Update of counting variable
Instructions to be repeated

67
Q

What is the scope of the counting variable in a for loop?

A

From its declaration to the end of the block governed by the for loop

68
Q

Give some limitations of for loops

A

Have to know before the loop starts how many times to repeat

69
Q

If you want to execute a piece of code once and then potentially a number of further times what loop would you use?

A

Do-while

70
Q

What is the key difference between a for/while and a do while

A

Loop block is always executed once in the do while loop

71
Q

What is method overloading?

A

Defining two(or more) methods in the same class with the same name but different parameters

72
Q

Does the arithmetic addition operator has higher precedence than the arithmetic multiplication operator?

A

No

73
Q

Does the && operator have higher precedence than the || operator?

A

No

74
Q

Does the assignment operator have higher precedence than relational operators?

A

Yes

75
Q

What does it mean if an object’s field values are encapsulated?

A

They can’t be seen directly or accessed by other objects or that object’s methods

76
Q

Give a benefit of encapsulation

A

Improves control over how field values are read and updated

Helpful in structuring and maintaining software(can change one part without affecting others)

77
Q

What is an accessor method?

A

Returns the value held in a field

78
Q

What is a mutator method?

A

Sets the content of a field to certain vaue

79
Q

What do modifiers in java control?

A

Visibility
Mutability
Association with class / object

80
Q

Give examples of some modifiers

A
Public
Private
Protected
Static
Final
81
Q

Describe a static modifier and state what it can be applied to

A
Modifier for fields and methods
Means that a member is associated with class as a whole rather than individual objects
82
Q

What is the rule for static and non static accessibility

A

A static thing cannot access a non-static thing

83
Q

What are the restrictions on public modifier?

A

Class or member can be accessed from anywhere, no restrictions

84
Q

What are the restrictions on a private modifier?

A

Means that a member can’t be accessed from anywhere outside the class

85
Q

What are the restrictions of a protected modifier?

A

Means that a member can only be accessed from the defining class, package or subclass

86
Q

When should you use a final modifier?

A

To declare a field to be constant

87
Q

What is a constructor?

A

A special method that is executed when an object is created

88
Q

What are some properties of a constructor?

A
  • can initialise the object as required
  • can take parameters, like methods
  • doesn’t return any results
  • always has the same name as the class
89
Q

What is a default constructor?

A

Simple constructor defined automatically if we don’t write any more constructors
Creates instance and fills in default attribute values

90
Q

How do you link constructors?

A

Using the this keyword

91
Q

What is method overloading?

A

Methods with the same name but different parameters

92
Q

When is method overloading useful?

A

When methods are closely related in purpose

93
Q

What is an array?

A

Special java object that contains a collection of values

94
Q

How are arrays declared?

A

The name of the type followed by square brackets

95
Q

Declare an array of integers

A

int[] myArray;

96
Q

Give a disadvantage of arrays

A

Have to know how many elements at the time of writing program

97
Q

At what number do array indexes start?

A

0

98
Q

What index place would the nth element have?

A

n-1

99
Q

What are magic constants?

A

Literal constants embedded in the program

100
Q

What are the solutions for magic constants?

A

Make constants with a name

101
Q

How are final variables conventionally written?

A

In all UPPERCASE

102
Q

Write the syntax for an enhanced for loop

A

for(int item: numbers)

system.out.println(“Count is “ + item);

103
Q

What does item take the value of in the enhanced for loop

A

Next value in the array

104
Q

Give a benefit and a disadvantage of the enhanced for loop

A

More elegant - avoids the need for an explicit counter variable and test
Little less flexible

105
Q

How are parameters passed in Java?

A

By value, the parameter is treated just like a variable defined within the method

106
Q

Define a 2D array

A

A 2D array is an array of arrays

107
Q

What is a model

A

An abstract representation of a scenario/entity/concept

108
Q

What are some benefits of modelling?

A

Easier to

  • understand
  • find errors
  • communicate
109
Q

What are we interested in object orientated models?

A

Information to be stored

Operations on information

110
Q

What is the difference between a model and a program?

A

Different levels of abstraction

111
Q

What is the point of building a software model?

A

Too big an abstraction gap between specification and code, especially for large and complex problems

112
Q

What does UML stand for?

A

Unified Modelling Language

113
Q

Give some examples of UML diagram types?

A

Class, object, use case, sequence

114
Q

What is a program in an object orientated language?

A
Set of class definitions
At least one class with a main method
115
Q

What do UML diagrams contain information about?

A

Attributes
Operations
Relationships with other classes

116
Q

What are inline attributes?

A

When there is an attribute in the class diagram with the type and not a relationship arrow

117
Q

What are multiplicities?

A

Way to specify how many instances may be associated

118
Q

Where is the number in the multiplicities?

A

Each end of association

119
Q

What does navigability indicate?

A

Whether instances of a class know about instances of associated class

120
Q

What does # stand for in modifiers?

A

Protected

121
Q

How are static modifiers denoted in UML?

A

Underline attribute and method names

122
Q

What are the steps in the modelling process?

A

Determine classes
Determine fields
Determine methods and parameters
Determine relationships between classes

123
Q

What is a UML object diagram?

A

Shows a snapshot of computer memory at a particular point during execution

124
Q

What does the subclass inherit from?

A

Superclass

125
Q

What is inheritance?

A

Relationship between classes where attributes are inherited from a superclass to a subclass

126
Q

Give an example of a relationship that may have inheritance involved

A

Pet - Dog, with Pet being the superclass and Dog being the subclass

127
Q

Give a rule about inheritance

A

A subclass can only inherit directly from one superclass

128
Q

What is the default superclass if none is specified

A

Object

129
Q

What keyword is used for calling the constructor in a superclass

A

Super

130
Q

What is the basic idea of substitutability?

A

You can use an instance of a subclass anywhere that an instance of its superclass would be valid

131
Q

What is an advantage of using inheritance?

A

Avoids redefining duplicate versions of fields and methods

132
Q

What is overriding?

A

Redefining a method in a subclass is called overriding

133
Q

What must be the same in a method when it is overriding?

A

Parameters and return type

134
Q

What is overloading?

A

Means defining more than one version of a method within a class

135
Q

What is different between each overloaded method?

A

Different parameters

136
Q

What type of classes CANNOT BE EXTENDED

A

Final

137
Q

What types of methods cannot be overridden?

A

Final

138
Q

What is late binding?

A

May have a variable/parameter referring to an object whose type we don’t know until runtime

139
Q

How can we deal safely with late binding?

A

Check using instanceof

140
Q

What are the values of b and a after this code?
int a = 1;
int b = a++;

A

b == 1

a == 2

141
Q

What are the values of a and b after the following code?
int a = 1;
int b = ++a;

A

a == 2

b == 2

142
Q

What is an abstract class?

A

An abstract class is a class that cannot be instantiated but is still useful in structuring the inheritance hierarchy

143
Q

Give an example of a potential abstract class?

A

Mammal

Person

144
Q

How do you declare an abstract class?

A

public abstract class Fish{

}

145
Q

What types of methods can abstract classes contain?

A

Methods with implementation

Methods without implementation

146
Q

What must happen when writing a class that extends an abstract class

A

Programmer must implement ALL of the abstract methods declared in the abstract class UNLESS the class itself is declared as abstract

147
Q

How does Java accomplish multiple inheritance?

A

Interfaces

148
Q

What are interfaces?

A

Contracts for how different parts of software may interact with one another

149
Q

What can interfaces contain in java?

A

Constants
Method headers
Static methods

150
Q

Can you make instances of Interface

A

No

151
Q

Write code for declaring an interface?

A

public interface IPerson{

}

152
Q

All methods declared in an interface are implicitly ___?

A

public

153
Q

Give some benefits of interfaces

A

Abstraction
- can write code that uses objects without knowing exactly what class they belong to
Combining code written by different people at different times

154
Q

Give an example of code where the class MyClass inherits interface 1 and interface 2

A

public class MyClass implements Interface1, Interface2 {…}

155
Q

What will happen if you have a class that inherits two interfaces which both have contain constants with the same identifier

A

There will be an error

156
Q

When do we use abstract classes?

A

Sharing code among closely related classes
Many common methods or fields
Need non-static or non-final fields

157
Q

When do we use interfaces?

A

Unrelated classes implement same methods
Specify behaviour but do not care who implements it
For multiple inheritance