Java Virtual Machine Flashcards

1
Q

Java compilers start with Java source code and create class files containing what type of code?

A

Java Byte Code.

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

(T/F) When a Java program is executed, the byte code class file is either interpreted or compiled, or both.

A

True.

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

Are there other languages that can compile Java byte code? If so, what is the advantage?

A

Yes. Scala is an example. (Most of Twitter uses Scala).

The advantage is that it allows them to be architecture independent.

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

Is JVM a stack based architecture or register based?

A

Stack Based.

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

What is a Java Class File?

A

A stream of 8-bit bytes consisting of a single ClassFile structure.

There is a C structure to define what it is.

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

In JVM, loads and stores are between the memory and…

A

The Stack.

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

In the JVM, arithmetic operations get their operands from the stack and leave their results where?

A

Back on the stack.

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

A JVM instruction consists of one-byte opcode that specifies the operation to be performed. How many arguments can an opcode have?

A

Zero or more.

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

Give an example of a JVM inner loop.

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

In JVM, variables are typed. Primitive types are assigned a one letter type code. For example, integers are identified by I. Class names use what letter?

A

L followed by a fully qualified name.

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

What are some examples of the JVM type definitions?

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

In JVM, method signatures are indicated by a ‘(‘. What are some examples of method signatures definition in JVM?

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

What are JVM’s three kinds of variables?

A
  • Static members of a class
  • Non-Static members of a class
  • Local variables in methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Static Members of a Class

When using ‘getstatic’ and ‘putstatic’ to push or pop a static variable on the stack, what information is required?

A
  • Classname
  • Fieldname
  • Type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Non-Static Members of a Class

In JVM, ‘getfield’ and ‘putfield’ require the classname, fieldname, and type to be provided when pushing and popping fields. Since a class can have multiple instances of a field, what else is required?

A

The reference to the object.

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

Local Variables in a Class are stored in method frames. These frames get created when methods are called and it includes an operand stack. The local variables (parameters and declared locally) are stored in what type of data structure?

A

The local variables are stored in an array and accessed by index number.

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

What instruction is used to load integer/boolean local variables to the top of the stack and remove them from the top of the stack?

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

What instruction is used to load objects to the top of the stack and remove them from the top of the stack?

A
  • aload - loads a reference to an object
  • astore - stores a reference to an object
19
Q

What instruction is used to load doubles to the top of the stack and remove them from the top of the stack?

A
  • dload
  • dstore
20
Q

What instruction is used to load constants to the top of the stack and remove them from the top of the stack?

A
  • ldc
21
Q

Static Methods In JVM

A
22
Q

In JVM

A
23
Q

Non-Static Methods In JVM

What does the local variable array look like?

A
24
Q

Give an example of the bytecode for the following method.

A
25
Q

What are some bytecode arithmetic and logical operations?

A
  • iadd - add two ints
  • ladd - add two longs
  • fadd - add two floats
  • dadd - add two doubles

All binary operations remove the top two items from the stack and leave the resulting value on top of the stack.

26
Q

In JVM, it is possible to jump to an instruction other than the next one in the sequence. What has to be provided to transfer control to another instruction?

A

A label has to the instruction has to be provided.

27
Q

In JVM, what are some of the cases when control transfer is required?

A
  • Conditional compare to zero
  • Conditional compare to null
  • Compare the top two elements of the stack
  • Unconditional transfer
28
Q

Show an example of the following

A
29
Q

Show an example of the following:

A
30
Q

Show an example of the following:

A
31
Q

Give an example of the following:

A
32
Q

In JVM, what does dup and swap do?

A
  • dup - duplicates the top of the stack
  • swap - swaps the top two elements of the stack
33
Q

In JVM, what are the three method invocation instructions:

A
34
Q

In JVM, describe invokevirtual.

A
35
Q

In JVM, describe invokestatic.

A
36
Q

In JVM, describe invokespecial.

A
37
Q

In Java, the return word is not necessary. Give a reason.

A

The return is implemented in the bytecode.

38
Q

In JVM, the choice of a return instruction depends on the type of result to be returned from the method. Name some of the various return instructions.

A
39
Q

In JVM, the following method is given. Give an example of its instructions to add the two integers.

A
40
Q

In JVM, the following method is given. Give an example of the caller.

A
41
Q
A
42
Q

Give an instruction example of the following code segment:

A
43
Q

Give an instruction example of the following code segment:

A
44
Q

Give an example on instantiating an object with the new operator.

A