Сообщения

Сообщения за апрель, 2021

GIT - Bogdan Stashchuk

1. Shell commands -> mkdir - make directory -> ls - list files and directories -> cd - change directory -> . - alias of the current directory -> .. - alien of the parent directory -> pwd - prints path for the current directory -> open . - opens folder -> touch - create new file -> > - write to the file -> >> - append to the file -> cat - list content of the file -> nano - edit file -> echo - print to terminal -> man - help on specific command -> rm - remove files and directories 2. How git works under the hood -> git init - create new git repository -> git add . - move file from untracked or modified stage to staged stage -> git commit -m "message" - move file from staged stage to unmodified stage -> if we change any file that is already tracked it will change its state to modified -> git status - we see status of files -> git rm --cached text3.txt - onstage file, remove file to untagged area   3. Git bra

File. IO and NIO

 1.How to create a file. package file ; import java.io.File ; public class MyFile { public File createFile ( String filePath ) { File myFile = new File( filePath ) ; return myFile ; } } package file ; import java.io.File ; public class Main { public static void main ( String [] args ) { MyFile file = new MyFile() ; File myFile = file .createFile( "test.txt" ) ; } } To create a file in Java, you can use the  createNewFile()  method. This method returns a boolean value:  true  if the file was successfully created, and  false  if the file already exists. Note that the method is enclosed in a  try...catch  block. This is necessary because it throws an  IOException  if an error occurs (if the file cannot be created for some reason): package file ; import java.io.File ; import java.io.IOException ; public class CreateFiles { public File create ( String fileName ) { try { File myFile = new File( fileName ) ;

Generics

Изображение
                                                                                         Generics 1.  public class Lists { // Here is a method that accepts an array of any type and converts it to a list public static < T > List < T > toList ( T [] arr ) { List < T > list = new ArrayList <>(); for ( T elt : arr ) list . add ( elt ); return list ; } public static < T > List < T > toList2 ( T ... arr ) { List < T > list = new ArrayList <>(); for ( T elt : arr ) list . add ( elt ); return list ; } public static < T > void addAll ( List < T > list , T ... arr ) { for ( T elt : arr ) list . add ( elt ); } }   2.  List < Number > nums = new ArrayList <>(); List < Integer > ints = Arrays . asList ( 1 , 2 ); List < Double > dbls = Arrays . asList ( 2.2 , 3.3 ); nums . addAll ( ints ); nums . addAll ( dbls ); System . out . printl

Spring

 Bean - The object that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, and otherwise managed by a Spring IoC container. These beans are created with the configuration metadata that you supply to the container.

Try Catch Finally. Try with resources

 Finally - ensures us that this part of code(I mean code inside Finally braces) will be executed. import java.io.BufferedWriter ; import java.io.FileWriter ; import java.io.IOException ; public class MyFileWriter { public static void writeToFile ( String text , String file ) throws Exception { BufferedWriter bw = null ; FileWriter fw = null ; try { fw = new FileWriter( file ) ; bw = new BufferedWriter( bw ) ; bw .write( text ) ; } catch ( IOException ex ) { System . err .format( "IOException: " + ex ) ; } finally { try { if ( bw != null ) bw .close() ; if ( fw != null ) fw .close() ; } catch ( IOException ex ) { System . err .format( "IOException " + ex ) ; } } } } Here we can see that if something happens in first catch then finally will be

SOLID principles

 SOLID: 1. S - SRP: The single responsibility principle. A class should have one, and only one, reason to change. This means that every class, or similar structure, in your code should have only one job to do.  2. O - OCP: The Open Closed Principle. You shoul be able to extend a classes behaviour, without modifying it. Open to extention means that you shoul design your classes so that new functionality can be added as new requirements are generated. Closed for modifications means that once you have developed a class you shoud never modify it, except to correct bugs. 3. L - LSP: Liskov substitution priciple. Derived classes must be substitutable for ther base classes. That means we have to construct our hierarchy from simple to complex. So that complex extends from simple.  4. I - ISP: The interface segregation principle. It states that client should not be forced do depend upon interface members they do not use. 5. D - DIP: Dependency inversion principle. It states that high-level modu