100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Samenvatting Object Oriented Architectures $6.96   Add to cart

Summary

Samenvatting Object Oriented Architectures

 34 views  0 purchase
  • Course
  • Institution

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

Preview 4 out of 50  pages

  • January 2, 2023
  • 50
  • 2022/2023
  • Summary
avatar-seller
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

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller xanderdjema. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $6.96. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

72042 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$6.96
  • (0)
  Add to cart