CMSC 131 EXAM 1 QUESTIONS WITH VERIFIED
ANSWERS
Object - Answers - The principal entities that are manipulated by a Java program
Class - Answers - A blueprint or template for the structure of an object. The structure
around which all Java programs are based. A typical program has many classes.
Method - Answers - Java's term for a procedure or subroutine. Every method belongs to
some class, and a class may have many methods
Main Method - Answers - There must be exactly one method called main. This is where
execution begins.
public static void main(String args[]){
//body
}
Statements - Answers - Individual instructions. There are many different types of
statements. Each method consists of some number of statements.
Declarations - Answers - (Ex of statement) Declare (and initialize) variables
Assignment - Answers - (Ex of statement) Compute and assign a new value to a
variable
Method invocation - Answers - (Ex of statement) Execute a method (which may return a
result)
Control flow - Answers - The order in which statements are executed. General rule is
top to bottom.
What is Java compiled into? - Answers - Java bytecode
What do you need to run Java bytecode? - Answers - A bytecode interpreter ("Java
Virtual Machine")
Why is Java more portable than C or C++? - Answers - C/C++ programs are compiled
into machine code (rather than Java bytecode) and executed directly by CPU.
A class consists of a combination of data units, called ___________, and computation
units, called ___________. - Answers - variables,
methods
, Methods - Answers - Where all the computation takes place. Each method has a name,
a list of arguments enclosed in parentheses, and body, enclosed in curly braces.
Ex:
public static void main (String[]args){
//body
}
Variables - Answers - Data items that the methods operate on. Can be of various types.
List all primitive variable types - Answers - 8 types: byte, short, int, long, float, double,
boolean, and char
What do expressions/operators do? - Answers - Manipulate variables
Ex:
x = (2*y-z)/32
Comments - Answers - Used to indicate programmer's intent. Do not affect program's
execution. There are line comments ( using // ) and block comments ( using /star ... star/
)
Debugging - Answers - Process of finding and fixing problems
"Compile time" errors - Answers - Caught by compiler.
Ex:
Syntax errors
Variable type errors
"Run time" errors - Answers - appears during program execution
Ex:
division by zero
semantic errors
Different types of data require _________ __________ of memory. - Answers - different
amounts. The compiler's job is to reserve sufficient memory
Operations can only be performed between variables with _____________ types. -
Answers - compatible
Valid Variables Names - Answers - -Starts with: a letter (a-z or A-Z), or dollar sign ($), or
underscore ( _ )
-Followed by: zero or more letter, dollar signs, underscores, or integers
-Cannot be any of reserved names (class, float, int, if, etc.)
Camel case - Answers - A capitalization style
Ex:
ANSWERS
Object - Answers - The principal entities that are manipulated by a Java program
Class - Answers - A blueprint or template for the structure of an object. The structure
around which all Java programs are based. A typical program has many classes.
Method - Answers - Java's term for a procedure or subroutine. Every method belongs to
some class, and a class may have many methods
Main Method - Answers - There must be exactly one method called main. This is where
execution begins.
public static void main(String args[]){
//body
}
Statements - Answers - Individual instructions. There are many different types of
statements. Each method consists of some number of statements.
Declarations - Answers - (Ex of statement) Declare (and initialize) variables
Assignment - Answers - (Ex of statement) Compute and assign a new value to a
variable
Method invocation - Answers - (Ex of statement) Execute a method (which may return a
result)
Control flow - Answers - The order in which statements are executed. General rule is
top to bottom.
What is Java compiled into? - Answers - Java bytecode
What do you need to run Java bytecode? - Answers - A bytecode interpreter ("Java
Virtual Machine")
Why is Java more portable than C or C++? - Answers - C/C++ programs are compiled
into machine code (rather than Java bytecode) and executed directly by CPU.
A class consists of a combination of data units, called ___________, and computation
units, called ___________. - Answers - variables,
methods
, Methods - Answers - Where all the computation takes place. Each method has a name,
a list of arguments enclosed in parentheses, and body, enclosed in curly braces.
Ex:
public static void main (String[]args){
//body
}
Variables - Answers - Data items that the methods operate on. Can be of various types.
List all primitive variable types - Answers - 8 types: byte, short, int, long, float, double,
boolean, and char
What do expressions/operators do? - Answers - Manipulate variables
Ex:
x = (2*y-z)/32
Comments - Answers - Used to indicate programmer's intent. Do not affect program's
execution. There are line comments ( using // ) and block comments ( using /star ... star/
)
Debugging - Answers - Process of finding and fixing problems
"Compile time" errors - Answers - Caught by compiler.
Ex:
Syntax errors
Variable type errors
"Run time" errors - Answers - appears during program execution
Ex:
division by zero
semantic errors
Different types of data require _________ __________ of memory. - Answers - different
amounts. The compiler's job is to reserve sufficient memory
Operations can only be performed between variables with _____________ types. -
Answers - compatible
Valid Variables Names - Answers - -Starts with: a letter (a-z or A-Z), or dollar sign ($), or
underscore ( _ )
-Followed by: zero or more letter, dollar signs, underscores, or integers
-Cannot be any of reserved names (class, float, int, if, etc.)
Camel case - Answers - A capitalization style
Ex: