Formation JAVA8
Formation JAVA8
JAVA8
Programmation fonctionnelle
Key words :
Stream API
Upcast , downcast
@override : redéfinir
**ComparingtInt**
**********************************************************************************
Abstraction :
SOLID :
Single-Responsibility Principle · Open for extension -Closed for modification ,interface ,
dependency inversion
Principle Description
Single Responsibility Principle Each class should be responsible for a single part or functionality of
Interface Segregation Principle No client should be forced to depend on methods that it does not us
Interface :
Test :
If (o instanceof Deplacement )
((Deplacement).o).déplacer() ;
Expression lambda :
one single line : programmation fonctionnelle
anonymous function
only 1 single abstract method
@override
return a+b ;}
};
Appel : c.op(3 , 5)
On peut redéfinir op une autre fois :
c.op(20,4)
Calcul c = X :: somme
-----------------------------------------------------------------
@override
Return null ; }
Collections.sort(comparator.comparingInt(
----------------------------------------------------------------------------------------------------------------------------
sequentiel : arraylist ,
thread : vector
Collection.sort()
Map : tableau
ArrayList:
Implements a dynamic array to store elements.
Provides fast random access (constant-time) for reading
elements by index.
Slower at inserting and deleting elements in the middle
because it may require shifting elements.
Better suited for scenarios where you need frequent random access
and iteration but fewer insertions and deletions.
Good for read-heavy use cases.
LinkedList:
Implements a doubly-linked list to store elements.
Provides fast insertion and deletion of elements in the middle
(constant-time) because it only requires changing references.
Slower at random access (linear-time) because you need to
traverse the list from the beginning or end to access an
element by index.
Better suited for scenarios where you need frequent insertions and
deletions in the middle of the list.
Good for write-heavy use cases.
Vector:
A Vector is a specific data structure provided by some programming
languages like Java (e.g., java.util.Vector).
It is a part of the Java Collections Framework (prior to Java 1.2) and
is essentially a dynamic array.
It is synchronized by default, making it thread-safe, but this can
impact performance in multi-threaded scenarios.
They are suitable when you need a resizable array-like data structure, especially
in older Java code where synchronization is required.
List:
1. Data Structure:
A "list" typically refers to a specific data structure that holds
an ordered collection of elements.
Lists are commonly used in many programming languages,
and they allow you to store and manipulate data in a
sequence.
2. Usage:
Lists are used to store and manage a collection of items where
the order of items matters, and you may need to access them
by their index.
Lists are often used for tasks like maintaining a collection of
items in a specific order, implementing dynamic arrays, and
performing various list-specific operations like adding,
removing, and retrieving elements.
3. Common Examples:
In Python, you have lists represented by square brackets (e.g.,
[1, 2, 3] ).
In Java, lists are part of the Java Collections Framework and
can be implemented using classes like ArrayList or LinkedList
(e.g., ArrayList<Integer>
Collections :
"List" and "Collections" are related concepts in programming, but
they have different meanings and usages. Here are the key
differences between them:
List:
1. Data Structure:
A "list" typically refers to a specific data structure that
holds an ordered collection of elements.
Lists are commonly used in many programming
languages, and they allow you to store and manipulate
data in a sequence.
2. Usage:
Lists are used to store and manage a collection of items
where the order of items matters, and you may need to
access them by their index.
Lists are often used for tasks like maintaining a
collection of items in a specific order, implementing
dynamic arrays, and performing various list-specific
operations like adding, removing, and retrieving
elements.
3. Common Examples:
In Python, you have lists represented by square
brackets (e.g., [1, 2, 3]).
In Java, lists are part of the Java Collections Framework
and can be implemented using classes like ArrayList or
LinkedList (e.g., ArrayList<Integer> ).
Collections:
1. Scope:
"Collections" is a broader term that refers to a group of
elements or objects.
It is a more general concept than a "list" and can
encompass various data structures like lists, sets,
maps, and more.
2. Usage:
Collections are used to manage and manipulate groups
of data or elements. They don't necessarily imply a
specific order or indexing mechanism.
The term "collections" is often associated with libraries
or frameworks that provide data structures and
algorithms for handling collections of data in a more
abstract and generalized way.
3. Common Examples:
In Java, the term "collections" often refers to the Java
Collections Framework, which includes interfaces like
List, Set, Map, and various implementations for each. It
provides a comprehensive set of data structures for
managing collections.
In Python, collections can refer to various built-in data
types like lists, sets, and dictionaries, but it can also
refer to the collections module, which provides
specialized data structures like namedtuple, deque, and
Counter.
The Map interface defines a set of methods for working with key-value
pairs. Some of the commonly used methods include:
1. put(K key, V value): Associates the specified value with the specified
key in the map.
2. get(Object key): Returns the value to which the specified key is
mapped, or null if the key is not found.
3. remove(Object key): Removes the key-value pair with the specified
key from the map and returns the value.
4. containsKey(Object key): Checks if the map contains a mapping for
the specified key.
5. keySet(): Returns a set of all keys in the map.
6. values(): Returns a collection of all values in the map.
7. entrySet(): Returns a set of key-value pairs (entries) in the map.
-----------------------------------------------------------------------------------
Dans la classe anonyme : Utilisation d’une variable globale ne peut pas être modifiable -> must be
final
Static functions : méthode de classe, méthode testa3mel que les paramètres mte3ha, on peut
l’appeler sans faire l’instanciation de la classe
Interface fonctionnelle :