Data Structures and Java Class Library Unit 4-6

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

What method is used for formatting the input with SimpleDateFormat?

.format();

What method is used for formatting the output with SimpleDateFormat?

.parse();

What is a data stream?

A data stream transports data from the data source to a data sink

What are the disadvantages with an array? (comma separated)

A full array has to be reinitialized in runtime and the elements copied to allocate more space which can block large chunks of the memory, the removal of gaps is a slow process because each subsequent element has to be moved, limited built in functionality

What rules apply when adding elements to a Map?

A key is unique in that it either does not exist at all or exists only once in a map. Only one value exists for a key. If a pair of key and value is to be stored in a map in which the key already exists, the corresponding value is simply overwritten.

What is special about the List data structure?

A list allows an undefined amount of data to be stored where the elements have an fixed order, elements can be retrieved randomly or sequentially.

How can elements of a map be iterated over?

A map cannot be used with an iterator. Instead, the interface offers special views of the elements, which allow, for example, iteration over all keys or all values (for example, the values() method).

What are the special features of a set in Java?

A set in Java represents a set in the mathematical sense. All implementations of this interface ensure that no element exists twice. More precisely, they ensure that the following condition never applies to any element pair x and y: x.equals(y) == true.

What is the principle of the stack data structure?

A stack is a data structure that follows the LIFO principle, last in first out, meaning the last element added is the first element to be removed.

What is an iterator?

A tool to work with collections, it allows the developer to iterate over all elements in a collection in a simple manner.

What is an extended for-loop and how is it different for an for-loop?

An extended for-loop allows for easier handling of collections. Instead of the for-loops traditional initialization, condition and increment, the extended for-loop uses two parameters. A substitute object and the collection to iterate, separated by a colon.

What are the benefits and drawbacks with an linkedlist?

An linked list can be modified easily since the internal pointers can be redirected to remove or accomodate an element. The drawback is that to find an element the whole list has to be searched making the retrieval slow.

What is the advantage of using StringBuffer?

Any number of strings can be appended using the append method, without creating additional objects unnecessarily. The added strings are kept in a temporary buffer and the resulting string is only assembled when the toString method is called.

Term used for any data in any format?

Arbitrary data

What are arrays and how are they stored in memory?

Arrays are the most basic and common data structure that allows the developer to store several elements of the same datatype. The elements of an array is stored sequentially one after another in memory.

Why can all collections in the collections framework be processed using an iterator?

Because the interface Collection is derived from the interface Iterable, meaning all collections realize the Iterable interface and are thus iterable.

How can one avoid the problem with OS using different character separators?

By using the constant File.separator

What is the modern way to manipulate dates?

Calendar and it's derived classes

What are the two main types of data streams in Java? (comma separated)

Character oriented data stream, byte oriented data stream

When would you choose a HashSet over a TreeSet and vice versa?

Choose HashSet for faster performance and when order is not important. Choose TreeSet when you need elements sorted, at the cost of slower performance.

What is a drawback with collections if you want to work with primitive data types?

Collections can only store reference data types and not primitive data types. To store primitive data types their corresponding wrapper class has to be used instead.

In your own words, explain the purpose of the class Date in Java

Date objects represent dates with millisecond precision.

The usage of an array contains three steps, which? (comma separated)

Declaration, instantiation, initialization

What are the advantages with an array? (comma separated)

Directly usable without import, can contain any data type from primitive to custom classes, accessing elements at an specific index is an fast operation and is independent of the size of the array

What is the difference between an arraylist and linkedlist?

Even though both implement the interface List the they store the elements in different ways. An arraylist stores it's elements in an array which gives it the benefits and drawbacks of an array. An linkedlist uses an double-linked list to store the elements, giving it the the benefits and drawbacks of an linked list.

Once you have a root how do you list all files?

File[] files = root.listFiles();

what is the syntax for listing all roots?

File[] roots = File.listRoots();

Describe the concept of a data stream pipeline.

In a data stream pipeline, several data streams are interconnected and form the individual stages of the pipeline and pass the read or written data to the next stage.

What does the default constructor of a Date object do?

It creates an object with the exact time of its creation

Explain what is meant when strings are "immutable" in Java.

It means that the content of a string is not changed after its creation. All editing methods always return a new string.

According to which principle does the queue data structure work?

It works according to the FIFO principle, First In First Out, this means that the first element inserted in a queue is also the first element removed from the queue

What class is used for formatting output and input of Date objects?

SimpleDateFormat

What solution does Java offer to chain many long strings?

StringBuffer

What distinguishes character strings from the primitive data types in Java?

Strings are real objects in Java with their own methods.

explain the purpose of the class GregorianCalendar

The class GregorianCalendar represents the calendar used in Europe to determine dates.

How are data streams in Java code connected to a pipeline?

The constructors of the individual data streams are interleaved. One starts with the data stream that is closest to the program and passes the next data stream in the direction of the data source or sink.

How is the file system path formatted?

The individual hierarchy levels are marked by a character that separates the names of the individual elements

What does the package java.io contain?

The library contains all important classes for handling the file system, directories and files

What is the collections framework?

The library contains frequently used data structures with corresponding search and sorting algorithms, it also includes other useful classes and interfaces.

What is meant by the literal notation of strings?

The literal notation of strings allows one to specify strings directly in the source code without calling a constructor. String objects can be specified in Java with double quotation marks.

What is the difference between the methods mkdir and mkdirs?

The method mkdir you can only create one directory, if the path contains more than one non-existent directory the operation will fail. The method mkdirs on the other hand allows you to create all non-existent directories along the path.

In which cases are arrays too slow, even with random access?

This case occurs if the index of the stored element is not also the identifying characteristic. An index does not help in such cases since all elements must be searched for their identifying characteristic.

How can primitive values be transformed into strings and vice versa?

Transforming primitive values into strings can be done by using the String class method valueOf. One can convert a string back into a primitive type by using the static method parse of the corresponding wrapper class.

How are individual attributes increased and decreased in a GregorianCalendar object?

Using the method roll. One specifies the attribute to roll and the value which to roll the attribute.

How are individual attributes set for a GregorianCalendar object?

Using the method set. One specifies the attribute to set and the value to which to set the attribute.

What problem occurs when chaining numerous strings and what is the cause?

When chaining many strings, string concatenation, many temporary string objects are generated. This happens because string objects are immutable.

Give an example when arrays are unsustainable in practice.

When the needed length of an array is unknown, to cover for an unknown amount of elements the resulting reserved memory would be impactful, especially with several initializations.

Explain the purpose and operation of the split method of the class String.

With the split method, a string can be split along a separator or a separator string. Split returns a string array with the resulting parts.

What does the File class represent?

directories and files

What's the syntax for an extended for-loop ?

for(Customer c : collection){}

Iterators in Java has three methods, list them and describe the methods function.

hasNext(), checks whether there is a subsequent element in the collection and returns a boolean. next(), positions the iterator on the next element in the collection and returns a reference. remove(), removes the element the iterator is currently standing on.

What is a data source?

input of the data, data comes from here

You can instantiate and initialize an array at the same time, what's the syntax for this if you want to create an array with three integers called numbers? (populate with 1,2,3)

int[] numbers = new int[]{1,2,3}

What possibilities does Java offer for sequential processing of elements in an collection? (comma separated)

iterator, extended for-loop

What superclasses is used for byte oriented data streams, input and output? (comma separated)

java.io.InputStream, java.io.OutputStream

What superclasses is used for character oriented data streams, input and output? (comma separated)

java.io.Reader, java.io.Writer

What possibilities does Java offer to implement a stack? (full path Interfaces, comma separated)

java.util.Stack, java.util.Deque

What's the syntax for creating an SimpleDateFormat with the pattern 25-01-2023 ?

new SimpleDateFormat("dd-MM-yyyy");

What is a data sink?

output of the data, the data goes there

What is a input stream?

the data that runs from the source to your program

What is a output stream?

the data that runs from your program to the source

What is the pattern for formatting a date in ISO format? Use the following three examples: 2013-06-23, 2012-12-24, and 2010-01-19.

yyyy-MM-dd


Ensembles d'études connexes

Pamoka 1 - Aš esu studentės, o tu?

View Set

Management principles ch.12 case study

View Set

Introduction to Economics Test# 2 Monopolistic Competition and Oligopoly.

View Set

Microbiology Chapter 21 Smartbook

View Set