Fix typos

This commit is contained in:
Marcello 2021-09-20 19:35:32 +02:00
parent 76550dfa3c
commit 51a1738c74
84 changed files with 759 additions and 876 deletions

View file

@ -67,7 +67,7 @@ public interface I<Type>DAO {
## `<Type>DAO`
Class implementing `I<Type>DAO` and handling the comunication with the db.
Class implementing `I<Type>DAO` and handling the communication with the db.
```java
package dao;
@ -80,8 +80,8 @@ public class <Type>DAO implements I<Type>DAO {
private <Type> results;
private Statement statement; // SQL instruction contenitor
private ResultSet rs; // Query results contenitor
private Statement statement; // SQL instruction container
private ResultSet rs; // Query results container
private DB db;
public <Type>DAO() {

View file

@ -1,16 +1,16 @@
# Java Collection Framework - JCF
All classes that permit the handling of groups of objects constituite the Java Collection Framework.
All classes that permit the handling of groups of objects constitute the Java Collection Framework.
A Collection is a *container* in which several objects are grouped in a *single entity*.
The **Java Collection Framework** is constituited by:
The **Java Collection Framework** is constituted by:
- **Interfaces** the define the operations of a generic collection. They can be split into two categories:
- **Collection**: used to optimize operations of insertion, modification and deletion of elements in a group of objects.
- **Map**: optimized for look-up operations.
- **Classes** that implement the interfaces using different data structures.
- **Algorithms** consistng in methods to operate over a collection.
- **Algorithms** consisting in methods to operate over a collection.
![Java Collection Hierarchy](../.images/java_java-collection-framework.png "Java Collection Hierarchy")
@ -19,12 +19,12 @@ The **Java Collection Framework** is constituited by:
### Collection Functions
```java
boolean add (Object o) e.g., <x>.add (<y>) //append to colelction, false if fails
boolean add (Object o) e.g., <x>.add (<y>) //append to collection, false if fails
boolean add (int index, Object o) //insertion at given index
boolean addAll (Collection c) //appends a collection to another
void clear() //remove items from container
boolean contains (Object o) //true if object is in collection
boolean containsAll (Collection c) //true if all items of collectio are in another
boolean containsAll (Collection c) //true if all items of collection are in another
boolean isEmpty (Object o) e.g., if (<x>.isEmpty()) ... //true if collection is empty
boolean remove (Object o) //remove object from collection
Object remove (int index) //remove object at given index
@ -60,19 +60,19 @@ ArrayList<Type> ArrayListName = new ArrayList<>(); //resizable array (JAVA 1.
ArrayListName.add(item); //append item to collection
ArrayListName.add(index, item); // add item at positon index, shift all item from index and successive towards the end af the ArrayList
ArrayListName.add(index, item); // add item at position index, shift all item from index and successive towards the end af the ArrayList
ArrayListName.set(index, item); // substitute EXISTING item
ArrayListName.get(index); //access to collection item
ArrayListName.remove(item) //remove first occurence of item from collection
ArrayListName.remove(item) //remove first occurrence of item from collection
ArrayListName.remove(index) //remove item at position index
ArrayListName.clear() //emties the ArrayList
ArrayListName.clear() //empties the ArrayList
ArrayListName.contains(object); // check if object is in the ArrayList
ArrayListName.IndexOf(object); // returns the index of the object
ArrayListName.isEmpty(); // check wether the list is empty
ArrayListName.size(); //dimension of the ArrayList
ArrayListName.tirmToSize(); // reduce ArrayList size to minimum needed
// ArrayList size doubles when a reseize is needed.
// ArrayList size doubles when a resize is needed.
//run through to the collection with functional programming (JAVA 1.8+)
ArrayListName.forEach(item -> function(v));
@ -94,7 +94,7 @@ class ClassName implements Comparable<ClassName> {
List<ClassName> list;
//valorize List
Collections.sort(list); //"natuarl" sorting uses compareTo()
Collections.sort(list); //"natural" sorting uses compareTo()
```
Otherwise a `Comparator()` must be implemented:
@ -116,7 +116,7 @@ Comparator<ClassName> comparator = new Comparator<ClassName>() {
List<ClassName> list;
//valorize List
Collections.sort(list, comparator); //"natuarl" sorting uses compareTo()
Collections.sort(list, comparator); //"natural" sorting uses compareTo()
```
`Comparator<T>` and `Conmparable<T>` are functional interfaces
`Comparator<T>` and `Comparable<T>` are functional interfaces

View file

@ -1,115 +0,0 @@
# Java Server Pages Cheat Sheet
Java embedded in html.
Codice + JSP salvati in file `.war`
[TEMP Notes Source](https://github.com/maboglia/CorsoJava/blob/master/appunti/057_JSP_appunti.md#corso-jsp---le-direttive)
## Directives
Le direttive Le direttive permettono di definire la struttura di tutto il documento JSP. Indicano gli aspetti principali del *servlet* in cui sarà convertito il file JSP.
Sono processati al momento della conversione in servlet, a compile-time.
Le direttive esistenti sono: *page*, *include* e *taglib*.
- `<%@ page attribute="value" %>`
- `<%@ include file="path" %>`
- `<%@ taglib ...%>`
Introdotte dal simbolo `@` possono contenere diversi attributi, in alcuni casi concatenabili come per la direttiva import.
### Attributi Direttiva `Page`
**`import="package.class"`**
Lista di package o classes, separati da virgola, che saranno importati per essere utilizzati nel codice java.
**`session ="true | false"`**
Specifica se la pagina fa parte di una sessione HTTP. Se si inizializza a true, è disponibile l'oggetto implicito sessione.
**`buffer ="dimensione-kb"`**
Specifica la dimensione di un buffer di uscita di tipo stream, per il client.
**`errorPage="url"`**
Specifica una pagina JSP che sarà processata nel caso si verifichi un errore.
**`isErrorPage="true|false"`**
Indica che la pagina è una pagina di errore JSP e può mostrare a video l'output dell'errore verificatosi. Per default è settata false.
**`contentType="MIME-Type"`**, **`contentType="MIME-Type; charset=Character-Set"`**
valore MIME di default è text/html
### Direttiva `Include`
Indica al motore JSP di includere il contenuto del file corrispondente, inserendolo al posto della direttiva nella pagina JSP. Il contenuto del file incluso è analizzato al momento della traduzione del file JSP e si include una copia del file stesso nel servlet generato. Una volta incluso, se si modifica il file non sarà ricompilato nel servlet. Il tipo di file da includere può essere un file html (*statico*) o un file jsp (*dinamico*).
```jsp
<html>
<head>
<title> pagina di prova Direttive </title>
</head>
<body>
<h1>pagina di prova Direttive inclusione</h1>
<%@ include file="/hello_world.html" %>
<%@ include file=”/login.jsp” %>
</body>
</html>
```
### Direttiva `Taglib`
Permette estendere i marcatori di JSP con etichette o marcatori generati dall'utente (etichette personalizzate).
Sintassi: `<%@ taglib uri="taglibraryURI" prefix="tagPrefix" %>`
Esempi librerie standard:
- JSTL core
- JSTL sql
- JSTL function
## Implicit Objects
JSP utilizza gli oggetti impliciti (built-in).
Gli oggetti impliciti sono oggetti istanziati automaticamente dallambiente JSP, non dobbiamo preoccuparci di importarli e istanziarli.
Per utilizzarli è sufficiente usare la sintassi `nomeOggetto.nomeMetodo`.
Oggetti disponibili per luso in pagine JSP:
- **out**: per scrivere codice HTML nella risposta (System.out di Java)
- **session**: dati specifici della sessione utente corrente
- **request**: richiesta HTTP ricevuta e i suoi attributi, header, cookie, parametri, etc.
- **page**: la pagina e le sue proprietà.
- **config**: dati di configurazione
- **response**: risposta HTTP e le sue proprietà.
- **application**: dati condivisi da tutte le pagine della web application
- **exception**: eventuali eccezioni lanciate dal server; utile per pagine di errore
- **pageContext**: dati di contesto per lesecuzione della pagina
Gli oggetti impliciti possono essere:
- oggetti legati alla servlet relativa alla pagina JSP
- oggetti legati allinput e alloutput della pagina JSP
- oggetti che forniscono informazioni sul contesto in cui la JSP viene eseguita
- oggetti risultanti da eventuali errori
Ambito Definisce dove e per quanto tempo saranno accessibili gli oggetti (oggetti impliciti, JavaBeans, ...):
- di pagina: l'oggetto è accessibile dal servlet che rappresenta la pagina
- di richiesta: l'oggetto viene creato e poi distrutto dopo l'uso
- di sessione: l'oggetto è accessibile durante tutta la sessione
- di applicazione: l'oggetto è accessibile dal servlet che rappresenta la pagina
---
## Code in JSP Page
`<% /* code here */ %>` is used to embed java code in a JSP page.
`<%= var %>` is used to get a value from a variable to be displayed.
### Request Parameters
```java
Type variable = request.getParameter("request_parameter"); // parameter of a GET request
```

View file

@ -32,7 +32,7 @@ public class <className> extends HttpServlet {
// POST REQUEST: add stuff to DB, page, ...
doGet(request, response); // return same page with new conted added (default case)
doGet(request, response); // return same page with new content added (default case)
}
}
```

View file

@ -25,7 +25,7 @@ public static void main (String[] args) {
}
```
### Variable Assignement
### Variable Assignment
`Type variable_1 = <expr>, ..., variable_n = <expr>;`
@ -59,7 +59,7 @@ System.out.printf("string %..", variable);
System.out.println(String.format(format, args));
```
Methods ereditated from C. The value pf the variable substitutes %.
Methods inherited from C. The value pf the variable substitutes %.
`%d` int, `%f` float, `%c` char, `%s` string, `%e` scientific notation.
`%digitNumber.decimalDigitNumber` specifies the space occupied by the output.
@ -81,9 +81,9 @@ scanner.close() //closing of Scanner, releases memory
int variable_int_1 = scanner.nextInt(); //takes integer number
String string_1 = scanner.nextLine(); //takes line of text (\n ends line)
String string_1 = scanner.next(); //takes text (spacec ends word)
String string_1 = scanner.next(); //takes text (space ends word)
double variable_double_1 = scanner.nextDouble(); //takes double decimal number
boolean variable_bool = scanner.netxBoolean(); //takes boolean value
boolean variable_bool = scanner.nextBoolean(); //takes boolean value
//(TRUE, FALSE, true, false, True, False)
```
@ -110,7 +110,7 @@ If not specified int & double are the default types.
### Floating-Point numbers & Precision Calcs
Don't use `==` or `!=` to confront floating value numbers since they use approximation or have a lot of digits.
It's best to check if the difference between two numbers is small enought.
It's best to check if the difference between two numbers is small enough.
For high precision calcs is best to use `BigDecimal`.
### Type Conversion (casting) & Type checking
@ -126,7 +126,7 @@ Every primitive type has a corresponding wrapper class.
Wrapper classes permits the creation of an object with the same type of a primitive type but with added methods and constants.
```java
WrapperClass objectName = new WrapperClass(primitiveValue); //decalration
WrapperClass objectName = new WrapperClass(primitiveValue); //declaration
WrapperClass objectName = primitiveValue; //shortened declaration
@ -182,19 +182,19 @@ int i = integer.parseInt(string);
```java
string.equals(otherString); // returns TRUE if the strings are equal
srting.equalsIgnoreCase(otherString); // returns TRUE if the strings are equals ignoring the case
string.charAt(index); // returns the character at positon INDEX
string.equalsIgnoreCase(otherString); // returns TRUE if the strings are equals ignoring the case
string.charAt(index); // returns the character at position INDEX
string.startsWith(otherString); // returns TRUE if string starts with otherString
string.endsWith(otherString) // returns TRUE if string ends with otherString
string.concat(otherString); // concatenation of two strings
string.indexOf(otherString); // returns index of the first occurrence of othre string
string.lastIndexOf(otherString); // returns index of the last occurrence of othre string
string.indexOf(otherString); // returns index of the first occurrence of other string
string.lastIndexOf(otherString); // returns index of the last occurrence of other string
string.length(); // returns the length of the string
string.toLowerCase(); // transform the string in uppercase characters
string.toUpperCase(); // transform the string in lowercase characters
string.repalce(character, newCharacter); // substitutes character with newCharacter
string.replaceAll(regex, replacecment);
string.substring(start, end); // returns a substring starting as START and ending at END (incluced)
string.replace(character, newCharacter); // substitutes character with newCharacter
string.replaceAll(regex, replacement);
string.substring(start, end); // returns a substring starting as START and ending at END (included)
string.trim(); // removes spaces before and after the string
string.Split(delimiter); // return a String[] generated by splitting string at the occurrence of delimiter
string.compareTo(otherString);
@ -207,7 +207,7 @@ string.compareTo(otherString);
- `1` if `otherString` precedes `string`
`compareTo()` compares the lexicographic order (based on UNICODE).
To compare in alphabetical order voth strings must have the same case.
To compare in alphabetical order both strings must have the same case.
### Mathematical Operations
@ -280,7 +280,7 @@ a `^` b | bitwise **XOR**
a `<<` b | bitwise left shift
a `>>` b | bitwise right shift
### Compound Assignement Operators
### Compound Assignment Operators
operator | operation
-----------|----------
@ -298,8 +298,8 @@ a `>>=` b | a = a >> b
### Operator Precedence
1. unary operators `++` , `--`, `!`
2. binary arithmetic opeartors `*`, `/`, `%`
3. binary arithmetic opeartors `+`, `-`
2. binary arithmetic operators `*`, `/`, `%`
3. binary arithmetic operators `+`, `-`
4. boolean operators `<`, `>` , `<=`, `>=`
5. boolean operators `==`, `!=`
6. bitwise operator `&`
@ -414,8 +414,8 @@ The iterator declared in the for is a local variable and can be used only in the
### Assertion Checks
If the asertion check is enabled (`java -ebableassetrions programName`) the execution of the algorithm is terminated if an assertion fails.
Asseretions can be used to check if a variable has a wanted value in a precise point in the code (Sanity Check).
If the assertion check is enabled (`java -ebableassetrions programName`) the execution of the algorithm is terminated if an assertion fails.
Assertions can be used to check if a variable has a wanted value in a precise point in the code (Sanity Check).
```java
assert <booleanExpression>;
@ -451,7 +451,7 @@ ClassName.methodName(arguments); //if method is used outside its class
## Array
## Array Delcaration
## Array Declaration
```java
Type[] arrayName = new Type[dimension];
@ -468,10 +468,10 @@ Type[] arrayName;
arrayType = new Type[dimension];
```
## Array Creation by Initializzation
## Array Creation by Initialization
`Type[] arrayName = {value1, value2, ...}`
Array dimansion is determined by the number of values.
Array dimension is determined by the number of values.
### Arrays as method parameters
@ -517,7 +517,7 @@ Type[]...[] arrayName = new Type[dimension1]...[dimensionN];
Type arrayName[]...[] = new Type[dimension1]...[dimensionN];
```
### Multi-Dimensional Arrats as parameters
### Multi-Dimensional Arrays as parameters
```java
static Type methodName (Type[]...[] ArrayName) {
@ -538,7 +538,7 @@ static Type[]...[] methodName (parameters) {
### Array Length of multi-dimensional arrays
```java
array.length //row lenght
array.length //row length
array[rowIndex].length //column length
```
@ -557,15 +557,15 @@ static void viewTable (Type[][] matrix){
## Recursion Guidelines
The core of the recursion must be constituited by a *conditional instruction* that permits to handle the cases basend on the method argument.
*At laest one* of the alternatives must contain a recurive call to che mathod. The call must resolve recuced version of the task handled by the method.
*At leats one* of the alternatives must not contain a recursive call or it must produce a value that constituites a base case or an arrest value.
The core of the recursion must be constituted by a *conditional instruction* that permits to handle the cases based on the method argument.
*At least one* of the alternatives must contain a recursive call to che method. The call must resolve reduced version of the task handled by the method.
*At leats one* of the alternatives must not contain a recursive call or it must produce a value that constitutes a base case or an arrest value.
## Exception Handling
An **Exception** is an object used to signal an anomalous event.
**Checked Exceptions** must be handled in a catch meanwhile **Uncchecked Exceptions** do not need to be catched like `RuntimeException`.
Unchecked exceptions usually mean thathere is an error in the logic of the program that must be fixed.
**Checked Exceptions** must be handled in a catch meanwhile **Unchecked Exceptions** do not need to be cached like `RuntimeException`.
Unchecked exceptions usually mean that there is an error in the logic of the program that must be fixed.
### `Try-Catch-Finally`
@ -576,7 +576,7 @@ try {
//monitored code
} catch (SpecificException e) {
//in case of errors use this
} catch (SpecificException1 | SpecficException2 | ... | SpecificExceptionN e) {
} catch (SpecificException1 | SpecificException2 | ... | SpecificExceptionN e) {
//in case of errors use this
} catch (Exception e) {
//in case of error use this
@ -594,7 +594,7 @@ A `try-catch` construct can handle multiple exceptions at once. Every `catch` i
try (
//resource definition
){
//dangerious code
//dangerous code
} catch (Exception e) {
//in case of error use this
} finally {
@ -619,7 +619,7 @@ The `throws` keyword is used to indicate what exception Type may be thrown by a
`throws` is used together with a exception class. It's used to send the exception to the method caller.
```java
Type methodName(parameters) throws ExcpetionClass {
Type methodName(parameters) throws ExceptionClass {
if (condition) {
throw new SpecificException("error message");
}
@ -651,7 +651,7 @@ public class CustomException extends Exception {
### Access Modifiers
`public` variables, methoda, classes are usable outside of class of definition.
`public` variables, methods, classes are usable outside of class of definition.
`private` variables, methods, classes are *only* usable inside class of definition.
`protected` variables, methods, classes can be accessed *only* by defining class, it's descendants and the package.
`final` classes and methods cannot be extended or overridden.
@ -701,28 +701,28 @@ It's possible to use `this` to distinguish between instance and static variables
### Classes and Reference Addresses
A an instance of a class doesen't contain an object of that class but a memory address in whitch the object is memorized.
operations of assignement (`=`) and confront (`==`) act on the memory address and not on the values of the objects.
To confront object is necessary to define a `equals()` method that chacks if the values of the object attributes are equal.
A an instance of a class doesn't contain an object of that class but a memory address in which the object is memorized.
operations of assignment (`=`) and confront (`==`) act on the memory address and not on the values of the objects.
To confront object is necessary to define a `equals()` method that checks if the values of the object attributes are equal.
### Constructors
Constructrs are special methods that are invoked with the `new` operator when an object is instantiated.
Constructors are special methods that are invoked with the `new` operator when an object is instantiated.
Constructors assign the starting values of the object attributes.
If a constructor id defined Java doesen't create the default constructor.
If a constructor id defined Java doesn't create the default constructor.
```java
class ClassName (){
//attributes dclaration (aka instance variables)
//attributes declaration (aka instance variables)
//constuctor
//constructor
public ClassName(parameters){
this.attribute = value; //value is passed to the constructor at obj instantiation
}
public ClassName(parameters, otherParameters){
this(parameters); // invoke other consstructor for subset of parameters, must be FIRST INSTRUCTION
this(parameters); // invoke other constructor for subset of parameters, must be FIRST INSTRUCTION
this.attribute = value; // deal with the remaining parameters
}
}
@ -731,7 +731,7 @@ class ClassName (){
### Static Variables
`Type staticVariable = value;`
Statc variables are shared by all objects of a class and all static method can act upon them.
Static variables are shared by all objects of a class and all static method can act upon them.
Static variable do not belong to the class objects.
### Getters & Setter Methods
@ -760,7 +760,7 @@ Public String toString(){
### Static Methods in Classes
Static methods are used to effectuate operations not applied to objects.
Outside of the class of definition thay are invoked with ClassName.methodName()
Outside of the class of definition that are invoked with ClassName.methodName()
Static method **cannot** act on instance variables.
### Method Overloading
@ -778,14 +778,14 @@ Child class **must** implement a constructor that instantiates the parent (super
`super()` instantiates the superclass of the child class.
```java
class ChildClass extends PerentClass{
class ChildClass extends ParentClass{
public ChildClass(parentParameters, childParameters){
super(parentParameters); // if omitted super() is calles (parent's default constructor)
// assignement of child attributes
super(parentParameters); // if omitted super() is calls (parent's default constructor)
// assignments of child attributes
}
//calss overrides parent class (must have same name)
//calls overrides parent class (must have same name)
@Override
Type methodName(parameters){
//code here
@ -795,7 +795,7 @@ class ChildClass extends PerentClass{
}
```
An overridden method that returns a `ParentClass` can be overridden to return a `ChildClass`. This is the only case in which an overridden method can change the retured type.
An overridden method that returns a `ParentClass` can be overridden to return a `ChildClass`. This is the only case in which an overridden method can change the returned type.
An overridden method can change the access modifier as long as the new modifier is more "permissive".
A `ParentClass` type can contain a `ChildClass` object. This is useful for using collections and arrays of objects.
@ -805,17 +805,17 @@ ParentClass objectName = ChildClass(); // upcast
(ChildClass)ParentClassObject; // downcast
```
### Abstact Classes & Abstract Methods
### Abstract Classes & Abstract Methods
An Abstact Class is a particular class that contains an Abstact Method.
This type of class cannot be instantiated but is used leave the specific implementatio of some of it's methods to extending classes.
Abstact classes are marked by the `abstract` keyword.
An Abstract Class is a particular class that contains an Abstract Method.
This type of class cannot be instantiated but is used leave the specific implementation of some of it's methods to extending classes.
Abstract classes are marked by the `abstract` keyword.
An abstract method is a method witout imlementation.
An abstract method is a method without implementation.
The methods **must** be `public` and marked with the `abstract` keyword.
```java
//abstarct class
//abstract class
abstract class className{
//attributes here
//constructor here
@ -828,12 +828,12 @@ abstract class className{
### Interfaces
An Interface is a class with *only* abstact methods. An interface has more flexibility than an abstract class.
Interfaces are used to set requirements for child clases without specifing how to satisfy those requirements since it's methods will be implemented in child classes.
An Interface is a class with *only* abstract methods. An interface has more flexibility than an abstract class.
Interfaces are used to set requirements for child classes without specifying how to satisfy those requirements since it's methods will be implemented in child classes.
An Interface is marked by the `interface` keyword.
If an implementing class implements only `some` of the interface's mathod than the class **must be abstract**.
If an implementing class implements only `some` of the interface's method than the class **must be abstract**.
Interfaces' methods are always `abstract` and `public`, no need for the kyword.
Interfaces' methods are always `abstract` and `public`, no need for the keyword.
Interfaces' attributes are always `public static final`, no need for the keyword.
A class can implement *more than one* Interface.
@ -849,7 +849,7 @@ public interface InterfaceName{
public interface OtherInterface extends InterfaceName {
//attributes here
Type methodName(); // inherited from extended interface
Type otherMethod(); // defined in thes interface
Type otherMethod(); // defined in the interface
}
class ClassName implements Interface1, Interface2 {...}
@ -858,16 +858,16 @@ class ClassName implements Interface1, Interface2 {...}
Types of Interfaces:
- Normal (multiple methods)
- Single Abstract Method (`@FunctionalInterface`, used with *Lamda Expressions*)
- Single Abstract Method (`@FunctionalInterface`, used with *Lambda Expressions*)
- Marker (Empty, *no methods*)
Since Java 1.8 interfaces can implements also `static` methods.
### Enumerations
Enums are used to restrict the type of data to a set of the possible constatnt values.
Enums are used to restrict the type of data to a set of the possible constant values.
Enums are classes which constructor is private by default.
It's still possible to createa a custom constructor to add values.
It's still possible to create a custom constructor to add values.
```java
enum enumName {
@ -887,13 +887,13 @@ enum enumName {
private Type value;
Type enumName(Type paramenter) {
Type enumName(Type parameter) {
this.value = parameter;
}
//getters are allowed, the values is a constant --> no setters
public Type getValue(){
retrurn this.value;
return this.value;
}
}
@ -916,7 +916,7 @@ AnonymousClass objectName = new AnonymousClass(Type parameter, ...) {
### Cloning
```java
class ClassName implements Cloneable {
class ClassName implements Clonable {
}
```
@ -1012,13 +1012,13 @@ try{
}
// write on the file
outSteram.print("");
outSteram.println("");
outStream.print("");
outStream.println("");
outStream.close() // close stream and write buffer contents.
```
**Note**: writing operations do not write direcly on the file. The sent data is collected in a **buffer**. When the buffer is *full* the data is written in the file. This is called *buffering* and is used to spped up operations.
**Note**: writing operations do not write directly on the file. The sent data is collected in a **buffer**. When the buffer is *full* the data is written in the file. This is called *buffering* and is used to append up operations.
#### Reading from a file
@ -1047,31 +1047,31 @@ try {
// code here
}
// BuffredReader Methods
// BufferedReader Methods
public String readLine() throws IOException // return file line or null (file has ended)
public int read() throws IOException // return an integer representin a char or -1 (file has ended)
public int read() throws IOException // return an integer representing a char or -1 (file has ended)
public long skip(n) throws IOException // skip n characters
public void close() throws IOException // closes the stream
```
#### `File()` class
The File class is an abstraction of the file and it's path. The abstraction is independant from the OS.
The File class is an abstraction of the file and it's path. The abstraction is independent from the OS.
```java
File("path/to/file") // UNIX like path
File("path\\to\\file") // Windows path
file.canRead() // true if file is readeble
file.canRead() // true if file is readable
file.canWrite() // true if file is writable
file.delete() // true if file has been deleted
file.exists() // check if exist a file with the filename used in the constructor
file.getName() // returns the filename
file.getPath() // returns the file's path
file.lenghth() // file lenght in bytes
file.length() // file length in bytes
```
### Bynary Files
### Binary Files
#### Writing to a binary file
@ -1146,7 +1146,7 @@ Needed for a class to be *serializable*:
- all instance variables are serializable
- superclass, if exists, is serializable or has default constructor
An array is serializable if it's base type is a rerializable object.
An array is serializable if it's base type is a serializable object.
```java
SerializableObject[] array = (SerializableObject[])inStream.readObject(); // read returns Object, cast needed
@ -1158,7 +1158,7 @@ SerializableObject[] array = (SerializableObject[])inStream.readObject(); // re
Functional interfaces provide target types for *lambda expressions*.
General purpose `@functioanlInterfaces`:
General purpose `@functionalInterfaces`:
```java
// takes input, performs actions, return boolean
@ -1189,7 +1189,7 @@ In java a *stream* is a [Monad][1]. Monads allow the programmer to compose a seq
The features of Java stream are:
- A stream is not a data structure instead it takes input from the Collections, Arrays or I/O channels.
- Streams dont change the original data structure, they only provide the result as per the pipelined methods.
- Streams don't change the original data structure, they only provide the result as per the pipelined methods.
- Each intermediate operation is lazily executed and returns a stream as a result, hence various intermediate operations can be pipelined. Terminal operations mark the end of the stream and return the result.
**Intermediate Operations**:

View file

@ -25,7 +25,7 @@ server.port=server_port
Model of a table of the DB
```java
package <base_pakcage>.entities;
package <base_package>.entities;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
@ -106,7 +106,7 @@ public interface IEntityService {
In `EntityService.java`:
```java
package com.lamonacamarcello.libri.services;
package <base_package>.services;
import java.util.List;
@ -162,7 +162,7 @@ public class EntityService implements IEntityService {
REST API routes & endpoints to supply data as JSON.
```java
package com.lamonacamarcello.libri.integration;
package <base_package>.integration;
import java.util.List;
@ -178,7 +178,7 @@ import <base_package>.services.IEntityService;
@RequestMapping("/api") // controller route
public class EntityRestCtrl {
@Autowired // connection to service (obj created by spring as needed: Inverion Of Control)
@Autowired // connection to service (obj created by spring as needed: Inversion Of Control)
private IEntityService service;
@GetMapping("entities") // site route