├── .gitignore
├── 12-SmallProject
├── ref
│ ├── 2048
│ │ ├── a
│ │ ├── src
│ │ │ └── com
│ │ │ │ └── hackbulgaria
│ │ │ │ └── corejava
│ │ │ │ └── game2048
│ │ │ │ ├── Random.java
│ │ │ │ ├── Main.java
│ │ │ │ ├── GlobalRandom.java
│ │ │ │ ├── ConsoleVisualizer.java
│ │ │ │ └── GameBoard.java
│ │ ├── .gitignore
│ │ ├── .classpath
│ │ ├── README.md
│ │ ├── build.xml
│ │ ├── .project
│ │ ├── .externalToolBuilders
│ │ │ └── New_Builder.launch
│ │ └── LICENSE
│ └── ConsoleTicTacToe
│ │ ├── src
│ │ └── com
│ │ │ └── hackbulgaria
│ │ │ └── corejava
│ │ │ └── tictactoe
│ │ │ ├── GameState.java
│ │ │ ├── UserInputFetcher.java
│ │ │ ├── UserInput.java
│ │ │ ├── ConsoleVisualizer.java
│ │ │ ├── Main.java
│ │ │ ├── ConsoleInputFetcher.java
│ │ │ └── GameBoard.java
│ │ ├── bin
│ │ └── com
│ │ │ └── hackbulgaria
│ │ │ └── corejava
│ │ │ └── tictactoe
│ │ │ ├── Main.class
│ │ │ ├── GameBoard.class
│ │ │ ├── GameState.class
│ │ │ ├── UserInput.class
│ │ │ ├── UserInputFetcher.class
│ │ │ ├── ConsoleVisualizer.class
│ │ │ ├── ConsoleInputFetcher.class
│ │ │ └── UserInput$InputType.class
│ │ ├── .classpath
│ │ ├── .project
│ │ └── .settings
│ │ └── org.eclipse.jdt.core.prefs
└── problems.md
├── 18-ThreadsParallel
├── WebCrawler
│ ├── .attach_pid5957
│ ├── bin
│ │ ├── Main.class
│ │ ├── WebCrawler.class
│ │ ├── RESTConsumer$1.class
│ │ └── RESTConsumer.class
│ ├── .settings
│ │ ├── org.eclipse.m2e.core.prefs
│ │ └── org.eclipse.jdt.core.prefs
│ ├── target
│ │ └── classes
│ │ │ ├── META-INF
│ │ │ ├── MANIFEST.MF
│ │ │ └── maven
│ │ │ │ └── URLvsURI
│ │ │ │ └── URLvsURI
│ │ │ │ ├── pom.properties
│ │ │ │ └── pom.xml
│ │ │ └── com
│ │ │ └── hackbulgaria
│ │ │ └── corejava
│ │ │ ├── Main.class
│ │ │ └── WebCrawler.class
│ ├── src
│ │ └── com
│ │ │ └── hackbulgaria
│ │ │ └── corejava
│ │ │ ├── Main.java
│ │ │ └── WebCrawler.java
│ ├── .project
│ ├── .classpath
│ └── pom.xml
├── materials.md
└── problems.md
├── 02-DebuggingFun
├── DebuggingFun
│ ├── bin
│ │ └── .gitignore
│ ├── libs
│ │ └── commons-io-2.4.jar
│ ├── src
│ │ └── com
│ │ │ └── hackbulgaria
│ │ │ └── corejava
│ │ │ ├── FaultyProblem1.java
│ │ │ ├── FaultyProblem2.java
│ │ │ ├── FaultyProblem6.java
│ │ │ ├── FaultyProblem5.java
│ │ │ ├── FaultyProblem3.java
│ │ │ ├── FaultyProblem7.java
│ │ │ ├── FaultyProblem4.java
│ │ │ └── Utils.java
│ ├── .project
│ ├── test
│ │ └── com
│ │ │ └── hackbulgaria
│ │ │ └── corejava
│ │ │ ├── FaultyProblem5Test.java
│ │ │ ├── FaultyProblem6Test.java
│ │ │ ├── FaultyProblem3Test.java
│ │ │ ├── FaultyProblem7Test.java
│ │ │ ├── FaultyProblem2Test.java
│ │ │ ├── FaultyProblem1Test.java
│ │ │ └── FaultyProblem4Test.java
│ ├── .classpath
│ └── .settings
│ │ └── org.eclipse.jdt.core.prefs
├── agenda2.md
├── pre2.md
└── problems2.md
├── 11-OOP2
├── references
│ └── ConsoleTicTacToe
│ │ ├── .gitignore
│ │ └── .project
├── materials.md
└── problems.md
├── 07-Files1
├── testData.zip
├── pre.md
└── problems.md
├── 15-Networking3
├── jdom-1.1.3.zip
├── rome-1.0.jar
├── materials.md
└── problems.md
├── 17-JavaTooling
├── links.md
└── problems.md
├── Extra-JDBCvsORM
└── Java_database_presentation.1.ppt
├── 10-StructuredData
├── testData
│ └── links.md
├── materials.md
├── pre.md
└── problems.md
├── 01-TypesArraysStrings
├── Project1
│ ├── bin
│ │ └── com
│ │ │ └── hackbulgaria
│ │ │ └── corejava
│ │ │ ├── Problems2.class
│ │ │ ├── Problems2Impl.class
│ │ │ ├── Problems2Factory.class
│ │ │ └── tests
│ │ │ └── Problems2Tests.class
│ ├── src
│ │ └── com
│ │ │ └── hackbulgaria
│ │ │ └── corejava
│ │ │ ├── Problems2Factory.java
│ │ │ ├── Problems2.java
│ │ │ └── Problems2Impl.java
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ │ └── org.eclipse.jdt.core.prefs
│ └── test
│ │ └── com
│ │ └── hackbulgaria
│ │ └── corejava
│ │ └── tests
│ │ └── Problems2Tests.java
├── agenda1.md
├── pre1.md
└── problems1.md
├── 19-ThreadsConcurrent
├── WaitNotifyMechanism
│ ├── bin
│ │ └── com
│ │ │ └── hackbulgaria
│ │ │ └── corejava
│ │ │ ├── WaitNotifyMechanism.class
│ │ │ ├── WaitNotifyMechanism$1.class
│ │ │ └── WaitNotifyMechanism$2.class
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ │ └── org.eclipse.jdt.core.prefs
│ └── src
│ │ └── com
│ │ └── hackbulgaria
│ │ └── corejava
│ │ └── WaitNotifyMechanism.java
└── problems.md
├── 13-Networking1
├── materials.md
└── problems.md
├── 14-Networking2
├── materials.md
└── problems.md
├── 16-Generics2
├── materials.md
└── problems.md
├── attachSources.md
├── 03-OOP1
├── agenda3.md
├── pre3.md
└── problems3.md
├── 05-Exceptions
├── pre5.md
└── problems5.md
├── 06-Exam1
├── solution
│ ├── Main.java
│ ├── DateLogger.java
│ ├── ListUtils.java
│ └── Logger.java
└── tasks.md
├── courseProgress.md
├── 04-CollectionsAndGenerics1
├── pre4.md
└── problems4.md
├── 00-JavaPlatformIntroduction
├── agenda0.md
└── problems0.md
├── README.md
├── 000-StartHere
└── start-here.md
├── 08-WorkingWithLibraries
└── problems.md
└── 20-Exam2
└── problems.md
/.gitignore:
--------------------------------------------------------------------------------
1 | *.*~
2 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/2048/a:
--------------------------------------------------------------------------------
1 | babababaa
2 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/.attach_pid5957:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/bin/.gitignore:
--------------------------------------------------------------------------------
1 | /com
2 |
--------------------------------------------------------------------------------
/11-OOP2/references/ConsoleTicTacToe/.gitignore:
--------------------------------------------------------------------------------
1 | /bin
2 |
--------------------------------------------------------------------------------
/07-Files1/testData.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/07-Files1/testData.zip
--------------------------------------------------------------------------------
/15-Networking3/jdom-1.1.3.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/15-Networking3/jdom-1.1.3.zip
--------------------------------------------------------------------------------
/15-Networking3/rome-1.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/15-Networking3/rome-1.0.jar
--------------------------------------------------------------------------------
/17-JavaTooling/links.md:
--------------------------------------------------------------------------------
1 | *mvn site*
2 | https://www.youtube.com/watch?feature=player_detailpage&v=ZnPkpwrj2E8#t=341
3 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/bin/Main.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/18-ThreadsParallel/WebCrawler/bin/Main.class
--------------------------------------------------------------------------------
/Extra-JDBCvsORM/Java_database_presentation.1.ppt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/Extra-JDBCvsORM/Java_database_presentation.1.ppt
--------------------------------------------------------------------------------
/10-StructuredData/testData/links.md:
--------------------------------------------------------------------------------
1 | *Latest stub articles from wikipedia*
2 | http://dumps.wikimedia.org/metawiki/latest/metawiki-latest-stub-articles.xml.gz
3 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/bin/WebCrawler.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/18-ThreadsParallel/WebCrawler/bin/WebCrawler.class
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/libs/commons-io-2.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/02-DebuggingFun/DebuggingFun/libs/commons-io-2.4.jar
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/bin/RESTConsumer$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/18-ThreadsParallel/WebCrawler/bin/RESTConsumer$1.class
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/bin/RESTConsumer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/18-ThreadsParallel/WebCrawler/bin/RESTConsumer.class
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/target/classes/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Built-By: georgi
3 | Build-Jdk: 1.7.0_55
4 | Created-By: Maven Integration for Eclipse
5 |
6 |
--------------------------------------------------------------------------------
/01-TypesArraysStrings/Project1/bin/com/hackbulgaria/corejava/Problems2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/01-TypesArraysStrings/Project1/bin/com/hackbulgaria/corejava/Problems2.class
--------------------------------------------------------------------------------
/12-SmallProject/ref/2048/src/com/hackbulgaria/corejava/game2048/Random.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava.game2048;
2 | public interface Random {
3 | int nextInt(int n);
4 | boolean nextBoolean();
5 | }
6 |
--------------------------------------------------------------------------------
/01-TypesArraysStrings/Project1/bin/com/hackbulgaria/corejava/Problems2Impl.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/01-TypesArraysStrings/Project1/bin/com/hackbulgaria/corejava/Problems2Impl.class
--------------------------------------------------------------------------------
/02-DebuggingFun/agenda2.md:
--------------------------------------------------------------------------------
1 | - A little recap on our previous meetings
2 | - How to debug in Eclipse
3 | - Debugging problems
4 | - Finish all String problems
5 | - Declaring (static) methods
6 | - Introduction to JUnit
7 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/target/classes/com/hackbulgaria/corejava/Main.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/18-ThreadsParallel/WebCrawler/target/classes/com/hackbulgaria/corejava/Main.class
--------------------------------------------------------------------------------
/01-TypesArraysStrings/Project1/bin/com/hackbulgaria/corejava/Problems2Factory.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/01-TypesArraysStrings/Project1/bin/com/hackbulgaria/corejava/Problems2Factory.class
--------------------------------------------------------------------------------
/02-DebuggingFun/pre2.md:
--------------------------------------------------------------------------------
1 | *On Enums in Java*
2 | http://javarevisited.blogspot.com/2011/08/enum-in-java-example-tutorial.html
3 |
4 | *A video for Junit and Eclipse*
5 | http://www.intertech.com/Blog/express-junit-training-video/
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/src/com/hackbulgaria/corejava/tictactoe/GameState.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava.tictactoe;
2 |
3 | public enum GameState {
4 | PLAYING, PLAYER_1_WON, PLAYER_2_WON, DRAW
5 | }
6 |
--------------------------------------------------------------------------------
/01-TypesArraysStrings/Project1/bin/com/hackbulgaria/corejava/tests/Problems2Tests.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/01-TypesArraysStrings/Project1/bin/com/hackbulgaria/corejava/tests/Problems2Tests.class
--------------------------------------------------------------------------------
/10-StructuredData/materials.md:
--------------------------------------------------------------------------------
1 | JAXB and annotations
2 | http://www.vogella.com/tutorials/JAXB/article.html
3 |
4 | Jettison/JAXB integration
5 | http://blog.bdoughan.com/2011/04/jaxb-and-json-via-jettison-namespace.html
6 |
7 |
8 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/Main.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/Main.class
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/target/classes/com/hackbulgaria/corejava/WebCrawler.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/18-ThreadsParallel/WebCrawler/target/classes/com/hackbulgaria/corejava/WebCrawler.class
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/src/com/hackbulgaria/corejava/tictactoe/UserInputFetcher.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava.tictactoe;
2 |
3 |
4 | public interface UserInputFetcher {
5 | public UserInput fetchUserInput();
6 | }
7 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/GameBoard.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/GameBoard.class
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/GameState.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/GameState.class
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/UserInput.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/UserInput.class
--------------------------------------------------------------------------------
/19-ThreadsConcurrent/WaitNotifyMechanism/bin/com/hackbulgaria/corejava/WaitNotifyMechanism.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/19-ThreadsConcurrent/WaitNotifyMechanism/bin/com/hackbulgaria/corejava/WaitNotifyMechanism.class
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/UserInputFetcher.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/UserInputFetcher.class
--------------------------------------------------------------------------------
/19-ThreadsConcurrent/WaitNotifyMechanism/bin/com/hackbulgaria/corejava/WaitNotifyMechanism$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/19-ThreadsConcurrent/WaitNotifyMechanism/bin/com/hackbulgaria/corejava/WaitNotifyMechanism$1.class
--------------------------------------------------------------------------------
/19-ThreadsConcurrent/WaitNotifyMechanism/bin/com/hackbulgaria/corejava/WaitNotifyMechanism$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/19-ThreadsConcurrent/WaitNotifyMechanism/bin/com/hackbulgaria/corejava/WaitNotifyMechanism$2.class
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/ConsoleVisualizer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/ConsoleVisualizer.class
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/ConsoleInputFetcher.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/ConsoleInputFetcher.class
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/UserInput$InputType.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackBulgaria/Core-Java-1/HEAD/12-SmallProject/ref/ConsoleTicTacToe/bin/com/hackbulgaria/corejava/tictactoe/UserInput$InputType.class
--------------------------------------------------------------------------------
/15-Networking3/materials.md:
--------------------------------------------------------------------------------
1 | *What is a servlet according to Oracle*
2 | http://docs.oracle.com/javaee/5/tutorial/doc/bnafe.html
3 |
4 | *And now read a normal answer from stack overflow*
5 | http://stackoverflow.com/questions/7213541/what-is-java-servlet
6 |
7 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/2048/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # Package Files #
7 | *.jar
8 | *.war
9 | *.ear
10 |
11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12 | hs_err_pid*
13 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/2048/src/com/hackbulgaria/corejava/game2048/Main.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava.game2048;
2 |
3 | public class Main {
4 | public static void main(String[] args) {
5 | ConsoleVisualizer visualizer = new ConsoleVisualizer(new GameBoard());
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/01-TypesArraysStrings/agenda1.md:
--------------------------------------------------------------------------------
1 |
2 | ### Agenda #2 ###
3 | -Welcome to Eclipse
4 | -Coding style format import
5 | -Import Preferences and Quick Keys setup (Refactor Menu, Create getter, setter)
6 | -Hello world from Eclipse
7 | -Packages,Eclipse Views
8 | -Primitive types, arrays
9 | -if/for/while, switch
10 |
--------------------------------------------------------------------------------
/13-Networking1/materials.md:
--------------------------------------------------------------------------------
1 | *InetAddress class in java*
2 | http://www.codeproject.com/Tips/553321/InetAddress-Java-Class
3 |
4 | *Working with urls*
5 | http://docs.oracle.com/javase/tutorial/networking/urls/index.html
6 |
7 | *All abouts sockets*
8 | http://docs.oracle.com/javase/tutorial/networking/sockets/
9 |
--------------------------------------------------------------------------------
/14-Networking2/materials.md:
--------------------------------------------------------------------------------
1 | *URL vs URI*
2 | http://stackoverflow.com/questions/176264/whats-the-difference-between-a-uri-and-a-url
3 |
4 | *Reading directly from a URL*
5 | http://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html
6 |
7 | *Apache HTTP Client*
8 | http://hc.apache.org/httpclient-3.x/tutorial.html
9 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/target/classes/META-INF/maven/URLvsURI/URLvsURI/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven Integration for Eclipse
2 | #Wed Jul 30 19:32:34 EEST 2014
3 | version=0.0.1-SNAPSHOT
4 | groupId=URLvsURI
5 | m2e.projectName=WebCrawler
6 | m2e.projectLocation=/home/georgi/Dev/workspace/WebCrawler
7 | artifactId=URLvsURI
8 |
--------------------------------------------------------------------------------
/16-Generics2/materials.md:
--------------------------------------------------------------------------------
1 | **Oracle's trail and example on generics**
2 | http://docs.oracle.com/javase/tutorial/java/generics/index.html
3 |
4 | **Oracle's trail on annotations**
5 | http://docs.oracle.com/javase/tutorial/java/annotations/index.html
6 |
7 | **MKYoung custom annotation tutorial**
8 | http://www.mkyong.com/java/java-custom-annotations-example/
9 |
--------------------------------------------------------------------------------
/19-ThreadsConcurrent/WaitNotifyMechanism/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/src/com/hackbulgaria/corejava/FaultyProblem1.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | public class FaultyProblem1 {
4 | public long getLargestPalindrome(long N) {
5 | N--;
6 | if (Utils.isPalindrome(N)) {
7 | return N;
8 | } else {
9 | return getLargestPalindrome(N-1);
10 | }
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/2048/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/src/com/hackbulgaria/corejava/FaultyProblem2.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | public class FaultyProblem2 {
4 |
5 | public int getNearestPowerOf2(int x) {
6 | int i = 1;
7 | while (x != 1) {
8 | x /= 2;
9 | i++;
10 | }
11 |
12 | return (int) Math.pow(2, i);
13 | }
14 |
15 |
16 |
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/attachSources.md:
--------------------------------------------------------------------------------
1 | ###Attaching JDK 7 sources to Eclipse###
2 |
3 | 1. First, download the sources zip from
4 | http://www.java.net/download/openjdk/jdk7/promoted/b147/openjdk-7-fcs-src-b147-27_jun_2011.zip
5 |
6 | 2. Window -> Prefernces -> Java -> Installed JRES.
7 | Select your active one and click 'Edit'
8 | Then choose 'rt.jar' from the list below.
9 | Click on 'Source Attachment'.
10 | Point Eclipse to your .zip file
11 |
--------------------------------------------------------------------------------
/10-StructuredData/pre.md:
--------------------------------------------------------------------------------
1 | What is XML? The tutorial at W3Schools:
2 | http://www.w3schools.com/xml/default.asp
3 |
4 | What is JSON? The tutorial at W3Schools:
5 | http://www.w3schools.com/json/
6 |
7 | Comparison between the two:
8 | http://stackoverflow.com/questions/2636245/choosing-between-json-and-xml
9 | http://stackoverflow.com/questions/15154049/xml-vs-json-which-one-is-better-for-storing-small-chunk-of-data
10 |
--------------------------------------------------------------------------------
/11-OOP2/materials.md:
--------------------------------------------------------------------------------
1 | The KISS principle : )
2 | http://en.wikipedia.org/wiki/KISS_principle
3 |
4 | DRY code vs WET code
5 | http://en.wikipedia.org/wiki/Don%27t_repeat_yourself
6 |
7 | SOLID acronym exaplanation
8 | http://en.wikipedia.org/wiki/Solid_%28object-oriented_design%29
9 |
10 | StackOveflow on high cohesion, loose coupling and decoupling
11 | http://stackoverflow.com/questions/3085285/cohesion-coupling
12 |
--------------------------------------------------------------------------------
/03-OOP1/agenda3.md:
--------------------------------------------------------------------------------
1 | - Everything is OOP!
2 | - What is a class? What is an object?
3 | - Method overloading, method overriding, virtual functions?
4 | - State/behaviour
5 | - Data Encapsulation, Subtype polymorphism, Liskov Principle
6 | - Object, equals, hashCode, getClass, toString, wait, notify, notifyAll
7 | - Constructors, on object construction in java, what happens on new()...
8 | - Subtyping (extending class)
9 | - interfaces/abstract classes
--------------------------------------------------------------------------------
/12-SmallProject/ref/2048/README.md:
--------------------------------------------------------------------------------
1 | 2048
2 | ====
3 |
4 | 2048 game implemented in Java, in order to test whether it is good homework @ Core-Java-1 course.
5 | Idea based on http://gabrielecirulli.github.io/2048/
6 |
7 | ### Running the game
8 | Just download the `build/2048.jar` jar file, and run `java -jar `
9 | Left arrow for moving everything to the left
10 | Right arrow for moving everything to the right, etc.
11 |
--------------------------------------------------------------------------------
/03-OOP1/pre3.md:
--------------------------------------------------------------------------------
1 | *On OOP in General*
2 | https://www.youtube.com/watch?v=lbXsrHGhBAU
3 |
4 | *OOP Trail @ Oracle*
5 | http://docs.oracle.com/javase/tutorial/java/concepts/index.html
6 |
7 | *Class and Objects @ Oracle (Those pages are actually Sun's property!)*
8 | http://docs.oracle.com/javase/tutorial/java/javaOO/
9 |
10 | *More on Classes and objects*
11 | http://www.javaworld.com/article/2075202/core-java/object-oriented-language-basics-part-1.html?page=1
--------------------------------------------------------------------------------
/01-TypesArraysStrings/Project1/src/com/hackbulgaria/corejava/Problems2Factory.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | public class Problems2Factory {
4 | String OATH_TOKEN = "THIS IS MY DEAR PASSWORD";
5 |
6 | public static Problems2 createProblems2Instance() {
7 | return new Problems2Impl();
8 | }
9 |
10 | public static void main(String[] args) {
11 | }
12 |
13 | public static void meh(Integer k) {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/05-Exceptions/pre5.md:
--------------------------------------------------------------------------------
1 | *Exceptions hierarch in Java*
2 | http://www.javamex.com/tutorials/exceptions/exceptions_hierarchy.shtml
3 |
4 | *Try/catch/finally example*
5 | http://www.tutorialspoint.com/java/java_exceptions.htm
6 |
7 | *Try with resources in Java 7*
8 | http://www.mkyong.com/java/try-with-resources-example-in-jdk-7/
9 |
10 | *Overriding methods with Exceptions in java*
11 | http://stackoverflow.com/questions/5875414/method-overriding-and-exceptions
12 |
--------------------------------------------------------------------------------
/01-TypesArraysStrings/Project1/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/01-TypesArraysStrings/Project1/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/src/com/hackbulgaria/corejava/FaultyProblem6.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | public class FaultyProblem6 {
4 | public static long pow(int a, int b) {
5 | if (b == 1){
6 | return a;
7 | }
8 | if (b % 2 == 1) {
9 | return a * pow(a, b - 1);
10 | } else {
11 | long power = pow(a, b / 2);
12 | return power * power;
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/2048/src/com/hackbulgaria/corejava/game2048/GlobalRandom.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava.game2048;
2 | public enum GlobalRandom implements Random {
3 | INSTANCE;
4 |
5 | private final java.util.Random random = new java.util.Random(12345);
6 |
7 | @Override
8 | public int nextInt(int n) {
9 | return random.nextInt(n);
10 | }
11 |
12 | @Override
13 | public boolean nextBoolean() {
14 | return random.nextBoolean();
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | DebuggingFun
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/materials.md:
--------------------------------------------------------------------------------
1 | *Oracle's concurency trail*
2 | http://docs.oracle.com/javase/tutorial/essential/concurrency/index.html
3 |
4 | *Multithreading example*
5 | http://www.tutorialspoint.com/java/java_multithreading.htm
6 |
7 | *Lars Vogel's threading tutorial*
8 | http://www.vogella.com/tutorials/JavaConcurrency/article.html#forkjoin
9 |
10 | *Paralel execution with Executor, Future and Completion Service*
11 | http://www.javapractices.com/topic/TopicAction.do?Id=247
12 |
--------------------------------------------------------------------------------
/11-OOP2/references/ConsoleTicTacToe/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | ConsoleTicTacToe
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | ConsoleTicTacToe
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/19-ThreadsConcurrent/WaitNotifyMechanism/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | WaitNotifyMechanism
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/test/com/hackbulgaria/corejava/FaultyProblem5Test.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import org.junit.Test;
6 |
7 | public class FaultyProblem5Test {
8 |
9 | @Test
10 | public void test() {
11 | assertEquals(1, FaultyProblem5.kthFac(0, 1));
12 |
13 | assertEquals(2, FaultyProblem5.kthFac(1, 2));
14 |
15 | assertEquals(720, FaultyProblem5.kthFac(2, 3));
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/src/com/hackbulgaria/corejava/FaultyProblem5.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 |
4 | public class FaultyProblem5 {
5 | public static long kthFac(int k, int n) {
6 | long res = 1;
7 | long limit = n;
8 | for (long i = 2; i <= limit; i++) {
9 | res *= i;
10 | if (i == limit && k > 0) {
11 | k--;
12 | limit = res;
13 | }
14 | }
15 | return res;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/test/com/hackbulgaria/corejava/FaultyProblem6Test.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import org.junit.Test;
6 |
7 | public class FaultyProblem6Test {
8 |
9 | @Test
10 | public void test() {
11 | assertEquals(1, FaultyProblem6.pow(1, 999999999));
12 | assertEquals(8, FaultyProblem6.pow(2, 3));
13 | assertEquals(16, FaultyProblem6.pow(2, 4));
14 | assertEquals(1, FaultyProblem6.pow(4, 0));
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/src/com/hackbulgaria/corejava/FaultyProblem3.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | public class FaultyProblem3 {
4 |
5 | public String reverseEveryWordInString(String sentence){
6 | String[] words = sentence.split(" ");
7 | for (String word: words){
8 | sentence = sentence.replace(word, reverse(word));
9 | }
10 | return sentence;
11 | }
12 |
13 | private CharSequence reverse(String word) {
14 | return Utils.reverseMe(word);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/06-Exam1/solution/Main.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava.exam1;
2 |
3 | public class Main {
4 | public static void main(String[] args) {
5 | Logger logger = new Logger();
6 | logger.log("This should get printed");
7 | logger.log(4, "This should not get printed");
8 |
9 | logger.log(1, "This is very important");
10 |
11 | DateLogger dateLogger = new DateLogger();
12 | dateLogger.log("prints everything, so I get printed");
13 |
14 | dateLogger.setLevel(1);
15 | dateLogger.log(2,"won't get printed");
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/2048/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/src/com/hackbulgaria/corejava/Main.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | import java.io.IOException;
4 | import java.net.URI;
5 | import java.net.URISyntaxException;
6 | import java.util.concurrent.ExecutionException;
7 |
8 | public class Main {
9 | public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException,
10 | ExecutionException {
11 | WebCrawler crawler = new WebCrawler();
12 |
13 | URI startLocation = new URI("http://9gag.com/");
14 | URI result = crawler.crawl(startLocation, "junk");
15 | System.out.println("result :" + result.toString());
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | WebCrawler
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.m2e.core.maven2Nature
21 | org.eclipse.jdt.core.javanature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.7
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.7
12 |
--------------------------------------------------------------------------------
/01-TypesArraysStrings/Project1/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.7
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.7
12 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.7
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.7
12 |
--------------------------------------------------------------------------------
/19-ThreadsConcurrent/WaitNotifyMechanism/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.7
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.7
12 |
--------------------------------------------------------------------------------
/06-Exam1/solution/DateLogger.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava.exam1;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.Date;
5 |
6 | public class DateLogger extends Logger {
7 | private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("hh:mm:ss dd.mm.yyyy");
8 |
9 | public DateLogger() {
10 | this(Integer.MAX_VALUE);
11 | }
12 |
13 | public DateLogger(int logLevel) {
14 | super(logLevel);
15 | }
16 |
17 | @Override
18 | protected void print(int msgLevel, String message) {
19 | String date = DATE_FORMAT.format(new Date());
20 | System.out.print(String.format("|%s| ", date));
21 | super.print(msgLevel, message);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.7
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
12 | org.eclipse.jdt.core.compiler.source=1.7
13 |
--------------------------------------------------------------------------------
/courseProgress.md:
--------------------------------------------------------------------------------
1 | - ~~Java, javac, jar, PATH, classpath, Java's ecosystem~~
2 | - ~~IDE's, Eclipse, Hello World~~
3 | - ~~Linking and using libraries from Eclipse~~
4 | - ~~Debugging (level 1)~~
5 | - Debugging (level 2)
6 | - ~~Working with unit tests~~
7 | - ~~Writing unit tests~~
8 | - ~~OOP (level 1)~~
9 | - ~~OOP (level 2)~~
10 | - OOP (level 3)
11 | - ~~Collections and generics (level 1)~~
12 | - ~~Collections and generics (level 2)~~
13 | - ~~Working with Files~~
14 | - ~~Defensive Programming~~
15 | - ~~Working with XML and JSON~~
16 | - ~~Network Programming~~
17 | - ~~Multithreaded Programming~~
18 | - Working with annotations
19 | - Ant
20 | - ~~Maven~~
21 | - Regular Expressions
22 | - Advanced IDE usages Level 1
23 | - Advanced IDE usages Level 2
24 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/test/com/hackbulgaria/corejava/FaultyProblem3Test.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import org.junit.Before;
6 | import org.junit.Test;
7 |
8 | public class FaultyProblem3Test {
9 |
10 | private FaultyProblem3 faultyProblem3;
11 |
12 | @Before
13 | public void setUp() {
14 | this.faultyProblem3 = new FaultyProblem3();
15 | }
16 |
17 | @Test
18 | public void test() {
19 | assertEquals("gnikrow", faultyProblem3.reverseEveryWordInString("working"));
20 | assertEquals("tahw dluoc", faultyProblem3.reverseEveryWordInString("what could"));
21 | assertEquals("si siht laer efil", faultyProblem3.reverseEveryWordInString("is this real life"));
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/06-Exam1/solution/ListUtils.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava.exam1;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.List;
6 |
7 | public class ListUtils {
8 | public static List reverse(List list) {
9 | ArrayList arrayList = new ArrayList(list);
10 | Collections.reverse(arrayList);
11 | return arrayList;
12 | }
13 |
14 | public static List sort(List list) {
15 | ArrayList arrayList = new ArrayList(list);
16 | Collections.sort(arrayList);
17 | return arrayList;
18 | }
19 |
20 | public static boolean isMonotonic(List list) {
21 | return list.equals(sort(list)) || list.equals(reverse(sort(list)));
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/src/com/hackbulgaria/corejava/tictactoe/UserInput.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava.tictactoe;
2 |
3 | import java.awt.Point;
4 |
5 | public class UserInput {
6 | public enum InputType {
7 | NORMAL, QUIT, UNDO, REDO;
8 | }
9 |
10 | private static final Point INVALID_POINT = new Point(-1, -1);
11 |
12 | private final Point inputPoint;
13 | private final InputType type;
14 |
15 | public UserInput(int x, int y) {
16 | inputPoint = new Point(x, y);
17 | type = InputType.NORMAL;
18 | }
19 |
20 | public UserInput(InputType type) {
21 | inputPoint = INVALID_POINT;
22 | this.type = type;
23 | }
24 |
25 | public Point getPoint() {
26 | return inputPoint;
27 | }
28 |
29 | public InputType getType() {
30 | return this.type;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/test/com/hackbulgaria/corejava/FaultyProblem7Test.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import org.junit.Test;
6 |
7 | public class FaultyProblem7Test {
8 |
9 | @Test
10 | public void test() {
11 | // Code code = new Code("System.out.println(\"Hello World\");");
12 | // Utils.eval(code, "Eval");
13 |
14 | assertEquals(2, FaultyProblem7.binarySearch(3, 1, 2, 3, 4, 5, 6, 7, 8));
15 | assertEquals(7, FaultyProblem7.binarySearch(8, 1, 2, 3, 4, 5, 6, 7, 8));
16 | assertEquals(0, FaultyProblem7.binarySearch(1, 1, 2, 3, 4, 5, 6, 7, 8));
17 | assertEquals(-1, FaultyProblem7.binarySearch(9, 1, 2, 3, 4, 5, 6, 7, 8));
18 |
19 |
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/2048/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 2048
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.ui.externaltools.ExternalToolBuilder
15 | full,incremental,
16 |
17 |
18 | LaunchConfigHandle
19 | <project>/.externalToolBuilders/New_Builder.launch
20 |
21 |
22 |
23 |
24 |
25 | org.eclipse.jdt.core.javanature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/test/com/hackbulgaria/corejava/FaultyProblem2Test.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import org.junit.Before;
6 | import org.junit.Test;
7 |
8 | public class FaultyProblem2Test {
9 |
10 | private FaultyProblem2 faultyProblem2;
11 |
12 | @Before
13 | public void setUp() {
14 | this.faultyProblem2 = new FaultyProblem2();
15 | }
16 |
17 | @Test
18 | public void test() {
19 | assertEquals(128, faultyProblem2.getNearestPowerOf2(129));
20 | assertEquals(128, faultyProblem2.getNearestPowerOf2(240));
21 | assertEquals(2, faultyProblem2.getNearestPowerOf2(2));
22 | assertEquals(16, faultyProblem2.getNearestPowerOf2(20));
23 | assertEquals(1, faultyProblem2.getNearestPowerOf2(1));
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/07-Files1/pre.md:
--------------------------------------------------------------------------------
1 | *Always close streams*
2 | http://www.javapractices.com/topic/TopicAction.do;jsessionid=8DC1E976F93832427DBF51B275870889?Id=8
3 |
4 | *try-with-resources recap*
5 | http://docs.oracle.com/javase/7/docs/technotes/guides/language/try-with-resources.html
6 |
7 | *Buffered reading from File - java*
8 | http://www.mkyong.com/java/how-to-read-file-from-java-bufferedreader-example/
9 |
10 | *Buffered writing in File - java*
11 | http://www.mkyong.com/java/how-to-write-to-file-in-java-bufferedwriter-example/
12 |
13 | *Class/Interface Index in java.io*
14 | http://docs.oracle.com/javase/7/docs/api/java/io/package-tree.html
15 |
16 | *Closeable's hierarchy (not quite, but well, sort of ...) in java*
17 | http://ttp.essex.ac.uk/images/examples/io_closeable/5.png
18 |
19 | *IO trail @ Oracle*
20 | http://docs.oracle.com/javase/tutorial/essential/io/index.html
21 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/test/com/hackbulgaria/corejava/FaultyProblem1Test.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import org.junit.Before;
6 | import org.junit.Test;
7 |
8 | public class FaultyProblem1Test {
9 |
10 | private FaultyProblem1 faultyProgram;
11 |
12 | @Before
13 | public void setUp(){
14 | this.faultyProgram = new FaultyProblem1();
15 | }
16 |
17 | //F5 -> IN!
18 | //F6
19 | // |
20 | // next line
21 | //F7 <-- out
22 |
23 | @Test
24 | public void test() {
25 | assertEquals(1, faultyProgram.getLargestPalindrome(2));
26 | assertEquals(535, faultyProgram.getLargestPalindrome(544));
27 | assertEquals(121, faultyProgram.getLargestPalindrome(126));
28 | assertEquals(898, faultyProgram.getLargestPalindrome(908));
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/src/com/hackbulgaria/corejava/tictactoe/ConsoleVisualizer.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava.tictactoe;
2 |
3 | public class ConsoleVisualizer {
4 |
5 | private final GameBoard gameBoard;
6 |
7 | public ConsoleVisualizer(GameBoard gameBoard) {
8 | this.gameBoard = gameBoard;
9 | }
10 |
11 | public void printGame() {
12 | final StringBuilder board = new StringBuilder();
13 | for (int y = 0; y < GameBoard.BOARD_LENGTH; y++) {
14 | for (int x = 0; x < GameBoard.BOARD_LENGTH; x++) {
15 | if (gameBoard.isOwnedByP1(y, x)) {
16 | board.append("X");
17 | }
18 | if (gameBoard.isOwnedByP2(y, x)) {
19 | board.append("O");
20 | } else if (gameBoard.isEmpty(y, x)) {
21 | board.append(".");
22 | }
23 | }
24 | board.append(System.lineSeparator());
25 | }
26 | System.out.println(board);
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/src/com/hackbulgaria/corejava/FaultyProblem7.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | import java.lang.Thread.State;
4 |
5 | public class FaultyProblem7 {
6 | public static int binarySearch(int element, int... array) {
7 | // Utils.killMeIfIGetStuck();
8 |
9 | int low = 0;
10 | int high = array.length - 1;
11 |
12 | int mid = (low + high) / 2;
13 | while (high - low > 1) {
14 |
15 | if (element == array[mid]) {
16 | return mid;
17 | }
18 | if (element < array[mid]) {
19 | high = mid;
20 | } else {
21 | low = mid;
22 | }
23 | }
24 |
25 | if (array[high] == element)
26 | return high;
27 | if (array[low] == element)
28 | return low;
29 |
30 | return -1; // not found
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/src/com/hackbulgaria/corejava/FaultyProblem4.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | public class FaultyProblem4 {
4 | public static boolean areEqual(Integer e, Integer k) {
5 | k++;
6 | k--;
7 | return e == k;
8 | }
9 |
10 | public static boolean areEqual(float a, float b) {
11 | return a == b;
12 | }
13 |
14 | /**
15 | * Return whether there is an index i,
16 | * such that a[i,a.length] equals b[i, a.length];
17 | * @param a
18 | * @param b
19 | * @return
20 | */
21 | public static boolean haveEqualSubstrings(String a, String b) {
22 | for (int i = 0; i < a.length(); i++) {
23 | String substringA = a.substring(i, a.length() - 1);
24 | String substringB = b.substring(i, a.length() - 1);
25 | if (substringA.equals(substringB)){
26 | return true;
27 | }
28 | }
29 | return false;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/2048/.externalToolBuilders/New_Builder.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/src/com/hackbulgaria/corejava/tictactoe/Main.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava.tictactoe;
2 |
3 | import com.hackbulgaria.corejava.tictactoe.UserInput.InputType;
4 |
5 | public class Main {
6 | public static void main(String[] args) {
7 | UserInputFetcher inputFetcher = new ConsoleInputFetcher();
8 | GameBoard gameBoard = new GameBoard();
9 | ConsoleVisualizer visualizer = new ConsoleVisualizer(gameBoard);
10 |
11 | UserInput input;
12 | do {
13 | visualizer.printGame();
14 | input = inputFetcher.fetchUserInput();
15 | GameState gameState = gameBoard.play(input);
16 | if (gameState != GameState.PLAYING) {
17 | System.out.println(pickMessage(gameState));
18 | return;
19 | }
20 |
21 | } while (input.getType() != InputType.QUIT);
22 | }
23 |
24 | private static String pickMessage(GameState gameState) {
25 | switch (gameState) {
26 | case PLAYER_1_WON:
27 | return "Player 1 won!";
28 | case PLAYER_2_WON:
29 | return "Player 2 won!";
30 | case DRAW:
31 | return "Its a draw!";
32 | default:
33 | return "";
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 | URLvsURI
4 | URLvsURI
5 | 0.0.1-SNAPSHOT
6 |
7 | src
8 |
9 |
10 | maven-compiler-plugin
11 | 3.1
12 |
13 | 1.7
14 | 1.7
15 |
16 |
17 |
18 |
19 |
20 |
21 | commons-io
22 | commons-io
23 | 20030203.000550
24 |
25 |
26 | org.apache.httpcomponents
27 | httpclient
28 | 4.3
29 |
30 |
31 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/target/classes/META-INF/maven/URLvsURI/URLvsURI/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 | URLvsURI
4 | URLvsURI
5 | 0.0.1-SNAPSHOT
6 |
7 | src
8 |
9 |
10 | maven-compiler-plugin
11 | 3.1
12 |
13 | 1.7
14 | 1.7
15 |
16 |
17 |
18 |
19 |
20 |
21 | commons-io
22 | commons-io
23 | 20030203.000550
24 |
25 |
26 | org.apache.httpcomponents
27 | httpclient
28 | 4.3
29 |
30 |
31 |
--------------------------------------------------------------------------------
/04-CollectionsAndGenerics1/pre4.md:
--------------------------------------------------------------------------------
1 | *Simplest use of an ArrayList*
2 | http://www.mkyong.com/java/how-to-loop-arraylist-in-java/
3 |
4 | *Check out some of the public methods of ArrayList*
5 | See its behaviour, what it can and can't do :)
6 | http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html
7 |
8 | *Some examples of the most used collections class in Java: ArrayList*
9 | http://javarevisited.blogspot.com/2011/05/example-of-arraylist-in-java-tutorial.html
10 |
11 | *Difference between Iterator and ListIterator* (if you are unfamiliar with iterators, skip this one for now : )
12 | http://stackoverflow.com/questions/10977992/difference-between-iterator-and-listiterator
13 |
14 | *Diagram of ALL of java's collections framework:*
15 | http://www.codejava.net/java-core/collections/overview-of-java-collections-framework-api-uml-diagram
16 |
17 | ####Part 2####
18 | *A HashMap example*
19 | http://www.tutorialspoint.com/java/java_hashmap_class.htm
20 |
21 | *HashMap vs Hashtable vs TreeMap in Java*
22 | http://www.programcreek.com/2013/03/hashmap-vs-treemap-vs-hashtable-vs-linkedhashmap/
23 |
24 | *Equals and hashcode in java*
25 | http://stackoverflow.com/questions/27581/overriding-equals-and-hashcode-in-java
26 |
27 |
--------------------------------------------------------------------------------
/01-TypesArraysStrings/Project1/src/com/hackbulgaria/corejava/Problems2.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | public interface Problems2 {
4 | boolean isOdd(int number);
5 |
6 | boolean isPrime(int number);
7 |
8 | int min(int... array);
9 |
10 | int kthMin(int k, int[] array);
11 |
12 | float getAverage(int[] array);
13 |
14 | long getSmallestMultiple(int upperBound);
15 |
16 | long getLargestPalindrome(long N);
17 |
18 | int[] histogram(short[][] image);
19 |
20 | long doubleFac(int n);
21 |
22 | long kthFac(int k, int n);
23 |
24 | int getOddOccurrence(int[] array);
25 |
26 | long pow(int a, int b);
27 |
28 | long maximalScalarSum(int[] a, int[] b);
29 |
30 | int maxSpan(int[] array);
31 |
32 | boolean canBalance(int[] array);
33 |
34 | int[][] rescale(int[][] original, int newWidth, int newHeight);
35 |
36 | String reverseMe(String argument);
37 |
38 | String copyEveryChar(String input, int k);
39 |
40 | String reverseEveryWord(String arg);
41 |
42 | boolean isPalindrome(String argument);
43 |
44 | boolean isPalindrome(int number);
45 |
46 | int getPalindromeLength(String input);
47 |
48 | int countOcurrences(String needle, String haystack);
49 |
50 | String decodeURL(String input);
51 |
52 | int sumOfNumbers(String input);
53 |
54 | boolean areAnagrams(String A, String B);
55 |
56 | boolean hasAnagramOf(String string, String string2);
57 | }
58 |
--------------------------------------------------------------------------------
/00-JavaPlatformIntroduction/agenda0.md:
--------------------------------------------------------------------------------
1 | ### Agenda #1 ###
2 | - Представете се
3 | - Малко организационно:
4 | - как ще протече курса: Решаваме неща тук, после ви давам за четене/гледане домашно (материали за следващия път)
5 | - в началото ще преговарям/обобщавам нещата, които съм ви дал
6 | - решаваме още задачи
7 | - Java - a little history
8 | + started as 'Oak' in 1991 => дъб
9 | + Created by Sun
10 | + renamed to 'java', due to large ammounts of coffee the team used in development
11 | + released 1996
12 | + Java
13 | + Compile once, run everywhere
14 | #1 Development Platform
15 | 9 Millions Developers
16 | 1 Billion Java Downloads per Year
17 | 3 Billion devices run Java
18 | 97% of Enterprise Desktops run Java
19 | 100% of BLU-RAY Disc Players ship with Java
20 | http://www.javacodegeeks.com/2014/03/java-facts-to-blow-your-mind.html
21 | Jit Compiler in J2SE (Java 1.2)
22 | - Java, JRE, JVM, JDK
23 | - JSR, JCP
24 | - JSE, J2EE, J2ME
25 | - Sun, Oracle, Google
26 | - Cross-platform, compatibility
27 | - Javac
28 | - classpath
29 |
30 | //what IDE does for us
31 | C:\>javac -sourcepath src -classpath classes;lib\Banners.jar ^
32 | src\farewells\GoodBye.java -d classes
33 | //source and target explanations
34 | C\:>javac -sodurce 1.6 -target 1.6 -bootclasspath C:\jdk1.6.0\lib\rt.jar ^
35 | -extdirs "" OldCode.java
36 |
37 | //bootclasspath option
38 |
39 | - javap
40 | - the javadoc tool
41 | - jar format
42 | - Common VM Arguments
43 |
44 |
45 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/ConsoleTicTacToe/src/com/hackbulgaria/corejava/tictactoe/ConsoleInputFetcher.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava.tictactoe;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStreamReader;
6 | import java.util.InputMismatchException;
7 | import java.util.Scanner;
8 |
9 | import com.hackbulgaria.corejava.tictactoe.UserInput.InputType;
10 |
11 | public class ConsoleInputFetcher implements UserInputFetcher {
12 |
13 | private final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
14 |
15 | @Override
16 | public UserInput fetchUserInput() {
17 | String userInput;
18 | try {
19 | userInput = bufferedReader.readLine();
20 | if (userInput.trim().equals("u")) {
21 | return new UserInput(InputType.UNDO);
22 | } else if (userInput.trim().equals("r")) {
23 | return new UserInput(InputType.REDO);
24 | } else if (userInput.trim().equals("q")) {
25 | return new UserInput(InputType.QUIT);
26 | }
27 |
28 | Scanner scanner = new Scanner(userInput);
29 | int y = scanner.nextInt();
30 | int x = scanner.nextInt();
31 | scanner.close(); // just a good style, but this is not necessary
32 | // here.
33 |
34 | return new UserInput(x, y);
35 | } catch (InputMismatchException badInput) {
36 | badInput.printStackTrace();
37 | return new UserInput(InputType.QUIT);
38 | } catch (IOException e) {
39 | e.printStackTrace();
40 | return new UserInput(InputType.QUIT);
41 | }
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/06-Exam1/solution/Logger.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava.exam1;
2 |
3 | import java.util.logging.Level;
4 |
5 | public class Logger {
6 | private static final int DEFAULT_LOG_LEVEL = 3;
7 | private static final int DEFAULT_MESSAGE_LEVEL = 3;
8 | private int logLevel;
9 |
10 | public Logger() {
11 | this(DEFAULT_LOG_LEVEL);
12 | }
13 |
14 | public Logger(int level) {
15 | setLevel(level);
16 | }
17 | public void setLevel(int level) {
18 |
19 | validateLevel(level);
20 | this.logLevel = level;
21 | }
22 |
23 | public void log(int msgLevel, String message) {
24 | validateLevel(msgLevel);
25 | if (msgLevel <= logLevel) {
26 | print(msgLevel, message);
27 | }
28 | }
29 |
30 | protected void print(int msgLevel, String message) {
31 | System.out.println(msgLevel + " => " + message);
32 | }
33 |
34 | private void validateLevel(int msgLevel) {
35 | if (msgLevel <= 0) {
36 | throw new InvalidLogLevelException(msgLevel);
37 | }
38 | }
39 |
40 | public void log(String message) {
41 | log(DEFAULT_MESSAGE_LEVEL, message);
42 | }
43 |
44 | public static class InvalidLogLevelException extends RuntimeException {
45 | private static final long serialVersionUID = 1L;
46 |
47 | public InvalidLogLevelException(int msgLevel) {
48 | super("Invalid level given! Level should be > 0, given " + msgLevel);
49 | }
50 |
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/02-DebuggingFun/problems2.md:
--------------------------------------------------------------------------------
1 | ###Some debugging fun###
2 | 1) Get latest changes from HackBulgaria repo
3 | `git pull`
4 | or
5 | `git clone https://github.com/HackBulgaria/Core-Java-1.git`
6 |
7 | 2) Import the DebuggingFun project in Eclipse
8 | - if you use 'import existing projects Eclipse it will not copy it in your workspace
9 | - if you use 'import from file system'
10 |
11 |
12 | //The ProjectName for all of the three problems below should be 'TDDIntro'
13 |
14 | ###JUnit Hello world###
15 | Implement a method 'getNumberOfDigits(int)' which just counts the number of digits.
16 |
17 | 1) Write the signature of the method
18 | 2) Write the test, make sure it fails beautifully. Think of some edge cases.
19 | 3) Implement the method
20 | 4) Pass your own test! Woohoo!
21 |
22 |
23 | ###Implement a join method###
24 | Java does not have a String join method. Apache StringUtils does have, but, well, that's not an excuse.
25 |
26 | Make a method that joins strings, with a **glue** given from the caller of your method.
27 |
28 | Can you think of a way for it to work with every object, not just string? Even primitives?
29 |
30 | //Glue is the first argument => " "
31 | `stichMeUp(" ", "Днес", "видях", 5, "ходещи", "медузи") => "Днес видях 5 ходещи медузи"`
32 |
33 | 1) Think of a good name for this method
34 | 2) Make a test class
35 | 3) Make several test cases, see that your tests fail mightily : )
36 | 4) Implement!
37 |
38 | ###Reduce file path! In Java. In a test-driven way. ###
39 | See Problem 27 @ https://github.com/HackBulgaria/Programming101/blob/master/week0/simple_problems2.md
40 |
--------------------------------------------------------------------------------
/19-ThreadsConcurrent/problems.md:
--------------------------------------------------------------------------------
1 | ### A demonstration of a race condition
2 | Create a project 'Threads'.
3 |
4 | Create a static variable `counter`.
5 | Create two threads - A and B.
6 | In their `run()` methods just increment the shared variable 2_000_000 times.
7 |
8 | Start the two threads, join them, and print out `counter`. What happens? Why?
9 | Print out the time needed.
10 |
11 | ##### Introduce critical blocks
12 | Now wrap the incrementing in a synchronized block in each thread. (They should be **synchronized on the same monitor**).
13 | First, wrap the whole `for` statements in a synchronized blocks.
14 |
15 | See the result is now correct, and observe the minor performance penalty.
16 |
17 | Now, move the synochronized block `inside` the `for` statements.
18 | Notice the increased performance penalty.
19 |
20 |
21 | ##### Replace the synchronized blocks with a call to a synchronized method increment()
22 |
23 | ##### Replace the synchronized stuff with an AtomicInteger. Notice the performance penalty!
24 |
25 | ##### Replace the Atomic Integer with wait/notify + mutex variable mechanism
26 | The scenario we want is the following:
27 | - Thread A obtains the mutex (`wait()`s until the mutex is available)
28 | - Works (increments the integer)
29 | - Then calls `notify` on the monitor
30 | - Which fires the Thread B, which does the same
31 |
32 |
33 | ### Implement a simple blocking queue.
34 | A blocking queue is just like a regular queue, with the difference that if someone calls `poll()` and the queue is empty, the call is blocked until somebody adds an element to the queue. After an element is added, the caller (the one who called `poll()`) gets unblocked and the `poll()` call returns.
35 |
--------------------------------------------------------------------------------
/00-JavaPlatformIntroduction/problems0.md:
--------------------------------------------------------------------------------
1 | ### Verify java is working and is in $PATH ###
2 | ```java -version```
3 |
4 | ```javac -version```
5 |
6 | ```javap -version```
7 |
8 | Friendly advice: These should be the same version, or you might have a bad time :)
9 |
10 | ### Compiling fun with javac and java###
11 | - Open a terminal. Navigate to any folder whatsoever. Make a new Empty.java file. Try to compile it with javac. See what happens.
12 | - Make a class named Program. Try to compile it with javac.
13 | - Rename the class to Empty. Compile it.
14 | - Make a main method. Make it print "Hello world!". Compile it and run it.
15 | - Make the main method print its arguments (String[] args). Make the for loop as you would make one in C or C++, and use the System.out.println method for printing to the console.
16 |
17 | ### Getting to know what classpath is###
18 | - Open a terminal, navigate to some folder. Make a new A.java file with a legitimate class A declared in it.
19 | - Do the same for a file/class named B.
20 | - Declare a public method in B.
21 | - In class A, make a *main method*
22 | - Instantiate B in it and call B's public method.
23 | - Try, compile and run A. Does it run? Why? How does it know about B? What about import statements?
24 |
25 | - Now move B up one folder to '..'
26 | - Try compiling and running it.
27 |
28 | - Add -cp ".." to your javac command and try again.
29 |
30 | ###Bundle them both###
31 | - jar -c A.class
32 | - Does this command look familiar to you? : )
33 |
34 | ### Disassembly with javap ###
35 | - Disassemble Empty.class
36 | - Does this look familiar to you? This is what Eclipse is doing when you open a look up a class file with no source attached.
37 |
38 |
39 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/test/com/hackbulgaria/corejava/FaultyProblem4Test.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import org.junit.Test;
6 |
7 | public class FaultyProblem4Test {
8 |
9 | @Test
10 | public void testFloats() {
11 | for (int i = 2; i < 97; i++) {
12 | for (int j = 3; j < i * 17; j++) {
13 | float a = (float) i / j;
14 | float b = 1 / ((float) j / i);
15 | System.out.println(a + ", " + b);
16 | assertTrue(FaultyProblem4.areEqual(a, b));
17 | }
18 | }
19 | }
20 |
21 | @Test
22 | public void testAgainFloats(){
23 | assertTrue(FaultyProblem4.areEqual(0/6, 0/5));
24 | assertTrue(FaultyProblem4.areEqual(401/399, 1/(399/401)));
25 | }
26 |
27 | @Test
28 | public void testInts() {
29 | assertTrue(FaultyProblem4.areEqual(4, 4));
30 | assertTrue(FaultyProblem4.areEqual(0, 0));
31 | assertTrue(FaultyProblem4.areEqual(500, 500));
32 |
33 | // Защо са верни горните, а този тест фейлва? ^^^
34 | assertTrue(FaultyProblem4.areEqual(new Integer(511), (Integer) 511));
35 | }
36 |
37 | @Test
38 | public void testSubstringEquality() throws Exception {
39 | String a = "how do you do";
40 | String b = "how do you do";
41 |
42 | assertTrue(FaultyProblem4.haveEqualSubstrings(a, b));
43 |
44 | a = "Bearded Man";
45 | b = "Non-bearded Man";
46 | assertFalse(FaultyProblem4.haveEqualSubstrings(a, b));
47 |
48 | a = "Speaks";
49 | b = "Freaky";
50 | assertFalse(FaultyProblem4.haveEqualSubstrings(a, b));
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/problems.md:
--------------------------------------------------------------------------------
1 | ### Paralel minimal point calculations
2 |
3 | Create a static method `generatePoints()` which returns a `List` - `java.awt.Point`
4 | Implement it, generating a 100 000 points (in java that is written `100_000`) points with random coordinates - ranging from 0 to 10_000.
5 |
6 | Now, for each of those points, I'd like you to find it's nearest point. Do this in a method `Map getNearestPoints(List generatedPoints)`
7 |
8 | As you can see, it takes a while. By my calculations, it should take like 100-250 seconds to complete (depending on your CPU speed).
9 |
10 | Now introduce some multithreading to speed it up.
11 | Declare and implement a method `doCalculations(List inPoints, int indexFrom, int indexTo, Map outMap)`.
12 | Move your calculations logic from `getNearestPoints` to `doCalculations`, but work strictly from `indexFrom`, to `indexTo`.
13 |
14 | Now in your `getNearestPoints(List generatedPoints)` method, start two Threads that call `doCalculations`, in their run methods, one from 0 to half of the elements, the other from half of the elements to the last of them.
15 |
16 | Measure speedup between the two implementations (See `System.currentTimeMillis()`).
17 |
18 | Introduce a third and forth thread. Does your implementation go faster?
19 |
20 | ### Paralel web crawler
21 |
22 | You remember your webcrawler project, right?
23 | There is a bottleneck in it - while you are waiting for an answer from the server, your CPU does nothing.
24 | Now, if you were to make several requests at once, it would be better.
25 |
26 | Try io crawl 9gag.com, for instance, and print every page you've visited. See the speed is not that great.
27 | Now Introduce parallelisation and speed up in your solution. Use an approach similiar to the approach for task #1.
28 |
29 | If your web crawler project is not working, use the one in this github folder instead. (It's a Maven project, you will need to fetch all dependencies).
30 |
--------------------------------------------------------------------------------
/12-SmallProject/ref/2048/src/com/hackbulgaria/corejava/game2048/ConsoleVisualizer.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava.game2048;
2 |
3 | import java.io.IOException;
4 |
5 | import jline.Terminal;
6 |
7 | import com.hackbulgaria.corejava.game2048.GameBoard.GameResult;
8 | import com.hackbulgaria.corejava.game2048.GameBoard.MoveDirection;
9 |
10 | public class ConsoleVisualizer {
11 | private static final int VIRTUAL_DOWN = 14;
12 | private static final int VIRTUAL_UP = 16;
13 | private static final int VIRTUAL_RIGHT = 6;
14 | private static final int VIRTUAL_LEFT = 2;
15 | private final GameBoard gameBoard;
16 |
17 | public ConsoleVisualizer(GameBoard gameBoard) {
18 | this.gameBoard = gameBoard;
19 |
20 | printBoard();
21 | GameResult result = GameResult.UNDETERMINED;
22 |
23 | while (result == GameResult.UNDETERMINED) {
24 | MoveDirection direction = getPlayerMove();
25 |
26 | if (gameBoard.canMove(direction)) {
27 | result = gameBoard.move(direction);
28 | }
29 | printBoard();
30 | }
31 |
32 | if (result == GameResult.WIN) {
33 | System.out.println("You won!");
34 | } else {
35 | System.out.println("Sorry, you lost :(");
36 | }
37 | }
38 |
39 | private MoveDirection getPlayerMove() {
40 | MoveDirection moveDirection = null;
41 | try {
42 | Terminal terminal = Terminal.setupTerminal();
43 | int c = terminal.readVirtualKey(System.in);
44 | if (c == VIRTUAL_LEFT) {
45 | moveDirection = MoveDirection.MOVE_LEFT;
46 | } else if (c == VIRTUAL_RIGHT) {
47 | moveDirection = MoveDirection.MOVE_RIGHT;
48 | } else if (c == VIRTUAL_UP) {
49 | moveDirection = MoveDirection.MOVE_UP;
50 | } else if (c == VIRTUAL_DOWN) {
51 | moveDirection = MoveDirection.MOVE_DOWN;
52 | }
53 | } catch (IOException e) {
54 | e.printStackTrace();
55 | }
56 | return moveDirection;
57 | }
58 |
59 | private void printBoard() {
60 | for (int y = 0; y < GameBoard.BOARD_SIZE; y++) {
61 | for (int x = 0; x < GameBoard.BOARD_SIZE; x++) {
62 | System.out.print(gameBoard.getValue(y, x) + " ");
63 | }
64 | System.out.println();
65 | }
66 | System.out.println();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Core-Java-1
2 | ===========
3 |
4 | This is the official GitHub repo for Core Java Course in [Hack Bulgaria](http://hackbulgaria.com) - http://hackbulgaria.com/course/Java-1/
5 |
6 | The course launched on May 27-th.
7 | Information about the course can be found at http://hackbulgaria.com/course/Java-1/ (Bulgarian)
8 |
9 | You would likely want to check the start-here/start-here.md for information on the stuff you should do/install prior to course launch : )
10 |
11 | If you have never programmed before, this is a not a course for you. If you want to learn programming the right way, see http://hackbulgaria.com and look for "Programming 101" : )
12 |
13 |
14 | ### About this repo
15 | Every folder in the repo starting with a number contains links/problems/materials about a specific subject/theme/area.
16 | They are usually named named:
17 | - `problems.md` - for the tasks you need to solve
18 | - `pre.md` - for the prereading you should do **beforehand**
19 | - `materials.md` if you'd likely need to use the links/resources *while solving tasks from* `problems.md` .
20 |
21 | ### Outline
22 |
23 | - **Week 0** - Java Platform Introduction, Eclipse/JDK installings and configurations, Types, Arrays, Strings in Java
24 | - **Week 1** - Introduction to debugging, 'Find-the-error-in-the-code-via-debugging' problems, Classes/Overloading/Overriding/OOP
25 | - **Week 2** - Collections and Generics (usage), Defensive Programming/Error Handling and first "feedback-exam"
26 | - **Week 3** - Working with the filesystem, working with foreign code, linking libraries
27 | - **Week 4** - Practical Teamwork - pair programming, working in a team using git/github, working with XML/JSON
28 | - **Week 5** - Working with XML/JSON, a small team project
29 | - **Week 6** - Networking1 - Client/Server socket-based remote execution protocol
30 | - **Week 7** - Networking2 - HTTP, Consuming REST services, downloading stuff, crawling web sites
31 | - **Week 8** - Networking3 - Servlets, Consuming RSS, Generics in Java 2, Deploy-on-app-server-with-maven
32 | - **(Bonus) Week 9** - Multithreading - Parallel Execution, Java concurrency mechanisms, job-interview-like exam
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/19-ThreadsConcurrent/WaitNotifyMechanism/src/com/hackbulgaria/corejava/WaitNotifyMechanism.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | public class WaitNotifyMechanism {
4 | public static long startTime = System.currentTimeMillis();
5 | public static Integer counter = 0;
6 | public static final Object monitor = new Object();
7 | private static int turn = 0;
8 |
9 | public static void increment() {
10 | System.out.println("Incrementing from Thread : " + Thread.currentThread().getName() + " " + counter );
11 | counter++;
12 | }
13 |
14 | public static void main(String[] args) throws InterruptedException {
15 | Thread t1 = new Thread() {
16 | public void run() {
17 | for (int i = 0; i < 2_000_000; i++) {
18 | synchronized (monitor) {
19 | while (turn != 1) {
20 | try {
21 | monitor.wait();
22 | } catch (InterruptedException e) {
23 | e.printStackTrace();
24 | }
25 |
26 | }
27 | increment();
28 |
29 | turn = (turn + 1) % 2;
30 | monitor.notify();
31 | }
32 |
33 | }
34 | }
35 | };
36 | Thread t2 = new Thread() {
37 |
38 | public void run() {
39 | for (int i = 0; i < 2_000_000; i++) {
40 | synchronized (monitor) {
41 | while (turn != 0) {
42 | try {
43 | monitor.wait();
44 | } catch (InterruptedException e) {
45 | e.printStackTrace();
46 | }
47 | }
48 |
49 | increment();
50 |
51 | turn = (turn + 1) % 2;
52 | monitor.notify();
53 | }
54 | }
55 | }
56 | };
57 | t1.setName("T1");
58 | t2.setName("T2");
59 | t1.start();
60 | t2.start();
61 | t1.join();
62 | t2.join();
63 | System.out.println(counter);
64 | System.out.println(System.currentTimeMillis() - startTime);
65 | }
66 | }
--------------------------------------------------------------------------------
/01-TypesArraysStrings/pre1.md:
--------------------------------------------------------------------------------
1 | ###Recap of what we did the last time:###
2 |
3 | The 'git/github'/recap article (if you are not familiar with git/github)
4 | https://github.com/HackBulgaria/Programming101/blob/master/week1/git.md
5 |
6 |
7 | JRE, JDK, JVM (if you still don't know what they are)
8 | http://stackoverflow.com/questions/11547458/what-is-differences-between-jvm-jdk-jre-openjdk
9 |
10 | Path and classpath (if you are having trouble differentiating those two)
11 | http://docs.oracle.com/javase/tutorial/essential/environment/paths.html
12 |
13 | On debugging with Eclipse
14 | https://blog.codecentric.de/en/2013/04/again-10-tips-on-java-debugging-with-eclipse/
15 |
16 | Primitive Data types in Java
17 | http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
18 |
19 | Arrays in Java
20 | http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
21 | http://stackoverflow.com/questions/2267790/how-are-arrays-implemented-in-java
22 | http://docs.oracle.com/javase/specs/jls/se8/html/jls-10.html#jls-10.8
23 |
24 | Some Q&A
25 | http://docs.oracle.com/javase/tutorial/java/nutsandbolts/QandE/questions_variables.html
26 |
27 | Operators
28 | http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html
29 | http://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.html
30 |
31 | On Control flow - if, for, while, do-while, switch
32 | http://docs.oracle.com/javase/tutorial/java/nutsandbolts/flow.html
33 |
34 |
35 |
36 | ###For our second meeting : ) ###
37 |
38 |
39 | Wrapper Classes
40 | http://en.wikipedia.org/wiki/Primitive_wrapper_class
41 |
42 | On autoboxing and unboxing in Java
43 | http://javarevisited.blogspot.com/2012/07/auto-boxing-and-unboxing-in-java-be.html
44 |
45 | On instanceof and isAssignableFrom
46 | http://stackoverflow.com/questions/496928/what-is-the-difference-between-instanceof-and-class-isassignablefrom
47 |
48 | Most important stuff on String
49 | http://javarevisited.blogspot.com/2013/07/java-string-tutorial-and-examples-beginners-programming.html
50 |
51 | StringBuilder vs StringBuffer?
52 | http://javarevisited.blogspot.com/2011/07/string-vs-stringbuffer-vs-stringbuilder.html
53 |
54 | On Unicode (Joel on Software)
55 | http://www.joelonsoftware.com/articles/Unicode.html
56 |
57 | On String interning
58 | http://en.wikipedia.org/wiki/String_interning
59 | http://java-performance.info/string-intern-in-java-6-7-8/
60 |
61 | Introduction to JUnit
62 | http://courses.cs.washington.edu/courses/cse143/11wi/eclipse-tutorial/junit.shtml
--------------------------------------------------------------------------------
/000-StartHere/start-here.md:
--------------------------------------------------------------------------------
1 | ##Start Here!##
2 |
3 | Welcome :)
4 |
5 | Here are a few things you should probably get done before the start of the core java course:
6 |
7 | **1)** Install JDK 7
8 |
9 | *Windows:* use Oracle's JDK from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
10 | or
11 |
12 | *Linux:* use your distribution's jdk-7 package:
13 | (Check http://openjdk.java.net/install/)
14 |
15 | *Mac OS X:* Use the native updater to update Java to a release > 7u25.
16 | 7u25 is disabled by Apple because of severe security issues.
17 |
18 | **2)** Make sure java binaries are registered in PATH
19 | and that they are **the same version**
20 |
21 | ```
22 | java -version
23 |
24 | java version "1.7.0_51"
25 | OpenJDK Runtime Environment (IcedTea 2.4.4) (7u51-2.4.4-0ubuntu0.12.04.2)
26 | OpenJDK Server VM (build 24.45-b08, mixed mode)
27 | ```
28 | ```
29 | javac -version
30 | javac 1.7.0_51
31 | ```
32 |
33 | **3)** Install Eclipse Kepler from Eclipse site:
34 | https://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/keplersr2-with-java8-patches
35 | Do not use your Linux distribution's Eclipse distribution. It would most likely be outdated.
36 |
37 | **4)** Read the Google style-guide for Java source code:
38 | http://google-styleguide.googlecode.com/svn/trunk/javaguide.html
39 |
40 | We will be using very similiar style guide, but with the following modifications:
41 | - 4 spaces for identation instead of 2.
42 | - 120 lines for line-wrapping instead of 80.
43 |
44 | **5)** Import eclipse preferences (the .epf file) in Eclipse
45 | `File->Import->General->Preferences`
46 |
47 | **6)** Import the code formatter (the .xml file) in Eclipse
48 | `Window->Preferences-> Write 'Format' in the search field up left-> Select the one below 'Java' -> Click on Import`
49 |
50 | **7)** Create yourself a GitHub account!
51 | If you have never worked with git or GitHub, see the excellent article from
52 | HackBulgaria's programming 101 course:
53 | https://github.com/HackBulgaria/Programming101/tree/master/week1/git.md
54 |
55 | ##But why aren't we using java 8 VM?##
56 | Because the community is not quite ready:
57 | - Eclipse is not exactly java8 ready: http://www.eclipse.org/downloads/java8/
58 | - Maven and m2eclipse are not java8 ready : https://bugs.eclipse.org/bugs/show_bug.cgi?id=420848
59 | - Ant in Eclipse is not java8 ready: http://wiki.eclipse.org/Ant/Java8
60 | - No deployment packages for OpenJDK 8 for most Linux distributions.
61 |
62 | And so on and so on. You will likely run into quite some problems, as the community is not ready with the tooling, support and guidance. Of course, one can install java 8 vm and take it for a test-drive, but serious development needs tools. And at the present moment, they are in transition. Give it a little time.
--------------------------------------------------------------------------------
/15-Networking3/problems.md:
--------------------------------------------------------------------------------
1 | ### Servlet/HelloWorld
2 | - Create an Http Servlet. Override the `doGet` method, and write 'HelloWorld!' to the response's outputStream.
3 | - Run your application on Eclipse ('Run as Server').
4 | - See your own message at 'localhost:8080/YourAppName/YourServletName'
5 | - Make your servlet respond at 'localhost:8080/YourAppName/' (Edit the @WebServlet annotation path to '/')
6 | - See that your servlet now responds at 'localhost:8080/YourAppName/'
7 | - Now undo your change (restore the @WebServlet annotation path).
8 | - Right click on your project -> Java EE tools -> Generate Deployment descriptor stub.
9 | - - You will now have a 'web.xml' file. It is called a deployment descriptor.
10 | - - Edit the deployment descriptor, and add a first welcome-file tag pointing to 'YourServletName'. We want to register the servlet as a welcome page for your server :)
11 | - Check the 'html source code' returned by your servlet. You will see no HTML tags. Why?
12 | - Write an HTML response to your client. For instance `
Now that's a big title!
`
13 |
14 | Congratulations. You've just witnessed what ASP/JSP/PHP is all about. We are not going to do any of that ~~sh**~~ stuff.
15 |
16 |
17 | ### Simple news agregator
18 | Do you know what an [RSS](http://en.wikipedia.org/wiki/RSS) is?
19 | It is a simple format for describing **content** (just the content, and not it's visualization). It is an XML-based format.
20 |
21 | [This is an RSS](http://www.sportal.bg/uploads/rss_category_2.xml)
22 | Your task is simple - create a service (using just a servlet), that shows the latest news **in bulgarian** in the following categories:
23 | - General/Bulgaria
24 | - Technology
25 | - Sport
26 |
27 | Write the ~~ugliest~~ simplest html output you possibly can.
28 | Something like is completely OK.
29 | 
30 |
31 |
32 | If you don't know HTML, it's okay, just check http://www.w3schools.com/html/html_basic.asp You'll learn a few tricks in no time.
33 |
34 | Hints:
35 | - Pick some RSS feed links from popular news websites. Dnevnik.bg, sportal.bg, etc have RSS feed functionality. Maybe even FMI had one?
36 | - Do not parse the XML yourself. There are libraries for that, use the ones given in this github folder (the ROME library).
37 | - Add both jars in the WEB-INF/lib folder. Don't do anything after that, Eclipse will automatically add them to the project's build path.
38 | - Use this ROME tutorial: http://blog.manishchhabra.com/2011/10/rome-library-example-for-parsing-rss-and-atom-feeds/
39 |
40 |
41 | ### Simple JSON pretty printer service.
42 | Just look at the JSON at http://hackbulgaria.com/api/checkins . It is horrible - completely unreadable. What are the elements? What are the JSON objects? You cannot easily tell.
43 |
44 | - Deploy a servlet, that accepts a named "POST" parameter "json".
45 | - Read the json as a POST parameter given to the request (as a parameter from the `HttpServletRequest` via the `getParameter` method.)
46 | - Use google gson to pretty-print the json given.
47 | - See how to it here: http://stackoverflow.com/questions/4105795/pretty-print-json-in-java
48 |
--------------------------------------------------------------------------------
/18-ThreadsParallel/WebCrawler/src/com/hackbulgaria/corejava/WebCrawler.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | import java.io.IOException;
4 | import java.net.MalformedURLException;
5 | import java.net.URI;
6 | import java.net.URISyntaxException;
7 | import java.util.ArrayList;
8 | import java.util.Collections;
9 | import java.util.HashSet;
10 | import java.util.List;
11 | import java.util.Set;
12 | import java.util.concurrent.ExecutionException;
13 | import java.util.regex.Matcher;
14 | import java.util.regex.Pattern;
15 |
16 | import org.apache.commons.io.IOUtil;
17 | import org.apache.http.HttpResponse;
18 | import org.apache.http.client.HttpClient;
19 | import org.apache.http.client.methods.HttpGet;
20 | import org.apache.http.client.utils.URIUtils;
21 | import org.apache.http.impl.client.DefaultHttpClient;
22 |
23 | public class WebCrawler {
24 | private final Set visitedUrls = Collections.synchronizedSet(new HashSet());
25 |
26 | public URI crawl(URI currentLocation, final String needle) throws URISyntaxException, MalformedURLException,
27 | InterruptedException, ExecutionException {
28 | String urlContents = downloadContents(currentLocation);
29 | visitedUrls.add(currentLocation);
30 |
31 | if (urlContents.contains(needle)) {
32 | return currentLocation;
33 | } else {
34 | for (String link : getAllLinks(urlContents)) {
35 | final URI asUri = normalizeLink(currentLocation, link);
36 | if (!visitedUrls.contains(asUri) && isInsideDomain(currentLocation, asUri)) {
37 | URI result = crawl(asUri, needle);
38 | if (result != null) {
39 | return result;
40 | }
41 | }
42 | }
43 | }
44 | return null;
45 | }
46 |
47 | private static boolean isInsideDomain(URI currentLocation, URI asUrl) throws URISyntaxException {
48 | return currentLocation.getHost().equals(asUrl.getHost());
49 | }
50 |
51 | private URI normalizeLink(URI currentLocation, String link) throws MalformedURLException, URISyntaxException {
52 | URI uri = new URI(link);
53 | if (uri.getScheme() != null && uri.getHost() != null) {
54 | return uri;
55 | }
56 | return URIUtils.resolve(currentLocation, uri);
57 | }
58 |
59 | private static String downloadContents(URI startLocation) throws URISyntaxException {
60 | HttpClient httpClient = new DefaultHttpClient();
61 | System.out.println("Currently crawling : " + startLocation);
62 | HttpGet get = new HttpGet(startLocation);
63 | try {
64 | HttpResponse response = httpClient.execute(get);
65 | String contents = IOUtil.toString(response.getEntity().getContent());
66 | return contents;
67 | } catch (IOException e) {
68 | e.printStackTrace();
69 | // IO Error when connecting to the server, whatever, just return
70 | // empty contents
71 | return "";
72 | }
73 | }
74 |
75 | private static List getAllLinks(String content) {
76 | ArrayList resultList = new ArrayList<>();
77 | String regex = "";
78 | Pattern pattern = Pattern.compile(regex);
79 | Matcher matcher = pattern.matcher(content);
80 | while (matcher.find()) {
81 | resultList.add(matcher.group(1));
82 | }
83 | return resultList;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/02-DebuggingFun/DebuggingFun/src/com/hackbulgaria/corejava/Utils.java:
--------------------------------------------------------------------------------
1 | package com.hackbulgaria.corejava;
2 |
3 | import java.io.File;
4 | import java.io.FileWriter;
5 | import java.io.IOException;
6 | import java.io.Writer;
7 | import java.lang.Thread.State;
8 | import java.net.MalformedURLException;
9 | import java.net.URL;
10 | import java.net.URLClassLoader;
11 |
12 | import javax.tools.JavaCompiler;
13 | import javax.tools.ToolProvider;
14 |
15 | import org.apache.commons.io.FileUtils;
16 |
17 | public class Utils {
18 | public static String reverseMe(String argument) {
19 | return new StringBuilder(argument).reverse().toString();
20 | }
21 |
22 | public static boolean isPalindrome(String argument) {
23 | return argument.equals(reverseMe(argument));
24 | }
25 |
26 | public static boolean isPalindrome(long number) {
27 | return isPalindrome(String.valueOf(number));
28 | }
29 |
30 | public static void killMeIfIGetStuck() {
31 | final Thread threadToKill = Thread.currentThread();
32 | new Thread(new Runnable() {
33 |
34 | @Override
35 | public void run() {
36 | try {
37 | Thread.sleep(2000);
38 | if (threadToKill.getState().equals(State.RUNNABLE) && "binarySearch".equals(threadToKill.getStackTrace()[0].getMethodName())) {
39 |
40 | // every time you do this Barekov gets another vote!
41 | threadToKill.stop();
42 | }
43 | } catch (final InterruptedException e) {
44 | e.printStackTrace();
45 | }
46 | }
47 | }).start();
48 | }
49 |
50 |
51 |
52 | public static Class> eval(Code code, String fileName) {
53 | File root = new File(isWindows()? "C:\\" : "/tmp/java-fun/");
54 | File sourceFile = new File(root, fileName + ".java");
55 | root.mkdirs();
56 |
57 | try {
58 | FileUtils.write(sourceFile, code.wrappedCode);
59 | } catch (IOException e) {
60 | e.printStackTrace();
61 | }
62 |
63 | JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
64 | javaCompiler.run(null, null, null, sourceFile.getPath());
65 |
66 | URLClassLoader urlClassLoader = null;
67 | try {
68 | urlClassLoader = URLClassLoader.newInstance(new URL[] { root.toURI().toURL() });
69 | } catch (MalformedURLException e1) {
70 | e1.printStackTrace();
71 | }
72 | try {
73 | return Class.forName(fileName, true, urlClassLoader);
74 | } catch (ClassNotFoundException e) {
75 | e.printStackTrace();
76 | }
77 | return null;
78 | }
79 |
80 | private static boolean isWindows() {
81 | return System.getProperty("os.name").toLowerCase().contains("win");
82 | }
83 |
84 | public static class Code {
85 | private String wrappedCode;
86 |
87 | public Code(String code){
88 | this.wrappedCode = "public class Eval { static { " + code + " } } ";
89 | }
90 |
91 | @Override
92 | public String toString() {
93 | return wrappedCode + super.toString();
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/14-Networking2/problems.md:
--------------------------------------------------------------------------------
1 | ### Download a file with java
2 | Using only URL and the stream classes, download this photo: http://d3dsacqprgcsqh.cloudfront.net/photo/aozrdx0_700b.jpg to a location of your choosing
3 |
4 | ##### Now accept files from the command line and label your program the 'java wget'. Woohoo!
5 |
6 | ### Make a simple website crawler (Pair Programming)
7 | Have you grown tiiiiiiired of looking for stuff on websites that simply seems is not in the navigation menu at all?
8 | You grow tired of that... and suddenly, baaaam! Someone skypes you the link. It was there, how could I have not seen it.
9 |
10 |
11 | Today, we will put an end to that.
12 |
13 | Write a simple web crawler, that is receiving a URL as a command line parameter and a "needle" to search for.
14 | Needle is text, usually a sentence.
15 |
16 | What your crawler should do is simple
17 | - GET the contents of the URL received
18 | - Check if the contents contain "needle"
19 | - If they do, output the URL and exit
20 | - If they don't, **get all the links** from the URL given and repeat for every link.
21 |
22 | Hints/tips:
23 | - **Don't go out of the website's scope** - if a link in `abv.bg` points to google, well, don't follow google, please...
24 | - **Don't visit the same URL twice**
25 | - **Use regular expressions** for getting links. If you are unfamiliar with them, use the following method:
26 | ```java
27 | private static List getAllLinks(String content) {
28 | ArrayList resultList = new ArrayList<>();
29 | String regex = "";
30 | Pattern pattern = Pattern.compile(regex);
31 | Matcher matcher = pattern.matcher(content);
32 | while (matcher.find()) {
33 | resultList.add(matcher.group(1));
34 | }
35 | return resultList;
36 | }
37 | ```
38 | - **If you are not comfortable with even using something as ugly as regular expressions, you can do it with regular string matching. It will be harder though :(**
39 | - Use small websites for testing. For example, http://ebusiness.free.bg is one site you can use. It has very, very few links. (Search for the word 'Револвираща'.)
40 |
41 | ### Get/print all the people that have signed for more than 1 course at Hack Bulgaria.
42 | Some people have signed for Core Java.
43 | Some people have signed for Front-end Javascript.
44 | Some people have signed for Angular-JS.
45 |
46 | They are people that have signed for more than one course.
47 | Using the https://hackbulgaria.com/api/students/ API, the [Jettison library](http://jettison.codehaus.org/) and [Apache HttpClient](http://hc.apache.org/httpclient-3.x/tutorial.html), consume the REST service given and print out all the people, who have signed for more that 1 course.
48 |
49 |
50 | ##### Addendum: Print out the people with the most visits.
51 | See, whenever you visit HackBulgaria and use our WiFi, your MAC addresses get logged. If you have 'filled the forms' when registering at the HackBulgaria website, you can now see who has been coming and who hasn't been coming to the lectures.
52 |
53 | ```
54 | {"date": "2014-06-05", "student_id": 35, "student_courses": [{"group": 1, "name": "Frontend JavaScript"}], "student_name": "Светимир Игнатов"}
55 | ```
56 |
57 | Using https://hackbulgaria.com/api/checkins/, the [Jettison library](http://jettison.codehaus.org/) and [Apache HttpClient](http://hc.apache.org/httpclient-3.x/tutorial.html), consume the REST service given and print out pairs of String-Integer, where the key (String) is the name of a Person, and the value (Integer) is the number of times he was at HackBulgaria. Sort the pairs when printing - people with more checkins should come before people with less checkins.
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/08-WorkingWithLibraries/problems.md:
--------------------------------------------------------------------------------
1 | ### Send an email about the 'Suarez' accident
2 |
3 | Have you seen the Suarez-Chiellini biting accident from the World Cup in Brazil? It was both hilarious and weird-ish at the same time.
4 | In the dawn of the internet, when skype, snapchat and stuff like that did not exist, people were sending a lot of emails to each other with funny stuff.
5 |
6 | Send an email to someone about the suarez biting accident. Attach a gif of the biting accident, available [here](http://d3dsacqprgcsqh.cloudfront.net/photo/azbW3zq_460sa_v1.gif)
7 |
8 | Integrate and use the apache commons-email library from http://commons.apache.org/proper/commons-email/userguide.html
9 |
10 | Note: The commons-email library depends on the javax.mail library, which you should download from somewhere.
11 |
12 | ### JToaster
13 |
14 | Ivan stays a lot on his computer. His mother is afraid he will spoils his vision.
15 | As you know very well, you should take a break of at least 5 minutes (actually, it should be 15, but this *might* be outdated).
16 |
17 | Help Ivan maintain his eagle-like vision. Write a program that waits 45 minutes, and the shows a notification saying 'Get a little rest, will you?' (or a message of your choosing :D)
18 |
19 | Use the incredibly-complex JToaster library. Download it from http://jtoaster.sourceforge.net/
20 | Use the methods `showToaster`, `setToasterWidth`, `setToasterHeight`, `setToasterIcon`, `setToasterColor`, `setBackgroundImage`, `setStep`, etc. to customize and make the coolest toaster you can imagine. Also, set a nice background, something like
21 |
22 | ![This dog] (http://www.mnn.com/sites/default/files/editorial/Corgeek.jpg)
23 |
24 |
25 | Also, check out the `Thread.sleep` method.
26 |
27 |
28 | ### Make a QuickCodeInspector desktop application
29 |
30 | Ever needed to really, really quickly inpsect some code?
31 | Here is a one cool syntax highlighter for java https://code.google.com/p/java-syntax-highlighter/
32 |
33 | 1) Create a program, that receives a file path as a command-line argument (args[0] in `main(String[] args)`)
34 | 2) For the File given, launch a syntax highlighter windows as the example in the link above.
35 |
36 | Come back when you are done with 1) and 2).
37 |
38 | Does it work so far? Marvelous.
39 | 3) *Not mandatory*. Now, for the fun, export your program as a *runnable* jar. (See Eclipse->Export). Register your program as one that can handle .java files in your OS (the way to do this will vary among OS and distributions)
40 | For ubuntu see http://askubuntu.com/questions/289337/how-can-i-change-file-association-globally.
41 |
42 | For windows, create a **.bat** file, containing somthing like:
43 | ```
44 | "C:\Program Files\Java\jre7\bin\javaw.exe" -jar "C:\Users\Adriana\Desktop\QuickCodeInspector.jar" %1 %
45 | ```
46 | 1) C:\Program Files... -> Is the path to your javaw.exe location
47 | 2)-jar C:\Users..... -> is the path to your QuickCodeInspector.jar
48 | 3) Just append %1 % at the end of the .bat script.
49 | After that, try opening .java files with your application, by using **open with** and pointing to your .bat file.
50 |
51 | Go and check your cool java program that opens .java files for you. (Remove the entry later!).
52 |
53 | 4) Set a title on the window that matches the name of the file being viewed!
54 | 5) How cool would it be if we could navigate through all the files of the current directory with the arrows of the keyboard?
55 | In order to do that, make the jframe **focusable**, add a **KeyEventListener**, and when the user presses the arrow-next on the keyboard (see [key-code table](http://www.foreui.com/articles/Key_Code_Table.htm)), `dispose()` the frame and create a new one with a syntax highlighter configured for the next file.
56 | 6) Make this work recursively for all the files in the folder.
57 |
58 |
--------------------------------------------------------------------------------
/06-Exam1/tasks.md:
--------------------------------------------------------------------------------
1 | Both tasks should go into a project named Exam1.
2 | Later on you will be asked to give a link to your solution (to the Exam1 project). All tasks but the last one should have good test cases with them.
3 |
4 | ### Make a method 'sort', which sorts a copy of a List
5 | `Collections.sort` is really cool, but it sorts collections in place.
6 | Write a **utility** method `sort`, that sorts a **copy of the given** `List`, and returns it. Use `Integer` as type for your `List`.
7 |
8 | ### Make a method 'reverse', which reverses a copy of a List.
9 | Write a **utility** method `reverse`, that takes a `List`, **reverses** a copy of it and returns the reversed copy. Use `Integer` as type for your `List` argument.
10 |
11 | ### Check if the given List is monotonous
12 | Make a **utility** method, that returns **boolean** whenever the `List` given is monotonic.
13 | ```java
14 | YourClass.yourMethod(Arrays.asList(1,2,3,4,5,6)); //true
15 | YourClass.yourMethod(Arrays.asList(6,5,4,3,2,1,1,1); //true
16 | YourClass.yourMethod(Arrays.asList(1,2,1,4,5,4)); //false
17 | ```
18 | **Bonus** Maximum 1 line of code allowed. :)
19 |
20 | ### Make a logger class
21 |
22 | Disclaimer: To **log** somethings means simply to write it to the console.
23 |
24 | A *logger* class is a class that people use when they want something written on the console. Of course, one can always use `System.out.println()`, but it is a churn, and logger classes tend to offer good methods for writing a little more complicated stuff to the console (see examples below).
25 |
26 | A logger class also has something called `LEVEL`, which is usually an integer.
27 | `LEVEL` represents the **importance** of the message logged. For instance, `logger.log(3, "something)` means that the priority for message **"something"** is **3**.
28 |
29 | And when a `LEVEL` is **set to the logger**, the logger **ignores logging calls for higher levels**.
30 | For instance:
31 | ```java
32 | Logger logger = new Logger(3); //set LEVEL to 3
33 | //I can also call 'new Logger()', in which case use a default LEVEL of 3
34 |
35 | logger.log(2, "Somewhat important message"); //gets logged as "2 => Somewhat important message"
36 | logger.log(3, "Less important message"); // also gets logged!
37 | logger.log(5, "Not important"); //this is less important than LEVEL, so it will **not be logged**.
38 | logger.log("Meh"); //overload without a LEVEL parameter, use 3 as default.
39 |
40 | ....
41 | looger.setLevel(2);
42 | logger.log("My message"); //does not get printed!
43 | ```
44 |
45 | `LEVEL` is always expected to be > 0. Your class should not encourage/tolerate behavior like:
46 | `logger.log(INTEGER.MIN_VALUE, "THIS is most important message in the world!!!")`. This is not a correct call and calling your method like this is a programmer mistake. **Make sure you do not accept such usage.**
47 |
48 |
49 | **It is important to note that LEVEL must be settable at runtime, after the logger object has been created.**
50 |
51 |
52 |
53 | Also, it is quite important on how the log message look like. In order for your log messages to be more informative, include the *current date and time* of the logging.
54 | Make a class `DateLogger`, which logs messages, but prepends
55 | Example
56 |
57 | ```java
58 | Logger logger = new DateLogger(); //I am not obliged to set a log level, by default your class should print everything in this case
59 | logger.log("My message"); //this is an overload without a LEVEL parameter. In this situation, assume the LEVEL given to you is 3.
60 | //|22:14:01 14.06.2014| 3 => My message
61 | ```
62 |
63 | To summarize:
64 | - Create a `Logger` class. Make a constructor accepting log `LEVEL`. Make a default constructor with a default log level of 3.
65 | - Implement a `log(int level, String message)` and `log(String message)`
66 | - Do not log messages if the level given is higher than the currently set in the logger.
67 | - Protect users of this class from invalid usage
68 | - Create a sublcass `DateLogger`. Override it's methods so that date and time is added to every logged message (see examples above).
69 | - It's okay (just for now, and just for this task!), not to use TDD. This is because I have not shown you mocking, and we have not talked about PrintStreams, PrintWriters, etc. in Java.
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/16-Generics2/problems.md:
--------------------------------------------------------------------------------
1 | ### Declare an annotation type 'ClassInfo'
2 | It should contain information about:
3 | - author of the class
4 | - revision of the class (by default it should be 1)
5 | - should the class be 'checked' (by default it should be) //this 'checked' thing is a bogus one, I just made it up so you can use a boolean default
6 | - an array of 'related' classes (Class>[])
7 |
8 | - Annotatate a class with this annotation. Fill in the 'required' information
9 | - In a main method, instantiate the annotated class. Using the `getClass().getAnnotations()`, print out all the annotations declared for your annotated class.
10 | - Now fetch your own annotation using `yourInstance.getClass().getAnnotation(YourAnnotationName.class);`
11 | - Print out all the filled information
12 |
13 |
14 | ###1. Create a Box class
15 |
16 | A Box class can hold an instance.
17 |
18 | ```java
19 | Box box = new Box<>();
20 | box.set(3);
21 | System.out.println(box.get()); //=>3
22 |
23 |
24 | Box box = new Box<>("this example belongs to Oracle");
25 | System.out.println(box.get()) //"this example belongs to Oracle"
26 | ```
27 |
28 | Demonstrate the usage of the class you wrote in a main method, setting an `Integer`, a `String`, and a `List` list to the box.
29 |
30 | ###2. Create a Pair class
31 | **F** stands for first, **S** stands for second.
32 |
33 | ```java
34 | Pair pair = new Pair<>();
35 | pair.setFirst(3);
36 | pair.setSecond("string");
37 |
38 | System.out.println(pair.toString()); //=> <3, "string"> (Implement the to string method as well)
39 | System.out.println(pair.first()); //=> 3 (first() here returns an *Integer*, not an *Object*!)
40 | System.out.println(pair.second()); //=> "string"
41 |
42 | Pair pair = new Pair<>(3, "string");
43 | System.out.println(pair.toString()); //=> <3, "string">
44 | ```
45 |
46 | Demonstrate the usage of your Pair class in a similiar manner.
47 |
48 | ###3. Write a static newInstance method
49 | Declare a method that receives a Class clazz, and returns a new instance of T. See http://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#newInstance--
50 |
51 |
52 | ###4. Write a 'Favourites' class
53 | Write a class `Favourites`, with which I can do the following:
54 | ```java
55 | Favourites favourites = new Favourites();
56 | favourites.add(String.class, "myString");
57 | favourites.add(Integer.class, 3);
58 |
59 | System.out.println(favourites.get(Integer.class)) => //3
60 | ```
61 | No compile time warnings : )
62 | Hints: See `cast` method on `Class` class. There is more than 1 solution to this task.
63 |
64 |
65 | Demonstrate the usage of your class.
66 |
67 | Can you make the `Favourites` class iterable? No casts/ compiler warnings allowed : )
68 |
69 | ###5. Write an 'Arrays.asList' - like method.
70 | ```java
71 | List ints = asList(1,2,3,4,5);
72 | List strings = asList("1","2","3","4","5");
73 |
74 | //also, give an explanation to what is happening in the lines below :)
75 | List> whatIsThis = asList(null,null,null);
76 | List