Chapter 1 Flashcards

1
Q

Constructors

A

There are two key points to note about the constructor: the name of the constructor matches the name of the class, and there’s no return type.

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

The rules for what a Java code file contains

A

■ Each file can contain only one class.

■ The filename must match the class name, including case, and have a .java extension.

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

A value is assigned to a reference in one of two ways:

A

■ A reference can be assigned to another object of the same type.

■ A reference can be assigned to a new object using the new keyword.

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

important differences you should know between primitives and reference types.

A

First, reference types can be assigned null, which means they do not currently refer to an object. Primitive types will give you a compiler error if you attempt to assign them null.

Next, reference types can be used to call methods when they do not point to null. Primitives do not have methods declared on them. Primitives do not have methods.

Finally, notice that all the primitive types have lowercase type names. All classes that come with Java begin with uppercase.

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

Three rules to remember for legal identifiers:

A
  • The name must begin with a letter or the symbol $ or _.
  • Subsequent characters may also be numbers.
  • You cannot use the same name as a Java reserved word
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Rule for instance variables

A

they are available as soon as they are defined and last for the entire lifetime of the object itself.

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

The rule for class (static) variables

A

they go into scope when declared like the other variables types. However, they stay in scope for the entire life of the program.

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

The rules on scope: (Local, instance, and class variables)

A

Local variables—in scope from declaration to end of block

Instance variables—in scope from declaration until object garbage collected

Class variables—in scope from declaration until program ends

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

PIC

A

Package declaration- Required? - No
Import statements - Required? - No
Class declaration - Required? - YES

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

_______ ________ can be defined in the same file, but only ___ of them is allowed to be public

A
  • multiple classes
  • one
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

A file is also allowed to have _______ class be public. As long as there isn’t more than ___ public class in a file, it is okay.

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

System.gc()

A

Is not guaranteed to run, and you should be able to recognize when objects become eligible for garbage collection.

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

An object is no longer reachable when one of two situations occurs

A
  • The object no longer has any references pointing to it.
  • All references to the object have gone out of scope.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

finalize()

A

Could run zero or one time.

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

Benefits of Java

A
  • Object Oriented
  • Encapsulation
  • Platform Independent
  • Robust
  • Simple
  • Secure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly