chapter 1 Flashcards

1
Q

What are 8 benefits of Java?

A
  1. Object Oriented
  2. Encapsulation
  3. Platform Independent
  4. Robust
  5. Simple
  6. Secure
  7. Multithreaded
  8. Backward Compatibility
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the the basic building blocks in java programs?

A

classes

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

What is an oject?

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 is a reference?

A

A variable that points to an object.

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

What are the two primary elements of a class in Java?

A

methods and fields (variables).

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

What makes up a method signature?

A

method name and parameter types.

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

What makes up a method declaration?

A

method name, parameter types, and return type.

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

Describe three different types of comments in java.

A
single line comment
// comment 
multi line comments
/**/
or
/**
 * Java Doc comment
 */
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Where does a Java program begin execution?

A

the main()

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

What must a file have to compile Java code?

A

A .java file extension and a filename that matches the class name.

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

What is the result of compiling a .java file?

A

A file of bytecode by the same name but with a .class extension.

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

How many public classes are allowed in a file?

A

one.

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

What is the syntax for the single-file source-code-command?

A

java HelloWorld.java

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

What is the single-file source-code-command

A

Command to run java programs that exist in a single file.

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

Does the single-file source-code-command produce a .class file?

A

No, the program is contained in memory.

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

What are the constraints placed on programs run with the single-file source-code-command?

A

They are for programs with only one class.

Can only import code that came with the JDK.

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

What are packages?

A

Logical groupings of classes.

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

What do import statements do?

A

Tell java which package to look in for a class.

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

How do you know a package comes from the JDK?

A

The package name starts with java or javax.

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

What is the “*” in the context of importing packages in Java?

A

A wildcard that matches all classes in a package.

21
Q

What is the one package that is automatically imported in Java?

A

java.lang.

22
Q

Is it required to import a class that is in the same package?

A

No, Java automatically looks in the current package for other classes.

23
Q

How do you resolve two package imports with wildcards where there are class name conflicts? (e.g. Date class)

A
Explicitly import one class name, it takes precedence over any wildcards present.
import java.util.Date;
import java.sql.*;
24
Q

How can you use two classes with the same name in Java?

A
Use the fully qualified class name.
public class foo {
java.util.Date date;
java.sql.Date sqlDate;
}
25
What option is used with the javac command to specify the directory to place generated class files?
- d | e. g. javac -d classes foo/Bar.java
26
What are the options to specify the class path when running the java command?
-cp -classpath --class-path Location of classes needed to compile a program.
27
What does the jar command do?
Creates an archive for classes and resources, and can manipulate or restore individual classes or resources from an archive.
28
What is the command to create a jar file?
jar - jarName.jar currentDir
29
what does the -c, --create option with the jar command do?
Creates a new JAR file.
30
What does the -v, --verbose option with the jar command do?
Prints details when working with JAR files.
31
What does the -f , --file option with the jar command do?
Provides the jar name.
32
What does the -C option with the jar command do?
Provides the directory containing files to be used to create the JAR.
33
Is a package declaration required in a class file?
No.
34
Are import statements required in a class file?
No.
35
Is a class declaration required in a class file?
Yes.
36
Are field declarations required in a class file?
No.
37
Are method declarations required in a class file?
No.
38
Where does a package declaration go in a class file?
First line in the file.
39
Where do import statements go in a class file?
Immediately after the package (if present).
40
Where does the class declaration go in a class file?
Immediately after the import statements (if any).
41
Where do field declarations go in a class file?
Any top level element in a class.
42
Where do method declarations go in a class file?
Any top level element in a class.
43
What must the public class name in a file match?
The name of the file.
44
How many classes can be defined in a file?
multiple.
45
During the OCM exams, what are common cases where you don't need to check for imports?
1. Code that begins with a class name. 2. Code that begins with a method declaration. 3. Code snippets that would normally be inside a class or method. 4. Code that has line numbers that don't begin with 1.
46
What does JDK stand for?
Java Devlopment Kit.
47
What does the JDK contain?
The compiler and JVM launcher.
48
What does JVM stand for?
Java Virtual Machine.
49
What does the JVM run?
bytecode.