• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/45

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

45 Cards in this Set

  • Front
  • Back
Assume a class BankAccount has been created, and the following statement correctly creates an instance of the class:

BankAccount account = new BankAccount(5000.0);

What is true about the following statement?
System.out.print(account);
the account object's toString method will be called.
Giving the following Java statement, which statement will write"Eagle" to the file DiskFile.txt?
PrintWriter diskOut = new PreintWriter("DiskFile.txt");
diskOut.println("Eagle");
When using the DecimalFormat class, which of the following will .1359 to 013.6%?
000.0%
What will be returned from a method, if the following is the method header?

public Rectangle getRectangle()
the address of an object of the Rectangle class
To compare two objects in a java class you must____.
write an equals method that will make a field comparison of the two objects.
What will generate a random number from 0 -1.0?

Random rand = new Random();
System.out.print(rand.nextDouble());
What is the import statement for PrintWriter?
import java.io.*;
What will the following output return?

Scanner keyboard = new Scanner(System.in);

String filename;

System.out.print("Enter the filename: ");

filename = keyboard.readString();

PrintWriter outFile = new PrintWriter(filename);
Nothing. There is a syntax error.
You have a defined a class CheckingAccount with a public static field named account and created a CheckingAccount object referenced by the variable, bankAccount. Which of the following will reference the account?
CheckingAccount.account;
What will open a file named MyFile.txt and allow you to read data from it?
File fileName = new File("MyFile");

Scanner inputFile = new Scanner(fileName);
How is an object created from a class?
import java.util.Random;

Random randomNumbers= new Random();
Methods of the Random Class
nextInt(int n) - T
Use three useful methods from the math class?
Math.pow();

Math.sqrt();

Math.PI

Math.rnd();
What does the JOptionPane class do?
Allows you to display a message or input
• Give the method for the JOptionPane to display output?

Give an example?
JOptionPane.showMessageDialog

JOptionPane.showMessageDialog(null, “Hello World”);
Parse Methods
// Store 2599 in iVar.
Int iVar = Integer.parseInt(“2599”);
DecimalFormat class
What does the # sign mean?
suppresses zeros
What does the zero mean in that format?
i
t means that is will display the position but if the # sign is there it will suppress the decimal.
What’s the difference between an input file and an output file
Input a file in which you would input data…read data
Output a file into which you would write a file from your data.
What’s the import statement that you need in an file operation?
import java.io*;
static fields and static methods are also known as _____.
Class fields or class methods.
To invoke a static method or use a static field, ______, rather than the object name, is used.
the class name
When a class contains a static method, it is not necessary to create an ________.
instance of the class in order to use the method
static methods may not communicate with instance fields, only_______.
static fields
Normally, each object has its own data space, but if a variable is declared as static, only ______ of the variable exists
private static int count;
one copy
An object reference variable that does not currently point to an object is called a________.
null reference
The reserved word null can be used to explicitly set a null reference:
name = null;

or

if (name == null)
System.out.println("Invalid");
The _____ reference is simply a name that an object can use to refer to itself.
this
The _______ reference can be used to allow a parameter to have the same name as an instance field.

public void setLength(double length)
{
this.length = length;
}
this
The _______ method of a class can be called explicitly: (distance is an object of the FeetInches class)
toString()
an example of String method being used:
System.out.println("The distance you entered is "
+ distance.toString());
An example of the the toString() method does not have to be called explicitly but is called implicitly whenever you concatenate an object of the class with a string:
System.out.println("The distance you entered is "
+ distance);
All objects have a toString() method that returns______ & ______ of the object.
the class name

a hash of the memory address
When objects are no longer needed they should be _____.
destroyed
The _______ will reclaim memory from any object that no longer has a valid reference pointing to it.
garbage collector
Instead of using the == operator to compare two objects, we should use the _____.
equals method
The equals method will compare objects by their _______ rather than by their memory addresses.
contents
Java uses the method signature (name, type of parameters and order of parameters) to determine which method to call?
Overloaded method
Operations performed by the I/O classes may throw an _______.
IOException
An example of throws IOException:
public static void main (String[] args) throws IOException
input file name is stored in variable file
String line, file = "inventory.txt";

File openFile = new File (file);
Scanner inFile = new Scanner (openFile);
The _____ class is used to open the input file.
File

nextLine method is from Scanner class
When reading text tiles, an example that reads reads one line of text file as String data and stores it in the variable line:
line = inFile.nextLine();
_________________ creates a loop which will iterate until all the lines of the file are read:
while (inFile.hasNext())
An example of closing a file:
inFile.close();