Przejdź do głównej zawartości

Posty

Wyświetlanie postów z maj, 2019

Sorting algor

BubbleSort // BubbleSort System . out . println ( "BubbleSort" ); for ( int i = 0 ; i < data . length - 1 ; i ++){ for ( int j = 0 ; j < data . length - 1 - i ; j ++){ if ( data [ j ] > data [ j + 1 ]) { int temp = data [ j ]; data [ j ]= data [ j + 1 ]; //swap data [ j + 1 ]= temp ; } } } mało efektywny z uwagi na podwójny loop tylko do małych data sets efektywność O(n^2) SelectionSort raczej wolny algorytm z uwagi na podwójny loop małe data set efektywność O(n^2) System . out . println ( "SelectionSort" ); int i , j , minV , minI , temp = 0 ; for ( i = 0 ; i < data . length ; i ++){ minV = data [ i ]; minI = i ; for ( j = i ; j < data . length ; j ++){ if ( data [

Stream peak() metoda - Java

API Note: This method exists mainly to support debugging, where you want to see the elements as they flow past a certain point in a pipeline: Stream.of("one", "two", "three", "four") .filter(e -> e.length() > 3) .peek(e -> System.out.println("Filtered value: " + e)) .map(String::toUpperCase) .peek(e -> System.out.println("Mapped value: " + e)) .collect(Collectors.toList()); Metoda pozwala wyprintować aktualny stan streamu. Rodzaje operacji na strumieniach: posredniczace tzw intermediate kończące - tzw terminal bezstanowe - np filter stanowe - sort redukcyjne - np max WAZNE Strumienie są wywoływane w sposób leniwy (lazy) tzn dane sa przetwarzane w momencie wywołania metody końcowej tj terminal Transformacje nie modyfikuja wejściowych danych z których strumień został stworzony  https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-su

Runnable and Call able - Java rekrutacja

Runnable - interfejs zawierający metode run() - obiekt implementujący tą metodę tworzy wątek thread public interface Runnable The Runnable interface should be implemented by any class whose instances are intended to be executed by a thread. The class must define a method of no arguments called run. This interface is designed to provide a common protocol for objects that wish to execute code while they are active. For example, Runnable is implemented by class Thread. Being active simply means that a thread has been started and has not yet been stopped.  In addition, Runnable provides the means for a class to be active while not subclassing Thread. A class that implements Runnable can run without subclassing Thread by instantiating a Thread instance and passing itself in as the target. In most cases, the Runnable interface should be used if you are only planning to override the run() method and no other Thread methods. This is important because classes should not be subclassed

wait and notify() Methods in Java - rekrutacja

Synchronizacja wątków. Procesor może wykonywać wiele zadań jednoczenśnie - concurrent software. Java wspiera współbieżność jest potrzebna synchronizacja ponieważ różne wątki threads mogą w tym samym czasie usiłować zmodyfikować ten sam zasób jeśli nie są zarządzane poprawinie. Object.wait() - zawiesza wątek - thread suspension Object.notify() - wznów wątek - thread wake up Object.notifyAll() - wznowienie wszystkich wątków