Java 12-17

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

Lambdas and Strings introduce

functional technology (using functions to simplify tasks ==> we care about the what not how)

listIterator() ListIterator<Type> iterator = list.listIterator();

gets a bidirectional list iterator (think of head and tail pointer in linked list)

frequency()

gives the number of times an object is found in a collection Collections.frequency(Collection, object)

Collectors

its a stream that combines elements into an object using its method ie. joining() Collectors.joining(" ")

Map

key and value pairs. No duplicate keys are allowed (keys are the 'pointers')

Intermediate Operations use

lazy evaluation

disjoint() Collections.disjoint(Collection1, Collection2)

method _____ tells t/f if elements in two collections are disjoint or not

Bound Instance Method form

objectName:instanceMethodName example System.out::println ==> x -> System.out.println(x)

fill() Collections.fill(list, object o)

overwrites all the elements in the collection with the object passed in

Eager Evaluation

perform the operation as requested

shuffle()

randomly puts the elements in a list Collections.shuffle(list)

StringBuilder.reverse();

reverses the StringBuilder

Collections Methods

sort() binarySearch() reverse() shuffle() fill() copy() min() max() addAll() frequency() disjoint()

sort()

sort() funtion has two version, one that just takes in the collection and uses that collection's compareTo function, Collections.sort(List) or one that takes in a collection and a comparator compare function() which defines a new way of comparing objections in the collection Collections.sort(List, compare() from Comparator )

Intermediate Operations

specify tasks to perform on a stream's elements before a terminal operation produces a result ex. map(), filter(), sorted()

newBufferedWriter, BufferedWriter

static methods _____ recaives a Path specifying the file to open for writing ("xx.xml") and if the file exists it returns a ____ that class JAXB will use to write text to the file

Autoboxing

the automatic conversion between a primitive value and a corresponding wrapper object happens when we try to add elements to a List. ie, ArrayList.add(2) ==> int 2 turns into an Integer

listIterator.previous();

the method _____ Gets the previous element while iterating. a list method

Lambda expressions enable you

to create methods that can be treated as data. You can, - pass lambdas as arguments to other methods (ie map()) - assign lambda expressions to variables for later use - return lambda expressions from methods

a List List<Account> in class Accounts

to serialize a _____, it must be defined as an instance variable of a class.

external iteration

when you explicitly write out the iteration details. ie a for(int i = 0; i < 10; i++){ }

Lambdas and Streams help us

write certain kinds of programs faster, simpler, more concisely, and with fewer bugs than previous techniques

In counter-controlled iteration

you determine what you want then how you want to do it.

How elements move through stream pipelines

- Each new stream is simply an object representing the processing steps that have been specified to the point in the pipeline. - Changing intermediate operation method calls adds to the set of processing steps to perform on each element. - The last stream object contains all the processing steps to perform on each stream element. - When you initiate a stream pipeline with a terminal operation, the intermediate operations processing step are applied to elements before moving on

List Properties

- ordered Collection that can contain duplicate elements - zero indexed - has methods for manipulating elements (such as replace, get) - implemented by ArrayList, LinkedList, Vector

mapping intermediate operation example

.map((int x) -> {return x *2; }) This is how we write a mapping intermediate operation. It takes in a method/lambda as an argument, the method/lambda has one parameter, and has one statement (may possibly do more, I do not know the full extensiveness)

Byte array

A Byte Array Input Stream reads from a byte array in memory. A Byte Array Output Stream outputs to a _________ ___________ in memory.

True

A LinkedList can contain duplicate values.

False. It can contain duplicate values not keys. (Think of keys as pointers. )

A Map can contain duplicate keys.

stream

A PrintWriter (p. 654) writes characters to a______________.

False. Attempting to insert a null element causes a NullPointerException.

A PriorityQueue permits null elements.

False. By definition, it cannot.

A Set can contain duplicate values.

serialized

A ____ object is represented by XML that includes the object's data

property

A _____ is defined by creating set and get methods with specific naming conventions. Typically, such methods manipulate a corresponding private instance variable that has the same name as the _(same word), but this is not required. The get method is usually "is" not "get" ie "isName".

Method Reference

A ______ is a lambda that simply calls another method, we can just call that method. Object::method name

property listener

A ______ is an event handler that's invoked when a property's value changes. In the event handler, you can respond to the property change in a manner appropriate for your app.

Path

A ________ (p. 647) represents the location of a file or directory. Path objects do not open files or provide any file-processing capabilities.

Print Stream

A ________ ___________ (p. 674) performs text output. System.out and System.err are PrintStreams.

Line Number Reader

A ________ ____________ _________ (p.676) is a buffered character stream that tracks the number of lines read.

Relative Path

A __________ ___________ (p.647) starts from the directory in which the application began executing.

Directory Stream

A ___________ ___________ (p.647) enables a program to iterate through the contents of a directory.

Separator character

A ____________ ______________ (p.650) is used to separate directories and files in the path. Section 15.4 Sequential-Access Text Files

Sequence Input Stream

A _____________ __________ ______________ concatenates several InputStreams. When the program reaches the end of an input stream, that stream closes, and the next stream in the sequence opens.

literal's value

A character ____ is its integer value in Unicode

getIterator() ie Collection.getIterator(); ArrayList.getIterator() ==> i++;

A collection method which gives us the iterator

Set

A collection that does not contain duplicate elements

on Mouse Dragged

A control's ____ event handler specifies what to do when the user drags the mouse on the control.

Collection

A data structure. An object that contains references to other objects. Contains methods such as add, clear, compare.

Concrete subclasses

A filter stream (p. 674) provides additional functionality, such as aggregating data bytes into meaningful primitive-type units. FilterInputStream (p. 674) and FilterOutputStream are typically extended, so some of their filtering capabilities are provided by their ____________ ______________.

Collections

A framework for different data structures. Contains static (not dependent on class) methods such as search and sort.

predicate

A lambda/condition used to filter elements. example. Passed into filter()

toArray()

A list method which lets us convert a list into an array.

mapToObj() .mapToObj(String::valueOf)

A method To map an int to a different object example: String Just extra stuff, ie the lambda that can go in it className::staticMethodName x --> String.valueOf(x) //Converts x to string

ListIterator: set(Object o)

A method that at current element, sets to the one of the objects in the parameters.

Arrays: asList()

A method that gets an Array as a List Notice its a static method.

reverse()

A method that reverses the objects in the collection is ______

ListIterator: hasPrevious()

A method which checks to see if we have a previous element.

Anonymous method

A method without a name. An anonymous method is a code block that is passed as a parameter to a delegate.

True. It's a method. Didn't really learn/use this. GridPane.setColumnSpan(yourNode, GridPane.REMAINING);

A node can span multiple columns in a GridPane.

True

A node's position should be defined relative to its parent node and the other nodes in its parent.

Type-Wrapper Class

A object representation of a primitive type. It is a final class. Thus, cannot be extended. Contains methods, such as Integer.MAX

List

A ordered (inserted to end) collection that can contain duplicate elements

short circuit.

A performance feature of lazy evaluation is the ability to perform ______ evaluation— that is, to stop processing the stream pipeline as soon as the desired result is available.

terminal operation

A stream operation that computes an end product (either forEach or reduced). formally: initiates a stream pipeline's processing and produces a result. It tells the intermediate operations to start.

False! A string is immutable. It cannot be changed. You can however use a StringBuilder string which can be modified.

A string can be modified after it's created

reduction

A termination operation that reduces the stream of elements into one value. Ex. sum(), count(), average(), min(), max()

binarySearch()

A type of search where the Collection must be sorted! returns index if found, or negative of where the object would be indexed.

Difference Between ArrayList and Vector

A vector is synchronized, meaning its thread safe, meaning that its built to handle multiple threads. ArrayList is unsynchronized, and not thread safe. But it does perform much better than Vector.

layout

A(n) ___ determines the size and positioning of nodes in the scene graph

textfield

A(n) ____ can display text and accept text input from the user

TitledPane

A(n) ____ displays a title at its top and is a collapsible panel containing a layout node, which in turn contains other nodes.

FXML

A(n) ____ file contains the description of a JavaFX GUI.

Iterator

A(n) ____ is used to iterate through a collection and can remove elements from the collection during the iteration.

lambda expression

A(n) ____ represents an anonymous method—a shorthand notation for imple- menting a functional interface.

stage

A(n) ____ represents the app's window.

LinkedList addFirst()

Adds an element to the beginning of the list.

LinkedList add()

Adds an element to the end of the list

LinkedList addLast()

Adds an element to the end of the list

deserialized

After a serialized object has been written into a file, it can be read from the file and ____ - that is, the XML that represents the object and its data can be used to recreate the object in memory

Type Interface <>

Allows us to make Collection/Method Generic (Can pass in a String, Media, etc...) ex. ArrayList<String> arr = new ArrayList<>();

controller class

An FXML GUI's event handlers are defined here. initialize method is defined here (starts everything)

IntStream

An _____ (package java.util.stream) is a specialized stream for manipulating int values.

Absolute Path

An ___________ _____________ (p. 647) contains all the directories, starting with the root directory (p. 647), that lead to a specific file or directory. Every file or directory on a disk drive has the same root directory in its path.

True.

An absolute path contains all the directories, starting with the root directory, that lead to a specific file or directory.

index

An element in a List can be accessed by using the element's ________ .

filter() ex. Stream.filter((x)->{x%2==2;})

An intermediate operation which takes in a lambda which is used as a condition to check against the elements in the stream. returns boolean for the elements that match the condition (or the predicate)

@XMLElement

Annotation ____ (package javax.xml.bind.annotation) indicates that the private instance variables should be serialized Important because the instance variable is not public and there's no corresponding public read-write property

s1 += s2;

Append the string s2 to the string s1 using +=

addAll()

Appends all elements in an array to a collection. Collections.addAll(Collection , Array)

addAll(Collection 2) Collection1.addAll(Collection2)

Appends all of collection2 elements into Collection1

cell factory

As the ListView displays items, it gets ListView cells from its ____

Autoboxing

Assuming that myArray contains references to Double objects, _____ occurs when the statement "myArray[0] = 1.25;" executes.

Auto-unboxing

Assuming that myArray contains references to Double objects, ________ occurs when the statement "double number = myArray[0];" executes.

False.Text files are human readable in a text editor. Binary files might be hu- man readable, but only if the bytes in the file represent ASCII characters.

Binary files are human readable in a text editor.

public instance variables

By default, JAXB serializes only an objects ___ ___ ___ and public read-write properties

False. It lets you pick values from 0.0 to 100.0

By default, a Slider allows you to select values from 0 to 255.

False. Class Formatter contains method format, which enables formatted data to be output to the screen or to a file.

Class Formatter contains method printf, which enables formatted data to be output to the screen or to a file.

Piped-character streams

Class Piped Reader (p. 676) and class Piped Writer (p. 676) implement _________ ___________ ___________ for transferring data between threads.

StringBuilder buffer1 = new StringBuilder(); //capacity = 16 StringBuilder buffer2 = new StringBuilder(10); //capacity = 10 StringBuilder buffer3 = new StringBuilder("hello"); //capacity = 16+5(size of string) StringBuilder buffer4 = new StringBuilder(charArray) //capacity = 16 + size

Class StringBuilder provides constructors that enable StringBuilders to be initialized with no characters and an initial capacity of 16 characters, with no characters and an initial capacity specified in the integer argument, or with a copy of the characters of the String argument and an initial capacity that's the number of characters in the String argument plus 16. Also provides what where it has a CharArray

FXCollections

Class ____ provides static methods for creating and manipulating observable collections.

buffer character-based streams.

Classes BufferedReader (p. 675) and BufferedWriter (p. 675) _____________ ____________ _____________ ______________

Char arrays

Classes Char Array Reader (p. 676) and Char Array Writer (p. 676) manipulate ___________ ____________.

file I/O

Classes FileReader (p. 676) and FileWriter (p. 676) perform character-based _____ _______.

Collect verus Collectors

Collect returns a single object of the stream Collectors combines the stream into the single object They are of different streams and have specific return types

Different types of Collections

Collection (Root of others), Set, Map, List, Queue

contains(Object o)

Collection method which checks if an object is in it.

disjoint()

Collections algorithm ______ determines if two collections have elements in common.

False. Collections is a class; Collection is an interface.

Collections is an Interface.

s1.equals(s2)

Compare the string in s1 to the string in s2 for equality of contents

Hard Disks

Computers store files on secondary storage devices (p.645) such as ________ ________.

Files

Computers use ___________ for long-term retention of large amounts of persistent data (p. 645), even after the programs that created the data terminate.

copy() Collections.copy(destinationList, originalList)

Copies elements from one collection into the other

x -> pow(x, 3) //short hand //long (int x) --> {return pow(x, 3);}

Create a one-parameter lambda that returns the cube of its argument.

s1.length()

Determine the length of the string in s1

StringBinding

DoubleProperty method asString returns a(n) ___ object (which is an Observable value) that produces a String representation of the DoubleProperty

setUserData

Each JavaFX control has a _____ method that receives an Object. You can use this to store any object you'd like to associate with that control - typically this Object is used when responding to the control's events.

StringProperty

Each TextField has a text property that's returned by its textProperty method as a(n) ____ (package javafx.beans.property)

MouseEvent

Each _____ handler you define must provide one parameter type ____. When the event occurs, this parameter contains information about the event, such as location, where it was pressed, which node it interacted with, etc.

True

Each layout pane has a getChildren method that returns an ObservableList<Node> collection containing the layout's child nodes.

True

Every concrete Application subclass must directly or indirectly override method start.

Mechanism

Every operating system provides a _________________ to determine the end of a file, such as an end-of- file marker (p. 645) or a count of the total bytes in the file.

exists() Files.exists(pathObject)

Files Static Method ____________ (p. 648) receives a Path and determines whether it exists (either as a file or as a directory) on disk.

Binary Files, Text Files

Files created using byte-based streams are _________________ (p. 646). Files created using character- based streams are ______ (p. 646). Text files can be read by text editors, whereas binary files are read by a program that converts the data to a human-readable format.

size() Files.size(Path object)

Files static method ______ (p. 648) receives a Path and returns a long representing the number of bytes in the file or directory. For directories, the value returned is platform specific.

isDirectory() Files.isDirector(pathObject.)

Files static method __________ (p. 648) receives a Path and returns a boolean indicating whether that Path represents a directory on disk.

True.

Files static method exists receives a Path and determines whether it exists (either as a file or as a directory) on disk

Path objects

Files static method new DirectoryStream (p. 648) returns a Directory Stream <Path> containing ________ __________ for a directory's contents.

getLastModifiedTime() Files.getLastModifiedTime(Path object)

Files static method______________ (p. 648) receives a Path and returns a FileTime (package java.nio.file.attribute) indicating when the file was last modified.

Queue

First in, First Out collection

key, value

For Maps, a BiConsumer's first parameter represents the _____ and its second repre- sents the corresponding ____ .

parallelize

Functional programs are easier to ______ (i.e., perform multiple operations simulta- neously) so that your programs can take advantage of multi-core architectures to en- hance performance.

subList(int fromIndex, int toIndex) list.subList(start, end)

Get a sublist from larger list.

max() Collections.max(list)

Gets the maximum element in the collection

min()

Gets the minimum element in the collection Collections.min(list)

Boxing

Going from primitive type to type-wrapper object.

Unboxing

Going from type-wrapper object to primitive type

double

If you do not specify a capacity increment, the system will _____ the size of the Vec- tor each time additional capacity is needed.

accessibility features

In a Java SE 8 update, JavaFX added _____ to help people with visual impairments use their devices. These features include screen-reader support, GUI navigation via the keyboard and a high-contrast mode to make controls more readable.

False. It shouldn't in general. Me: If anything it should be computed that way its as responsive as possible.

In general, a node's size should be defined explicitly

True

In the RGBA color system, every color is represented by its red, green, blue color values, each ranging from 0 to 255, where 0 denotes no color and 255 full color. The alpha value (A) - which ranges from 0.0 to 1.0 - represents a color's opacity, with 0.0 being completely transparent and 1.0 completely opaque.

Byte-based I/O

InputStream and OutputStream are abstract classes for performing _____________________ ______.

bulk (meaning on the entire collection). Examples include add, clear, compare

Interface Collection contains ________ operations (i.e., operations performed on the entire collection).

Input stream

Interface Data Input describes methods for reading primitive types from an ________ __________. Classes Data Input Stream (p. 674) and RandomAccess File each implement this interface.

Output stream

Interface Data Output describes methods for writing primitive types to an _________ ___________. Classes Data Output Stream (p. 674) and Random Access File each implement this interface.

lazy

Intermediate stream operations are ____ —they aren't performed until a terminal operation is invoked.

hasNext()

Iterator method that tells us if we have a following element.

remove()

Iterator method to remove current element.

True .remove()

Iterators can remove elements.

XML serialization JAXB.marshal(the objects, the file)

JAXB (Java architecture for XML -- for manipulating objects) enables you to perform ______ - which JAXB refers to as marshaling.

JAXB.unmarshal(file, Object.class)

JAXB static method _____ reads the contents of the xml file and converts the XML int to specified object. //There's more details to this but unimportant rn

JAXB.marshal(object, outputfile)

JAXB static method ______ to serialize as XML the objects contained in the List. It does the whole list with one method.

POJOS (plain old Java objects)

JAXB works with ______ - no special superclasses or interfaces are required for XML serialization support

nested types

Java allows you to declare classes, interfaces, and enums inside other classes, called

executing—System.in, System.out and System.err.

Java also can associate streams with different devices. Three stream objects are associated with devices when a Java program begins _______________,___________________and __________________

ArrayList and Vector

Java classes ____ and _____ provide the capabilities of array like data structures that can resize themselves dynamically.

Bytes

Java views each file as a sequential stream of ________ (p.645).

hierarchy

JavaFX Scene Builder Document window's ______ section shows the structure of the GUI and allows you to select and allows you to select and reorganize controls.

Model-View-Controller (MVC)

JavaFX applications in which the GUI is implemented as FXML adhere to the ______ design patter, which sepeareate the apps data (M) from the apps GUI (V) and the processing logic (C).

True

JavaFX properties are observable - when a property's value changes, other objects can respond accordingly.

True

JavaFX's TableView control (pacakage javafx.scene.control) displays tabular data in rows and columns, and supports interactions with that data.

WebView

JavaFX's ____ control enables you to embed web content in your JavaFX apps.

True

Lambda expressions can be used anywhere functional interfaces are expected.

functional interfaces

Lambda expressions implement ______.

True

Layout panes are container nodes that arrange their child nodes in a scene graph relative to one another, based on their sizes and positions

LinkedList vs ArrayList/Vector

LinkedList ==> efficient add method inefficient get method ArrayList ==> inefficient add method efficient get method

mapping (lambdas and streams)

Maintain the number of elements in a stream. Tranform the elements into new elements. ie go from int 1, to string "a" or from 2 to 4 (x+2)... etc.

StringBuilder.setCharAt(0, 'H');

Method ____ (p. 614) sets the character at the specified position.

StringBuilder.setLength(10)

Method _____ increases or decreases the length of a StringBuilder.

False. When summing the elements, the identity value is 0 and when getting the product of the elements the identity value is 1

Method reduce's first argument is formally called an identity value—a value that, when combined with a stream element using the IntBinaryOperator produces the stream element's original value. For example, when summing the elements, the identity value is 1 and when getting the product of the elements the identity value is 0.

Collections contain static methods

Methods such as search, sort,

False, they mostly use relative positioning

Most JavaFX layout panes use fixed positioning.

toString() pathObject.toString()

Path method ___ (p. 648) returns a String representation of the Path.

toAbsolutePath() pathObject.toAbsolutePath()

Path method _____ (p. 648) converts the Path on which it's called to an absolute path.

isAbsolute() pathObject.isAbsolulte()

Path method _______ (p. 648) returns a boolean indicating whether a Path represents an absolute path to a file or directory.

getFileName() pathObject.getFileName()

Path method ___________ (p. 648) gets the String name of a file or directory without any location information.

VBox

Places the nodes in a single column

HBox

Places the nodes in a single row

BorderPane

Places the nodes in the top, right, bottom, left, and center regions.

Writing coding that modifies a variable can possibly lead to errors:

Potential errors: - Initializing for loops control variable incorrectly - Wrong loop-continuation condition - increment control variable is incorrect - The code inside the for loop is incorrect

False. Property bindings are not limited to JavaFX controls. Package javafx.beans.property contains many classes that you can use to define bindable properties in your own classes.

Property bindings are limited to JavaFX controls

True

RadioButtons function as mutually exclusive options.

Collect verus Reduce

Reduce : reduce all the elements in a stream to a single value, ex. sum() Collect: reduce all the elements in a stream to a single object (ie data-structure) ex.collect(Collectors.joining(" ")) //returns sequence as a string. "1 2 3 4"

clear() list.clear()

Removes everything from a list.

collect() terminal operation

Returns an object that refers to all elements in the stream .collect(Collectors.joining(" "))

size() list.size()

Returns the number of elements from a list.

MAX Height

Setting a nodes ____ property to MAX_VALUE enables the node to occupy the full height of its parent node.

Imperative Programming

Specifying how

True

Stream method findFirst is a short-circuiting terminal operation that processes the stream pipeline but terminates processing as soon as an object is found.

False. Stream method flatMap receives a Function that maps an object into a stream

Stream method flatMap receives a Function that maps a stream into an object. For ex- ample, the object could be a String containing words and the result could be another intermediate Stream<String> for the individual words.

literal

String ____ are often referred to as String objects and are written in a program in double quotes

valueOf String.valueOf(____) can be an int ex. String.valueOf(1) ==> "1"

String class static method ____ returns its argument converted to a string.

charAt str.charAt(int index)

String method ___ (p. 599) returns the character at a specific position.

substring s1.substring(int start) or s1.substring(start, end-1)

String method ___ copies and returns part of an existing string object.

equals s1.equals(s2)

String method ___ tests for equality. The method returns true if the contents of the Strings are equal, false otherwise. Method equals uses a lexicographical comparison (p. 602) for Strings.

toCharArray

String method ____ (p. 610) returns a char array containing a copy of the string's characters.

replace s1.replace(char old, char new)

String method ____ returns a new string object that replaces every occurrence in a String of its first character argument with its second character argument.

length str.length()

String method ____ returns the number of characters in a String

compareTo s1.compareTo(s2) s1 val - s2 val determines it val are the ASCII vals. ie "b".compareTo("s") = -

String method ____ uses a lexicographical comparison and returns 0 if the Strings are equal, a negative number if the string that calls compareTo is less than the argument String and a positive number if the string that calls compareTo is greater than than the argument String.

concat s1.concat("") "b".concat("r") ==> "br"

String method _____ (p. 608) concatenates two string objects and returns a new string object.

equalsIgnoreCase s1.equalsIgnoreCase(s2) s1 = "hello" s2 = "HELLO" ret true

String method _____ performs a case-insensitive string comparison.

regionMatches str1.regionMatches(int toffset, String other, int ooffset, int len): Case sensitive test. str1.regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len): It has option to consider or ignore the case.

String method ______ (p. 601) compares portions of two strings for equality.

s1.toUpperCase() //"ABCD" s1.toLowerCase() //"abcd"

String method ______ (p.609) returns a new string with upper case letters in the positions where the original string had lowercase letters. String method _____ (p. 610) returns a new string with lowercase letters in the positions where the original string had uppercase letters.

s1.indexOf(s2) //starts from beginning s1.lastIndexOf(s2) //starts from back

String method indexOf (p. 605) locates the first occurrence of a character or a substring in a string. String method lastIndexOf (p. 605) locates the last occurrence of a character or a sub- string in a string.

trim() " ".trim() ==> ""

String method trim (p.610) returns a new string object in which all white-space characters(e.g., spaces, newlines and tabs) have been removed from the beginning and end of a string.

s1.startsWith("") s1.endsWith("")

String methods startsWith and endsWith (p. 604) determine whether a string starts with or ends with the specified characters, respectively.

immutable

String objects are ____, after they're created, their character contents cannot be changed

StringBuilder.length()

StringBuilder method ____ (p. 612) returns the number of characters currently stored in a StringBuilder

StringBuilder.charAt(0)

StringBuilder method ____ (p. 614) returns the character at the specified index.

StringBuilder.capacity()

StringBuilder method _____ (p. 612) returns the number of characters that can be stored in a StringBuilder without allocating more memory.

char[] charArray = new char[StringBuilder.length()]; StringBuilder.getChars(0, StringBuilder.length(), charArray, 0);

StringBuilder method _____ (p. 614) copies characters in the StringBuilder into the character array passed as an argument.

StringBuilder.ensureCapacity(75);

StringBuilder method ______ (p. 613) ensures that a StringBuilder has at least the specified capacity.

StringBuilder.insert(0, objectRef);

StringBuilder's overloaded ____ (p. 617) methods insert primitive-type, character-array, String, Object or CharSequence values at any position in a StringBuilder.

StringBuilder.append(objectRef);

StringBuilder's overloaded _____ methods (p. 615) add primitive-type, character-array, String, Object or CharSequence (p. 615) values to the end of a StringBuilder.

letters, digits, and special characters (=, + , *, $, ...)

Strings can include

newBufferedReader, BufferedReader

TO read serialized data from a file A program opens the file for input by calling Files static method ______, which receives a Path specifying the file to open, and if the file exists and no exceptions occur, returns a _____ for reading from the file.

False. They are eager meaning they perform it when they get it.

Terminal operations are lazy—they perform the requested operation when they are called.

True

The FXMLLoader initializes the controller's @FXML instance variables

lambda's

The Java compiler can infer the types of a ______ parameters and the type returned by a lambda from the context in which the lambda is used. This is determined by the lambda's target type (p. 738)—the functional interface type that is expected where the lambda appears in the code.

Unicode character-based streams

The Reader (p. 675) and Writer (p. 675) abstract classes are ___________ ____________ ________ ___________. Most byte-based streams have corresponding character-based concrete Reader or Writer classes.

javafx.scene.shape

The ____ package contains various classes for creating 2D and 3D shape nodes that can be displayed in a scene graph.

constructor

The class that is used for the objects in serialization must provide public default or no-argument ______ to recreate the objects when they're read from the file

scene graph

The contents of a scene are placed in its _____.

True

The control that the user is interacting with "has the focus"

nodes

The elements in the scene graph are called ____/

Predicate<T>.

The functional interface ____ contains method test() that takes a T argument and returns a boolean, and tests whether the T argument satisfies a condition.

BinaryOperator<T>

The functional interface _____ contains method apply() that takes two T arguments, performs an operation on them (such as a calculation) and returns a value of type T.

True

The layout VBox arranges components vertically in a scene.

initalize

The method ____ is called by the FXMLLoader before the GUI is displayed.

Data source

The method that creates the stream. Ex. IntStream.rangeClosed(1,10); rangeClosed creates a sequence of ints 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

False. You can also have property listeners, where values change based on a change in something.

The only way to respond to a property change is via a property binding, which enables a property of one object to be updated when a property of another object changes.

get() Paths.get("file")

The static method ____ (p.647) of class Paths converts a String representing a file's or directory's location into a Path object.

forEach

The terminal stream operation _____ performs processing on every element in a stream.

Stage

The window in which a JavaFX app's GUI is displayed. Is an instance of class (same as term)

ObservableList

Though you can individually add ListView items you'll often bind a(n) ___ object to the ListView. provided methods for adding and removing elements

False. To create a custom ListView cell format, you must first define a subclass of the ListCell generic class (package javafx.scene.control) that specifies how to create a ListView cell.

To create a custom ListView cell format, you must first define a subclass of the CellFormat generic class (package javafx.scene.conrol) that specifies how to create a ListView cell

False. To respond to ListView selection changes, you register a listener for the MultipleSelectionModel's selectedItem property. (Because you can have multiple items in the list)

To respond to ListView selection changes, you register a listener for the SingleSelectionModel's selectedItem property.

False. The name of the property is Halignment.

To right align controls in a GridPane column, set it's Alignment property to RIGHT.

On Action

To specify what to do when a user interacts with a RadioButton, set its ____ event handler.

False. its getSelectedToggle

ToggleGroup method getToggle returns the Toggle that's currently selected.

streams

Unlike collections, _______ do not have their own storage—once a stream is processed, it cannot be reused, because it does not maintain a copy of the original data source.

GridPane

Use a ____________ to arrange GUI components into cells in a rectangular grid.

False. A collection stores references to objects not primitive types. They must be boxed first.

Values of primitive types may be stored directly in a collection.

False. == checks the reference (location in memory). You would have to use .equals() to compare values

When String objects are compared using ==, the result is true if the Strings contain the same values

primitive

When ___-type values are compared with ==, the result is true if both values are identical.

references

When ____ are compared with ==, the result is true if both refer to the same object.

False. Should say: "...does not override them, ..." instead of "overrides them." False? Because if you override it, then you lost it? UNless its refering to the original one?

When a class implements an interface with default methods and overrides them, the class inherits the default methods' implementations. An interface's designer can now evolve an interface by adding new default and static methods without breaking ex- isting code that implements the interface.

True. //Class Scanner doesn't save spot, or go from the back. It only reads in going forward till it terminates.

When reading data from a file using class Scanner, if you wish to read data in the file multiple times, the file must be closed and reopened to read from the beginning of the file.

Internal Iteration

When we do not need to specify how to iterate through elements

internal

With _____ iteration the library determines how to access all the elements in a col- lection to perform a task.

Buffered Output Stream

With a _________ __________ ____________ (p.674) each output operation is directed to a buffer (p.674) large enough to hold the data of many output operations. Transfer to the output device is performed in one large physical output operation (p. 674) when the buffer fills. A partially filled buffer can be forced out to the device at any time by invoking the stream object's flush method (p. 674).

Buffered Input Stream

With a __________ _________ __________ (p. 675), many "logical" chunks of data from a file are read as one large physical input operation (p. 675) into a memory buffer. As a program requests data, it's taken from the buffer. When the buffer is empty, the next actual physical input operation is performed.

False. As the load factor increases, fewer slots are available relative to the total number of slots, so the chance of a collision increases.

With hashing, as the load factor increases, the chance of collisions decreases.

(int value) -> {System.out.printf("%d", value);} or //not sure about below value -> System::printf("%d", value) //because only one parameter and its only doing one thing. shorthand since its a interfaceMethod of system (don't quote me on last part.)

Write a lambda that can be used in place of the following anonymous inner class: new IntConsumer() { public void accept(int value) { System.out.printf("%d ", value); } }

Math::sqrt

Write a method reference for Math method sqrt.

String::toUpperCase

Write a method reference that can be used in place of the following lambda: (String s) -> {return s.toUpperCase();}

() -> {return "Welcome to lambdas!";}

Write a no-argument lambda that implicitly returns the String "Welcome to lambdas!".

Formatter outNewMaster = new Formatter("newmast.txt");

Write a statement that opens file "newmast.txt" for output (and creation)—use for- matter variable outNewMaster.

Scanner inOldMaster = new Scanner(Paths.get("oldmast.txt"));

Write a statement that opens file "oldmast.txt" for input—use Scanner variable in- OldMaster.

Scanner inTransaction = new Scanner(Paths.get("trans.txt"));

Write a statement that opens file "trans.txt" for input—use Scanner variable in- Transaction.

Account account = new Account(); account.setAccount(inOldMaster.nextInt()); account.setFirstName(inOldMaster.next()); account.setLastName(inOldMaster.next()); account.setBalance(inOldMaster.nextDouble());

Write the statements needed to read a record from the file "oldmast.txt". Use the data to create an object of class Account—use Scanner variable inOldMaster. Assume that class Account is the same as the Account class in Fig. 15.9.

TransactionRecord transaction = new Transaction(); transaction.setAccount(inTransaction.nextInt()); transaction.setAmount(inTransaction.nextDouble());

Write the statements needed to read a record from the file "trans.txt". The record is an object of class TransactionRecord—use Scanner variable inTransaction. Assume that class TransactionRecord contains method setAccount (which takes an int) to set the account number and method setAmount (which takes a double) to set the amount of the transaction.

ToggleGroup

You add multiple RadioButtons to a(n) ____ to ensure that only one RadioButton in a given group is selected at a time.

False. You can add Labels to a GUI that describe other controls. In such cases, you such set each Label's labelFor property to the specific control the label describes

You can add Labels to a GUI that describe other controls. In such cases, you such set each Label's describesControl property to the specific control the label describes

False. Everything you can do in Scene Builder also can be accomplished in Java code.

You can build JavaFX GUIs only by using Scene Builder

Simplifying Lambdas

You can eliminate Lambda's parameter type (x) -> {return x*2;} You can eliminate parentheses if just one parameter: x -> {return x*2;} You can eliminate return {} and ; if only one statement in body x -> x*2 if no parameter, must have parentheses () -> _____

Unmodifiable wrapper

You can use a(n) _____ to create a collection that offers only read-only access to oth- ers while allowing read-write access to yourself.

ChangeListener<Number>

You implement interface ___ to respond to events when the user moves a slider's thumb.

False. You can use JavaFX Scene Builder for drag and drop, no coding needed

You must create JavaFX GUIs by hand coding them in Java.

False. These three streams are created for you when a Java application begins executing.

You must explicitly create the stream objects System.in, System.out and System.err.

False. You override class Application's start method to display a JavaFX app's stage

You override class Applications launch method to display a JavaFX app's stage.

JavaFX Scene Builder

_____ allows you to build JavaFX GUIs using drag-and-drop techniques.

Capturing

_____ lambdas use local variables from the enclosing lexical scope.

Declarative

_____ programing specifies the what

Class Paths

______ ________ (p. 647) is used to get a Path object representing a file or directory location.

Class Files

______ __________ (p.647) provides static methods for common file and directory manipulations, including methods for copying files; creating and deleting files and directories; getting information about files and directories; reading the contents of files; getting objects that allow you to manipulate the contents of files and directories; and more.

Pipes

___________ (p. 673) are synchronized communication channels between threads. One thread sends data via a PipedOutputStream (p. 673). The target thread reads information from the pipe via a PipedInputStream (p. 673).

Class Formatter

___________ _______________ (p.647) enables formatted data to be output to the screen or to a file in a manner similar to System.out.printf.

Byte-based streams

_______________ __________(p.646) represent data in binary format.

Character-based input; Output

________________ __________ and ___________ can be performed with classes Scanner and Formatter.

Character-based streams

________________ ___________(p.646) represent data as sequences of characters.

Buffering

________________ is an I/O-performance enhancement technique. ____(same word) reduces the number of I/O operations by combining smaller outputs together in memory. The number of physical I/O operations is much smaller than the number of I/O requests issued by the program.

Class JFileChooser

_____________________ (p. 670) is used to display a dialog that enables users of a program to easily select files or directories from a GUI.

GridPane

a JavaFX Pane component that positions graphical components in a two-dimensional grid

stream pipeline

a chain of methods that move a stream's elements through a sequence of tasks.

Anonymous Inner Class

a class that's declared without a name and typically appears inside a method declaration. One object of the class must be created before this is called. It can access top level instance variables and static variable/method, but limited access to local.

forEach() .forEach(System.out::println)

a collections method which takes in one object (element) at a time and performs a method on that value, does it for all example

event handler

a method that responds to user interaction

A lambda consists of

a parameter list followed by the arrow token (->) and a body: (parameter list) -> {body;}

stream

a sequence of elements of which you perform a task. (can incorrectly think of it as an array/string)

Scene Graph

a tree data structure of an app's visual elements, such as GUI controls, shapes, images, video, text, and more.

Node

a visual element in the scene graph

XML

a widely used language for describing data

List Methods

add() ==> add to end size() ==> get number of elements get(int index)

mutator

also know as modifier, its when a variable is changed (modified)

Iterator Object

an Iterator that is defined by the Collection Type. Ie, in a for loop, our iterator is usually i++.

Controls

are GUI components, such as Labels that display text, TextFields that enable a program to receive user input, Buttons that users click to initiate actions, and more.

StringBuilder

class _____ for creating and manipulating dynamic string information—that is, modifiable strings.

Scene

defines the GUI Everything is on this.

lazy evaluation

do not perform any operations on the stream's elements until a terminal operation is called to produce a result

Terminal Operations use

eager evaluation


Ensembles d'études connexes

Chapters 13-18 Ricci 2nd edition

View Set

mccall psyc380 chapter 14 - self-confidence

View Set

Chapter 7 Critical thinking questions

View Set

CHAPTER 64 - Management of Patients with Neurologic Infections, Autoimmune Disorders, and Neuropathies

View Set

Personal Finance: Savings by Nation

View Set

7.4 - Divide powers with same base

View Set