Ch1: Java Building Blocks Flashcards

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
Q

what is double?

A

64-bit floating-point value

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

what is char?

A

16-bit Unicode value

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

What is boolean?

A

true or false

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

What is an example of a floating point literal?

A

123.45f

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

In order of size, what are the integral primitives?

A

byte > short > int > long

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

In order of size, what are the floating-point primitives?

A

float > double

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

What range of values can a byte hold?

A

-128 to 127

32
Q

What data type is used for integral numeric literals?

A

int

33
Q

How do you specify a numeric literal should be a long?

A

Add an L to the end (123L)

34
Q

What number bases can we specify for numeric literals?

A

Decimal (default), Octal, Hexadecimal, Binary

35
Q

How do you specify a numeric literal is octal?

A

Lead with a zero (eg, 0123)

36
Q

How do you specify a numeric literal is hex?

A

Lead with zero and x/X (eg, 0xFF)

37
Q

How do you specify a numeric literal is binary?

A

Lead with a zero and b/B (eg, 0b10)

38
Q

What is the rule for underscores in numeric literals?

A

Underscores must have a number on both sides (eg, 1_000.75)

39
Q

How do you initialize multiple variables on the same line?

A

String s1 = “foo”, s2 = “bar”;

40
Q

What is a local variable?

A

A variable defined within a method

41
Q

What is the result of trying to use a local variable before it is initialized?

A

An error is thrown

42
Q

What is a reference type variable?

A

A pointer to an object in memory

43
Q

What is the result of trying to use an instance variable before it is initialized?

A

The action will be taken on the default value

44
Q

What is the result of trying to use a class variable before it is initialized?

A

The action will be taken on the default value

45
Q

What is an instance variable?

A

A variable defined within a class, but outside of a method.

46
Q

What is a class variable?

A

A variable defined within a class with the static keyword.

47
Q

What’s another word for a field in a class?

A

instance variable

48
Q

What is the default value for instance variables of type boolean?

A

false

49
Q

What is the default value for instance variables of numeric types?

A

0 or 0.0

50
Q

What is the default value for instance variables that are object references?

A

null

51
Q

What is the default value for instance variables of type char?

A

NUL

52
Q

What is the default value for class (static) variables of type boolean?

A

false

53
Q

What is the default value for class (static) variables of numeric types?

A

0 or 0.0

54
Q

What is the default value for class (static) variables of object references?

A

null

55
Q

What is the default value for class (static) variables of type char?

A

NUL

56
Q

What is the default value for local variables of type boolean?

A

Garbage

57
Q

What is the default value for local variables of numeric types?

A

Garbage

58
Q

What is the default value for local variables of object references?

A

Garbage

59
Q

What is the default value for local variables of type char?

A

Garbage

60
Q

What order should elements be within a class?

A
  1. Package declaration
  2. Import statements
  3. Class declaration
    * Field declarations and Method declarations can be anywhere within the “class” code block
61
Q

Where are java objects stored in memory?

A

On the heap

62
Q

What is another term for heap memory?

A

Free store

63
Q

What is another term form free store memory?

A

Heap memory

64
Q

Which method triggers garbage collection?

A

System.gc()

65
Q

What is the signature of the method that is ran when an object is garbage collected?

A

protected void finalize()

66
Q

What is the finalize() method?

A

A method that is run when an object is garbage collected

67
Q

How many times will finalize() run?

A

No more than once, potentially never. (0 or 1 times)

68
Q

What are the benefits of Java?

A
  • 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
Q

What data type is used for floating-point numeric literals?

A

double

70
Q

What is an example of an int literal?

A

123

71
Q

What is an example of a long literal?

A

123L

72
Q

What is an example of a float literal?

A

123.45F

73
Q

What is an example of a double literal?

A

123.45

74
Q

What data type is used for integral literals?

A

int

75
Q

What data type would the literal 123 be?

A

int

76
Q

What data type would the literal 123.45 be?

A

double