Java Basics Flashcards

1
Q

Java 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
2
Q

Class’s elements

A

Fields & methods

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

How many public classes a file can have?

A
  1. Each file can contain only one public class

2. The file name 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
4
Q

What is the main method structure?

A

public static void main(String [] args)
public static void main(String args [])
public static void main(String… args)
public static final void main(String [] args)

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

package

A

A grouping of classes, interfaces, enumerations, and annotated types.

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

What is the package that is automatically imported?

A

java.lang

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

What are imports needed for?

A

Imports are needed to be able to reference an external class.

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

default package

A

An unnamed package used when no package statement is present in the code. This is a special unnamed package that you should use only for throwaway code

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

What are wildcards used for?

A
Wildcards (*) are used to import all the classes from the a package. Importing all the classes in a package vs just the class that is going to be used does not slow down the program. Listing each of the classes makes the code easy to read. Using the wildcard can shorten the import list.
Only one (at the end) is permited in an import.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Imports precedence explicit vs wildcard

A

Explicit import takes precedence over any wildcards.

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

package compilation errors

A

package error on runtime only;

import at compile time.

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

class structure

A
package.
imports.
class declaration.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

bytecode

A

Compiled Java code. Bytecode appears in files with the .class extension.

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

What is the purpose of a constructor?

A

The purpose of the constructor is to initialize fields, although you can put any code in there.

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

Constructor return type

A

It has no return type.

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

Instance initializer

A

code block outside methods.

17
Q

Order of initialization

A

Fieds and instance initilizer blocks are run in the order in wich they appear in the file.
The constructor runs after above have run.

18
Q

What is a default constructor?

A

default constructor is the one that is not provided by the user but by the jvm.