Java Unit 2
pseudocode
"fake" code that uses a mixture of natural language and code.
variable
A named memory location whose value can change while the program is running.
assignment statement
A statement that gives the variable or constant on the left of an assignment operator the value of the expression on the right side of the assignment operator.
one
A variable can only hold _______ value at a time!
d.
A variable declared with a class is called a(n) a. method b. identifier c. keyword d. object
reference variable
A variable that points to the memory address of an object instead of of its value.
primitive variable
A variable which stores an actual value.
flowchart
A visual of an algorithm.
beginning
All variable declarations should occur at the (beginning / end) of the method.
syntax error
An error caused by not following the rules of Java.
machine code
Bytecode files are NOT in ___________________ ____________ so they can not be processed by the machine.
are
Class names (are / aren't) capitalized.
capital
Class names begin with a (capital / lowercase) letter.
source code
Code written by the programmer.
JFrame theGui = new JFrame ( );
Declare and instantiate a reference variable with a class name of "j frame" and the object name "the gui."
packages
Groups of related classes, also called librariers.
code conventions
Guidelines about commenting; naming packages, classes, methods, and variables; and formatting code.
objects
Have specific data and behavior.
objectName.methodName( );
How do you call a method? (Use "method name" for method and "object name" for object).
1 bit
How many bits are in a boolean?
2 bytes
How many bytes are in a char?
8 bytes
How many bytes are in a double?
4 bytes
How many bytes are in an int?
Classname objectName = new Classname( );
How to do you construct an object? (Use "class name" for class and "object name" for object).
double
If at least one side is _____________________, Java automatically does real division.
int
If both sides are __________, Java automatically does integer division.
.class
In Java, compiled files have the extension ____________.
c.
Java was developed by a. Microsoft b. Apple c. Sun Microsystems d. W3C
lowercase
Method names begin with a (capital / lowercase) letter.
lowercase
Package names begin with a (capital / lowercase) letter.
algorithm
Set of steps to solve a problem.
just-in-time compiler
The ____________________________________________ converts bytecode to machine code before it is executed with the JVM, can lead to a slightly slower run-time.
Java Virtual Machine
The ______________________________________________ interprets bytecode, allowing Java to be portable since this can reside on any system.
classes
These define the data and methods of an object (template for an object).
modulus division
This operator finds the remainder.
initialize
To assign a variable a value in a declaration statement.
False
True or False: A constant value can be changed from its initial assignment.
True
True or False: A double value can be cast to an int.
True
True or False: A program with a syntax error will not compile.
True
True or False: A run-time error halts program execution at the statement that cannot be executed.
False
True or False: A run-time error is also called a syntax error.
False
True or False: An abstract data type is also called a primitive data type.
True
True or False: An escape sequence must be used to display a double quotation mark (").
True
True or False: An exception is a error that affects program execution.
True
True or False: An interpreter is software that runs each bytecode instruction of a compiled Java program.
False
True or False: Compiled source code files have the extension .java.
True
True or False: Documentation comments are copied into a separate HTML document using a javadoc tool.
True
True or False: Identifiers are case sensitive.
False
True or False: In a format string specifier, a - indicates right alignement.
False
True or False: Modulus division truncates the decimal portion of the quotient to result in a integer.
False
True or False: Multiple variables with different data types can be declared in a single statement.
False
True or False: Platform-independent applications can only be run on computers with a Windows operating system.
False
True or False: Statements must end with a period.
True
True or False: The System class contains methods for displaying output.
False
True or False: The int data type requires more memory than the double data type.
True
True or False: The object-oriented programming approach allows programmers to create modules that can be used over and over again.
True
True or False: The statement numPlayers += 2; is the same as numPlayers = numPlayers +2;
True
True or False: The statement system.out.println ("Hello world!"); will generate a syntax error.
True
True or False: Values represented by the double data type are referred to as floating point.
false
True or False: Variable names can begin with a number.
True
True or False: class is a keyword.
object oriented programming
Uses classes (modules) that are resuable.
lowercase
Variable names begin with a (capital / lowercase) letter.
1. Specification 2. algorithm 3. code design 4. implementation 5. test and debug
What are the five sections of the Case Study approach?
Process other than input or output.
What does this symbol represent in a flowchart?
input or output
What does this symbol represent in a flowchart?
start
What does this symbol represent in a flowchart?
a.
What effect does \n have when included in an output string? a. Output is moved to the next line. b. A \n is displayed in the output. c. A tap (8 spaces) is displayed in the output. d. A N is displayed in the output.
a.
What happens to the decimal portion of a number when a double is cast to an int? a. The decimal portion is truncated. b. The decimal portion is rounded. c. Nothing, a syntax error occurs. d. The value is added to a number.
Understanding what the program should do.
What is Specification in the Case Study approach?
/* */
What is a multi-line comment?
Problem solve in english.
What is algorithm in the Case Study approach?
How to accomplish algorithms in Java.
What is code design in the Case Study approach?
Writing the code.
What is implementation in the Case Study approach?
Fixing errors
What is testing and debugging in the Case Study approach?
/** Name: * Date: * Assignment: */ public class FirstProgram { public static void main(String[ ] args) { } }
What is the basic outline for documentation comments (use "first program" for class)?
b.
What is the result of the following expression when x is 125? x%6 a. 0 b. 5 c. 20 d. 20.5
d.
Which Scanner class method is used to return a string that does not contain spaces from the input stream? a. nextBoolean ( ) b. nextInt ( ) c. nextLine ( ) d. next ( )
c.
Which data type is most appropriate for whether an employee qualifies for a bonus? a. int b. double c. boolean d. char
d.
Which flowchart symbol indicates the start or end of a program? a. rectangle b. diamond c. parallelogram d. oval
a.
Which flowchart symbol represents a process? a. rectangle b. diamond c. parallelogram d. oval
d.
Which is NOT a feature of object-oriented languages? a. encapsulation b. inheritance c. polymorphism d. platform-dependent
b.
Which is a set of guidelines for writing an application? a. comments b. code conventions c. algorithm d. class
d.
Which is a valid identifier? a. $12 b. void c. 55 d. diameter
b.
Which is another name for package? a. object b. library c. method d. string
a.
Which is used to enclose single or multiline comments? a. /* */ b. // // c. /** */ d. ! !
d.
Which keyword does a constant declaration begin with? a. import b. constant c. int d. final
d.
Which method displays output to the screen and then moves the insertion point to the next line? a. format() b. main() c. print() d. println()
c.
Which occurs in a statement that violates the rules of Java? a. a logic error b. an output error c. a syntax error d. an argument
c.
Which of the following represent correctly-formed comments? 1. // Happy 2. /* Sorry /* 3. /* Wise */ a. 1 only b. 1 and 2 only c. 1 and 3 only d. 3 only
c.
Which process converts source code to code that the computer understands? a. running b. executing c. compiling d. interpreting
a.
Which statement assigns the value 15 to radius? a. radius = 15; b. radius == 15; c. 15 = radius; d. 15radius;
c.
Which statement declares and instantiates a new object named dot using a class named Oval? a. dot = new Oval ( ); b. Oval dot = new; c. Oval dot = new Oval ( ); d. Oval dot = Oval ( );
b.
Which statement displays " Hello, world! " on the screen? a. System.out.println ( 'Hello, world! ' ); b. System.out.println ( "Hello, world! " ); c. System.println ( 'Hello, world! ' ); d. system.println ( 'Hello, world! ' );
c.
Which statement is used to make the members of a package accessible to an application? a. class b. public c. import d. static
b.
Which would be the resulting bytecode file name if testApplication.java is compiler? a. testApplication.cmd b. testApplication.class c. testApplication.java d. testApplication.jit
double salary = 87900.32;
Write a statement to declare a variable named salary initialized to the value of 87900.32.
never
You should (always / never) perform a calculation in an output statement.
b.
public class MulticulturalGoodbye { public static void main(String [ ] args) { System.out.println ("good-bye"); System.out.print ("adios\n"); System.out.println ("au voire"); } } MulticulturalGoodbye produces output similar to: a. good-bye adios au voire b. good-bye adiosau voire c. good-byeadiosau voire d. good-byeadios au voire
c.
public class MulticulturalGoodbye { public static void main(String [ ] args) { System.out.println ("good-bye"); System.out.print ("adios\n"); System.out.println ("au voire"); } } Which is a string argument in MulticulturalGoodbye? a. public b. System.out.print c. "good-bye" d. }