fdsa


Kartei Details

Karten 496
Sprache Deutsch
Kategorie Informatik
Stufe Andere
Erstellt / Aktualisiert 06.12.2020 / 24.01.2021
Weblink
https://card2brain.ch/box/20201206_java_2_3
Einbinden
<iframe src="https://card2brain.ch/box/20201206_java_2_3/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>

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

Is the call to serviceloader fast?

No

What is a service provider?

Implementation of a service provider interface

What do we have to add to the module-info.java when we are implementing a service provider?

provides interfaceName with className;

Do we have to recompile the service interface,. .. if we add a nw service provider implementation?

no, the service locator is able to observe that there was now a service provider implementation available and find it for us

How many service providers are allowed for a service provider interface within a module?

only one provuiider of a provider interface in a module

What is the signature of the two methods in serviceloader we have to know?

  • public static <S> ServiceLoader<S> load(Class<S> service) 
  • public Stream<Provider<S>> stream()

What does a traditionally try statement have at least?

try statement and at least a catch or a finally block

In which order are the resources cloused with try-with-resources?

In the reverse order that they are declared

What are the 5 checked exceptions we have to be familiar with?

FileNotFoundException, IOException, NotSerialziableException, ParseException, SQLException

From what Exception inherits NumberFormatException?

IllegalArgumentException

From what Exception inherits FileNotFoundException and NotSerializableException?

IOException

Does close in AutoClosable have to throw an exception?

the implemented version of close() can chose to throw an exception or a subclass or not throw any exceptions at all

In which scope are resources which are declared within a try-with-resources block?

in the scope within the try block

When is it possible to declare resources which are used within try-with-resoruces?

Also prior to the try-with-resorucres-statement if they are marked final or are effectively final

Where are supresses exceptions added?

Only to exceptions thrown in the try clause

Whats the syntax of assert?

assert test_value;

assert test_value: message;

--> may include optional parantheses and a message:

assert ("Bla".equals(bla)): "Failed";

What are the 4 important time classes for the exam?

  • java.time.LocalDate
  • java.time.LocalTime
  • java.time.LocalDateTime
  • java.time.ZonedDateTime

Can we call new LocalDate()?

No

Does this work?: 
LocalDate date = LocalDate.of(2020, Month.OCTOBER, 20);
LocalTime time = LocalTime.of(11,12,34);
System.out.println(date.format(DateTimeFormatter.ISO_LOCAL_TIME));
System.out.println(time.format(DateTimeFormatter.ISO_LOCAL_DATE));

No, will throw an exception because of incompatible types

How to add custom text values to dateTimeFormatters?

excape the text by surrounding it with a pair of single quotes: '
DateTimeFormatter.ofPattern("MMM dd', Party''s at' hh:mm);

How to get the users current locale?

Locale.getDefault()

How to get the german language from locale?

Locale.GERMAN

How to get the german region from Locale?

Locale.GERMANY

How to use the locale-builder?

new Locale.Builder().setRegion("US").setLanguage("en").build();