Skip to content

Instantly share code, notes, and snippets.

View oshi192's full-sized avatar

Yurii Kosakivskyi oshi192

  • Toronto ON, Canada
View GitHub Profile
@oshi192
oshi192 / SOLID
Last active March 16, 2018 12:24
SOLID princeples
//---------------------Single responsibility principle -----------------------------------------
// 1 class - 1 duty, in other words in one class could be one public method
// for example - the screwdriver has something to twist. If you make it massive, then
// it can be used for hammering nails
// (though this is not very convenient),
---------------------------------
// or another example: human Greg
// he opened courses for something by himself.
@oshi192
oshi192 / OOP
Last active March 16, 2018 16:14
OOP principles
//---------------------------abstraction--------------------------------
// when we translit the object from real world to our class
// we chose only the fatures witch e need in our class
// for example create a class "Rectangle", and we need 4 variables for it description
// they are coordinates of high left corner, width and height.
class rect{
float x,y,w,h;
void draw(){}
@oshi192
oshi192 / The Numbers App.md
Last active March 20, 2018 08:42
The Number App (homeTask) 16.02.18-17.02.18
import java.util.Scanner;
public class Application{
    public static void main(String ... args){
        Scanner sc = new Scanner(System.in);
        int answer; 	    //our answer will be in this variable	   //
        int number;		//our number				   //
        int firstStart = 0; //to know if we see the menu at first time //
        String s;  

How many different ways can you write "for" cycle?

Traditional For loop - contains three parts: the initialization, the condition, and afterthought or commonly known as increment/decrement. Classic for:

for ( int index = start_value; index < end_value; index += increment_value /*or index -= increment_value*/ ) 
          { 
             // Do this code  
          } 
@oshi192
oshi192 / Strings.md
Last active March 29, 2018 12:06
operations with Strings

Operations with Strings

Description: String is a class witch has array of char field. the length of the String is fixed!!!! (as an any array). You can think that you are changing a string, but in fact, you are creating a new string and putting old meanings with new changes in it.

The operations that we can do

  • concatenation we can concatenate 2 strings using "+" or "+=" or "concat()". For example:
String s;
@oshi192
oshi192 / Queque.md
Last active April 6, 2018 15:14
Java Collections - Queue

Queue

basic info

Queue - is very usefull structure, it designed for holding elements prior to processing. In this structure you can add elements in the end point but it can be removed in the peek of queue. Order elements in a FIFO (first-in-first-out) manner.

methods

there are metods that throws exception or return some value;

  • add(e) - Inserts the specified element into this queue if it is possible.Returning true upon success and throwing an IllegalStateException if no space is currently available. (also can throw ClassCastException, NullPointerException, IllegalArgumentException).
  • offer(e) - insert element in queque if possible, otherwise returning false. But also can throws exception (ClassCastException, NullPointerException, IllegalArgumentException).
  • remove() - methods remove and return the head of the queue. If queque is empty throws an NoSuchElementException exception.
  • poll() - methods remove and return the head of the queue. If queque is empty returns null.

ArrayList

basic info

This structure allows you to store data in a linear linear collection of data elements (list). The place where the elements of the ArrayList are stored is an array. As we know the length of the array does not change. so to add some element, we need to create a new larger array, then move the data from the previous array and add a new element. Similar actions will be with the removal. but it's all happening inside the ArrayList. From the outside there are quite convenient methods to work with him.

Implemented interfaces:

Serializable, Cloneable, Iterable, Collection, List, RandomAccess

some methods

  • add(E e) - Appends the specified element to the end of this list.

LinkedList

basic info

This structure allows you to store data in a linear linear collection of data elements (list). Each element is merged into a cell of this list, in turn the cell contains some element, and the links to the next and the previous elements. which allows you to store data not consistently as in the array. And they can be located across different parts of the memory.

Implemented interfaces:

Serializable, Cloneable, Iterable, Collection, Deque, List, Queue

some methods

  • add(E e) - Appends the specified element to the end of this list.
  • add(int index, E element) - Inserts the specified element at the specified position in this list.
import java.util.ArrayList;
import java.util.LinkedList;

public class Main {
    private static final int LIST_LENGTH = 500000;

    public static void main(String[] args) {

        ArrayList<Integer> arrayList = createArrayList();

java.util

Interfaces

  • List An ordered collection (also known as a sequence).The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.
  • Deque A linear collection that supports element insertion and removal at both ends. The name deque is short for "double ended queue" and is usually pronounced "deck". Most Deque implementations place no fixed limits on the number of elements they may contain, but this interface supports capacity-restricted deques as well as those with no fixed size limit. This interface defines methods to access the elements at both ends of the deque. Methods are provided to insert, remove, and examine the element. Each of these methods exists in two forms: one throws an exception if the operatio