From 6dfe2ba51c1038d961163d287258f76a6553de92 Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Wed, 25 Mar 2015 19:03:57 +0200 Subject: [PATCH 01/20] Added estimation for reading --- week1/2-OOP/prereading.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/week1/2-OOP/prereading.md b/week1/2-OOP/prereading.md index de733f3..dbfc481 100644 --- a/week1/2-OOP/prereading.md +++ b/week1/2-OOP/prereading.md @@ -1,19 +1,40 @@ *On OOP in General* https://www.youtube.com/watch?v=lbXsrHGhBAU +Q&A : What are the main principles of OOP programming? +What is Polymorphism? +What is Encapsolation? +What is Data Abstraction? +What is Inheritance? +Whis is the founding principle...? +Time : 30 min *OOP Trail @ Oracle* http://docs.oracle.com/javase/tutorial/java/concepts/index.html +Time : 15 min + *Class and Objects @ Oracle (Those pages are actually Sun's property!)* http://docs.oracle.com/javase/tutorial/java/javaOO/ http://docs.oracle.com/javase/tutorial/java/concepts/object.html +Q&A : What is Class? +What is Interface? +What is isntace field, what is class field? +How is the behaviour of the class defined? +What is "this" keyword? How it is used? +Time : 30 min *More on Classes and objects* http://www.javaworld.com/article/2075202/core-java/object-oriented-language-basics-part-1.html?page=1 +Time : 15 min *Constructors & new()* http://www.javaworld.com/article/2076204/core-java/understanding-constructors.html http://www.javaworld.com/article/2076614/core-java/object-initialization-in-java.html +Q&A : Default init values ? +What if I use return in constructor? +Usage of super and this in constructors? +Usage of try/catch in contructors? +Time : 45 min *Abstract classes vs Interfaces* http://www.programmerinterview.com/index.php/java-questions/interface-vs-abstract-class/ From 5aca17635933d7ae335b1d68b13aad65f1bd233f Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Wed, 25 Mar 2015 19:05:53 +0200 Subject: [PATCH 02/20] Update prereading.md --- week1/2-OOP/prereading.md | 1 + 1 file changed, 1 insertion(+) diff --git a/week1/2-OOP/prereading.md b/week1/2-OOP/prereading.md index dbfc481..211c128 100644 --- a/week1/2-OOP/prereading.md +++ b/week1/2-OOP/prereading.md @@ -1,5 +1,6 @@ *On OOP in General* https://www.youtube.com/watch?v=lbXsrHGhBAU + Q&A : What are the main principles of OOP programming? What is Polymorphism? What is Encapsolation? From 00759193d74b758999cb2712cbac69c66e929e68 Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Wed, 25 Mar 2015 19:08:22 +0200 Subject: [PATCH 03/20] Update prereading.md --- week1/2-OOP/prereading.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/week1/2-OOP/prereading.md b/week1/2-OOP/prereading.md index 211c128..dcd31e1 100644 --- a/week1/2-OOP/prereading.md +++ b/week1/2-OOP/prereading.md @@ -1,6 +1,5 @@ *On OOP in General* https://www.youtube.com/watch?v=lbXsrHGhBAU - Q&A : What are the main principles of OOP programming? What is Polymorphism? What is Encapsolation? @@ -8,7 +7,7 @@ What is Data Abstraction? What is Inheritance? Whis is the founding principle...? Time : 30 min - +---------- *OOP Trail @ Oracle* http://docs.oracle.com/javase/tutorial/java/concepts/index.html Time : 15 min From 31ec04c59b8fd424c5ef584166fffcb98961f8ca Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Wed, 25 Mar 2015 19:22:48 +0200 Subject: [PATCH 04/20] Update prereading.md --- week1/2-OOP/prereading.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/week1/2-OOP/prereading.md b/week1/2-OOP/prereading.md index dcd31e1..a35606b 100644 --- a/week1/2-OOP/prereading.md +++ b/week1/2-OOP/prereading.md @@ -1,11 +1,11 @@ *On OOP in General* https://www.youtube.com/watch?v=lbXsrHGhBAU Q&A : What are the main principles of OOP programming? -What is Polymorphism? -What is Encapsolation? -What is Data Abstraction? -What is Inheritance? -Whis is the founding principle...? +1.What is Polymorphism? +2.What is Encapsolation? +3.What is Data Abstraction? +4.What is Inheritance? +5.Whis is the founding principle...? Time : 30 min ---------- *OOP Trail @ Oracle* From 1cb4a120bf7e547297c54efcb6f2df76d56b8366 Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Wed, 25 Mar 2015 19:26:35 +0200 Subject: [PATCH 05/20] Update prereading.md --- week1/2-OOP/prereading.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/week1/2-OOP/prereading.md b/week1/2-OOP/prereading.md index a35606b..12fad95 100644 --- a/week1/2-OOP/prereading.md +++ b/week1/2-OOP/prereading.md @@ -1,13 +1,13 @@ *On OOP in General* https://www.youtube.com/watch?v=lbXsrHGhBAU Q&A : What are the main principles of OOP programming? -1.What is Polymorphism? -2.What is Encapsolation? -3.What is Data Abstraction? -4.What is Inheritance? -5.Whis is the founding principle...? +# What is Polymorphism? +# What is Encapsolation? +# What is Data Abstraction? +# What is Inheritance? +# Whis is the founding principle...? Time : 30 min ----------- + *OOP Trail @ Oracle* http://docs.oracle.com/javase/tutorial/java/concepts/index.html Time : 15 min From b07fd14e85c8e0e228d0611fbc8440581e88a6ab Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Wed, 25 Mar 2015 19:27:17 +0200 Subject: [PATCH 06/20] Update prereading.md --- week1/2-OOP/prereading.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/week1/2-OOP/prereading.md b/week1/2-OOP/prereading.md index 12fad95..20248cd 100644 --- a/week1/2-OOP/prereading.md +++ b/week1/2-OOP/prereading.md @@ -1,11 +1,11 @@ *On OOP in General* https://www.youtube.com/watch?v=lbXsrHGhBAU Q&A : What are the main principles of OOP programming? -# What is Polymorphism? -# What is Encapsolation? -# What is Data Abstraction? -# What is Inheritance? -# Whis is the founding principle...? +* What is Polymorphism? +* What is Encapsolation? +* What is Data Abstraction? +* What is Inheritance? +* Whis is the founding principle...? Time : 30 min *OOP Trail @ Oracle* From b1baa89bf0e25f30797bfd8e9a55ae425164b0c9 Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Wed, 25 Mar 2015 19:27:36 +0200 Subject: [PATCH 07/20] Update prereading.md --- week1/2-OOP/prereading.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/week1/2-OOP/prereading.md b/week1/2-OOP/prereading.md index 20248cd..0cb8eea 100644 --- a/week1/2-OOP/prereading.md +++ b/week1/2-OOP/prereading.md @@ -1,12 +1,13 @@ *On OOP in General* https://www.youtube.com/watch?v=lbXsrHGhBAU -Q&A : What are the main principles of OOP programming? +# Q&A : +* What are the main principles of OOP programming? * What is Polymorphism? * What is Encapsolation? * What is Data Abstraction? * What is Inheritance? * Whis is the founding principle...? -Time : 30 min +# Time : 30 min *OOP Trail @ Oracle* http://docs.oracle.com/javase/tutorial/java/concepts/index.html From 0bc506485a38fcd75e013ff518601b89c75b30c4 Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Wed, 25 Mar 2015 19:28:57 +0200 Subject: [PATCH 08/20] Update prereading.md --- week1/2-OOP/prereading.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week1/2-OOP/prereading.md b/week1/2-OOP/prereading.md index 0cb8eea..fedccb2 100644 --- a/week1/2-OOP/prereading.md +++ b/week1/2-OOP/prereading.md @@ -1,13 +1,13 @@ *On OOP in General* https://www.youtube.com/watch?v=lbXsrHGhBAU -# Q&A : +*Q&A* * What are the main principles of OOP programming? * What is Polymorphism? * What is Encapsolation? * What is Data Abstraction? * What is Inheritance? * Whis is the founding principle...? -# Time : 30 min +*Time : 30 min* *OOP Trail @ Oracle* http://docs.oracle.com/javase/tutorial/java/concepts/index.html From 564af82d91bd576c4fbc617b341cf9fbe4f3d16d Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Wed, 25 Mar 2015 19:29:36 +0200 Subject: [PATCH 09/20] Update prereading.md --- week1/2-OOP/prereading.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week1/2-OOP/prereading.md b/week1/2-OOP/prereading.md index fedccb2..25850b5 100644 --- a/week1/2-OOP/prereading.md +++ b/week1/2-OOP/prereading.md @@ -1,12 +1,12 @@ *On OOP in General* -https://www.youtube.com/watch?v=lbXsrHGhBAU -*Q&A* +https://www.youtube.com/watch?v=lbXsrHGhBAU +*Q&A* * What are the main principles of OOP programming? * What is Polymorphism? * What is Encapsolation? * What is Data Abstraction? * What is Inheritance? -* Whis is the founding principle...? +* Whis is the founding principle...? *Time : 30 min* *OOP Trail @ Oracle* From f8f7c37f172360c297848f259cc45c0b6024dbf8 Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Thu, 26 Mar 2015 13:04:17 +0200 Subject: [PATCH 10/20] Update prereading.md --- week1/2-OOP/prereading.md | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/week1/2-OOP/prereading.md b/week1/2-OOP/prereading.md index 25850b5..ed08c0e 100644 --- a/week1/2-OOP/prereading.md +++ b/week1/2-OOP/prereading.md @@ -1,12 +1,15 @@ *On OOP in General* https://www.youtube.com/watch?v=lbXsrHGhBAU + *Q&A* + * What are the main principles of OOP programming? * What is Polymorphism? * What is Encapsolation? * What is Data Abstraction? * What is Inheritance? * Whis is the founding principle...? + *Time : 30 min* *OOP Trail @ Oracle* @@ -17,12 +20,15 @@ Time : 15 min *Class and Objects @ Oracle (Those pages are actually Sun's property!)* http://docs.oracle.com/javase/tutorial/java/javaOO/ http://docs.oracle.com/javase/tutorial/java/concepts/object.html -Q&A : What is Class? -What is Interface? -What is isntace field, what is class field? -How is the behaviour of the class defined? -What is "this" keyword? How it is used? -Time : 30 min + +*Q&A* +* What is Class? +* What is Interface? +* What is isntace field, what is class field? +* How is the behaviour of the class defined? +* What is "this" keyword? How it is used? + +*Time : 30 min* *More on Classes and objects* http://www.javaworld.com/article/2075202/core-java/object-oriented-language-basics-part-1.html?page=1 @@ -31,11 +37,14 @@ Time : 15 min *Constructors & new()* http://www.javaworld.com/article/2076204/core-java/understanding-constructors.html http://www.javaworld.com/article/2076614/core-java/object-initialization-in-java.html -Q&A : Default init values ? -What if I use return in constructor? -Usage of super and this in constructors? -Usage of try/catch in contructors? -Time : 45 min + +*Q&A* +* Default init values ? +* What if I use return in constructor? +* Usage of super and this in constructors? Where they should be put in the constructor? +* Usage of try/catch in contructors? + +*Time : 45 min* *Abstract classes vs Interfaces* http://www.programmerinterview.com/index.php/java-questions/interface-vs-abstract-class/ From 663544d1c32f59e35ec66e6a0d489023e4f6d76e Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Thu, 26 Mar 2015 13:32:44 +0200 Subject: [PATCH 11/20] Update prereading.md --- week1/2-OOP/prereading.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/week1/2-OOP/prereading.md b/week1/2-OOP/prereading.md index ed08c0e..85d317f 100644 --- a/week1/2-OOP/prereading.md +++ b/week1/2-OOP/prereading.md @@ -14,7 +14,7 @@ https://www.youtube.com/watch?v=lbXsrHGhBAU *OOP Trail @ Oracle* http://docs.oracle.com/javase/tutorial/java/concepts/index.html -Time : 15 min +*Time : 15 min* *Class and Objects @ Oracle (Those pages are actually Sun's property!)* @@ -32,7 +32,8 @@ http://docs.oracle.com/javase/tutorial/java/concepts/object.html *More on Classes and objects* http://www.javaworld.com/article/2075202/core-java/object-oriented-language-basics-part-1.html?page=1 -Time : 15 min + +*Time : 15 min* *Constructors & new()* http://www.javaworld.com/article/2076204/core-java/understanding-constructors.html @@ -50,14 +51,30 @@ http://www.javaworld.com/article/2076614/core-java/object-initialization-in-java http://www.programmerinterview.com/index.php/java-questions/interface-vs-abstract-class/ http://www.javaworld.com/article/2077421/learn-java/abstract-classes-vs-interfaces.html?null +*Time : 15 min* + *Override, overload, hide* http://docs.oracle.com/javase/tutorial/java/IandI/override.html +*Q&A* +* What is @Override annotation? +* Default methods in interfaces? Their scope and how are they hidden? + +*Time : 20 min* + *Subtyping & Liskov principle* https://www.youtube.com/watch?v=IL61KMYK0b8 +*Q&A* +*What is Liskov principle?* + +*Time : 10 min* *Default Methods* http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html +*Time : 20 min* + *Invariants* http://people.cs.aau.dk/~normark/oop-csharp/html/notes/contracts_themes-class-inv-sect.html + +*Time : 20 min* From 353ea2f072cc336d5efddf69f538dc371ba83f8f Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Mon, 30 Mar 2015 18:46:37 +0300 Subject: [PATCH 12/20] Added estimation for reading and Q&A section --- week2/1-CollectionsAndGenerics1/prereading.md | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/week2/1-CollectionsAndGenerics1/prereading.md b/week2/1-CollectionsAndGenerics1/prereading.md index 4ad7248..1a3fc0a 100644 --- a/week2/1-CollectionsAndGenerics1/prereading.md +++ b/week2/1-CollectionsAndGenerics1/prereading.md @@ -1,26 +1,55 @@ *Simplest use of an ArrayList* http://www.mkyong.com/java/how-to-loop-arraylist-in-java/ +*Time : 15 min* + *Check out some of the public methods of ArrayList* See its behaviour, what it can and can't do :) http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html +*Q&A* +* How would you implement a ArrayList + +*Time : 30 min* + *Some examples of the most used collections class in Java: ArrayList* http://javarevisited.blogspot.com/2011/05/example-of-arraylist-in-java-tutorial.html +*Time : 30 min* + *Difference between Iterator and ListIterator* (if you are unfamiliar with iterators, skip this one for now : ) http://stackoverflow.com/questions/10977992/difference-between-iterator-and-listiterator +*Time : 15 min* + *Diagram of ALL of java's collections framework:* http://www.codejava.net/java-core/collections/overview-of-java-collections-framework-api-uml-diagram +*Q&A* +* What is Set +* What is Map +* What do you understand about generics + +*Time : 20 min* + ####Part 2#### *A HashMap example* http://www.tutorialspoint.com/java/java_hashmap_class.htm +*Time : 30 min* + *HashMap vs Hashtable vs TreeMap in Java* http://www.programcreek.com/2013/03/hashmap-vs-treemap-vs-hashtable-vs-linkedhashmap/ +*Q&A* +* Differences between all + +*Time : 30 min* + *Equals and hashcode in java* http://stackoverflow.com/questions/27581/overriding-equals-and-hashcode-in-java +*Q&A* +* Mutable keys in Maps + +*Time : 20 min* From 91cf2ee1c547cc3578c695d5567f90f7fa4474c0 Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Mon, 30 Mar 2015 19:11:20 +0300 Subject: [PATCH 13/20] Update README.md --- week2/1-CollectionsAndGenerics1/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/week2/1-CollectionsAndGenerics1/README.md b/week2/1-CollectionsAndGenerics1/README.md index 5418cce..87e2986 100644 --- a/week2/1-CollectionsAndGenerics1/README.md +++ b/week2/1-CollectionsAndGenerics1/README.md @@ -38,6 +38,7 @@ boundedQueue.offer(4); boundedQueue.offer(5); System.out.println(boundedQueue.toString()); //3,4,5 ``` +*Hint:* View the java impl and interface:) ###4.Rotate the elements of a collection### Make a void *utility* method that rotates the contents of a collection. @@ -78,6 +79,8 @@ Lets say you have a `List`, where a Student is a class, containing two Sort them by their grades first. Their grades actually are integers => 2,3,4,5,6. If two students happen to have the same grades, sort those two by their names. +*hint* : Use Comparable or Comparator + ###8.Give me the median, quick!### Make an interface `Statistics`, which has these operations: @@ -145,6 +148,8 @@ System.out.println(todo.getTimeNeeded()) //sum of the time needed for every task See Comparable and Comparator classes in Java. Check out the PriorityQueue class. http://javarevisited.blogspot.com/2011/06/comparator-and-comparable-in-java.html +Use of generic classes. + ###10.Make a utility method that converts a hashMap into a very human-readable string### Make a *utility* method that takes a `HashMap` and *returns a String*, representing the HashMap. @@ -178,6 +183,10 @@ Retain the ordering of the elements! ##Epic bonus!## ###Cryptoanalysis fun### +======= +*Hint* +LinkedHashMap + There is an old technique for encrypting messages - shuffling the letters. For instance, if we take the string `Godzilla`, one crypted version of it is `Mrezotti`. The cipher here is From 557c33b6fa1869f6dcbf0dd7851acfc8b41e4136 Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Tue, 31 Mar 2015 00:32:09 +0300 Subject: [PATCH 14/20] Added additional reading section --- week2/1-CollectionsAndGenerics1/prereading.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/week2/1-CollectionsAndGenerics1/prereading.md b/week2/1-CollectionsAndGenerics1/prereading.md index 1a3fc0a..095be7f 100644 --- a/week2/1-CollectionsAndGenerics1/prereading.md +++ b/week2/1-CollectionsAndGenerics1/prereading.md @@ -53,3 +53,6 @@ http://stackoverflow.com/questions/27581/overriding-equals-and-hashcode-in-java * Mutable keys in Maps *Time : 20 min* + +*Additional reading* +http://javarevisited.blogspot.com/2013/10/what-is-priorityqueue-data-structure-java-example-tutorial.html From c88b537cfac4af23cd3cd000ef422234bd19f389 Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Fri, 3 Apr 2015 16:24:05 +0300 Subject: [PATCH 15/20] Updated with Q&A and time estimation. --- week2/2-Exceptions/prereading.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/week2/2-Exceptions/prereading.md b/week2/2-Exceptions/prereading.md index 4dcf481..c8c5f2f 100644 --- a/week2/2-Exceptions/prereading.md +++ b/week2/2-Exceptions/prereading.md @@ -1,9 +1,25 @@ *Exceptions hierarch in Java* http://www.javamex.com/tutorials/exceptions/exceptions_hierarchy.shtml +*Q&A* +* What is Throwable? +* What is Error? +* What is runtime exception? +* What is checked/uncheck exeption? +* What throw does in method? +* What is throws declaration of a method? +* EPIC QUESTION : What is Thread.setDefaultUncaughtExceptionHandler()? + +*Time : 30 min* + *Try/catch/finally example* http://www.tutorialspoint.com/java/java_exceptions.htm +*Q&A* +*What is the purpose of try/catch/finnaly? Give example with resources! What are the tricky parts this scheme? + +*Time : 30 min* + *Try with resources in Java 7* http://www.mkyong.com/java/try-with-resources-example-in-jdk-7/ From 28e66b6cb969ee829d068ac7e683fe4dcbe431a0 Mon Sep 17 00:00:00 2001 From: Nasko Date: Fri, 22 May 2015 15:09:04 +0300 Subject: [PATCH 16/20] commit --- .../corejava/WaitNotifyMechanism.java | 66 +++++++++++++++++++ .../producer_consumer/ConsumerThread.java | 17 +++++ .../producer_consumer/ProducerThread.java | 18 +++++ .../task2/producer_consumer/ThreadRunner.java | 38 +++++++++++ 4 files changed, 139 insertions(+) create mode 100644 week6/1-Multithreading/Core_Java_2_week6/src/com/hackbulgaria/corejava/WaitNotifyMechanism.java create mode 100644 week6/1-Multithreading/Core_Java_2_week6/src/week6/task2/producer_consumer/ConsumerThread.java create mode 100644 week6/1-Multithreading/Core_Java_2_week6/src/week6/task2/producer_consumer/ProducerThread.java create mode 100644 week6/1-Multithreading/Core_Java_2_week6/src/week6/task2/producer_consumer/ThreadRunner.java diff --git a/week6/1-Multithreading/Core_Java_2_week6/src/com/hackbulgaria/corejava/WaitNotifyMechanism.java b/week6/1-Multithreading/Core_Java_2_week6/src/com/hackbulgaria/corejava/WaitNotifyMechanism.java new file mode 100644 index 0000000..95eacc6 --- /dev/null +++ b/week6/1-Multithreading/Core_Java_2_week6/src/com/hackbulgaria/corejava/WaitNotifyMechanism.java @@ -0,0 +1,66 @@ +package com.hackbulgaria.corejava; + +public class WaitNotifyMechanism { + public static long startTime = System.currentTimeMillis(); + public static Integer counter = 0; + public static final Object monitor = new Object(); + private static int turn = 0; + + public static void increment() { + System.out.println("Incrementing from Thread : " + Thread.currentThread().getName() + " " + counter ); + counter++; + } + + public static void main(String[] args) throws InterruptedException { + Thread t1 = new Thread() { + public void run() { + for (int i = 0; i < 2_000_000; i++) { + synchronized (monitor) { + while (turn != 1) { + try { + monitor.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + increment(); + + turn = (turn + 1) % 2; + monitor.notify(); + } + + } + } + }; + Thread t2 = new Thread() { + + public void run() { + for (int i = 0; i < 2_000_000; i++) { + synchronized (monitor) { + while (turn != 0) { + try { + monitor.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + increment(); + + turn = (turn + 1) % 2; + monitor.notify(); + } + } + } + }; + t1.setName("T1"); + t2.setName("T2"); + t1.start(); + t2.start(); + t1.join(); + t2.join(); + System.out.println(counter); + System.out.println(System.currentTimeMillis() - startTime); + } +} diff --git a/week6/1-Multithreading/Core_Java_2_week6/src/week6/task2/producer_consumer/ConsumerThread.java b/week6/1-Multithreading/Core_Java_2_week6/src/week6/task2/producer_consumer/ConsumerThread.java new file mode 100644 index 0000000..bc0a660 --- /dev/null +++ b/week6/1-Multithreading/Core_Java_2_week6/src/week6/task2/producer_consumer/ConsumerThread.java @@ -0,0 +1,17 @@ +package week6.task2.producer_consumer; + + +public class ConsumerThread implements Runnable { + private MyBlockingQueue queue; + + public ConsumerThread(MyBlockingQueue queue) { + this.queue = queue; + } + + @Override + public void run() { + while (queue.size() > 0) { + queue.poll(); + } + } +} diff --git a/week6/1-Multithreading/Core_Java_2_week6/src/week6/task2/producer_consumer/ProducerThread.java b/week6/1-Multithreading/Core_Java_2_week6/src/week6/task2/producer_consumer/ProducerThread.java new file mode 100644 index 0000000..72927dc --- /dev/null +++ b/week6/1-Multithreading/Core_Java_2_week6/src/week6/task2/producer_consumer/ProducerThread.java @@ -0,0 +1,18 @@ +package week6.task2.producer_consumer; + +public class ProducerThread implements Runnable { + + private MyBlockingQueue queue; + public ProducerThread(MyBlockingQueue queue) { + this.queue = queue; + + } + + @Override + public void run() { + for (int i = 1; i < 1001; i++) { + queue.add(Thread.currentThread().getName() + ": " + i + " - " + System.nanoTime() + % 1_000_000); + } + } +} diff --git a/week6/1-Multithreading/Core_Java_2_week6/src/week6/task2/producer_consumer/ThreadRunner.java b/week6/1-Multithreading/Core_Java_2_week6/src/week6/task2/producer_consumer/ThreadRunner.java new file mode 100644 index 0000000..3810328 --- /dev/null +++ b/week6/1-Multithreading/Core_Java_2_week6/src/week6/task2/producer_consumer/ThreadRunner.java @@ -0,0 +1,38 @@ +package week6.task2.producer_consumer; + +public class ThreadRunner { + public static void main(String[] args) throws InterruptedException { + MyBlockingQueue queue = new MyBlockingQueue<>(100); + + ProducerThread p1 = new ProducerThread(queue); + ProducerThread p2 = new ProducerThread(queue); + ProducerThread p3 = new ProducerThread(queue); + + ConsumerThread c1 = new ConsumerThread(queue); + ConsumerThread c2 = new ConsumerThread(queue); + + Thread t1 = new Thread(p1); + t1.setName("producer 1"); + Thread t2 = new Thread(p2); + t2.setName("producer 2"); + Thread t3 = new Thread(p3); + t3.setName("producer 3"); + + Thread t4 = new Thread(c1); + t4.setName("consumer 1"); + Thread t5 = new Thread(c2); + t5.setName("consumer 2"); + + t1.start(); + t2.start(); + t3.start(); + t4.start(); + t5.start(); +// t1.join(); +// t2.join(); +// t3.join(); +// t4.join(); +// t5.join(); + + } +} From 05c7b8dd70f238cd048c316d6efdcf558a3f98cb Mon Sep 17 00:00:00 2001 From: Nasko Date: Fri, 22 May 2015 15:57:01 +0300 Subject: [PATCH 17/20] Modify gitignore with IntelliJ Idea specific folder --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index d33629a..c422136 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,11 @@ .mtj.tmp/ # Package Files # +*.jar *.war *.ear # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +*.idea/ From 9bffc5d2c8dcd7e88ea982fa2f65258395f2b0c5 Mon Sep 17 00:00:00 2001 From: Nasko Date: Fri, 22 May 2015 16:01:13 +0300 Subject: [PATCH 18/20] Strategy pattern problem --- .../OrderTaxProblem/src/Customer.java | 4 +++ .../interviews/OrderTaxProblem/src/Order.java | 27 +++++++++++++++++++ .../OrderTaxProblem/src/OrderItem.java | 6 +++++ .../OrderTaxProblem/src/Problem.java | 17 ++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 week8/interviews/OrderTaxProblem/src/Customer.java create mode 100644 week8/interviews/OrderTaxProblem/src/Order.java create mode 100644 week8/interviews/OrderTaxProblem/src/OrderItem.java create mode 100644 week8/interviews/OrderTaxProblem/src/Problem.java diff --git a/week8/interviews/OrderTaxProblem/src/Customer.java b/week8/interviews/OrderTaxProblem/src/Customer.java new file mode 100644 index 0000000..ad99d57 --- /dev/null +++ b/week8/interviews/OrderTaxProblem/src/Customer.java @@ -0,0 +1,4 @@ +public class Customer +{ + public String StateCode; +} diff --git a/week8/interviews/OrderTaxProblem/src/Order.java b/week8/interviews/OrderTaxProblem/src/Order.java new file mode 100644 index 0000000..6b8b8cf --- /dev/null +++ b/week8/interviews/OrderTaxProblem/src/Order.java @@ -0,0 +1,27 @@ +import java.util.LinkedList; +import java.util.List; + +public class Order +{ + public List orderItems = new LinkedList(); + public double CalculateTotal(Customer customer) + { + double total = 0; + for (OrderItem item : orderItems){ + total += item.Cost*item.Quantity; + }; + + double tax; + if (customer.StateCode == "BUL") + tax = total * .2; + else if (customer.StateCode == "GER") + tax = total * .3; + else + tax = .1; + + total = total + tax; + return total; + } + + +} \ No newline at end of file diff --git a/week8/interviews/OrderTaxProblem/src/OrderItem.java b/week8/interviews/OrderTaxProblem/src/OrderItem.java new file mode 100644 index 0000000..0ad8ef9 --- /dev/null +++ b/week8/interviews/OrderTaxProblem/src/OrderItem.java @@ -0,0 +1,6 @@ +public class OrderItem +{ + public int Quantity; + public double Cost; +} + diff --git a/week8/interviews/OrderTaxProblem/src/Problem.java b/week8/interviews/OrderTaxProblem/src/Problem.java new file mode 100644 index 0000000..5695ac7 --- /dev/null +++ b/week8/interviews/OrderTaxProblem/src/Problem.java @@ -0,0 +1,17 @@ +import java.util.LinkedList; + +public class Problem { + public static void main(String[] args) { + Customer bgCustomer = new Customer(); + bgCustomer.StateCode="BUL"; + + OrderItem item1 = new OrderItem(); + item1.Cost = 100; + item1.Quantity = 10; + + Order order = new Order(); + order.orderItems = new LinkedList(); + order.orderItems.add(item1); + System.out.println(order.CalculateTotal(bgCustomer)); + } +} From fde4a29981cce42ecdb884cdba7b69f9eb94dde6 Mon Sep 17 00:00:00 2001 From: Nasko Date: Fri, 22 May 2015 16:03:46 +0300 Subject: [PATCH 19/20] Added project specific Idea file to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c422136..0979f5d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ hs_err_pid* *.idea/ +*.iml From 6c0d2696c05fd22a839a13bd36384b9287b9dc00 Mon Sep 17 00:00:00 2001 From: Atanas Boikliev Date: Fri, 22 May 2015 16:05:33 +0300 Subject: [PATCH 20/20] IntelliJ specific files ignored --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0979f5d..a22fcf3 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,6 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +# IntelliJ specific files # *.idea/ *.iml