Exam 1 Flashcards

1
Q

Java is a fully ___.

A

Object-oriented language

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

High-level languages

A

Python/Java -meant for humans

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

Machine code

A

Low-level code that can be executed on a computer

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

Bytecode

A

Between high and low level code-easier to interpret into machine instructions

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

Interprets bytecode into machine code

A

Virtual machine -different ones needed for different OS

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

All Java programs require ___

A

Scaffolding -all code must be in body of a class

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

Static

A

Marks a method or field as belonging to the class it’s in -can be accessed without creating an object

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

Public

A

Accessible from anywhere outside the class

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

All strings must be enclosed in ___

A

Double-quotes

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

Maven

A

Organizers, compiles, and runs code.

Manages third-party dependencies by downloading from Internet

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

Java is a ___ typed language

A

Statically

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

To create a long or float (instead of int or double)

A

Add l or f to end of number

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

Primitive types

A

Integers, floats, characters, booleans

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

Reference types

A

Strings, arrays, objects

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

T/F: Any type can be concatenated to a string

A

True, using +

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

Result of arithmetic operators using both an int and a float

A

Float -more complex type

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

T/F: Strings are iterable

A

False
Also can’t use []. Must use charAt(int index) to find char

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

T/F: Java supports negative indexes

A

False. Index from 0 to length - 1

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

String literal pool

A

If same string literal used in multiple places, single copy stored and reused

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

All functions in Java are __

A

Methods

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

Assigning the return value of a void method to a variable results in a ___

A

Compiler error

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

T/F: A void method can return an empty (return;)

A

True

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

Except for void methods, all branches of a method must terminate with a ___ statement

A

Return

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

Structure of a for statement

A

Initialization -executed exactly once
Boolean expression - evaluated before each iteration
Modification statement -executed after each iteration

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

Safe type converting

A

Less complex type to more complex. No loss of data

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

Conversion of types can be forced using ___

A

Casting: int x = (int) 3356787645754;

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

Scanner

A

Package to read input.
next() next word entered until whitespace
nextLine() everything up to enter key
nextInt(), long, float…

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

Arrays are allocated as a __ block of memory

A

Contiguous

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

How to initialize an array

A

Integers = new int[10]

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

Array default values

A

0 for numeric types (including char),
False for booleans,
Null for reference types

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

2D arrays

A

Array of arrays, first dimension values are just addresses to other arrays

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

T/F: in try/catch, catch doesn’t need to specify the exception being caught

A

False

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

Methods available from creating file instance JUST using the File class constructor

A

exists -if file exists at path
IsDirectory - returns if file if a directory
getAbsolutePath
length -number of bytes

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

To read character data from text, the __ and __ packages are needed

A

FileReader and BufferedReader

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

Scanner, FileReader, and BufferedReader should be ___ when finished with

A

Closed. close()

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

How to handle checked exceptions

A

Using try/catch

Rethrowing by adding a throws declaration (string readline() throws IOException

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

T/F: Unlike unchecked exceptions, checked exceptions must be handled

A

True

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

Nearly all methods for reading data from files can throw a ___

A

IOException

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

Packages to write to files

A

FileWriter and PrintWriter

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

How to write to a file

A

[writer object].print(…) for a string
[writer object].println(…) for string with newline
[writer object].flush() pushes changes

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

Process that opens and maintains lock on file until close

A

Try-with-resources

42
Q

T/F: try-with-resources must have a catch block

A

False. If one is used, resources closed after. If omitted, checked exceptions will need to be rethrown.

43
Q

A class is like a ___.

A

Blueprint. Tells how to build, but can’t be used directly

44
Q

Construction of an object

A

Instantiation

45
Q

When object made, space for attributes are ___

A

Allocated in memory

46
Q

Java Package

A

Namespace used to group related classes together

47
Q

Scope of local variable

A

Block of code where it was defined

48
Q

Scope of a field and method

A

Entire class it is declared in

49
Q

Package scope

A

Classes within same package are visible to each other. Outside classes must import

50
Q

T/F: All classes have a constructor even if not defined

A

True. All fields will be assigned values using a default constructor

51
Q

Reference field of an instance of a class

A

this

52
Q

T/F: Java has default parameter values

A

False

53
Q

Java allows multiple methods to have same name as long as the ___ are different

A

Parameter lists

54
Q

Overloading

A

Having two methods with same name in same class

55
Q

Objects act like containers that hold their states and behaviors together in one, cohesive unit

A

Encapsulation

56
Q

Protected

A

Grants access to classes in same package and child classes

57
Q

Private

A

Grants access to objects of same class

58
Q

Data privacy

A

Protecting fields from being manipulated by other parts of the program

59
Q

Fields should be ___ and accessed via ___ methods

A

Private, public

60
Q

T/F: Accessors and Mutators should always be written

A

False. Only when needed by other parts of program.

61
Q

T/F: Accessors are common in complex enums

A

True

62
Q

Replacing an existing method with another implementation

A

Overriding

63
Q

== compares two values for ___

A

Shallow equality. Primitive if values are same. Objects if addresses are same

64
Q

equals(Object) used to compare for ___

A

Deep equality. Will return if they are the same object. Can be overridden. Should be used on strings.

65
Q

Returns an array of enumerated values

A

Enumerated.values()

66
Q

T/F: A method that uses static can only directly access other static methods/fields

A

True

67
Q

Static should mainly be used for___

A

Main and creating constants

68
Q

Final

A

Indicates that a variable value may never be changed.
Value MUST be assigned in constructor or when field declared. Won’t compile otherwise

69
Q

A variable that is predefined, static, and final

A

Constant

70
Q

UML

A

Unified Modeling Language

71
Q

In UML, the arrow points __ the class that is used.

A

To. e.g. pet with species field uses species enum. Points towards species.

72
Q

I’m UML, no arrow indicates the relationship is ___

A

Undirected. Both classes use each other.

73
Q

In UML, a dashed line

A

A weaker dependency. One class uses another, but its field isn’t made up of the other class. (Method may use other class as a parameter)

74
Q

JavaDoc should be used to document…

A

Classes and any public fields, methods, and constructors

75
Q

Remove whitespace from ends of a string

A

trim()

76
Q

Split string into tokens

A

split(regex)
“” Will split into individual characters
“ “ Will split on spaces

77
Q

Random

A

Used to generate pseudorandom numbers

78
Q

Every reference type in Java is related to ___

A

Object. Instances of any class can be used as arguments or return values when Object is declared as type.

79
Q

One class may ____ another class to inherit its accessible state and behavior

A

Extend. Creates a parent/child or superclass/subclass relationship

80
Q

Abstraction

A

Process of identifying common state and behavior and putting it into a parent class

81
Q

T/F: child classes inherit constructors of parent

A

False. Must define its own

82
Q

T/F: An instance of child can be used wherever parent is expected

A

True

83
Q

In UML, a ___ arrow points ____ the parent class

A

Closed, unfilled; towards (child dependent on)

84
Q

An object uses ___ to access state/behavior of parent class

A

super

85
Q

A child classes can override the method of a parent by defining a new method with ___

A

The exact same signature. Child’s version will be used. super.method() can be used if parent’s needed

86
Q

Polymorphism

A

Child classes inherit all states and behaviors of parent class
AND
if child used in place of parent and it has overriding methods, the child’s version will be used

87
Q

Abstract methods

A

Can only exist in abstract classes and interface, and must be implemented in child classes that extend/implement them

88
Q

T/F: Trying to instantiate an abstract classes will cause a compiler error

A

True

89
Q

An abstract class can have ___ and ___ methods

A

Concrete and abstract

90
Q

“clean sheet coding”

A

Writing code in empty file with little thought to upfront design

91
Q

Prefix notation

A

Operator precedes its operand

92
Q

Unary expression

A

An operator and exactly one other expression. Expression evaluated first then operator applied. ++ 5

93
Q

Binary expression

A

Operator and exactly 2 other expressions. Both expressions evaluated, then operator applied. + 4 5

94
Q

T/F: An interface is used when there is no state and only abstract behavior

A

True

95
Q

Given the choice, which is better for its polymorphism potential: abstract classes or interfaces?

A

Interfaces

96
Q

T/F: Interfaces may include static state and behavior

A

True

97
Q

A class that implements an interface establishes an ___

A

Inheritance relationship

98
Q

Public and abstract modifiers are ___ in non-static behavior in interfaces

A

Optional. And probably should be left off.

99
Q

T/F: Abstract classes that are children of other abstract classes MUST implement their abstract methods

A

False. Can continue to pass them down without implementation.

100
Q

In UML, relationships with interfaces are represented with a ___

A

Dashed line