Exam 1 Flashcards

(100 cards)

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
Safe type converting
Less complex type to more complex. No loss of data
26
Conversion of types can be forced using ___
Casting: int x = (int) 3356787645754;
27
Scanner
Package to read input. next() next word entered until whitespace nextLine() everything up to enter key nextInt(), long, float...
28
Arrays are allocated as a __ block of memory
Contiguous
29
How to initialize an array
Integers = new int[10]
30
Array default values
0 for numeric types (including char), False for booleans, Null for reference types
31
2D arrays
Array of arrays, first dimension values are just addresses to other arrays
32
T/F: in try/catch, catch doesn't need to specify the exception being caught
False
33
Methods available from creating file instance JUST using the File class constructor
exists -if file exists at path IsDirectory - returns if file if a directory getAbsolutePath length -number of bytes
34
To read character data from text, the __ and __ packages are needed
FileReader and BufferedReader
35
Scanner, FileReader, and BufferedReader should be ___ when finished with
Closed. close()
36
How to handle checked exceptions
Using try/catch Rethrowing by adding a throws declaration (string readline() throws IOException
37
T/F: Unlike unchecked exceptions, checked exceptions must be handled
True
38
Nearly all methods for reading data from files can throw a ___
IOException
39
Packages to write to files
FileWriter and PrintWriter
40
How to write to a file
[writer object].print(...) for a string [writer object].println(...) for string with newline [writer object].flush() pushes changes
41
Process that opens and maintains lock on file until close
Try-with-resources
42
T/F: try-with-resources must have a catch block
False. If one is used, resources closed after. If omitted, checked exceptions will need to be rethrown.
43
A class is like a ___.
Blueprint. Tells how to build, but can't be used directly
44
Construction of an object
Instantiation
45
When object made, space for attributes are ___
Allocated in memory
46
Java Package
Namespace used to group related classes together
47
Scope of local variable
Block of code where it was defined
48
Scope of a field and method
Entire class it is declared in
49
Package scope
Classes within same package are visible to each other. Outside classes must import
50
T/F: All classes have a constructor even if not defined
True. All fields will be assigned values using a default constructor
51
Reference field of an instance of a class
this
52
T/F: Java has default parameter values
False
53
Java allows multiple methods to have same name as long as the ___ are different
Parameter lists
54
Overloading
Having two methods with same name in same class
55
Objects act like containers that hold their states and behaviors together in one, cohesive unit
Encapsulation
56
Protected
Grants access to classes in same package and child classes
57
Private
Grants access to objects of same class
58
Data privacy
Protecting fields from being manipulated by other parts of the program
59
Fields should be ___ and accessed via ___ methods
Private, public
60
T/F: Accessors and Mutators should always be written
False. Only when needed by other parts of program.
61
T/F: Accessors are common in complex enums
True
62
Replacing an existing method with another implementation
Overriding
63
== compares two values for ___
Shallow equality. Primitive if values are same. Objects if addresses are same
64
equals(Object) used to compare for ___
Deep equality. Will return if they are the same object. Can be overridden. Should be used on strings.
65
Returns an array of enumerated values
Enumerated.values()
66
T/F: A method that uses static can only directly access other static methods/fields
True
67
Static should mainly be used for___
Main and creating constants
68
Final
Indicates that a variable value may never be changed. Value MUST be assigned in constructor or when field declared. Won't compile otherwise
69
A variable that is predefined, static, and final
Constant
70
UML
Unified Modeling Language
71
In UML, the arrow points __ the class that is used.
To. e.g. pet with species field uses species enum. Points towards species.
72
I'm UML, no arrow indicates the relationship is ___
Undirected. Both classes use each other.
73
In UML, a dashed line
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
JavaDoc should be used to document...
Classes and any public fields, methods, and constructors
75
Remove whitespace from ends of a string
trim()
76
Split string into tokens
split(regex) "" Will split into individual characters " " Will split on spaces
77
Random
Used to generate pseudorandom numbers
78
Every reference type in Java is related to ___
Object. Instances of any class can be used as arguments or return values when Object is declared as type.
79
One class may ____ another class to inherit its accessible state and behavior
Extend. Creates a parent/child or superclass/subclass relationship
80
Abstraction
Process of identifying common state and behavior and putting it into a parent class
81
T/F: child classes inherit constructors of parent
False. Must define its own
82
T/F: An instance of child can be used wherever parent is expected
True
83
In UML, a ___ arrow points ____ the parent class
Closed, unfilled; towards (child dependent on)
84
An object uses ___ to access state/behavior of parent class
super
85
A child classes can override the method of a parent by defining a new method with ___
The exact same signature. Child's version will be used. super.method() can be used if parent's needed
86
Polymorphism
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
Abstract methods
Can only exist in abstract classes and interface, and must be implemented in child classes that extend/implement them
88
T/F: Trying to instantiate an abstract classes will cause a compiler error
True
89
An abstract class can have ___ and ___ methods
Concrete and abstract
90
"clean sheet coding"
Writing code in empty file with little thought to upfront design
91
Prefix notation
Operator precedes its operand
92
Unary expression
An operator and exactly one other expression. Expression evaluated first then operator applied. ++ 5
93
Binary expression
Operator and exactly 2 other expressions. Both expressions evaluated, then operator applied. + 4 5
94
T/F: An interface is used when there is no state and only abstract behavior
True
95
Given the choice, which is better for its polymorphism potential: abstract classes or interfaces?
Interfaces
96
T/F: Interfaces may include static state and behavior
True
97
A class that implements an interface establishes an ___
Inheritance relationship
98
Public and abstract modifiers are ___ in non-static behavior in interfaces
Optional. And probably should be left off.
99
T/F: Abstract classes that are children of other abstract classes MUST implement their abstract methods
False. Can continue to pass them down without implementation.
100
In UML, relationships with interfaces are represented with a ___
Dashed line