java 2 2
ocp 2
ocp 2
Kartei Details
Karten | 141 |
---|---|
Sprache | Deutsch |
Kategorie | Informatik |
Stufe | Andere |
Erstellt / Aktualisiert | 22.09.2020 / 06.12.2020 |
Weblink |
https://card2brain.ch/box/20200922_java_2_2
|
Einbinden |
<iframe src="https://card2brain.ch/box/20200922_java_2_2/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>
|
Lernkarteien erstellen oder kopieren
Mit einem Upgrade kannst du unlimitiert Lernkarteien erstellen oder kopieren und viele Zusatzfunktionen mehr nutzen.
Melde dich an, um alle Karten zu sehen.
How to get a enum value of a string? What happens if it doesnt exist?
SomeEnumValue.valueOf("thename");
throws exception
Can a enum be extended?
No
Whats the problem hre?
switch(summer) {
case Season.FALL;
break;
case 0:
break;
}
Season.Fall doesnt work, should be FALL
Enum values cannot be compared with int
How to create a function with different behaviour for each enum?
within the enum class: public abstract...
-> has to be implemented by all enum-types
What are the properties of inner classes?
- can be declared public, protected, package-private or private
- can extend any class or implement interfaces
- can be marked abstract or final
- cannot declare static fields or methods except for static final fields
- can access members of the outer class including private members
What are the properties of static nested classes?
like a top-level-class except for:
- the nesting creates a namespace because the enclosing class name must be used to refer to it
- can be made private or use one of the other access modifiers to encapsulate it
- enclosing class can refer to the fields and methods of the static nested class
Poperties of local classes?
- do not have an access modifier
- cannot be declared static and cannot declare static fields or methods except for static final fields
- have access to all fields and methods of the enclosing class
- can access local variables if the variables are final or effectively final
What are rules for default interface methods?
- method may be declared only within an interface
- methoid must be marked with default keyword and include a method body
- method is assumed to be public
- method cannot be marked abstract, final or static
- method may be overridden by a class that implements the interface
- if a class inherits two or more default mehtods with the same method signature, then the class must override the method
How to call the getSpeed implementation of Walk here?
public class Cat implements Walk, Run {
public int getSpeed() { return 1; }
public int getWalkSpeed() {
return ????; // Todo
}
public static void main(String[] args) {
System.out.println(new Cat().getWalkSpeed());
}
}
walk.super.getSpeed();
What are rules for static interface method definitions?
- method must be marked with the static keyword and include a method body
- method without an access modifier is assumed to be public
- method cannot be marked abstract or final
- method is not inherited and cannot be accessed in a class implementing the interface without a reference to the interface name
What are rules for private interface method definitions?
- private interface method must be marked with the private modifier and include a method body
- private interface method may be called only by default and private (non static methods within the interface definition
- What are rules for private static interface method definitions?
- a private static method must be marked with private and static modifiers and include a method body
- a private static interface method may be called only by other methods without the interface definition
What ist the SAM rule?
single abstract method
What is the exception of the SAM rule?
the methods inherited by Object
Whats the rule with var in lambda expresions?
you can use var inside a lambda parameter list but if a var is used for one of the types in the parameter list then it must be used fo all parameters in the list
Wie kann man aus einem Path object ein File-objekt machen?
path.toFile(),
Muss die File existieren wenn man das parent/root directory eines Pathobjects auslesen möchte?
Nein
Kann man alle Funktionen der Path-Klasse nutzen ohne dass die File existiert?
Nein, Path.toRealPath() bspw nicht
Was macht der optionale Parameter und für was wird er genutzt? NOFOLLOW_LINKS
Symbolische links werden nicht traversed
-> test file existing, read file data, copy file, move file
Was macht der optionale Parameter und für was wird er genutzt? FOLLOW_LINKS
symbolische links werden traversed
-> traverse a directory-tree
Was macht der optionale Parameter und für was wird er genutzt? COPY_ATTRIBUTES
alle metadaten über eine file werden mitkopiert
-> copy file
Was macht der optionale Parameter und für was wird er genutzt? REPLACE_EXISTING
wenn targetfile existiert wird sie reülaced (ohne den parameter wird eine exception geworfen wenn die file schon existiert)
-> copy file, move file
Was macht der optionale Parameter und für was wird er genutzt? ATOMIC_MOVE
operation wird atomic ausgeführt, stellt sicher dass jeder prozess nur einen kompletten record sieht. Wenn das feature nicht supported ist im filesystem wird ggfs. eine exception geworfen
-> move file
Was gibt es für Methoden bei Path um basic informations über die Pfad-repräsentation zu bekommen?
* toString() : string repräsentation des gesamten Pfads
* getNameCount(): liste von namen im Pfad (happy/hippo/.. )
* getName(int) meist mit der methode oben verwendet, index ist index im pfad
Wie ist getName(int) indexed? was passiert mit dem root-element?
zero-index, file-system-root ist excluded
Wie erhält man den Filename eines PAth-objects? was ist besonders
getFileName() -> returned neue Pathinstanz mit dem filename
Wie erhält man den parent eines Paths? was ist besonders
getParent() returned null wenn kein parentpath, Wenn der Path relative ist hört die methode im top-lvl des paths auf, geht nicht zum filesystemroot
Wie erhält man den Root eines path-ojbjects? was ist besonders?
getRoot(), wenn relative dann null.
Wie kann man bei einem Pathobject checken ob es absolute ist=
isAbsolute()
Wie bekommt man ein abdsolutes Pathobject aus einem relativen Pathobject?
toAbsolutePath(), wenn schon absolute bekommt man eine kopie zurück
-
- 1 / 141
-