Chapter1 Flashcards

1
Q

Name primitive types in relative order:

A

Boolean, byte(8bit), short, Int, long, float(32bit), double(64bit), char(16bit)

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

long max = 312456789;

Does not compile. Why?

A

Needs ‘L’ on literal.

long max = 312456789L;

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

int i1, i2, i3 = 0;

How many declared?
How many initialized?

A

3 declared.

1 initialized.

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

Three rules for legal identifiers:

A

Must begin with letter, $ or _.
Subsequent characters may be numbers.
No reserved words (although different case technically allowed)

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

Local, instance and class variables? Difference between?

A

Local is in a method.
Instance is a field in a class.
Class variable shared across multiple objects using static.

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

Defaults for Boolean, byte, Int, float, double, char, objects

A

False, byte:0, Int:0, float:0.0, double:0.0, char:’\u0000’, object:null

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

Order of initialisation?

A

Fields and instance blocks run in order in which they appear. Then constructor runs.

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

A byte can God a value from …?

A

-128 to 127. A byte is 8 bits. A bit has two possible values. So 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 = 256. 0 needs to be included.

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

Name 3 other base numbers Java recognizes:

A

Octal 017
Hexadecimal 0xFf
Binary 0b10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
Which are valid?
boolean b1, b2;
String s1 = "1", s2;
double d1, double d2;
Int i1; int i2;
int i3; i4;
A
Legal
Legal
Not legal
Legal
Not legal
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Order of elements in a class… ie methods, import statements etc

A
Package declaration, import statements, class declaration, field and methods.
Only class declaration is required
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How many classes can there be in a file? Other rules?

A

Multiple. But only one must be public. Both can be not public. Also one must be named after file.

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

Rules about garbage collection?

A

Calling System.gc doesn’t guarantee garbage collection. An object remains on heap until it is no longer reachable: no references or all references gone out of scope.

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

finalize()?

A

Gets called if the garbage collector tries to collect object. Can run zero or one time.

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

Java is an interpreted language, it gets compiled to…

A

bytecode (a .class file). The same class files run everywhere.

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

Java is robust, why?

A

Manage memory on it’s own, automatic garbage collection, prevents memory leaks. C++ doesn’t.

17
Q

Java code runs inside…

A

The JVM. Makes it safe so code doesn’t do bad things to computer.

18
Q

Which variables must be initialized before use?

A

Local variables must be initialized. Instance an class do not need o e initialized.

19
Q

Does Java have operator overloading and pointers?

A

No.

20
Q

Is Java a functional programming language?

A

No. Object oriented.