fdsa


J. F.
Diese Karteikarten bieten einen umfassenden Überblick über die Java-Programmierung, insbesondere zu Themen wie Dateiverarbeitung, Funktionen und Sammlungen. Sie decken wichtige Konzepte wie das Arbeiten mit Pfaden, Dateien und Strings ab, sowie das Verhalten von Sammlungen und deren Sortiermethoden. Die Karteikarten sind ideal für Entwickler, die ihr Wissen in Java vertiefen möchten, insbesondere in Bezug auf die Handhabung von Sammlungen, das Sortieren und Vergleichen von Objekten sowie die Verwendung von Stream-APIs und Collectors.
Flashcards
496
Students
3
Language
German
Category
Computer Science
Level
Other
Created / Updated
06.12.2020 / 24.01.2021

Flashcards

Whats special about CopyOnWriteArrayList and CopyOnWriteArraySet?

tey copy all of their elements to a new underlying structure anytime an element is added, modified or removed from the collection

What does "modifing" mean in the context of CopyOnWriteArrayList and copyOnWriteArraySet?

when the reference in the collection is changed

What happens here?
List<Integer> favNumbers = new CopyOnWriteArrayList<>(List.of(4,3,42));
for(var n: favNumbers) {
  System.out.print(n + " ");
  favNumbers.add(9);
}
System.out.println();
System.out.println("Size: " + favNumbers.size());

4 3 42 
Size 6

What is special about BlockingQueue?

Its like a regular queue but it includes Methods that will wait a specfic amount of time to complete an operation

Whats the syntax for adding an item to the queue, wating the specified time and returning false if the time elapses before space is availiable in BlockingQueue?

boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException

Whats the syntax for  retrieving and removing an item from the queue, waiting for the specified time and returing null if the time elapses before the item is availiable in BlockingQueue?

E poll(long timeout, TimeUnit unt) throws InterruptedException

Whats a difference between concurrent and snychronized collections regarding the exceptions?

unlike the concurrent collections the snychronized collections also throw an exception if they are modified witihn an iterator by a single thread

How to create a parallelStream form an existing stream?

Calling parallel()

How to create a parallel stream from a collection?

calling parallelStream()

When Stream.concat is called on two parallel streams, is the result still parallel?

yes

When Stream.flatmap is called on two parallel streams, is the result still parallel?

No

What does parallel decomposition mean?

process of taking a task, breaking it up into smaller pieces that can be performed concurrently and then reassembling the results

Does forEachOrdered makes the whole stream serialized?

No

What does the streamoperation reduce() do?

combines a stream into a single object

What is the syntax of stream.reduce with parallel streams?

<U> U reduce(U identity, BiFunction<U, ? super T, U> accumulator, BinaryOperator<U> combiner)

Why is this problematic?
System.out.println(List.of(1,2,3,4,5,6)
 .parallelStream()
 .reduce(0, (a,b) -> (a-b)));

It may output -21,3 or some other value

Whats the syntax of Stream.collect with parallel Streams?

<R> R collect(Supplier<R> supplier, BiConsumer<R, ? super T> accumulator, BiConsumer<R,R> combiner)

What are the requirements to execute Stream.collect in parallell?

  • the stream is parallel
  • parameter of collect ooperation has the Characteristics.CONCURRENT
  • either the stream is unordered or the collector has the characteristic Characteristics.UNORDERED

What does "transitiv" do witihn a module-info.java?

Indicates the module and that all modules that use this module are dependent on another module

Which types of modules exists?

named, unnamed, automatic

What is the characteristics of a named module?

has the name inside the module-info and is on the module path

What is the characteristics of an automatic module?

is on the module path, has no module-info, is simply a regular jar-file on the module-path and treated as a module

How does code which is referencing an automatic module treat it?

As if there is a module-ionfo file and exports all packages. it determines the modulename

What are the two ways of determining the name of a automatic module?

* set a property called Automatic-Module-Name in the MANIFEST.MF file

* Java determines it by passing it off the filename of the jar file

Describe the algorithm of creating the name for a automatic file 

  • If MANIFEST.MF contains an Automatic-Module-Name use that. Otherwise:
  • Remove file extension from jar name
  • remove any version info from the end of the name
  • replace any remaining chars other than letters and numbers with dots
  • replace any sequences of dots with a single dot
  • remove the dot if it is the first or last char of the result

What is the charactersitics of a unamed module?

its on the classpath, a regular jar and could contain a module-info.java file but would be ignored as long as the module is on the classpath

Can code from the classpath access the module path? Whats about the other way around?

Yes but code on the module path is unable to read from the classpath

Is it possible to use only a part of the JDK?

Yes

Which module is availiable by default to all modular applications?

java.base

What are important comman modules?

  • java.base
  • java.desktop
  • java.logging
  • java.sql
  • java.xml

How to provide details about unsupported apis with jdeps?

with --jdk-internals

Which is the easiest MigrationStrategy for Modules?

bottum-up-migration

 

When does the bottom-up migration-strategy works best?

when you have the power to convert any JAR files that arent already modules

What are the steps of the bottom-up-module-migration-strategy?

  1. pick lowest-lvl project not migrated yet
  2. add module-info.java fille (add any exports to expose any package used by higherlvl jar files, also requires)
  3. move it from the classpath to modulepath
  4. ensure any project that have not yet been migrated stay as unnamed modules on the classpath
  5. repeat with the next-lowest-level project until you are done

When is a top-down-migration-strategy useful?

When you dont have control of every JAR file used by your application

What are the steps for the top-down-migration-strategy?

  1. place all projects on the module path
  2. pick the highes-level project that has not yet been migrated
  3. add module-info file to convert the automatic module into a named module (exports,requires, ..)
  4. repeat with the next-lowest-level project until you are done

Are circular dependencies allowed between modules?

no

Is it possible to have a cyclic dependency between packages within a module?

yes

Of what is a service composed?

A service is composed of an interface, any classes the interface references, and a way of looking up implemetations of the interface. The implementatinos are not part of the service

What does a service locator do? How does java helps us here?

is able to find any classes that implement a service provider interface. Java provides a ServiceLocator class to help with this task.
Te service provider interface type to its load() method and java will return any implementation services it can find

Study