Chapter 1 Java Building Blocks Flashcards

1
Q

What should be the name of the java class files ?

A

If you do have a public class, it needs to match the file name, including case. public class Animal2 would not compile in a file named Animal.java

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

What styles of comment you know in Java ?

A

There are three styles of comment: a single-line comment
(//), a multiline comment (/* */), and a Javadoc comment (/** */).

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

What does it mean when an import ends with wildcard (*) ?

A

A wildcard ending an import statement means you want
to import all classes in that package. It does not include packages that are inside that one.

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

What is java.lang ?

A

Special package that is automatically imported. You can still type this package in an import
statement, but you don’t have to.

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

What is initialized first when an object is instantiated (fields, blocks, constructor)?

A

When an object is instantiated, fields and blocks of code are
initialized first. Then the constructor is run.

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

Numeric literals are allowed to begin with.. ?

A

Numeric literals are allowed to begin with 0 (octal), 0x (hex), 0X (hex),
0b (binary), or 0B (binary). Numeric literals are also allowed to contain underscores as long as they are directly between two other numbers.

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

Which variable are initialized automatically and which not ?

A

Variables that represent fields in a class are automatically initialized to their corresponding “zero” or null value during object instantiation. Local variables must be specifically initialized.

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

What are the types of variables depending on their scope ?

A

Scope refers to that portion of code where a variable can be accessed. There are three kinds of variables in Java, depending on their scope: instance variables, class variables, and local variables. Instance variables are the nonstatic fields of your class. Class variables are the static fields within a class. Local variables are declared within a method.

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

Class elements order is… ?

A

For some class elements, order matters within the file. The package statement comes first if present. Then comes the import statements if present. Then comes the class declaration. Fields and methods are allowed to be in any order within the class.

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

When an object is eligible for garbage collection ?

A

An object becomes eligible for garbage collection when there are no more references to it or its references have all gone out of scope.

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

Which of the following are valid Java identifiers:

java.lang

Public

A
  • java lang is not valid because the dot (.) is not allowed in identifiers;
  • Java is case sensitive, so Public is not a reserved word and therefore a valid identifier;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly