Java for Mid

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

.java

A java source code file must end with the ____ file extension.

variable

A location in the computer's memory that may contain different values at various times throughout the execution of a program is called a(n) ____.

method call

A method is invoked with a(n) ____.

inheritance

A new class of objects can be created conveniently by ____ - the new class (called the subclass) starts with the characteristics of an existing class (called the superclass), possibly customizing them and adding unique characteristics of its own.

Virtual Machine (VM)

A(n) ____ is a software application that simulates a computer, but hides the underlying operating system and hardware from the programs that interact with it.

import declaration

A(n) ____ is not required if you always refer to a class with its fully qualified class name.

Byte code

A(n) ____ program can run on multiple platforms.

Integrated Development Environments (IDEs)

A(n) ____ provides many tools that support the software-development process, such as editors for writing and editing programs, debuggers for locating logic errors in programs and many other features.

variables, type

An array is a group of ____ (called elements or components) containing values that all have the same ____.

two-dimentional

An array that uses two indices is referred to as a(n) ____ array.

True

An expression containing the ||operator is true if either or both of its operands are true.

default package

By default, classes that are compiled in the same directory are considered to be in the same package, known as the ____.

assignment

Calculations are normally performed by ____ statements.

java.lang

Class "String" is in package ____.

an array of Strings, called args by convention

Command-line arguments are stored in ____.

public

Each class declaration that begins with keyword ____ must be stored in a file that has exactly the same name as the class and ends with the .java filename extension.

type, name

Each parameter must specify both a(n) ____ and a(n) ____.

The Scanner class is used to read the data, which is to be used in the program, from the source that is the keyboard or a file. This class is available in java.util package. The Scanner class can be used by importing the java.util package before beginning the class or by using the "fully qualified class name". If the Scanner class is used with "fully qualified class name", there is need to import the java.util package. Since this name contains the name of full package and the name of class.

Explain how a program could use class "Scanner" without importing it.

A parameter represents additional information that a method requires to perform its task. Each parameter required by a method is specified in the method's declaration. An argument is the actual value for a method parameter. When a method is called, the argument values are passed to the corresponding parameters of the method so that is can perform its task.

Explain the purpose of a method parameter. What is the difference between a parameter and an argument?

Most instance variable declarations are preceded with the keyword private. It is an access modifier. Variables or methods declared with access modifier private are accessible only to methods of the class in which they are declared. Thus, a class might provide a set method and a get method for an instance variable.

Explain why a class might provide a set method and a get method for an instance variable.

Using a floating point number to control a for statement may not work because floating point numbers are represented only approximately by most computers.

Explain why it occurs an error: for (k = 0.1; k != 1.0; k += 0.1) System.out.println(k);

test

Given the command java "MyClass test", the first command-line argument is ____.

prefixed

If the increment operator is ____ to a variable, first the variable is incremented by 1, then its new value is used in the expression.

false

If the loop-continuation condition in a "for" header is initially ____, the program does not a certain path of execution.

stack overflow

If there are more method calls than can be stored on the method-call stack, an error known as a(n) ____ occurs.

method overloading

It's possible to have several methods with the same name that each operate on different types or numbers of arguments. This feature is called method ____.

main

Java applications begin execution at method ____.

strongly typed

Java is a(n) ____ language; it requires all variables to have a type.

classes

Java programmers concentrate on creating ____, which contain fields and the set of methods that manipulate those fields and provide services to clients.

edit, compile, load, verify, execute

Java programs normally go through five phases ____, ____, ____, ____, and ____.

float, double

Java provides two primitive types for storing floating-point numbers in memory: ____ and ____.

class

Keyword ____ in a class declaration is followed immediately by the class's name.

new

Keyword ____ requests memory from the system to store an object, then calls the corresponding class's constructor to initialize the object.

modifier

Keyword public is an access ____.

true

Listing cases consecutively with no statements between them enables the cases to perform the same set of statements.

arrays. collections

Lists and tables of values can be stored in ____ and ____.

counter-controlled( or definite)

Repeating a set of instructions a specific number of times is called ____ repetition.

void

Return type ____ indicates that a method will not return a value.

nextLine

Scanner method ____ reads characters until it encounters a newline character, then returns those characters as a String.

nextDouble

Scanner method ____ returns a double value.

The Signleton's purpose is to control object creation, limiting the number of objects to only once.

Singleton in Java?

last-in, first-out

Stacks are known as ____ data structures; the last item pushed (inserted) onto the stack is the first item popped (removed) from the stack.

False. The "break" statement is used to exit the "switch" statement. The break statement is not required for the last case in a switch statement.

The "break" statement is required in the last case of a "switch" selection statement.

after

The "do...while" statement test the loop-continuation condition ____ executing the loop's body; therefore, the body always executes at least once.

Java bytecode

The Java compiler produces ____.

5

The Java expression 5/2+3 evaluates to ____.

division (/), remainder (%)

The arithmetic operators with the same precedence as multiplication are ____ and ____.

True

The comma(,) formatting flag in a format specifier (e.g. %, 20.2f) indicates that a value should be output with a thousands separator.

Java Virtual Machine (JVM)

The command java invokes the ____, which executes Java programs.

False. Bothe of the relational expressions must be true for the entire expression to be true when using the && operator.

The expression ((x > y) && (a < b)) is true if either x > y is true or a < b is true.

bytecodes

The file produced by the Java compiler contains ____ that are executed by the Java Virtual Machine.

%f

The format specifier ____ is used to output values of type float or double.

System.out.print, System.out.println, System.out.printf

Methods ____, ____ and ____ display information in a command window.

static

Methods that perform common tasks and do not require objects are called ____ methods.

Classes System and String are in package java.lang, which is implicitly imported into every java program, so all programs can use that package's classes without explicitly importing them. Most other classes you'll use in java program must be imported explicitly.

Most classes need to be imported before they can be used in an app. Why every app allowed to use classes "System" and "String" without first importing them?

input unit, output unit, memory unit, central processing unit, arithmetic and logic unit, secondary storage unit

The key logical units of the computer are the ____, ____, ____, ____, ____, and ____.

void

The keyword ____ indicates that a method does not return a value.

input unit

The logical unit that receives information from outside the computer for use by the computer is the ____.

stack frame, activation record

The method-call stack contains the memory for local variables on each invocation of a method during a program's execution. This data, stored as a portion of the method-call stack, is known as the ____ or ____ of the method call.

index

The number used to refer to a particular array element is called the element's ____.

machine language

The only language a computer can directly understand is that computer's ____.

object-oriented analysis and design

The process of analyzing and designing a system from an object-oriented point of view is called ____.

computer programming

The process of instructing the computer to solve a problem is called ____.

compilers

The programs that translate high-level language programs into machine language are called ____.

attributes

The size, shape, color and weight of an object are considered ____ of the object's class.

machine languages, assembly languages, high-level languages

The three types of languages discussed in the chapter are ____, ____, and ____.

return, return expression, or encountering the closing right brace of a method

The three ways to return control from a called method to a caller are ____, ____ and ____.

double precision

Variables of type double represent ____ floating=point numbers.

single

Variables of type float represent ____ - precision floating-point numbers.

The complier provides a default constructor with no parameters in any class that does not explicitly include a constructor. When a class has only the default constructor, its instance variables are initialized to their default values. Variables of types int, float, long, short, chart, byte, and double are initialized to 0. Variables of type boolean are initialized to false. Reference-type fields are initialized by default to the value null.

What is a default constructor? How are an object's instance variables initialized if a class has only a default constructor?

A local variable is declared in the body of a method and can be used only from the point at which it's declared through the end of the method declaration. An instance variable is declared in a class, but not in the body of any of the class's method. Also, instance variables are accessible to all methods of the class.

What is the difference between a local variable and an instance variable?

When you use keyword "new" subsequently the keyword new requests memory from the system to store an object, then calls the corresponding class's constructor to initialize the object.

What's the purpose of keyword "new"? Explain what happens when you use it.

.class

When a Java program is compiled, the file produced by the compiler ends with the ____ file extension.

sentinel, signal, flag or dummy

When it's not known in advance how many times a set of statements will be repeated, a(n) ____ value can be used to terminate the repetition.

innermost

When parentheses in an arithmetic expression are nested, the ____ set of parentheses is evaluated first.

int, char, long, float, double, byte, short, boolean

Which are primitive data types supported by the Java programming language? int, char, word, Object, long, float, double, byte, short, boolean, Array

double result = Math.pow(2.5, 3)

Write a Java Statement or a set of Java statements to accomplish each of the following tasks: Calculate the value of 2.5 raised to the power of 3, using the pow method.

i = 1; while (i <= 20) { System.out. print(i); if(i%5 == 0) System.out.println(); ++i;}

Write a Java Statement or a set of Java statements to accomplish each of the following tasks: Print the integers from 1 to 20, using a while loop and the counter variable i. Assume that the variable i has been declared, but not initialized. Print only five integers per line.

sum += x;

Write a Java statement to accomplish the following task: Add variable "x" to variable "sum", and assign the result to variable "sum".

q %= divisor; q = q % divisor;

Write a Java statement to accomplish the following task: Calculate the remainder after "q" is divided by "divisor" , and assign the result to "q". Write this statement in two different ways.

int sum = 0;

Write a Java statement to accomplish the following task: Declare variables "sum" of type "int" and initialize it to 0.

int x = 1;

Write a Java statement to accomplish the following task: Declare variables "x" of type "int" and initialize it to 1.

System.out.printf("The sum is: %d%n", sum);

Write a Java statement to accomplish the following task: Print "The sum is: ", followed by the value of variable "sum".

if (count > 10) System.out.println("Count is greater than 10");

Write a Java statement to accomplish the following task: Test whether variable count is greater than 10. If so, print"Count is greater than 10".

z = x++ +y; ( if you do ++x +y, execute x+1 first, and then +y. But if you do x++ +y, after adding x+y and then x+1)

Write a Java statement to accomplish the following task: Use one statement to assign the sum of x and y to z, then increment x by 1

total -= --x;

Write a Java statement to accomplish the following task: Use one statement to decrement the variable x by 1, then subtract it from variable "total" and store the result in variable "total".

x = x+1; x += 1; ++x; x++;

Write four different Java statements that each add 1 to integer variable x.

if (number != 7) System.out.println("The variable number is not equal to 7");

Write statements to accomplish the following tasks: If the variable "number" is not equal to 7, display "The variable number is not equal to 7"

value = input.NextInt();

Write statements to accomplish the following tasks: Input an integer and assign the result to int variable "value". Assume Scanner variable "input" can be used to read a value from the keyboard.

System.out.println("This is a Java program");

Write statements to accomplish the following tasks: Print "This is a Java program" on one line in the command window. Use method System.out.println.

System.out.printf("%s%n%s%n", "This is a Java", "program");

Write statements to accomplish the following tasks: Print "This is a Java program" on two lines in the command window. The first line should end with Java. Used method System.out.printf and two %s format specifiers.

System.out.print("Enter an integer: ")

Write statements to accomplish the following tasks: Prompt the user to enter an integer.

int c, thisIsAVariable, q7777, number;

Write statements to accomplish the following tasks: Declare variables c, thisIsAVariable, q7777, and number to be of type int.

c language

____ initially became widely known as the development language of the UNIX operating system.

The Unified Modeling Language

____ is a graphical language that allows people who design software systems to use an industry-standard notation to represent them.

CPU

____ is a logical unit of the computer that coordinates the activities of all the other logical units.

Output unit

____ is a logical unit that sends information which has already been processed by the computer to various devices so that it may be used outside the computer.

A high-level language

____ is a type of computer language that uses Englishlike abbreviations for machine-language instructions.

Android

____ is an operating system for mobile devices based on the Linux kernel and Java.

high level

____ languages are most convenient to the programmer for writing programs quickly and easily.

Release candidate

____ software is generally feature complete, (supposedly) bug free and ready for use by the community.

space characters, newlines, tabs

____, ____ and ____ are called white space.

The while statement can be used to implement any counter controlled loop but the for repletion statements is for specifies the counter controlled repetition details in a single line of code. The for statements are used for counter controlled repletion and the while statements for sentinel controlled repetition. the both while and for can each is used for either repetition type.

compare and contrast the while and for repetition statements.

Arithmetic and logic unit

is a logical unit of the computer that makes logical decision.

Arithmetic and logic unit

is a logical unit of the computer that performs calculations.

comments

____ are used to document a program and improve its readability.

//

____ begins an end-of-line comment.

floating-point number

A(n) ____ is a number with a decimal point, such as 7.33, 0.9333, 1000.123445.

0

Instance variables of types char, byte, short, int, long, float and double are all given the value ____ by default.

if statement

A decision can be made in a Java program with a(n) ____.

ellipsis (...)

A(n) ____ in the parameter list of a method indicates that the method can receive a variable number of arguments.

local variable

A variable known only within the method in which it's declared is called a(n) ____.

left brace, right brace

A(n) ____ begins the body of every method, and a(n) ____ ends the body of every method.

sequence, selection, repetition

All programs can be written in terms of three types of control structures: ____, ____, and ____.

SecureRandom

An object of class ____ produces truly random numbers.

The break statement, when the executed in a while, for, do while or switch, causes immediate exit from that statement. The break statement is used to escape early from a loop or to skip the remainder of a switch. And the continue statement skips the remaining statements in the loop body and proceeds with next interaction of the loop.

Compare and contrast the break and continue statements.

programs

Computers process data under the control of sets of instructions called ____.

top

Data can be added or removed only from the ____ of a stack.

1. a controlled variable (loop counter) 2. the initial value of the control variable 3. the increment by which the control variable is modified each time through the loop 4. the loop continuation condition that determines if looping should continue.

Describe the four basic elements of counter-controlled repetition.

do...while is used when the program needs to execute at least once.

Discuss a situation in which it would be more appropriate to use a do...while statement than a while statement.

information hiding

Objects enable the design practice of ____ - although they may know how to communicate with one other across well-defined interfaces, they normally are not allowed to know how other objects are implemented.

False. And array index must be an integer or an integer expression

T/F An array index should normally be of type "float"

True

T/F A nested control statement appears in the body of another control statement.

False. A primitive-type variable cannot be used to invoke a method-a reference to an object is required to invoke the object's methods.

T/F A primitive-type variable can be used to invoke a method.

False. A repetition statement specifies that an action is to be repeated while some condition remains true.

T/F A selection statement specifies that an action is to be repeated while some condition remains true.

False. A set of statements contained within a pair of braces is called a block.

T/F A set of statements contained within a pair of parentheses is called a block.

False. The expression is evaluated using operator precedence.

T/F A valid Java arithmetic expression whit no parentheses is evaluated from left to right.

True

T/F All variables must be given a type when they're declared.

True

T/F An "import" declaration is not required when one class in a package uses another in the same package.

True

T/F An algorithm is a procedure for solving a problem in terms of the actions to execute and the order in which they execute.

False. An array can store only values of the same type.

T/F An array can store many different types of values.

For individual primitive-type elements of an array: False. A called method receives and manipulates a copy of the value of such an element, so modifications do not affect the original value. If the reference of an array is passed to a method, however, modifications to the array elements made in the called method are indeed reflected in the original. For individual elements of a reference type: True. A called method receives a copy of the reference of such an element. and changes to the referenced object will be reflected in the original array element.

T/F An individual array element that's passed to a method and modified in that method will contain the modified value when the called method completes execution.

True

T/F Any class that contains public static void main(String[] args) can be used to execute an app.

False. By convention, method names begin with a lowercase first letter and all subsequent words in the name begin with a capital first letter.

T/F By convention, method names begin with an uppercase first letter, and all subsequent words in the name begin with a capital first letter.

False. Command-line arguments are separated by white space.

T/F Command-line arguments are separated by commas.

False. Comments do not cause any action to be performed when the program executes. They're used to document programs and improve their readability.

T/F Comments cause the computer to print the text after the // on the screen when the program execute.

True

T/F Empty parentheses following a method name in a method declaration indicate that the method does not require any parameters to perform its task.

True

T/F Every method's body is delimited by left and right braces ( { and } ).

False. Such literals are of type "double" by default.

T/F Floating-point values that appear in source code are known as floating-point literals and are type "float" by default.

False. Instance variables of type boolean are given the value false by default.

T/F Instance variables of type boolean are given the value true by default.

False. Java is case sensitive, so these variables are distinct.

T/F Java considers the variable number and NuMbEr to be identical.

False. Some operators ( like Assignment (=) ) are evaluated from right to left.

T/F Java operators are evaluated from left to right.

True

T/F Java provides the arithmetic compound assignment operators +=, -=, *=, /= and %= for abbreviating assignment expressions.

False. Primitive-type instance variables are initialized by default. Each local variable must explicitly be assigned a value.

T/F Primitive-type local variables are initialized by default.

True

T/F Pseudocode helps you think out a program before attempting to write it in a programing language.

True

T/F Reference-type instance variables are initialized by default to the value "null".

True

T/F Specifying the order in which statements execute in a program is called program control.

False. The "default" case is optional. If no default action is needed, then there's no need for a "default" case.

T/F The "default" case is required in the switch selection statement.

False. The operator *, / and % are higher precedence than operators + and -.

T/F The arithmetic operators *, /, %, + and - all have the same level of precedence.

False

T/F The following are all invalid variable names: 3g, 87, h22, and 2h

true

T/F The following are all valid variable names: _under_bar_, m93749, t5, j7, her_sales$, his_$account_total, a, b$, c, z, and z2.

True

T/F The number of arguments in the method call must match the number of parameters in the method declaration's parameter list.

False. The primitive types are portable across all computer platforms that support Java.

T/F The primitive types (boolean, char, byte, short, int, long, float and double) are portable across only Windows platforms.

Flase. The remainder operator can also be used with noninteger operands in Java.

T/F The remainder operator(%) can be used only with integer operands.

False. The unary cast operator (double) creates a temporary floating-point copy of its operand.

T/F The unary cast operator (double) creates a temporary integer copy of its operand.

False. Such variables are called local variables and can be used only in the method in which they're declared.

T/F Variables declared in the body of a particular method are known as instance variables and can be used in all methods of the class.

accelerometer

The Wii Remote, as well as many smartphones, use a(n) ____ which allows the device to respond to motion.

enhanced for statement

The ____ allows you to iterate through an array's elements without using a counter.

javac

The ____ command from the JDK compiles a Java program.

java

The ____ command from the JDK executes a Java application

Tranmission control protocol

The ____ ensures that messages, consisting of sequentially numbered pieces called bytes, were properly routed from sender to receiver, arrived intact and were assembled in the correct order.

bytecode verifier

The ____ examines bytecodes to ensure that they are valid.

scope

The ____ of a declaration is the portion of a program that can refer to the entity in the declaration by name.

&&

The ____ operator can be used to ensure that two conditions are both true before choosing a certain path of execution.

java

The ____ programming language is now used to develop large-scale enterprise applications, to enhance the functionality of web servers, to provide applications for consumer devices and for many other purposes.

c++

The ____ programming language was developed by Bjarne Stroustrup in the early 1980s at Bell Laboratories.

return

The ____ statement in a called method can be used to pass the value of an expression back to the calling method.

if else

The ____ statement is used to execute one action when a condition is true and another when that condition is false.

switch

The ____ statement selects among multiple actions based on the possible values of an integer variable or expression, or a "String".

continue

The ____ statement, when executed in a repetition statement, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.

sequence

The ____ structure is built into Java; by default, statements execute in the order they appear.

JVM's class loader

The ____ takes the .class files containing the program's bytecodes and transfers them to primary memory.

False. The switch statement does not provide a mechanism for testing ranges of values, so every value that must be tested should be listed in a separate case label.

To test for a range of values in a switch statement, use a hyphen (-) between the start and end values of the range in a "case" label.

primitive, reference

Types in Java are divided into two categories -- _____types and ____types.

for, while

Typically, ____ statements are used for counter-controlled repetition and ____ statements for sentinel-controlled repetition.

for(double d: numbers)

Use the enhanced for statement ____ to walk through "double" array "numbers".

args.length

Use the expression ____ to receive the total number of arguments in a command line. Assume that command-line arguments are stored in String[] args.

if

You can use the ____ statement to make decisions.

Memory unit, secondary storage unit

____ and ____ are logical units of the computer that retain information.

Keywords

____ are reserved for use by Java.


Kaugnay na mga set ng pag-aaral

Chapter 56: Assessment and Management of Patients with Female Physiologic Processes

View Set

Chapter 7 and 8- Linear Programming Models

View Set

MKT 340 ISU Peterson Final Study Guide

View Set