Chapter 2 Java Fundamentals – Flashcards

Unlock all answers in this set

Unlock answers
question
class header
answer
marks the beginning of a class definition
question
class
answer
serves as a container for an application
question
A java program must have at least one class definition.
answer
true
question
access specifier
answer
"public" - unrestricted controls where the class may be accessed from
question
"class"
answer
java key word that indicates the beginning of a class definition
question
"Simple"
answer
the class name.
question
body
answer
everything between the two braces {}
question
method header
answer
marks the beginning of a method
question
method
answer
a group of one or more programming statements that collectively has a name
question
semicolon
answer
marks the end of a statement in Java
question
//
answer
marks the beginning of a comment
question
( )
answer
used in a method header
question
{ }
answer
encloses a group of statements, such as the contents of a class or a method
question
" "
answer
encloses a string of characters, such as message that is to be printed on the screen
question
;
answer
marks the end of a complete programming statement
question
console output
answer
merely plain text
question
standard output device
answer
refers to the device that displays console output
question
API
answer
Application Programmer Interface; a standard library of prewritten classes for performing specific operations
question
"System" class System.out.println(" ");
answer
part of the Java API. it has member objects and methods for performing system-level operations, such as sending output to the console.
question
"out" object System.out.println(" ");
answer
member of the "System" class. provides methods for sending output to the screen
question
"print" and "println" methods System.out.println(" ");
answer
members of the "out" object. actually perform the work of writing characters on the screen.
question
argument
answer
the value that is to be displayed on the screen is placed inside the parentheses
question
escape sequence
answer
starts with the backslash character (), and is followed by one or more control characters. It allows you to control the way output is displayed by embedding commands within the string itself.
question
n
answer
newline escape sequence; advances the cursor to the next line for subsequent printing
question
t
answer
horizontal tab escape sequence; causes the cursor to skip over to the next tab stop
question
b
answer
backspace escape sequence; causes the cursor to back up, or move left, one position
question
r
answer
return escape sequence; causes the cursor to go to the beginning of the current line, not the next line
question
'
answer
single quote escape sequence; causes a single quote mark to be printed
question
"
answer
double quote escape sequence; causes a double quote mark to be printed
question
variable
answer
a named storage location in the computer's memory
question
literal
answer
a value that is written into the code of a program
question
variable declaration
answer
tells the compiler the variable's name and type of data it will hold Ex.) int value;
question
assignment statement
answer
Ex.) value = 5;
question
string concatenation operator
answer
when the + operator is used with strings; appends one string to another
question
identifier
answer
a programmer-defined name that represents some element of a program; use only alphabetic letters, digits, underscores, or dollar signs
question
key words
answer
make up the core of the java language and each has a specific purpose
question
self-documenting programs
answer
means you get an understanding of what the program is doing just by reading its code
question
Can identifiers begin with a digit?
answer
no
question
How are variables classified?
answer
according to their data type, which determines the kind of data that may be stored in them.
question
data type
answer
type of data that the variable can hold.
question
primitive data types
answer
data types which cannot be used to create objects
question
floating-point numbers
answer
allow precise measurements, fractional values; ex.) 1.7 -45.316
question
"float" data type
answer
considered a single precision data type; occupies 4 bytes of memory
question
"double" data type
answer
considered a double precision data type; occupies 8 bytes of memory
question
What does it mean to say that Java is a strongly typed language?
answer
it only allows you to store values of compatible data types in variables
question
"char" data type
answer
used to store characters
question
What is the difference between character literals and string literals?
answer
string literals are enclosed in double quote marks, and cannot be assigned to "char" variables. character literals are enclosed in single quote marks.
question
initialization
answer
declaration statement
question
"boolean" data type
answer
allows you to create variables that may hold one of two possible values: "true" or "false"
question
integer division
answer
the operator will perform this when both operands of the division operator are integers
question
truncated
answer
thrown away
question
precedence of arithmetic operators from highest to lowest?
answer
- (unary negation) * / % + -
question
associativity of arithmetic operators
answer
- (unary negation): right to left * / % : left to right + - : left to right
question
What do you need to use to raise a number to a power?
answer
Math.pow method ex.) result = Math.pow(4.0, 2.0); result = 4^2
question
How do you return the square root of a value?
answer
Math.sqrt method Ex.) result = Math.sqrt(9.0); System.out.println(Math.sqrt(25.0)); --> 5.0 is displayed on the screen as output
question
+=
answer
Example: x += 5; x = x + 5;
question
-=
answer
example: y -= 2; y = y - 2;
question
*=
answer
example: z *= 10; z = z * 10;
question
/=
answer
example: a /= b; a = a / b;
question
%=
answer
example: c %= 3; c = c % 3;
question
primitive data type ranking from highest to lowest
answer
double float long int short byte
question
widening conversion
answer
conversion of a value from lower-rank to higher-ranked type
question
narrowing conversion
answer
conversion of a value to lower-ranked type
question
cast operator
answer
lets you manually convert a value, even if it means that a narrowing conversion will take place.
question
named constant
answer
a variable whose value is read only and cannot be changed during the program's execution.
question
instance
answer
each object that is created from a class is called an instance of the class
question
primitive type variables
answer
hold the actual data items with which they are associated
question
class type variable
answer
does not hold the actual data item that is associated with, but holds the memory address of the data item it is associated with.
question
charAt(index)
answer
the argument "index" is an int value and specifies a character position in the string. The first character is at position 0, the second character is at position 1, and so forth. The method returns the character at the specified position. The return value is of the type "char".
question
length( )
answer
this method returns the number of characters in the string. the return value is of the type "int".
question
toLowerCase( )
answer
this method returns a new string that is the lowercase equivalent of the string contained in the calling object.
question
toUpperCase( )
answer
this method returns a new string that is the uppercase equivalent of the string contained in the calling object.
question
scope
answer
the part of the program that has access to the variable; a variable is visible only to statements inside the variable's scope
question
local variables
answer
variables that are declared inside a method
question
comments
answer
notes of explanation that document lines or sections of a program; compiler ignores them; intended for people reading the source code.
question
documentation comment
answer
/** */ typically written just before a class header, giving a brief description of the class or before method header giving a brief description of the method.
question
multi-line comment
answer
/* */ convenient for writing large blocks of comments
question
programming style
answer
refers to the way source code is visually arranged
question
What does import java.util.Scanner; do ?
answer
tells the java compiler where in the java library to find the Scanner class, and makes it available to your program
question
What does JOptionPane do ?
answer
allows you to quickly display a dialog box, which is a small graphical window displaying a message or requesting input.
question
message dialog
answer
a dialog box that displays a message; an OK button is also displayed
question
Input Dialog
answer
a dialog box that prompts the user for input and provides a text field where input is typed; an OK button and Cancel button are also displayed
question
showMessageDialog method
answer
used to display a message dialog
question
import javax.swing.JOptionPane;
answer
tells the compiler where to find the JOptionPane class and makes it available to your program.
question
showInputDialog method
answer
used to display an input dialog
question
System.exit(0);
answer
causes the program to end, and is required if you use the JOptionPane class to display dialog boxes.
question
What happens if the System.exit method is not called?
answer
a thread will continue to execute, even after the end of the main method has been reached
question
Does the System.exit method require an integer argument?
answer
yes
question
Every complete statement ends with a _______: a. period b. parenthesis c. semicolon d. ending brace
answer
c. semicolon
question
The following data 72 'A' "Hello World" 2.8712 are all examples of __________; a. variables b. literals c. strings d. none of these
answer
b. literals
question
a group of statements, such as the contents of a class or a method, are enclosed in _________; a. braces {} b. parentheses () c. brackets [] d. any of these will do
answer
a. braces {}
question
which of thee following are not valid assignment statements? (indicate all that apply); a. total = 9; b. 72 = amount; c. profit = 129 d. letter = 'w';
answer
b. 72 = amount; c. profit = 129
question
which of the following are not valid println statements? (indicate all that apply): a. System.out.println + "Hello World"; b. System.out.println("Have a nice day"); c. out.System.println(value); d. println.out(Programming is great fun);
answer
a. System.out.println + "Hello world"; c. out.System.println(value); d. println.out(programming is great fun);
question
the negation operator is _______; a. unary b. binary c. ternary d. none of these
answer
a. unary
question
This key word is used to declare a named constant. a. constant b. namedConstant c. final d. concrete
answer
c. final
question
These characters mark the beginning of a multi-line comment a. // b./* c.*/ d./**
answer
b. /*
question
these characters mark the beginning of a single-line comment a. // b. /* c. */ d. /**
answer
a.//
question
these characters mark the beginning of a documentation comment a. // b. /* c. */ d. /**
answer
d. /**
question
Which Scanner class method would you use to read a string as an input? a. nextString b. nextLine c. readString d. getLine
answer
b. nextLine
question
which scanner class ethod would you use to read a double as input? a. nextDouble b. getDouble c. readDouble d. none of these; you can't
answer
a. nextDouble
question
You can use this class to display dialog boxes a. JOptionPane b. BufferedReader c. InputStreamReader d. DialogBox
answer
a. JOptionPane
question
When Java converts a lower-ranked value to a higher-ranked type, it is called a(n) __________; a. 4-bit conversion b. escalating conversion c. widening conversion d. narrowing conversion
answer
c. widening conversion
question
this type of operator lets you manually convert a value, even if it means that a narrowing conversion will take place. a. cast b. binary c. uploading d. dot
answer
a. cast
question
true or false: a left brace in a java program is always followed by a right brace later in the program.
answer
true
question
true or false: a variable must be declared before it can be used
answer
true
question
true or false: variable names may begin with a number.
answer
false
question
true or false: you cannot change the value of a variable whose declaration uses the final key word
answer
true
question
true or false: comments that begin with // can be processed by javadoc.
answer
false
question
true or false: if one of an operator's operands is a double, and the other operand is an int, java will automatically convert the value of the double to an int.
answer
false
Get an explanation on any task
Get unstuck with the help of our AI assistant in seconds
New