Ch1: Java Building Blocks Flashcards

(76 cards)

1
Q

What can identifier names start with?

A

A letter, an underscore, or a dollar sign

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

Identifier names can have which characters?

A

A letter, an underscore, or a dollar sign. Subsequent characters may also have numbers.

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

What is an object?

A

A runtime instance of a class in memory

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

What are class methods called in other languages?

A

Functions or Procedures

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

What is the Java term for a function or procedure in a class?

A

A method

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

What are we referring to when we talk about the members of a class?

A

Methods and fields

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

What is the general term for methods and fields in a class?

A

Members

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

What is another word for a field in a class?

A

Instance variable

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

What is another word for a class or instance level variable?

A

field

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

What is the method signature for a program entry point? (The “Main” method)

A

public static void main(String[] args)

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

For the program entry point, is the Main method uppercase or lowercase?

A

Lowercase:

public static void main(String[] args)

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

What is the command to compile a file called “zoo.java”?

A

javac zoo.java

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

What is the command to run the class file “zoo.class”?

A

java zoo

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

Which class is always imported by default?

A

java.lang.*

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

How do you specify other class paths when running a java program?

A

java -cp “.:/path1/foo.jar:/path2/*” myPackage.MyClass

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

What is an Instance Initializer?

A

A code block ( {..} ) outside of a method, but inside of a class.

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

When an object is created, what is the order of initialization?

A
  1. Static fields and static initializers, in order
  2. Instance variables and instance initializers, in order
  3. Constructors
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the two types of data containers in Java?

A

Primitive types and reference types

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

List all primitive type keywords

A
boolean
byte
short
int
long
float
double
char
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is byte?

A

8-bit integral value

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

What is short?

A

16-bit integral value

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

what is int?

A

32-bit integral value

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

what is long?

A

64-bit integral value

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

what is float?

A

32-bit floating-point value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
what is double?
64-bit floating-point value
26
what is char?
16-bit Unicode value
27
What is boolean?
true or false
28
What is an example of a floating point literal?
123.45f
29
In order of size, what are the integral primitives?
byte > short > int > long
30
In order of size, what are the floating-point primitives?
float > double
31
What range of values can a byte hold?
-128 to 127
32
What data type is used for integral numeric literals?
int
33
How do you specify a numeric literal should be a long?
Add an L to the end (123L)
34
What number bases can we specify for numeric literals?
Decimal (default), Octal, Hexadecimal, Binary
35
How do you specify a numeric literal is octal?
Lead with a zero (eg, 0123)
36
How do you specify a numeric literal is hex?
Lead with zero and x/X (eg, 0xFF)
37
How do you specify a numeric literal is binary?
Lead with a zero and b/B (eg, 0b10)
38
What is the rule for underscores in numeric literals?
Underscores must have a number on both sides (eg, 1_000.75)
39
How do you initialize multiple variables on the same line?
String s1 = "foo", s2 = "bar";
40
What is a local variable?
A variable defined within a method
41
What is the result of trying to use a local variable before it is initialized?
An error is thrown
42
What is a reference type variable?
A pointer to an object in memory
43
What is the result of trying to use an instance variable before it is initialized?
The action will be taken on the default value
44
What is the result of trying to use a class variable before it is initialized?
The action will be taken on the default value
45
What is an instance variable?
A variable defined within a class, but outside of a method.
46
What is a class variable?
A variable defined within a class with the static keyword.
47
What's another word for a field in a class?
instance variable
48
What is the default value for instance variables of type boolean?
false
49
What is the default value for instance variables of numeric types?
0 or 0.0
50
What is the default value for instance variables that are object references?
null
51
What is the default value for instance variables of type char?
NUL
52
What is the default value for class (static) variables of type boolean?
false
53
What is the default value for class (static) variables of numeric types?
0 or 0.0
54
What is the default value for class (static) variables of object references?
null
55
What is the default value for class (static) variables of type char?
NUL
56
What is the default value for local variables of type boolean?
Garbage
57
What is the default value for local variables of numeric types?
Garbage
58
What is the default value for local variables of object references?
Garbage
59
What is the default value for local variables of type char?
Garbage
60
What order should elements be within a class?
1. Package declaration 2. Import statements 3. Class declaration * Field declarations and Method declarations can be anywhere within the "class" code block
61
Where are java objects stored in memory?
On the heap
62
What is another term for heap memory?
Free store
63
What is another term form free store memory?
Heap memory
64
Which method triggers garbage collection?
System.gc()
65
What is the signature of the method that is ran when an object is garbage collected?
protected void finalize()
66
What is the finalize() method?
A method that is run when an object is garbage collected
67
How many times will finalize() run?
No more than once, potentially never. (0 or 1 times)
68
What are the benefits of Java?
* Object Oriented (uses classes) * Encapsulated (uses access modifiers) * Platform Independent (compile once, run anywhere) * Robust (Managed memory - no pointers) * Simple (Easier than C++ - no pointers, no operator overloading) * Secure (Sandboxed inside JVM)
69
What data type is used for floating-point numeric literals?
double
70
What is an example of an int literal?
123
71
What is an example of a long literal?
123L
72
What is an example of a float literal?
123.45F
73
What is an example of a double literal?
123.45
74
What data type is used for integral literals?
int
75
What data type would the literal 123 be?
int
76
What data type would the literal 123.45 be?
double