Garantie de satisfaction à 100% Disponible immédiatement après paiement En ligne et en PDF Tu n'es attaché à rien 4.2 TrustPilot
logo-home
Resume

Samenvatting Object Oriented Architectures

Note
-
Vendu
-
Pages
50
Publié le
02-01-2023
Écrit en
2022/2023

Summary of 50 pages for the course Object Oriented Architectures at HoWest (theorie)












Oups ! Impossible de charger votre document. Réessayez ou contactez le support.

Infos sur le Document

Publié le
2 janvier 2023
Nombre de pages
50
Écrit en
2022/2023
Type
Resume

Sujets

Aperçu du contenu

Object Oriented Architectures
and Secure Development
Lecture 1 – Recap
Objects and classes
 Fields (properties, state)
 Methods (behaviour)
o Getters
o Setters
o toString / CompareTo / equals + hashCode / …
 Constructors
o Copy constructor
o Constructor chaining

Objects in collections
 List
o Classic
o Stack
o Queue
 Set
o Equals / hashCode
 Map
o Equals / hashCode

Other topics
 Exceptions
o Try
o Throw
o Catch
 Inheritance and interfaces
o Extends / implements
o Overriding methods
 Static
o Methods and fields
o Of the class, not of instances

Naming conventions
Capital letter + camel casing (all types: classes, interfaces, enums)
Small letter + camel casing (all methods, fields, variables, …)
Capital Letters, snake casing (static final fields (constants), enum instance names (not studied))




1 Object Oriented Architectures and Secure Development 2022-2023

,Lecture 2 – Stream API
 Java.util.stream
 Contains various classes to support functional-style operations on streams of elements. Nothing
to do with file I/O.
o Map
o Reduce
o Filter
o Foreach
o …
 But also lots more…

What is stream?
Represents a sequence of elements.
supports various types of operations, allowing for computations on said elements.




Example 1: creating a stream from a list of values
Stream.of("Jughead", "Betty", "Archie", "Veronica")
.map(String::toLowerCase)
.sorted()
.forEach(System.out::println);

1. Stream is mapped to another stream
2. We provide the method to apply to each element as argument

1. The :: operator is also called method reference operator
2. Pass a reference to methods – in this case – map() and forEach() methods
3. Is shorthand for a lambda expression that executes just one method, comparable to:

Stream.of("Jughead", "Betty", "Archie", "Veronica")
.map(e -> e.toLowerCase())
.sorted()
.forEach(e -> System.out.println(e));




2 Object Oriented Architectures and Secure Development 2022-2023

,Example 2: converting a collection into a stream
List<Product> products = new ArrayList<>();
products.add(new Product(1, "cookies", 2.99));
products.add(new Product(2, "chocolate", 3.99));
products.add(new Product(3, "bananas", 1.99));

products.stream()
.filter(e -> e.getPrice() > 2)
.sorted(Comparator.comparingDouble(Product::getPrice))
.forEach(System.out::println);

Intermediate versus terminal operations
Intermediate operations
 Returns a stream
 We can apply chaining – method1().method2().method3();
 Examples:
o .map()
o .filter()
o .sorted()
o .peek()

Stream.of("Jughead", "Betty", "Archie", "Veronica")
.map(String::toLowerCase)
.sorted()
.forEach(System.out::println);

Terminal operations
 Returns nothing (void) or non-stream result (int, double, …)
 Therefore, after a terminal operations, no longer possible to chain
 Examples:
o .forEach()
o .sum()
o .max()

Stream.of("Jughead", "Betty", "Archie", "Veronica")
.map(String::toLowerCase)
.sorted()
.forEach(System.out::println);

Creating streams
Stream.of(obj1, obj2, obj3, …)
IntStream.of(int1, int2, int3, …)
DoubleStream.of(dbl1, dbl2, dbl3, …)
LongStream.of(lng1, lng2, lng3, …)
Collection.stream()




3 Object Oriented Architectures and Secure Development 2022-2023

, Transforming object streams to primitive streams
double avg = products.stream()
.mapToDouble(e -> e.getPrice())
.average()
.orElse(0);
System.out.println(String.format("Average price is %.2f", avg));

 Average() returns a OptionalDouble
 Here, calling orElse(0) will return the double inside or 0 if there is none.
 Other useful method of OpttionalXXX: isPresent(Boolean)

Transforming primitive streams to object streams
IntStream.range(1, 4)
.mapToObj(e -> new Product(e, "Prod " + e, e*2))
.forEach(System.out::println);

Collect
 Very useful terminal operation
 Allows you to transform elements of a stream into a different result, such as List, Set or Map

List
List<Person> persons = new ArrayList<>();
persons.add(new Person("Jughead", 18));
persons.add(new Person("Betty", 18));
persons.add(new Person("Veronica", 21));
persons.add(new Person("Archie", 20));

List<Person> filteredPersons =
persons.stream()
.filter(p -> p.getAge() > 18)
.collect(Collectors.toList());

Map
Map<Integer, List<Person>> personsPerAge =
persons.stream()
.collect(Collectors.groupingBy(Person::getAge));

personsPerAge.forEach((a, p) -> System.out.println(
String.format("%s %s", a, p)));

Average
double avgAge =
persons.stream()
.collect(Collectors.averagingDouble(Person::getAge));

Summarize
DoubleSummaryStatistics stats =
persons.stream()
.collect(Collectors.summarizingDouble(Person::getAge));



4 Object Oriented Architectures and Secure Development 2022-2023
€6,49
Accéder à l'intégralité du document:

Garantie de satisfaction à 100%
Disponible immédiatement après paiement
En ligne et en PDF
Tu n'es attaché à rien

Faites connaissance avec le vendeur
Seller avatar
xanderdjema

Faites connaissance avec le vendeur

Seller avatar
xanderdjema
Voir profil
S'abonner Vous devez être connecté afin de suivre les étudiants ou les cours
Vendu
1
Membre depuis
2 année
Nombre de followers
0
Documents
11
Dernière vente
4 mois de cela

0,0

0 revues

5
0
4
0
3
0
2
0
1
0

Récemment consulté par vous

Pourquoi les étudiants choisissent Stuvia

Créé par d'autres étudiants, vérifié par les avis

Une qualité sur laquelle compter : rédigé par des étudiants qui ont réussi et évalué par d'autres qui ont utilisé ce document.

Le document ne convient pas ? Choisis un autre document

Aucun souci ! Tu peux sélectionner directement un autre document qui correspond mieux à ce que tu cherches.

Paye comme tu veux, apprends aussitôt

Aucun abonnement, aucun engagement. Paye selon tes habitudes par carte de crédit et télécharge ton document PDF instantanément.

Student with book image

“Acheté, téléchargé et réussi. C'est aussi simple que ça.”

Alisha Student

Foire aux questions