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
Q

What option is used with the javac command to specify the directory to place generated class files?

A
  • d

e. g. javac -d classes foo/Bar.java

26
Q

What are the options to specify the class path when running the java command?

A

-cp
-classpath
–class-path
Location of classes needed to compile a program.

27
Q

What does the jar command do?

A

Creates an archive for classes and resources, and can manipulate or restore individual classes or resources from an archive.

28
Q

What is the command to create a jar file?

A

jar - jarName.jar currentDir

29
Q

what does the -c, –create option with the jar command do?

A

Creates a new JAR file.

30
Q

What does the -v, –verbose option with the jar command do?

A

Prints details when working with JAR files.

31
Q

What does the -f , –file option with the jar command do?

A

Provides the jar name.

32
Q

What does the -C option with the jar command do?

A

Provides the directory containing files to be used to create the JAR.

33
Q

Is a package declaration required in a class file?

A

No.

34
Q

Are import statements required in a class file?

A

No.

35
Q

Is a class declaration required in a class file?

A

Yes.

36
Q

Are field declarations required in a class file?

A

No.

37
Q

Are method declarations required in a class file?

A

No.

38
Q

Where does a package declaration go in a class file?

A

First line in the file.

39
Q

Where do import statements go in a class file?

A

Immediately after the package (if present).

40
Q

Where does the class declaration go in a class file?

A

Immediately after the import statements (if any).

41
Q

Where do field declarations go in a class file?

A

Any top level element in a class.

42
Q

Where do method declarations go in a class file?

A

Any top level element in a class.

43
Q

What must the public class name in a file match?

A

The name of the file.

44
Q

How many classes can be defined in a file?

A

multiple.

45
Q

During the OCM exams, what are common cases where you don’t need to check for imports?

A
  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
Q

What does JDK stand for?

A

Java Devlopment Kit.

47
Q

What does the JDK contain?

A

The compiler and JVM launcher.

48
Q

What does JVM stand for?

A

Java Virtual Machine.

49
Q

What does the JVM run?

A

bytecode.