Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update prereadings #7

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
.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*

# IntelliJ specific files #
*.idea/
*.iml
50 changes: 49 additions & 1 deletion week1/2-OOP/prereading.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,80 @@
*On OOP in General*
https://www.youtube.com/watch?v=lbXsrHGhBAU
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? 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/
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*
9 changes: 9 additions & 0 deletions week2/1-CollectionsAndGenerics1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -78,6 +79,8 @@ Lets say you have a `List<Student>`, 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:

Expand Down Expand Up @@ -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<? extends Object, ? extends Object>`
and *returns a String*, representing the HashMap.
Expand Down Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions week2/1-CollectionsAndGenerics1/prereading.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,58 @@
*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*

*Additional reading*
http://javarevisited.blogspot.com/2013/10/what-is-priorityqueue-data-structure-java-example-tutorial.html
16 changes: 16 additions & 0 deletions week2/2-Exceptions/prereading.md
Original file line number Diff line number Diff line change
@@ -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/

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package week6.task2.producer_consumer;


public class ConsumerThread implements Runnable {
private MyBlockingQueue<String> queue;

public ConsumerThread(MyBlockingQueue<String> queue) {
this.queue = queue;
}

@Override
public void run() {
while (queue.size() > 0) {
queue.poll();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package week6.task2.producer_consumer;

public class ProducerThread implements Runnable {

private MyBlockingQueue<String> queue;
public ProducerThread(MyBlockingQueue<String> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package week6.task2.producer_consumer;

public class ThreadRunner {
public static void main(String[] args) throws InterruptedException {
MyBlockingQueue<String> 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();

}
}
4 changes: 4 additions & 0 deletions week8/interviews/OrderTaxProblem/src/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public class Customer
{
public String StateCode;
}
27 changes: 27 additions & 0 deletions week8/interviews/OrderTaxProblem/src/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.LinkedList;
import java.util.List;

public class Order
{
public List<OrderItem> orderItems = new LinkedList<OrderItem>();
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;
}


}
Loading