Week 10 - File Manipulation, Iterators, Reflection & Custom Annotations Flashcards
What is a regular expression?
a compact form to define a string
used to check the validity of strings
Write a regular expression for a string that starts with string “01” and is followed by 7 numerical digits from 0 to 9?
string.matches(“01[0-9]{7}”)
{a} for repetition a times, {a, b} from a to b times, {a,} from a to n
Write a regular expression for a string that matches either 00 or 111 or 0000?
string.matches(00|111|0000)
this expression requires exactly the same form, not ‘contains’
Write a regular expression for a string that matches either 00000 or 00001
string.matches(“0000(0|1)”)
Write a regular expression for a string that matches “trolo” with however many “lo” after
string.matches(“trolo(lo)*”)
string.matches(“trolo(lo)+”)
string.matches(“trolo(lo)?”)
(*) for repetition from 0 to n times, (+) from 1 to n, (?) from 0 to 1
[145] and [2-36-9] and [a-c]* mean the same as?
(1|4|5) and (2|3|6|7|8|9) and a string made only of characters a,b,c
We use square brackets for defining groups of characters
How many characterrs of internal buffer does the BufferedWriter maintain?
8192
During the write operation, the characters are written to the internal buffer or the disk?
internal buffer, not the disk
Which exception does reading and writing to the files throw and how to manage it?
It throws the IOException and it is managed with try-catch blokc or by adding the throws declaration in the method signature
In what package can we find the FileWriter and in which package can we find iterators?
java.io.package fro FileWriter class, java.util.package for iterators
What is an iterator?
An interface that faciliates the traversal of elements in a collection
What are the three main methods of Iterator interface?
boolean hasNext(): Returns true if there are more elements in the collection, false otherwise.
next(): returns the next element in the iteration. This method should be called only if hasNext() returns true. Otherwise, it may throw a NoSuchElementException.
void remove(): removes the last element returned by next() from the underlying collection. If the iterator does not support removal, it throws an UnsupportedOperationException.
Can private or final attributes be accessed and manipulated by reflection?
Yes.
Which methods do not need the object?
reflection related
static methods
What does the annotation do?
It simply provides information that can be used at compile time or runtime to perform further processing.