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;
17 Cards in this Set
- Front
- Back
Reusing constructors |
-One constructor can call other constructors. -The use the word this as the first word for the constructor public MyTime(int h, int m) { hours = h; mins = m; } public MyTime(int hhmm) { int h = hhmm/100; int m= hhmm%100; this(h,m) } |
|
what happens in memeory when an object is passed as a paramater to a method |
When the object is created a special space in memory is reserved for it, and the memory address is returned to the identifier. It is the memory address of the object that we pass as a parameter to a method. Which may make a new copy of the address |
|
find the size of an array |
array.length; it is not a method |
|
Default definition for whitespace |
Is space, tab, new line |
|
token definition |
A block of non-whitespace characters, note we can customise what we define as whitespace |
|
Which class would you use to write streams of characters to a file |
Use the FileWriter class FileWriter writer = new FileWriter("MyData.txt") The write method can be used to write a single character char c = '?'; writer.write(c); The file should be close after writer operations are complete |
|
File class; how to construct File object and what methods it has |
File f = new File("the file name"); f.exists() returns true if file exists f.length() returns the number of bytes in a file as an int f.delete() deletes the file f.canRead(), f.canWrite() f.isDirectory(), f.isFile() normal file f.lastModified() returns the time as a long f.setLastModified() set the modification time f.mkdir() creates a directory (folder) with this file name |
|
can use the file class to create a specific file rather than a String name |
File f = new File("MyData.txt") PrintWriter writer = new PrintWriter(f); |
|
When using PrintWriter, FileReader and File what must the constructors contain |
The filename in quotation marks ie "filename.txt" |
|
Reading Streams of raw bytes |
Use FileInputStream class FileInputStream input = new FileInputStream("MyData.txt") The read method returns a single byte encoded as an integer int next = input.read() returns -1 if at end of file If not at the end of file we can cast the integer as a byte and process the data required b = (byte) next; |
|
Writing Streams of raw bytes |
Use FileOutputStream class FileOutputStream output = new FileOutputStream("MyData.txt"); The write method can be used to write a single byte byte b = ...; output.write(b); The file should e closed after write operations are complete output.close(); |
|
Define what a JFrame object is |
An independent window or screen |
|
What must we import to use JFrame |
import javax.swing.*; |
|
What must we import to use the ActionListener class |
import java.awt.event.*; |
|
What is the easiest way to get a listener object? |
-Use our JFrame object to listen for ActionEvents -ButtonFrame must implement ActionListener as well as extend JFrame public class ButtonFrame extends JFrame implements ActionListener |
|
When we are using precision in String format is decimal point included in precision |
Yes, decimal place is counted, so if we have %5.2f means fieldwidth 5, so 2 for before decimal place, 1 for decimal, and 2 after decimal |
|
What to import if we want to JPanel |
import java.awt.*; |