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:
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()
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()
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));
4 Object Oriented Architectures and Secure Development 2022-2023
The benefits of buying summaries with Stuvia:
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
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
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.