CMSC 131 FINAL EXAM QUESTIONS WITH VERIFIED
ANSWERS
What is the Java Virtual Machine? - Answers - A program that simulates a real CPU
running compiled Java code.
What is byte code? - Answers - The Java compiler translates Java source code into
byte code, which is an intermediate language. The Java Virtual Machine executes the
byte code instructions.
How can you generate bytecode for a program called Test.java? - Answers -
What is the difference between a syntax error and a run time error? - Answers - Syntax
errors are related to the structure of the code and are detected before the program is
run, while runtime errors occur during the execution of the program
Can every class in Java have a main method? - Answers - No
What is the default value for a local variable? - Answers - None
What is the default value for a local variable? - Answers - The negative answer (int (and
the like)= 0, boolean = false, Object = null)
How do the String and StringBuffer classes differ? - Answers - You use the String class
when you are working with strings that cannot change while StringBuffer is used when
you want to manipulate the contents of the string on the fly.
What is the difference between method overloading and method overriding? - Answers -
Method overloading is used to increase the readability of the program. Method
overriding is used to provide the specific implementation of the method that is already
provided by its super class.
What is the difference between final int x and final static int x? - Answers - Final int
belongs to each individual int object while final static int is class wide.
What is the difference between a shallow copy and a deep copy? - Answers - In
Shallow copy, a copy of the original object is stored and only the reference address is
finally copied. In Deep copy, the copy of the original object and the copy are both stored
Which two methods of the Object class do we often override? - Answers - equals()
toString()
ANSWERS
What is the Java Virtual Machine? - Answers - A program that simulates a real CPU
running compiled Java code.
What is byte code? - Answers - The Java compiler translates Java source code into
byte code, which is an intermediate language. The Java Virtual Machine executes the
byte code instructions.
How can you generate bytecode for a program called Test.java? - Answers -
What is the difference between a syntax error and a run time error? - Answers - Syntax
errors are related to the structure of the code and are detected before the program is
run, while runtime errors occur during the execution of the program
Can every class in Java have a main method? - Answers - No
What is the default value for a local variable? - Answers - None
What is the default value for a local variable? - Answers - The negative answer (int (and
the like)= 0, boolean = false, Object = null)
How do the String and StringBuffer classes differ? - Answers - You use the String class
when you are working with strings that cannot change while StringBuffer is used when
you want to manipulate the contents of the string on the fly.
What is the difference between method overloading and method overriding? - Answers -
Method overloading is used to increase the readability of the program. Method
overriding is used to provide the specific implementation of the method that is already
provided by its super class.
What is the difference between final int x and final static int x? - Answers - Final int
belongs to each individual int object while final static int is class wide.
What is the difference between a shallow copy and a deep copy? - Answers - In
Shallow copy, a copy of the original object is stored and only the reference address is
finally copied. In Deep copy, the copy of the original object and the copy are both stored
Which two methods of the Object class do we often override? - Answers - equals()
toString()