Chapter 4-6 (Exam 2)

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Logical NOT

! (unary, boolean) reverses the truth of an expression

Logical AND

&& (binary, boolean) will evaluate to false as soon as it sees that one of its operands is a false expression

Objects

(a) can store data, fields (b) can perform operations, methods

public

+

private

-

Reading from a file

1. import java.io.*; 2. main -> throws IOException 3. File file= new File(filename); Scanner inputFile = new Scanner(file); 4. String line = inputFile.nextLine(); 5. inputFile.close();

Writing to a file

1. import java.io.*; 2. main -> throws IOException 3. PrintWriter outputFile = new PrintWriter(filename); 4. outputFile.println(friendname); 5. outputFile.close();

Decimal Format

1. import java.text.DecimalFormat; 2. DecimalFormat dollar = new DecimalFormat("#,##0.00); 3.dollar.format(totalSales);

In your textbook the general layout of a UML diagram is a box that is divided into three sections. The top section has the _______; the middle section holds _______; the bottom section holds _______. a. class name; attributes or fields; methods b. class name; object name; methods c. object name; methods; attributes or fields d. object name; class name; methods

A

Which of the following will open a file named MyFile.txt and allow you to append data to its existing contents? a. FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter); b. PrintWriter pwriter = new PrintWriter("MyFile.txt"); FileWriter outFile = new FileWriter(pwriter); c. PrintWriter outfile = new PrintWriter("MyFile.txt", true); d. PrintWriter outfile = new PrintWriter(true, "MyFile.txt"); e. None of these

A

When an object is passed as an argument to a method, what is passed into the method's parameter variable? a. the class name b. the object's memory address c. the values for each field d. the method names e. None of these

B

Local variables a. are hidden from other methods b. may have the same name as local variables in other methods c. lose the values stored in them between calls to the method in which the variable is declared d. All of the above e. None of a. , b. or c.

D

Which of the following are classes from the Java API? a. Scanner b. Random c. PrintWriter d. All of the above e. Only a. and b.

D

Which of the following is not a benefit derived from using methods in programming? a. problems are more easily solved b. simplifies programs c. code reuse d. all of the above are benefits e. Only a. and b.

D

A UML diagram does not contain: a. the class name. b. the method names. c. the field names. d. access modifiers e. object names

E

T/F A method in a class declared as static may be invoked by a client simply by using the name of the method alone.

False

T/F In the method header, the method modifier public means that the method belongs to the class, not a specific object.

False

T/F When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.

False

Reading data from a File

File myFile = new File("Costumers.txt"); Scanner inputFile = new Scanner(myFile);

T/F An argument passed by value to a method could be a constant, a variable, or an expression.

True

UML

Unified Modeling Language

Access Specifier

a Java keyword that indicates how a field or method can be accessed

Flags

a boolean variable that monitors some condition in a program

Class

a code that describes a particular type of object

no-arg constructor

a constructor that does not accept arguments

shadowing

a method may have a local variable with the same name as an instance field

constructor

a method that is automatically called when an object is created

The if-else statement

adds the ability to conditionally execute code when the if condition is false

The switch statement

allows you to use an ordinal value to determine how a program will branch

hasNext()

boolean method will return turn if another item can be read from the file

The break Statement

can be used to abnormally terminate a loop **not recommended

Sentinel value

can be used to notify the program to stop acquiring input (a non-possible value)

Comparing characters

characters are ordinal

static

class method

stale data

data that requires the calculation of various factors has this potential risk

The if statement

decides whether a section of code executes or not

Calling a method

displayMessage();

Comparing String objects

equals or compareTo methods (are both case sensitive)

Nested if statements

if statement appears inside another if statement

Strings are ___________________

immutable

Writing text to a File

import java.io*; PrintWriter outputFile = new PrintWriter("StudentData.txt"); outputFile.print(";lkasj;flkajs;"); outputFile.println(";laksdjfa;oi");

Random Class

import java.util.Random; Random randomNumbers =new Random();

y++

indicates that the variable will be incremented or decremented after the rest of the equation has been evaluated

--y

indicates that the variable will be incremented or decremented prior to the rest of the equation being evaluated

The if-else-if statements

makes certain types of nested decision logic simpler to write; else statements match up with the immediately preceding unmatched if statement

method signature

method name and parameter data types *NOT the return type

mutators

methods that modify the data of fields

accessors

methods that retrieve the data of fields

instance

object created from a class

void method

one that simply performs a task and then terminates

java.lang

package automatically available to any Java class

references are______________________

passed by address

arguments are _____________________

passed by value

value-returning method

performs a task and then sends a value back to the code that called it

The do-while loop

post-test loop use it where you want the statements to execute at least one time

The for loop

pretest loop use it where there is some type of counting variable that can be evaluated

The while loop

pretest loop use it where you do not want the statement to execute if the condition is false in the beginning

Method header

public static void displayMessage()

Conditional operator

ternary operator works like an if else statement BooleanExpression ? value 1: value 2

DecimalFormat Class

the full fractional value of doubles and floats will be printed

Input validation

the process of ensuring that user input is valid

binding

the process of matching a method call with the correct method

The printf method

to perform formatted console output System.out.printf(FormatString, ArgList)

overloading

two or more methods or constructors in a class that have the same name but different parameter lists

methods

used to break a problem down into small manageable pieces

Exception

when something unexpected happens in a Java program this is thrown

The continue Statement

will cause the currently executing iteration of a loop to terminate and the next iteration will begin

Increment and decrement operators

y++ --y

Logical OR

|| (binary, boolean) will evaluate to true as soon as it sees that one of its operands is a true expression


Ensembles d'études connexes

How to Read Like A Professor Ch. 12-Postlude

View Set

Nursing foundations PrepU exam 1

View Set

Chapter 46: Sexually Transmitted Infections

View Set

Fluids And Electrolytes Quiz Patho

View Set

IB History: First Indochina War (1946-1954) & Vietnam War (1955-1975)

View Set