├── itext-java-html-pdf
├── java.png
├── style.css
├── index.html
├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── hmkcode
│ │ └── App.java
├── pom.xml
└── .classpath
├── itext-create-pdf
├── helloworld.pdf
├── pagesettings.pdf
├── .classpath
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── hmkcode
│ ├── HelloWorld.java
│ └── PageSettings.java
├── java-spi
├── java-spi-impl1
│ ├── src
│ │ └── main
│ │ │ ├── resources
│ │ │ └── META-INF
│ │ │ │ └── services
│ │ │ │ └── com.hmkcode.api.MyServiceProviderInterface
│ │ │ └── java
│ │ │ └── com
│ │ │ └── hmkcode
│ │ │ └── impl
│ │ │ ├── MyServiceImpl1.java
│ │ │ └── MyServiceProviderImpl1.java
│ ├── lib
│ │ └── java-spi-api-1.0-SNAPSHOT.jar
│ └── pom.xml
├── java-spi-app
│ ├── lib
│ │ ├── java-spi-api-1.0-SNAPSHOT.jar
│ │ └── java-spi-impl1-1.0-SNAPSHOT.jar
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── hmkcode
│ │ │ └── app
│ │ │ ├── App.java
│ │ │ └── MyServiceLoader.java
│ └── pom.xml
└── java-spi-api
│ ├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── hmkcode
│ │ └── api
│ │ ├── MyService.java
│ │ └── MyServiceProviderInterface.java
│ └── pom.xml
├── servlet-file-upload
├── src
│ └── main
│ │ ├── webapp
│ │ ├── img
│ │ │ ├── facebook.png
│ │ │ ├── gae-logo.png
│ │ │ ├── twitter.png
│ │ │ ├── googleplus.png
│ │ │ └── tech-stack.jpg
│ │ ├── bootstrap
│ │ │ └── img
│ │ │ │ ├── glyphicons-halflings.png
│ │ │ │ └── glyphicons-halflings-white.png
│ │ ├── css
│ │ │ ├── mystyle.css
│ │ │ ├── dropzone.css
│ │ │ └── style.css
│ │ ├── WEB-INF
│ │ │ └── web.xml
│ │ ├── js
│ │ │ ├── myuploadfunction.js
│ │ │ └── jquery.iframe-transport.js
│ │ └── index.html
│ │ └── java
│ │ └── com
│ │ └── hmkcode
│ │ ├── vo
│ │ └── FileMeta.java
│ │ ├── FileUploadServlet.java
│ │ └── MultipartRequestHandler.java
├── .classpath
└── pom.xml
├── jackson-json-java
├── article.json
├── articles.json
├── .classpath
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── hmkcode
│ ├── vo
│ └── Article.java
│ └── App.java
├── simple-junit
├── target
│ ├── classes
│ │ └── com
│ │ │ └── hmkcode
│ │ │ └── junit
│ │ │ └── Math.class
│ ├── test-classes
│ │ └── com
│ │ │ └── hmkcode
│ │ │ └── junit
│ │ │ └── MathTest.class
│ └── surefire-reports
│ │ ├── com.hmkcode.junit.MathTest.txt
│ │ └── TEST-com.hmkcode.junit.MathTest.xml
├── .project
├── .classpath
├── src
│ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── hmkcode
│ │ │ └── junit
│ │ │ └── Math.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── hmkcode
│ │ └── junit
│ │ └── MathTest.java
└── pom.xml
├── mybatis-insert-generatedkey
├── src
│ ├── main
│ │ ├── resources
│ │ │ ├── test-data.sql
│ │ │ ├── schema.sql
│ │ │ ├── com
│ │ │ │ └── hmkcode
│ │ │ │ │ └── spring
│ │ │ │ │ └── mybatis
│ │ │ │ │ ├── mybatis-config.xml
│ │ │ │ │ └── mapper
│ │ │ │ │ └── Mapper.xml
│ │ │ └── spring-config.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── hmkcode
│ │ │ └── spring
│ │ │ └── mybatis
│ │ │ ├── service
│ │ │ └── Service.java
│ │ │ ├── vo
│ │ │ └── MyObject.java
│ │ │ ├── mapper
│ │ │ └── Mapper.java
│ │ │ └── App.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── hmkcode
│ │ └── spring
│ │ └── mybatis
│ │ └── AppTest.java
├── .classpath
└── pom.xml
├── java-lambda
├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── hmkcode
│ │ ├── OnClickListener.java
│ │ ├── Button.java
│ │ └── App.java
├── pom.xml
└── README.md
├── java-async-servlet
├── src
│ └── main
│ │ ├── webapp
│ │ ├── bootstrap
│ │ │ └── img
│ │ │ │ ├── glyphicons-halflings.png
│ │ │ │ └── glyphicons-halflings-white.png
│ │ ├── WEB-INF
│ │ │ └── web.xml
│ │ ├── index.html
│ │ └── js
│ │ │ └── myfunctions.js
│ │ └── java
│ │ └── com
│ │ └── hmkcode
│ │ ├── SyncServlet.java
│ │ └── AsyncServlet.java
├── .classpath
└── pom.xml
├── java-servlet-json
├── src
│ └── main
│ │ ├── webapp
│ │ ├── bootstrap
│ │ │ └── img
│ │ │ │ ├── glyphicons-halflings.png
│ │ │ │ └── glyphicons-halflings-white.png
│ │ ├── js
│ │ │ └── myfunctions.js
│ │ └── index.html
│ │ └── java
│ │ └── com
│ │ └── hmkcode
│ │ ├── vo
│ │ └── Article.java
│ │ └── JSONServlet.java
├── .classpath
└── pom.xml
├── castor-xml-object
├── mapped_article.xml
├── mapping.xml
├── .classpath
├── article.xml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── hmkcode
│ ├── vo
│ └── Article.java
│ ├── App.java
│ └── AppMapping.java
├── MapSort
├── README.md
└── src
│ └── com
│ └── hmkcode
│ ├── MapSort.java
│ ├── ValueComparator.java
│ └── Test.java
├── java-list-map
├── .classpath
├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── hmkcode
│ │ ├── vo
│ │ └── Person.java
│ │ ├── ListApp.java
│ │ └── MapApp.java
└── pom.xml
├── webservlet-annotation
├── .classpath
├── src
│ └── main
│ │ ├── webapp
│ │ ├── index.jsp
│ │ └── WEB-INF
│ │ │ └── web.xml
│ │ └── java
│ │ └── com
│ │ └── hmkcode
│ │ └── MyServlet.java
└── pom.xml
├── gson-json-java
├── .classpath
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── hmkcode
│ ├── vo
│ └── Article.java
│ └── App.java
├── junit-exception
├── .classpath
├── pom.xml
└── src
│ └── test
│ └── java
│ └── com
│ └── hmkcode
│ └── AppTest.java
├── websocket-java-api
├── websocket-glassfish-server
│ ├── src
│ │ └── main
│ │ │ ├── webapp
│ │ │ ├── WEB-INF
│ │ │ │ └── web.xml
│ │ │ ├── index.htm
│ │ │ └── websocket.js
│ │ │ └── java
│ │ │ └── com
│ │ │ └── hmkcode
│ │ │ └── MyServerEndpoint.java
│ ├── .classpath
│ └── pom.xml
└── websocket-app-client
│ ├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── hmkcode
│ │ ├── MyClient.java
│ │ └── App.java
│ ├── .classpath
│ └── pom.xml
├── java-inputstream-string
├── .classpath
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── hmkcode
│ ├── App.java
│ └── InputStreamToString.java
├── itext-java-pdf-table
├── .classpath
├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── hmkcode
│ │ ├── App.java
│ │ ├── Style.java
│ │ └── TableBuilder.java
└── pom.xml
├── xstream-java-xml
├── .classpath
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── hmkcode
│ ├── App.java
│ └── vo
│ └── Article.java
├── java-combinations
├── README.md
├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── hmkcode
│ │ ├── Recursive.java
│ │ ├── Shifting.java
│ │ └── ForwardBackward.java
└── Combination.java
├── java-excel-poi
├── pom.xml
├── .classpath
└── src
│ └── main
│ └── java
│ └── com
│ └── hmkcode
│ └── poi
│ ├── AppWrite.java
│ └── AppRead.java
├── java-jasper
├── src
│ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── hmkcode
│ │ │ ├── Country.java
│ │ │ └── App.java
│ │ └── resources
│ │ └── report.jrxml
└── pom.xml
├── java-simple-text-file-reader
└── src
│ └── main
│ └── java
│ └── com
│ └── hmkcode
│ └── TextFileReader.java
├── java-unzip
└── src
│ └── main
│ └── java
│ └── com
│ └── hmkcode
│ └── Unzip.java
└── java-stream
└── src
└── main
└── java
└── com
└── hmkcode
└── App.java
/itext-java-html-pdf/java.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/itext-java-html-pdf/java.png
--------------------------------------------------------------------------------
/itext-create-pdf/helloworld.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/itext-create-pdf/helloworld.pdf
--------------------------------------------------------------------------------
/itext-create-pdf/pagesettings.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/itext-create-pdf/pagesettings.pdf
--------------------------------------------------------------------------------
/java-spi/java-spi-impl1/src/main/resources/META-INF/services/com.hmkcode.api.MyServiceProviderInterface:
--------------------------------------------------------------------------------
1 | com.hmkcode.impl.MyServiceProviderImpl1
--------------------------------------------------------------------------------
/servlet-file-upload/src/main/webapp/img/facebook.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/servlet-file-upload/src/main/webapp/img/facebook.png
--------------------------------------------------------------------------------
/servlet-file-upload/src/main/webapp/img/gae-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/servlet-file-upload/src/main/webapp/img/gae-logo.png
--------------------------------------------------------------------------------
/servlet-file-upload/src/main/webapp/img/twitter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/servlet-file-upload/src/main/webapp/img/twitter.png
--------------------------------------------------------------------------------
/java-spi/java-spi-app/lib/java-spi-api-1.0-SNAPSHOT.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/java-spi/java-spi-app/lib/java-spi-api-1.0-SNAPSHOT.jar
--------------------------------------------------------------------------------
/servlet-file-upload/src/main/webapp/img/googleplus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/servlet-file-upload/src/main/webapp/img/googleplus.png
--------------------------------------------------------------------------------
/servlet-file-upload/src/main/webapp/img/tech-stack.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/servlet-file-upload/src/main/webapp/img/tech-stack.jpg
--------------------------------------------------------------------------------
/jackson-json-java/article.json:
--------------------------------------------------------------------------------
1 | {"title":"Jackson - Java to JSON & JSON to Java",
2 | "categories":["Java"],
3 | "address":"http://hmkcode.com/jackson-java-json"}
--------------------------------------------------------------------------------
/java-spi/java-spi-app/lib/java-spi-impl1-1.0-SNAPSHOT.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/java-spi/java-spi-app/lib/java-spi-impl1-1.0-SNAPSHOT.jar
--------------------------------------------------------------------------------
/java-spi/java-spi-impl1/lib/java-spi-api-1.0-SNAPSHOT.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/java-spi/java-spi-impl1/lib/java-spi-api-1.0-SNAPSHOT.jar
--------------------------------------------------------------------------------
/simple-junit/target/classes/com/hmkcode/junit/Math.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/simple-junit/target/classes/com/hmkcode/junit/Math.class
--------------------------------------------------------------------------------
/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyService.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.api;
2 |
3 | public interface MyService {
4 |
5 | void doSomething();
6 | }
7 |
--------------------------------------------------------------------------------
/mybatis-insert-generatedkey/src/main/resources/test-data.sql:
--------------------------------------------------------------------------------
1 | INSERT INTO myobject_table (objectId, ObjectName ) VALUES (my_sequence.nextVal,'name-1');
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/java-lambda/src/main/java/com/hmkcode/OnClickListener.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 |
4 | public interface OnClickListener {
5 | void onClick(Button button);
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/simple-junit/target/test-classes/com/hmkcode/junit/MathTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/simple-junit/target/test-classes/com/hmkcode/junit/MathTest.class
--------------------------------------------------------------------------------
/java-async-servlet/src/main/webapp/bootstrap/img/glyphicons-halflings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/java-async-servlet/src/main/webapp/bootstrap/img/glyphicons-halflings.png
--------------------------------------------------------------------------------
/java-servlet-json/src/main/webapp/bootstrap/img/glyphicons-halflings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/java-servlet-json/src/main/webapp/bootstrap/img/glyphicons-halflings.png
--------------------------------------------------------------------------------
/servlet-file-upload/src/main/webapp/bootstrap/img/glyphicons-halflings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/servlet-file-upload/src/main/webapp/bootstrap/img/glyphicons-halflings.png
--------------------------------------------------------------------------------
/java-servlet-json/src/main/webapp/bootstrap/img/glyphicons-halflings-white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/java-servlet-json/src/main/webapp/bootstrap/img/glyphicons-halflings-white.png
--------------------------------------------------------------------------------
/mybatis-insert-generatedkey/src/main/resources/schema.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE myobject_table (objectId INT PRIMARY KEY, objectName VARCHAR(255));
2 | CREATE SEQUENCE my_sequence START WITH 1 INCREMENT BY 1;
3 |
--------------------------------------------------------------------------------
/java-async-servlet/src/main/webapp/bootstrap/img/glyphicons-halflings-white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/java-async-servlet/src/main/webapp/bootstrap/img/glyphicons-halflings-white.png
--------------------------------------------------------------------------------
/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyServiceProviderInterface.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.api;
2 |
3 | public interface MyServiceProviderInterface {
4 |
5 | MyService getService();
6 | }
7 |
--------------------------------------------------------------------------------
/servlet-file-upload/src/main/webapp/bootstrap/img/glyphicons-halflings-white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/22alo/Java5/HEAD/servlet-file-upload/src/main/webapp/bootstrap/img/glyphicons-halflings-white.png
--------------------------------------------------------------------------------
/java-spi/java-spi-app/src/main/java/com/hmkcode/app/App.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.app;
2 |
3 | public class App
4 | {
5 | public static void main( String[] args )
6 | {
7 | MyServiceLoader.defaultProvider().getService().doSomething();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/jackson-json-java/articles.json:
--------------------------------------------------------------------------------
1 | [{"title":"Jackson - Java to JSON & JSON to Java","url":"http://hmkcode.com/jackson-java-json","categories":["Java"],"tags":["Java","Jackson","JSON"]},{"title":"Jackson - Java to JSON & JSON to Java","url":"http://hmkcode.com/jackson-java-json","categories":["Java"],"tags":["Java","Jackson","JSON"]}]
--------------------------------------------------------------------------------
/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceImpl1.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.impl;
2 |
3 | import com.hmkcode.api.MyService;
4 |
5 | public class MyServiceImpl1 implements MyService{
6 |
7 | @Override
8 | public void doSomething() {
9 | System.out.println("MyServiceImpl1");
10 |
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/simple-junit/target/surefire-reports/com.hmkcode.junit.MathTest.txt:
--------------------------------------------------------------------------------
1 | -------------------------------------------------------------------------------
2 | Test set: com.hmkcode.junit.MathTest
3 | -------------------------------------------------------------------------------
4 | Tests run: 5, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 0.06 sec
5 |
--------------------------------------------------------------------------------
/itext-java-html-pdf/style.css:
--------------------------------------------------------------------------------
1 | h1 {
2 | color:#ccc;
3 | }
4 | table tr td{
5 | text-align:center;
6 | border:1px solid gray;
7 | padding:4px;
8 | }
9 | table tr th{
10 | background-color:#84C7FD;
11 | color:#fff;
12 | width: 100px;
13 | }
14 | .itext{
15 | color:#84C7FD;
16 | font-weight:bold;
17 | }
18 | .description{
19 | color:gray;
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/castor-xml-object/mapped_article.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | http://hmkcode.com/castor-java-object-xml
4 | Java
5 | Java
6 | Castor
7 | XML
8 | Marshalling
9 | Unmarshalling
10 |
--------------------------------------------------------------------------------
/MapSort/README.md:
--------------------------------------------------------------------------------
1 | SORT JAVA MAP BY KEYS AND VALUES
2 | --------------------------------
3 |
4 | * "Key,Value" order in Java HashMap is not guaranteed.
5 | * Sorting a Map type class by "keys" is given by TreeMap, just TreeMap.putAll(map) will return sorted map by keys.
6 | * Sorting a Map by "values" needs one more step, we need to define a Comparator that compares values to each other.
7 |
8 |
--------------------------------------------------------------------------------
/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceProviderImpl1.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.impl;
2 |
3 | import com.hmkcode.api.MyService;
4 | import com.hmkcode.api.MyServiceProviderInterface;
5 |
6 | public class MyServiceProviderImpl1 implements MyServiceProviderInterface {
7 |
8 | @Override
9 | public MyService getService() {
10 | return new MyServiceImpl1();
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/java-list-map/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/webservlet-annotation/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/gson-json-java/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/itext-create-pdf/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/junit-exception/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/simple-junit/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | simple-junit
4 | NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.
5 |
6 |
7 |
8 | org.eclipse.jdt.core.javabuilder
9 |
10 |
11 |
12 | org.eclipse.jdt.core.javanature
13 |
14 |
--------------------------------------------------------------------------------
/java-async-servlet/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/MapSort/src/com/hmkcode/MapSort.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 |
4 | import java.util.Map;
5 | import java.util.TreeMap;
6 |
7 | public class MapSort {
8 |
9 | public static Map sortByValue(Map unsortedMap){
10 | Map sortedMap = new TreeMap(new ValueComparator(unsortedMap));
11 | sortedMap.putAll(unsortedMap);
12 | return sortedMap;
13 | }
14 | public static Map sortByKey(Map unsortedMap){
15 | Map sortedMap = new TreeMap();
16 | sortedMap.putAll(unsortedMap);
17 | return sortedMap;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/servlet-file-upload/src/main/webapp/css/mystyle.css:
--------------------------------------------------------------------------------
1 | #main{
2 |
3 | border:1px #F2F2F2 solid;
4 | padding:10px;
5 | margin:5px;
6 | min-width:1020px;
7 | text-align:center;
8 |
9 | }
10 |
11 | #input-div{
12 | width:500px;
13 | display:inline-block;
14 | vertical-align:top;
15 | padding:5px;
16 | border:1px #F2F2F2 solid;
17 |
18 | }
19 |
20 | #ref-div{
21 | width:500px;
22 | display:inline-block;
23 |
24 | vertical-align:top;
25 | padding:5px;
26 | }
27 |
28 | #user_twitter{
29 |
30 | text-align:center;
31 | }
--------------------------------------------------------------------------------
/webservlet-annotation/src/main/webapp/index.jsp:
--------------------------------------------------------------------------------
1 |
2 | <%@page contentType="text/html" pageEncoding="UTF-8"%>
3 |
5 |
6 |
7 |
8 |
9 | @WebServlet
10 |
11 |
12 | @WebServlet
13 |
14 | Test MyAnnotatedServlet
15 |
16 |
17 |
--------------------------------------------------------------------------------
/java-async-servlet/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 | java async servlet
8 |
9 | index.html
10 |
11 |
12 |
--------------------------------------------------------------------------------
/simple-junit/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/websocket-java-api/websocket-glassfish-server/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 | websocket-glassfish-server
9 |
10 | index.htm
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/java-inputstream-string/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/MapSort/src/com/hmkcode/ValueComparator.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.util.Comparator;
4 | import java.util.Map;
5 |
6 | public class ValueComparator implements Comparator {
7 |
8 | Map map;
9 |
10 | public ValueComparator(Map map){
11 | this.map = map;
12 | }
13 | public int compare(Object keyA, Object keyB){
14 |
15 | Comparable valueA = (Comparable) map.get(keyA);
16 | Comparable valueB = (Comparable) map.get(keyB);
17 |
18 | System.out.println(valueA +" - "+valueB);
19 |
20 | return valueA.compareTo(valueB);
21 |
22 | }
23 |
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/mybatis-insert-generatedkey/src/main/resources/com/hmkcode/spring/mybatis/mybatis-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/itext-java-pdf-table/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/simple-junit/src/main/java/com/hmkcode/junit/Math.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.junit;
2 |
3 | /**
4 | * Hello world!
5 | *
6 | */
7 | public class Math
8 | {
9 | public static void main( String[] args )
10 | {
11 | System.out.println( "Hello World!" );
12 | }
13 |
14 | public double sum(double x, double y){
15 | return x+y;
16 | }
17 | public double multiply(double x, double y){
18 | return x*y;
19 | }
20 | public double divide(double x, double y){
21 | return x/y;
22 | }
23 | public double subtract(double x, double y){
24 | return x - y;
25 | }
26 |
27 |
28 |
29 | }
--------------------------------------------------------------------------------
/java-lambda/src/main/java/com/hmkcode/Button.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | public class Button {
4 |
5 | private OnClickListener onClickListener;
6 | private String name;
7 |
8 | public void click(){
9 | this.onClickListener.onClick(this);
10 | }
11 |
12 |
13 | public String getName() {
14 | return name;
15 | }
16 |
17 | public void setName(String name) {
18 | this.name = name;
19 | }
20 |
21 | public OnClickListener getOnClickListener() {
22 | return onClickListener;
23 | }
24 |
25 | public void setOnClickListener(OnClickListener onClickListener) {
26 | this.onClickListener = onClickListener;
27 | }
28 |
29 |
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/servlet-file-upload/src/main/webapp/css/dropzone.css:
--------------------------------------------------------------------------------
1 | #dropzone {
2 | background: #ccccc;
3 | width: 150px;
4 | height: 50px;
5 | line-height: 50px;
6 | text-align: center;
7 | font-weight: bold;
8 | }
9 | #dropzone.in {
10 | width: 600px;
11 | height: 200px;
12 | line-height: 200px;
13 | font-size: larger;
14 | }
15 | #dropzone.hover {
16 | background: lawngreen;
17 | }
18 | #dropzone.fade {
19 | -webkit-transition: all 0.3s ease-out;
20 | -moz-transition: all 0.3s ease-out;
21 | -ms-transition: all 0.3s ease-out;
22 | -o-transition: all 0.3s ease-out;
23 | transition: all 0.3s ease-out;
24 | opacity: 1;
25 | }
--------------------------------------------------------------------------------
/xstream-java-xml/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/websocket-java-api/websocket-glassfish-server/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/itext-java-html-pdf/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | HTML to PDF
5 |
6 |
7 |
8 | HTML to PDF
9 |
10 | itext 7.1.9
11 | converting HTML to PDF
12 |
13 |
14 |
15 |
16 | | Title |
17 | iText - Java HTML to PDF |
18 |
19 |
20 | | URL |
21 | http://hmkcode.com/itext-html-to-pdf-using-java |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/MapSort/src/com/hmkcode/Test.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 |
4 | import java.util.HashMap;
5 | import java.util.Map;
6 |
7 | public class Test {
8 | public static void main(String[] args){
9 |
10 |
11 | Map map = new HashMap();
12 |
13 | //*value Class should implements the Comparable interface
14 | //*String implements Comparable by default.
15 |
16 | map.put("Z", "3");
17 | map.put("D", "4");
18 | map.put("A", "1");
19 | map.put("B", "2");
20 | map.put("F", "6");
21 | map.put("E", "5");
22 |
23 | System.out.println("Unsorted Map: "+map);
24 | System.out.println("Sorted Map By Values: "+MapSort.sortByValue(map));
25 | System.out.println("Sorted Map By Keys: "+MapSort.sortByKey(map));
26 |
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/java-list-map/src/main/java/com/hmkcode/vo/Person.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.vo;
2 |
3 | public class Person implements Comparable {
4 |
5 | private int age;
6 | private String name;
7 |
8 | public Person(String name, int age){
9 | this.name = name;
10 | this.age = age;
11 | }
12 | public int getAge() {
13 | return age;
14 | }
15 | public void setAge(int age) {
16 | this.age = age;
17 | }
18 | public String getName() {
19 | return name;
20 | }
21 | public void setName(String name) {
22 | this.name = name;
23 | }
24 | @Override
25 | public String toString() {
26 | return "Person [age=" + age + ", name=" + name + "]";
27 | }
28 | @Override
29 | public int compareTo(Person person) {
30 | return this.age-person.getAge();
31 | }
32 |
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/jackson-json-java/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/mybatis-insert-generatedkey/src/main/java/com/hmkcode/spring/mybatis/service/Service.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.spring.mybatis.service;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 |
7 | import com.hmkcode.spring.mybatis.mapper.Mapper;
8 | import com.hmkcode.spring.mybatis.vo.MyObject;
9 |
10 |
11 |
12 | public class Service {
13 |
14 | @Autowired
15 | private Mapper mapper;
16 |
17 | public int insertMyObject(MyObject myObject){
18 | return mapper.insertMyObject(myObject);
19 | }
20 |
21 | public int insertMyObject_Annotation(MyObject myObject){
22 | return mapper.insertMyObject_Annotation(myObject);
23 | }
24 | public List selectAllMyObjects(){
25 | return mapper.selectAllMyObjects();
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/java-servlet-json/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/mybatis-insert-generatedkey/src/main/resources/com/hmkcode/spring/mybatis/mapper/Mapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | SELECT nextVal('my_sequence')
11 |
12 |
13 |
14 | INSERT INTO myobject_table (objectId,objectName)
15 | VALUES (#{objectId},#{objectName})
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/java-combinations/README.md:
--------------------------------------------------------------------------------
1 | Algorithms for Finding all Possible Combinations of k Elements in an Array with Java Implementation
2 | ===================================================================================================
3 |
4 | Refer to the [http://hmkcode.github.io/calculate-find-all-possible-combinations-of-an-array-using-java/](http://hmkcode.github.io/calculate-find-all-possible-combinations-of-an-array-using-java/) for more info.
5 |
6 | Given an array of size N e.g. `e={'A','B','C','D','E'}` **N=5**, we want to find all possible combinations of K elements in that array. For example, if K=3 then one possible combination is of array **e** is `{'A','B','C'}. Here we have three different algorithms for finding *k*-combinations of an array.
7 |
8 | 
9 |
--------------------------------------------------------------------------------
/gson-json-java/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.hmkcode
6 | gson-json-java
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 | gson-json-java
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | com.google.code.gson
20 | gson
21 | 2.2.4
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/itext-create-pdf/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.hmkcode
6 | itext-create-pdf
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 | itext-create-pdf
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | com.itextpdf
20 | itextpdf
21 | 5.4.2
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/mybatis-insert-generatedkey/src/main/java/com/hmkcode/spring/mybatis/vo/MyObject.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.spring.mybatis.vo;
2 |
3 | import org.apache.ibatis.type.Alias;
4 |
5 | //@Alias("MyObject") will be used by /src/resources/com/hmkcode/spring/mybatis/mybatis-config.xml
6 | @Alias("MyObject")
7 | public class MyObject {
8 |
9 | private int objectId;
10 | private String objectName;
11 |
12 | public int getObjectId() {
13 | return objectId;
14 | }
15 |
16 | public void setObjectId(int objectId) {
17 | this.objectId = objectId;
18 | }
19 |
20 | public String getObjectName() {
21 | return objectName;
22 | }
23 |
24 | public void setObjectName(String objectName) {
25 | this.objectName = objectName;
26 | }
27 |
28 | public String toString(){
29 | return "\n Object [ id: "+this.objectId+" - name: "+this.objectName+ "\n]";
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/xstream-java-xml/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.hmkcode
6 | xstream-java-xml
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 | xstream-java-xml
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | com.thoughtworks.xstream
20 | xstream
21 | 1.4.4
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/java-async-servlet/src/main/webapp/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Java Async Servlet
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | Java Async Servlet
20 |
21 |
22 |
23 |
24 | | Request ID |
25 | Response ID |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/simple-junit/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.hmkcode
6 | simple-junit
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 | simple-junit
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | junit
20 | junit
21 | 4.11
22 | test
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/castor-xml-object/mapping.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/java-list-map/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.hmkcode
6 | java-list-map
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 | java-list-map
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | junit
20 | junit
21 | 3.8.1
22 | test
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/junit-exception/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.hmkcode
6 | junit-exception
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 | junit-exception
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | junit
20 | junit
21 | 4.11
22 | test
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/servlet-file-upload/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 | Archetype Created Web Application
8 |
9 | index.html
10 |
11 |
12 |
13 | upload
14 | com.hmkcode.FileUploadServlet
15 |
16 |
17 | upload
18 | /upload
19 |
20 |
--------------------------------------------------------------------------------
/castor-xml-object/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/java-async-servlet/src/main/webapp/js/myfunctions.js:
--------------------------------------------------------------------------------
1 | function sendAsync(seq) {
2 | var data = new Object();
3 | data.seq = seq;
4 | $.ajax({
5 | url: "/async",
6 | type: 'GET',
7 | data: data,
8 |
9 | success: function (data) {
10 | $("#ares-"+data).text("reponse "+data);
11 | },
12 | error:function(data,status,er) {
13 | alert("error: "+data+" status: "+status+" er:"+er);
14 | }
15 | });
16 | }
17 |
18 |
19 | $(document).ready(function(){
20 | $("#start").click(function(){
21 |
22 | $("tr:has(td)").remove();
23 |
24 | for(i = 1 ; i < 5 ; i++){
25 | $("#asyncResponse").append($('
')
26 | .append($(' | ').text("request -"+i))
27 | .append($(" | ").text("processing.."))
28 | );
29 | sendAsync(i);
30 | }
31 | });
32 |
33 |
34 | $("#exit").click(function(){
35 | sendAsync("exit");
36 | });
37 | })
38 |
--------------------------------------------------------------------------------
/castor-xml-object/article.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Java
4 | Java
5 | Castor
6 | XML
7 | Marshalling
8 | Unmarshalling
9 | http://hmkcode.com/castor-java-object-xml
10 | Castor - Java Object to XML & XML to Object Mapping
11 |
--------------------------------------------------------------------------------
/webservlet-annotation/src/main/java/com/hmkcode/MyServlet.java:
--------------------------------------------------------------------------------
1 |
2 | package com.hmkcode;
3 |
4 | import java.io.IOException;
5 | import java.io.PrintWriter;
6 |
7 | import javax.servlet.annotation.WebServlet;
8 | import javax.servlet.http.HttpServlet;
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 |
12 |
13 | @WebServlet(urlPatterns = {"/servlet"})
14 | public class MyServlet extends HttpServlet {
15 |
16 |
17 | private static final long serialVersionUID = 1L;
18 |
19 | @Override
20 | protected void doGet(HttpServletRequest request, HttpServletResponse response) {
21 | response.setContentType("text/html;charset=UTF-8");
22 | try{
23 | PrintWriter out = response.getWriter();
24 | out.println("Hello @WebServlet
");
25 | } catch (IOException ioe) {
26 |
27 | }
28 | }
29 |
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/webservlet-annotation/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 | webservlet-annotation
9 |
10 | index.jsp
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/java-spi/java-spi-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | 4.0.0
6 |
7 | com.hmkcode.api
8 | java-spi-api
9 | 1.0-SNAPSHOT
10 |
11 | java-spi-api
12 |
13 | http://www.example.com
14 |
15 |
16 | UTF-8
17 | 1.7
18 | 1.7
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/websocket-java-api/websocket-app-client/src/main/java/com/hmkcode/MyClient.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.io.IOException;
4 | import javax.websocket.ClientEndpoint;
5 | import javax.websocket.OnError;
6 | import javax.websocket.OnMessage;
7 | import javax.websocket.OnOpen;
8 | import javax.websocket.Session;
9 |
10 | @ClientEndpoint
11 | public class MyClient {
12 | @OnOpen
13 | public void onOpen(Session session) {
14 | System.out.println("Connected to endpoint: " + session.getBasicRemote());
15 | try {
16 | session.getBasicRemote().sendText("Hello");
17 | } catch (IOException ex) {
18 | }
19 | }
20 |
21 | @OnMessage
22 | public void onMessage(String message) {
23 | System.out.println(message);
24 | }
25 |
26 | @OnError
27 | public void onError(Throwable t) {
28 | t.printStackTrace();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/itext-java-html-pdf/src/main/java/com/hmkcode/App.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.io.FileInputStream;
4 | import java.io.FileNotFoundException;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 |
8 | import com.itextpdf.html2pdf.HtmlConverter;
9 |
10 | public class App
11 | {
12 | public static final String HTML = "Hello
"
13 | + "This was created using iText
"
14 | + "hmkcode.com";
15 |
16 |
17 | public static void main( String[] args ) throws FileNotFoundException, IOException
18 | {
19 |
20 | // String to PDF
21 | HtmlConverter.convertToPdf(HTML, new FileOutputStream("string-to-pdf.pdf"));
22 |
23 |
24 | // HTML file to PDF
25 | HtmlConverter.convertToPdf(new FileInputStream("index.html"),
26 | new FileOutputStream("index-to-pdf.pdf"));
27 |
28 |
29 | System.out.println( "PDF Created!" );
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/java-excel-poi/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.hmkcode
6 | java-excel-poi
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 | java-excel-poi
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | org.apache.poi
20 | poi
21 | 3.9
22 |
23 |
24 | org.apache.poi
25 | poi-ooxml
26 | 3.9
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/mybatis-insert-generatedkey/src/main/java/com/hmkcode/spring/mybatis/mapper/Mapper.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.spring.mybatis.mapper;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.ibatis.annotations.Insert;
6 | import org.apache.ibatis.annotations.Select;
7 | import org.apache.ibatis.annotations.SelectKey;
8 |
9 | import com.hmkcode.spring.mybatis.vo.MyObject;
10 |
11 |
12 | public interface Mapper {
13 |
14 | //if @Select is used table.column (name) & class.property (name) should be the same
15 |
16 |
17 | @Select("SELECT * FROM myobject_table")
18 | public List selectAllMyObjects();
19 |
20 |
21 | //SQL query in "Mapper.xml"
22 | public int insertMyObject(MyObject myObject);
23 |
24 | @Insert("INSERT INTO myobject_table (objectId,objectName) VALUES (#{objectId}, #{objectName})")
25 | @SelectKey(statement="SELECT nextVal('my_sequence')", keyProperty="objectId", before=true, resultType=int.class)
26 | int insertMyObject_Annotation(MyObject myObject);
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/itext-java-pdf-table/src/main/java/com/hmkcode/App.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.io.FileNotFoundException;
4 | import java.io.FileOutputStream;
5 |
6 | import com.itextpdf.text.Document;
7 | import com.itextpdf.text.DocumentException;
8 | import com.itextpdf.text.PageSize;
9 | import com.itextpdf.text.pdf.PdfWriter;
10 |
11 |
12 | public class App
13 | {
14 | public static void main( String[] args ) throws FileNotFoundException, DocumentException
15 | {
16 | // step 1
17 | Document document = new Document();
18 | document.setPageSize(PageSize.A4);
19 |
20 | // step 2
21 | PdfWriter.getInstance(document, new FileOutputStream("pdf.pdf"));
22 |
23 | // step 3
24 | document.open();
25 |
26 | // step 4 create PDF contents
27 | document.add(TableBuilder.createTable());
28 |
29 | //step 5
30 | document.close();
31 |
32 | System.out.println( "PDF Created!" );
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/itext-java-pdf-table/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.hmkcode
6 | itext-java-pdf-table
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 | itext-java-pdf-table
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | com.itextpdf
20 | itextpdf
21 | 5.4.2
22 |
23 |
24 | com.itextpdf.tool
25 | xmlworker
26 | 5.4.1
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/java-inputstream-string/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.hmkcode
6 | java-inputstream-string
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 | java-inputstream-string
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | commons-io
20 | commons-io
21 | 2.4
22 |
23 |
24 | com.google.guava
25 | guava
26 | 14.0.1
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/castor-xml-object/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.hmkcode
6 | castor-xml-object
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 | castor-xml-object
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 |
20 | org.codehaus.castor
21 | castor
22 | 1.2
23 |
24 |
25 | xerces
26 | xercesImpl
27 | 2.8.1
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/itext-java-html-pdf/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.hmkcode
6 | itext-java-html-pdf
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 | itext-java-html-pdf
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 | RELEASE
16 |
17 |
18 |
19 |
20 | com.itextpdf
21 | itext7-core
22 | 7.1.9
23 | pom
24 |
25 |
26 | com.itextpdf
27 | html2pdf
28 | 2.1.6
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/servlet-file-upload/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/java-jasper/src/main/java/com/hmkcode/Country.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | public class Country {
4 |
5 | private String code;
6 | private String name;
7 | private String url;
8 |
9 | public Country(String code, String name, String url) {
10 | this.code = code;
11 | this.name = name;
12 | this.url = url;
13 | }
14 |
15 | public String getCode() {
16 | return code;
17 | }
18 |
19 | public void setCode(String code) {
20 | this.code = code;
21 | }
22 |
23 | public String getName() {
24 | return name;
25 | }
26 |
27 | public void setName(String name) {
28 | this.name = name;
29 | }
30 |
31 | public String getUrl() {
32 | return url;
33 | }
34 |
35 | public void setUrl(String url) {
36 | this.url = url;
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return "Country{" +
42 | "code='" + code + '\'' +
43 | ", name='" + name + '\'' +
44 | ", url='" + url + '\'' +
45 | '}';
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/itext-create-pdf/src/main/java/com/hmkcode/HelloWorld.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.io.FileNotFoundException;
4 | import java.io.FileOutputStream;
5 |
6 | import com.itextpdf.text.Document;
7 | import com.itextpdf.text.DocumentException;
8 | import com.itextpdf.text.Paragraph;
9 | import com.itextpdf.text.pdf.PdfWriter;
10 |
11 |
12 | public class HelloWorld
13 | {
14 | public static void main( String[] args )
15 | {
16 | try {
17 |
18 | // 1. create the document
19 | Document document = new Document();
20 | // 2. get PdfWriter
21 | PdfWriter.getInstance(document, new FileOutputStream("helloworld.pdf"));
22 | // 3. open the document
23 | document.open();
24 | // 4. add the content
25 | document.add(new Paragraph("Hello World!"));
26 | // 5. close the document
27 | document.close();
28 |
29 | System.out.println("Document created!");
30 |
31 | } catch (FileNotFoundException e) {
32 | e.printStackTrace();
33 | } catch (DocumentException e) {
34 | e.printStackTrace();
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/java-lambda/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | 4.0.0
6 |
7 | com.hmkcode
8 | java-lambda
9 | 1.0-SNAPSHOT
10 |
11 | java-lambda
12 |
13 |
14 |
15 |
16 | maven-compiler-plugin
17 | 3.8.0
18 |
19 | 1.8
20 | 1.8
21 |
22 |
23 |
24 | org.codehaus.mojo
25 | exec-maven-plugin
26 | 1.6.0
27 |
28 | com.hmkcode.App
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/java-combinations/src/main/java/com/hmkcode/Recursive.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | public class Recursive {
7 |
8 | public static void main(String[] args) {
9 |
10 | List e = Arrays.asList("A", "B", "C", "D", "E");
11 | int k = 3;
12 | combination(e, k, "");
13 |
14 | }
15 | static int counter = 0;
16 | public static void combination(List e, int k, String accumulated){
17 |
18 | // 1. stop
19 | if(e.size() < k)
20 | return;
21 |
22 | // 2. add each element in e to accumulated
23 | if(k == 1)
24 | for(String s:e)
25 | print(accumulated+s);
26 |
27 | // 3. add all elements in e to accumulated
28 | else if(e.size() == k){
29 | for(String s:e)
30 | accumulated+=s;
31 | print(accumulated);
32 | }
33 |
34 | // 4. for each element, call combination
35 | else if(e.size() > k)
36 | for(int i = 0 ; i < e.size() ; i++)
37 | combination(e.subList(i+1, e.size()), k-1, accumulated+e.get(i));
38 |
39 | }
40 |
41 | public static void print(String c){
42 | counter++;
43 | System.out.println(counter+"\t"+c);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/java-async-servlet/src/main/java/com/hmkcode/SyncServlet.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.io.IOException;
4 | import javax.servlet.ServletException;
5 | import javax.servlet.annotation.WebServlet;
6 | import javax.servlet.http.HttpServlet;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 |
10 |
11 | @WebServlet(name="syncServlet",value = {"/sync"})
12 | public class SyncServlet extends HttpServlet
13 | {
14 | public static int index = 0;
15 |
16 | public SyncServlet(){
17 | System.out.println("SyncServlet - "+index++);
18 | }
19 |
20 | private static final long serialVersionUID = 1L;
21 |
22 | @Override
23 | protected void doGet(HttpServletRequest req, HttpServletResponse resp)
24 | throws ServletException, IOException {
25 |
26 |
27 | String seq = req.getParameter("seq");
28 |
29 | try {
30 | Thread.sleep(50 * Integer.parseInt(seq));
31 | } catch (NumberFormatException e) {
32 | e.printStackTrace();
33 | } catch (InterruptedException e) {
34 | e.printStackTrace();
35 | }
36 | resp.getWriter().write(seq);
37 |
38 |
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/java-spi/java-spi-impl1/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | 4.0.0
6 |
7 | com.hmkcode.impl
8 | java-spi-impl1
9 | 1.0-SNAPSHOT
10 |
11 | java-spi-impl1
12 |
13 | http://www.example.com
14 |
15 |
16 | UTF-8
17 | 1.7
18 | 1.7
19 |
20 |
21 |
22 |
23 | com.hmkcode.api
24 | java-spi-api
25 | 1.0-SNAPSHOT
26 | system
27 | ${project.basedir}/lib/java-spi-api-1.0-SNAPSHOT.jar
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/java-async-servlet/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.hmkcode
6 | java-async-servlet
7 | 1.0-SNAPSHOT
8 | war
9 |
10 | java-async-servlet
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | javax.servlet
20 | javax.servlet-api
21 | 3.1.0
22 |
23 |
24 |
25 |
26 |
27 | java-async-servlet
28 |
29 |
30 | org.eclipse.jetty
31 | jetty-maven-plugin
32 | 9.0.0.M5
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/java-spi/java-spi-app/src/main/java/com/hmkcode/app/MyServiceLoader.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.app;
2 |
3 | import java.nio.file.ProviderNotFoundException;
4 | import java.util.Iterator;
5 | import java.util.ServiceLoader;
6 |
7 | import com.hmkcode.api.MyServiceProviderInterface;
8 |
9 |
10 | public class MyServiceLoader {
11 |
12 | private static final String DEFAULT_PROVIDER = "com.hmkcode.impl.MyServiceProviderImpl1";
13 |
14 | public static MyServiceProviderInterface defaultProvider() {
15 | return provider(DEFAULT_PROVIDER);
16 | }
17 |
18 | public static MyServiceProviderInterface provider(String providerName) {
19 | ServiceLoader loader = ServiceLoader.load(MyServiceProviderInterface.class);
20 |
21 | Iterator it = loader.iterator();
22 | while (it.hasNext()) {
23 | MyServiceProviderInterface provider = it.next();
24 | if (providerName.equals(provider.getClass().getName())) {
25 | return provider;
26 | }
27 | }
28 | throw new ProviderNotFoundException("provider " + providerName + " not found");
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/jackson-json-java/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.hmkcode
6 | jackson-json-java
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 | jackson-json-java
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | com.fasterxml.jackson.core
20 | jackson-core
21 | 2.2.2
22 |
23 |
24 | com.fasterxml.jackson.core
25 | jackson-databind
26 | 2.2.2
27 |
28 |
29 | com.fasterxml.jackson.core
30 | jackson-annotations
31 | 2.2.2
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/websocket-java-api/websocket-glassfish-server/src/main/webapp/index.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Java API for WebSocket (JSR-356)
7 |
8 |
9 |
10 |
11 |
12 |
13 |
Java API for WebSocket (JSR-356)
14 |
15 | Not Connected
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | | # |
25 | Sender |
26 | Message |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/java-lambda/src/main/java/com/hmkcode/App.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 |
4 | public class App implements OnClickListener
5 | {
6 | public static void main( String[] args ){
7 | System.out.println( "Running App..." );
8 | new App().run();
9 | }
10 |
11 | public void run(){
12 |
13 | Button myButton = new Button();
14 | myButton.setName("MyButton");
15 |
16 | // 1. implements onClickListener
17 | //myButton.setOnClickListener(this);
18 |
19 | // 2. anonymous class
20 | /*myButton.setOnClickListener(new OnClickListener() {
21 | @Override
22 | public void onClick(Button button) {
23 | System.out.println(button.getName() +" Clicked! - anonymous class");
24 | }
25 | }); */
26 |
27 | // 3. lambda
28 | OnClickListener lambda = button -> { System.out.println(button.getName()+" Clicked! - lambda"); } ;
29 | myButton.setOnClickListener(lambda);
30 |
31 |
32 | // click the button
33 | myButton.click();
34 | }
35 |
36 |
37 | @Override
38 | public void onClick(Button button) {
39 | System.out.println(button.getName() +" Clicked! - implements interface");
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/java-excel-poi/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/websocket-java-api/websocket-glassfish-server/src/main/java/com/hmkcode/MyServerEndpoint.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.io.IOException;
4 | import java.util.LinkedList;
5 | import javax.websocket.EncodeException;
6 | import javax.websocket.OnClose;
7 | import javax.websocket.OnMessage;
8 | import javax.websocket.OnOpen;
9 | import javax.websocket.Session;
10 | import javax.websocket.server.PathParam;
11 | import javax.websocket.server.ServerEndpoint;
12 |
13 | @ServerEndpoint(value="/websocket/{client-id}")
14 | public class MyServerEndpoint {
15 |
16 | private static final LinkedList clients = new LinkedList();
17 |
18 | @OnOpen
19 | public void onOpen(Session session) {
20 | clients.add(session);
21 | }
22 | @OnMessage
23 | public void onMessage(String message,@PathParam("client-id") String clientId) {
24 | for (Session client : clients) {
25 | try {
26 | client.getBasicRemote().sendObject(clientId+": "+message);
27 |
28 | } catch (IOException e) {
29 | e.printStackTrace();
30 | } catch (EncodeException e) {
31 | e.printStackTrace();
32 | }
33 | }
34 | }
35 | @OnClose
36 | public void onClose(Session peer) {
37 | clients.remove(peer);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/java-jasper/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | 4.0.0
6 |
7 | com.hmkcode
8 | java-jasper
9 | 1.0-SNAPSHOT
10 |
11 | java-jasper
12 |
13 | http://www.example.com
14 |
15 |
16 | UTF-8
17 | 1.7
18 | 1.7
19 |
20 |
21 |
22 |
23 | net.sf.jasperreports
24 | jasperreports
25 | 6.10.0
26 |
27 |
28 |
29 |
30 | org.springframework
31 | spring-core
32 | 5.2.3.RELEASE
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/java-simple-text-file-reader/src/main/java/com/hmkcode/TextFileReader.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.FileNotFoundException;
5 | import java.io.FileReader;
6 | import java.io.IOException;
7 |
8 | public class TextFileReader {
9 |
10 | private BufferedReader buffer;
11 | private String currentLine = "";
12 | public TextFileReader(){
13 |
14 | }
15 |
16 | public void open(String file){
17 |
18 | try {
19 | close();
20 |
21 | buffer = new BufferedReader(new FileReader(file));
22 |
23 | } catch (FileNotFoundException e1) {
24 | e1.printStackTrace();
25 |
26 | }
27 |
28 | }
29 |
30 | public void close(){
31 |
32 | try {
33 | if(buffer != null){
34 | buffer.close();
35 | buffer = null;
36 | }
37 | } catch (IOException e) {
38 | e.printStackTrace();
39 | }
40 |
41 | }
42 |
43 | public String readLine() throws Exception{
44 | if(buffer != null){
45 | currentLine = buffer.readLine();
46 |
47 | if(currentLine == null)
48 | close();
49 |
50 | return currentLine;
51 | }
52 | else
53 | throw new Exception("No file to read...");
54 | }
55 |
56 | public String getCurrent(){
57 | return this.currentLine;
58 | }
59 |
60 | public boolean isReadable(){
61 | return (buffer != null && this.currentLine != null);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/java-inputstream-string/src/main/java/com/hmkcode/App.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 |
7 | public class App
8 | {
9 | public static void main( String[] args ) throws IOException
10 | {
11 |
12 | // 1. By java.util.Scanner
13 | InputStream inputStream = new ByteArrayInputStream("hmkcode..inputStream to String".getBytes());
14 | System.out.println("getStringByScanner: "+InputStreamToString.getStringByScanner(inputStream));
15 |
16 | // 2. By BufferedReader
17 | inputStream = new ByteArrayInputStream("hmkcode..inputStream to String".getBytes());
18 | System.out.println("getStringByBufferedReader: " +InputStreamToString.getStringByBufferedReader(inputStream));
19 |
20 | // 3. By Apache IO
21 | inputStream = new ByteArrayInputStream("hmkcode..inputStream to String".getBytes());
22 | System.out.println("getStringByApacheIO IOUtils.toString: "+InputStreamToString.getStringByApacheIO_toString(inputStream));
23 |
24 | // 4. By Apache IO
25 | inputStream = new ByteArrayInputStream("hmkcode..inputStream to String".getBytes());
26 | System.out.println("getStringByApacheIO IOUtils.copy: "+InputStreamToString.getStringByApacheIO_copy(inputStream));
27 |
28 |
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/websocket-java-api/websocket-glassfish-server/src/main/webapp/websocket.js:
--------------------------------------------------------------------------------
1 | var URL = "ws://localhost:8080/websocket-glassfish-server/websocket/web-client";
2 | var websocket;
3 |
4 | $(document).ready(function(){
5 | connect();
6 | });
7 |
8 | function connect(){
9 | websocket = new WebSocket(URL);
10 | websocket.onopen = function(evnt) { onOpen(evnt) };
11 | websocket.onmessage = function(evnt) { onMessage(evnt) };
12 | websocket.onerror = function(evnt) { onError(evnt) };
13 | }
14 | function sendMessage() {
15 | websocket.send($("#message").val());
16 | }
17 | function onOpen() {
18 | updateStatus("connected")
19 | }
20 | function onMessage(evnt) {
21 | if (typeof evnt.data == "string") {
22 |
23 | $("#received_messages").append(
24 | $('
')
25 | .append($(' | ').text("1"))
26 | .append($(' | ').text(evnt.data.substring(0,evnt.data.indexOf(":"))))
27 | .append($(' | ').text(evnt.data.substring(evnt.data.indexOf(":")+1))));
28 | }
29 | }
30 | function onError(evnt) {
31 | alert('ERROR: ' + evnt.data);
32 | }
33 | function updateStatus(status){
34 | if(status == "connected"){
35 | $("#status").removeClass (function (index, css) {
36 | return (css.match (/\blabel-\S+/g) || []).join(' ')
37 | });
38 | $("#status").text(status).addClass("label-success");
39 | }
40 | }
--------------------------------------------------------------------------------
/mybatis-insert-generatedkey/src/test/java/com/hmkcode/spring/mybatis/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.spring.mybatis;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.commons.logging.Log;
6 | import org.apache.commons.logging.LogFactory;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.test.context.ContextConfiguration;
11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12 |
13 | import com.hmkcode.spring.mybatis.service.Service;
14 | import com.hmkcode.spring.mybatis.vo.MyObject;
15 |
16 |
17 |
18 | import static org.junit.Assert.assertNotNull;
19 | import static org.junit.Assert.assertTrue;;
20 |
21 | /**
22 | * Unit test for simple App.
23 | */
24 |
25 | @RunWith(SpringJUnit4ClassRunner.class)
26 | @ContextConfiguration(locations = "/spring-config.xml")
27 | public class AppTest {
28 |
29 | private static Log log = LogFactory.getLog(AppTest.class);
30 |
31 | @Autowired private Service service;
32 |
33 |
34 | @Test
35 | public void testSelectAllMyObjects(){
36 | log.info("testing selectAllParent()...");
37 |
38 | List objects = service.selectAllMyObjects();
39 |
40 | assertNotNull("failure - object is null", objects);
41 |
42 | assertTrue("failure - expected 1 object", objects.size() == 1);
43 |
44 | log.info(objects);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/servlet-file-upload/src/main/webapp/js/myuploadfunction.js:
--------------------------------------------------------------------------------
1 | $(function () {
2 |
3 | $('#fileupload').fileupload({
4 |
5 | dataType: 'json',
6 |
7 | done: function (e, data) {
8 | $("tr:has(td)").remove();
9 | $.each(data.result, function (index, file) {
10 |
11 |
12 | $("#uploaded-files").append(
13 | $('
')
14 | .append($(' | ').text(file.fileName))
15 | .append($(' | ').text(file.fileSize))
16 | .append($(' | ').text(file.fileType))
17 | .append($(' | ').html("Click"))
18 | .append($(' | ').text("@"+file.twitter))
19 |
20 | )//end $("#uploaded-files").append()
21 | });
22 | },
23 |
24 | progressall: function (e, data) {
25 | var progress = parseInt(data.loaded / data.total * 100, 10);
26 | $('#progress .bar').css(
27 | 'width',
28 | progress + '%'
29 | );
30 | },
31 |
32 | dropZone: $('#dropzone')
33 | }).bind('fileuploadsubmit', function (e, data) {
34 | // The example input, doesn't have to be part of the upload form:
35 | var twitter = $('#twitter');
36 | data.formData = {twitter: twitter.val()};
37 | });
38 |
39 | });
--------------------------------------------------------------------------------
/castor-xml-object/src/main/java/com/hmkcode/vo/Article.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.vo;
2 |
3 | import java.util.LinkedList;
4 | import java.util.List;
5 |
6 | public class Article {
7 |
8 | private String title;
9 | private String url;
10 | private List categories;
11 | private List tags;
12 |
13 | public String getTitle() {
14 | return title;
15 | }
16 | public void setTitle(String title) {
17 | this.title = title;
18 | }
19 | public String getUrl() {
20 | return url;
21 | }
22 | public void setUrl(String url) {
23 | this.url = url;
24 | }
25 | public List getCategories() {
26 | return categories;
27 | }
28 | public void setCategories(List categories) {
29 | this.categories = categories;
30 | }
31 | public List getTags() {
32 | return tags;
33 | }
34 | public void setTags(List tags) {
35 | this.tags = tags;
36 | }
37 |
38 | public void addCategory(String category){
39 | if(this.categories == null)
40 | this.categories = new LinkedList();
41 | this.categories.add(category);
42 | }
43 | public void addTag(String tag){
44 | if(this.tags == null)
45 | this.tags = new LinkedList();
46 |
47 | this.tags.add(tag);
48 | }
49 | @Override
50 | public String toString() {
51 | return "Article [title=" + title + ", url=" + url + ", categories="
52 | + categories + ", tags=" + tags + "]";
53 | }
54 |
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/gson-json-java/src/main/java/com/hmkcode/vo/Article.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.vo;
2 |
3 | import java.util.LinkedList;
4 | import java.util.List;
5 |
6 | public class Article {
7 |
8 | private String title;
9 | private String url;
10 | private List categories;
11 | private List tags;
12 |
13 | public String getTitle() {
14 | return title;
15 | }
16 | public void setTitle(String title) {
17 | this.title = title;
18 | }
19 | public String getUrl() {
20 | return url;
21 | }
22 | public void setUrl(String url) {
23 | this.url = url;
24 | }
25 | public List getCategories() {
26 | return categories;
27 | }
28 | public void setCategories(List categories) {
29 | this.categories = categories;
30 | }
31 | public List getTags() {
32 | return tags;
33 | }
34 | public void setTags(List tags) {
35 | this.tags = tags;
36 | }
37 |
38 | public void addCategory(String category){
39 | if(this.categories == null)
40 | this.categories = new LinkedList();
41 | this.categories.add(category);
42 | }
43 | public void addTag(String tag){
44 | if(this.tags == null)
45 | this.tags = new LinkedList();
46 |
47 | this.tags.add(tag);
48 | }
49 | @Override
50 | public String toString() {
51 | return "Article [title=" + title + ", url=" + url + ", categories="
52 | + categories + ", tags=" + tags + "]";
53 | }
54 |
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/java-servlet-json/src/main/java/com/hmkcode/vo/Article.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.vo;
2 |
3 | import java.util.LinkedList;
4 | import java.util.List;
5 |
6 | public class Article {
7 |
8 | private String title;
9 | private String url;
10 | private List categories;
11 | private List tags;
12 |
13 | public String getTitle() {
14 | return title;
15 | }
16 | public void setTitle(String title) {
17 | this.title = title;
18 | }
19 | public String getUrl() {
20 | return url;
21 | }
22 | public void setUrl(String url) {
23 | this.url = url;
24 | }
25 | public List getCategories() {
26 | return categories;
27 | }
28 | public void setCategories(List categories) {
29 | this.categories = categories;
30 | }
31 | public List getTags() {
32 | return tags;
33 | }
34 | public void setTags(List tags) {
35 | this.tags = tags;
36 | }
37 |
38 | public void addCategory(String category){
39 | if(this.categories == null)
40 | this.categories = new LinkedList();
41 | this.categories.add(category);
42 | }
43 | public void addTag(String tag){
44 | if(this.tags == null)
45 | this.tags = new LinkedList();
46 |
47 | this.tags.add(tag);
48 | }
49 | @Override
50 | public String toString() {
51 | return "Article [title=" + title + ", url=" + url + ", categories="
52 | + categories + ", tags=" + tags + "]";
53 | }
54 |
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/itext-create-pdf/src/main/java/com/hmkcode/PageSettings.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.io.FileNotFoundException;
4 | import java.io.FileOutputStream;
5 |
6 | import com.itextpdf.text.Document;
7 | import com.itextpdf.text.DocumentException;
8 | import com.itextpdf.text.PageSize;
9 | import com.itextpdf.text.Paragraph;
10 | import com.itextpdf.text.Rectangle;
11 | import com.itextpdf.text.pdf.PdfWriter;
12 |
13 |
14 | public class PageSettings
15 | {
16 | public static void main( String[] args )
17 | {
18 | try {
19 |
20 | // 1. create the document page size: A4, margins: left:20 right:20 top:40 bottom:40
21 | Document document = new Document(PageSize.A4, 20f,20f,40f,40);
22 |
23 | //for custom pagesize
24 | //Rectangle pagesize = new Rectangle(216f, 720f);
25 |
26 | // 2. get PdfWriter
27 | PdfWriter.getInstance(document, new FileOutputStream("pagesettings.pdf"));
28 | // 3. open the document
29 | document.open();
30 | // 4. add the content
31 | document.add(new Paragraph("Hello World!"));
32 | // 5. close the document
33 | document.close();
34 |
35 | System.out.println("Document created!");
36 |
37 | } catch (FileNotFoundException e) {
38 | e.printStackTrace();
39 | } catch (DocumentException e) {
40 | e.printStackTrace();
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/servlet-file-upload/src/main/java/com/hmkcode/vo/FileMeta.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.vo;
2 |
3 | import java.io.InputStream;
4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5 |
6 |
7 | @JsonIgnoreProperties({"content"})
8 | public class FileMeta {
9 |
10 |
11 |
12 | private String fileName;
13 | private String fileSize;
14 | private String fileType;
15 | private String twitter;
16 |
17 |
18 | private InputStream content;
19 |
20 |
21 |
22 | public String getFileName() {
23 | return fileName;
24 | }
25 | public void setFileName(String fileName) {
26 | this.fileName = fileName;
27 | }
28 | public String getFileSize() {
29 | return fileSize;
30 | }
31 | public void setFileSize(String fileSize) {
32 | this.fileSize = fileSize;
33 | }
34 | public String getFileType() {
35 | return fileType;
36 | }
37 | public void setFileType(String fileType) {
38 | this.fileType = fileType;
39 | }
40 | public InputStream getContent(){
41 | return this.content;
42 | }
43 | public void setContent(InputStream content){
44 | this.content = content;
45 | }
46 | public String getTwitter(){
47 | return this.twitter;
48 | }
49 | public void setTwitter(String twitter){
50 | this.twitter = twitter;
51 | }
52 |
53 | @Override
54 | public String toString() {
55 | return "FileMeta [fileName=" + fileName + ", fileSize=" + fileSize
56 | + ", fileType=" + fileType + "]";
57 | }
58 |
59 |
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/webservlet-annotation/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 | 4.0.0
6 |
7 | com.hmkcode
8 | webservlet-annotation
9 | 1.0-SNAPSHOT
10 | war
11 |
12 | webservlet-annotation
13 |
14 |
15 |
16 |
17 | javax
18 | javaee-api
19 | 7.0-b82
20 | provided
21 |
22 |
23 |
24 |
25 |
26 |
27 | org.apache.maven.plugins
28 | maven-compiler-plugin
29 | 2.3.2
30 |
31 | 1.6
32 | 1.6
33 |
34 |
35 |
36 | org.eclipse.jetty
37 | jetty-maven-plugin
38 | 9.0.3.v20130506
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/java-inputstream-string/src/main/java/com/hmkcode/InputStreamToString.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.InputStreamReader;
7 | import java.io.StringWriter;
8 | import java.util.Scanner;
9 | import org.apache.commons.io.IOUtils;
10 |
11 | public class InputStreamToString {
12 |
13 | // 1. By java.util.Scanner
14 | public static String getStringByScanner(InputStream inputStream){
15 | return new Scanner(inputStream,"UTF-8").next();
16 | }
17 |
18 | // 2. By BufferedReader
19 | public static String getStringByBufferedReader(InputStream inputStream) throws IOException{
20 | BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
21 | String line = "";
22 | String result = "";
23 | while((line = bufferedReader.readLine()) != null)
24 | result += line;
25 | return result;
26 | }
27 |
28 | // 3. By Apache IO
29 | public static String getStringByApacheIO_toString(InputStream inputStream) throws IOException{
30 | return IOUtils.toString(inputStream);
31 | }
32 |
33 | // 4. By Apache IO
34 | public static String getStringByApacheIO_copy(InputStream inputStream) throws IOException{
35 | StringWriter writer = new StringWriter();
36 | IOUtils.copy(inputStream, writer, "UTF-8");
37 | return writer.toString();
38 | }
39 |
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/java-spi/java-spi-app/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | 4.0.0
6 |
7 | com.hmkcode.app
8 | java-spi-app
9 | 1.0-SNAPSHOT
10 |
11 | java-spi-app
12 |
13 | http://www.example.com
14 |
15 |
16 | UTF-8
17 | 1.7
18 | 1.7
19 |
20 |
21 |
22 |
23 |
24 | com.hmkcode.api
25 | java-spi-api
26 | 1.0-SNAPSHOT
27 | system
28 | ${project.basedir}/lib/java-spi-api-1.0-SNAPSHOT.jar
29 |
30 |
31 | com.hmkcode.impl
32 | java-spi-impl1
33 | 1.0-SNAPSHOT
34 | system
35 | ${project.basedir}/lib/java-spi-impl1-1.0-SNAPSHOT.jar
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/itext-java-html-pdf/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/websocket-java-api/websocket-glassfish-server/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 | com.hmkcode
6 | websocket-glassfish-server
7 | 1.0-SNAPSHOT
8 | war
9 | 4.0.0
10 | websocket-glassfish-server
11 |
12 |
13 |
14 | java.net-promoted
15 | https://maven.java.net/content/groups/promoted/
16 |
17 |
18 |
19 |
20 |
21 | javax
22 | javaee-api
23 | 7.0-b82
24 | provided
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.apache.maven.plugins
33 | maven-compiler-plugin
34 | 2.3.2
35 |
36 | 1.7
37 | 1.7
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/jackson-json-java/src/main/java/com/hmkcode/vo/Article.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.vo;
2 |
3 | import java.util.LinkedList;
4 | import java.util.List;
5 |
6 | import com.fasterxml.jackson.annotation.JsonIgnore;
7 | import com.fasterxml.jackson.annotation.JsonProperty;
8 |
9 | public class Article {
10 |
11 | private String title;
12 | //@JsonProperty("address")
13 | private String url;
14 | private List categories;
15 | //@JsonIgnore
16 | private List tags;
17 |
18 | public String getTitle() {
19 | return title;
20 | }
21 | public void setTitle(String title) {
22 | this.title = title;
23 | }
24 | public String getUrl() {
25 | return url;
26 | }
27 | public void setUrl(String url) {
28 | this.url = url;
29 | }
30 | public List getCategories() {
31 | return categories;
32 | }
33 | public void setCategories(List categories) {
34 | this.categories = categories;
35 | }
36 | public List getTags() {
37 | return tags;
38 | }
39 | public void setTags(List tags) {
40 | this.tags = tags;
41 | }
42 |
43 | public void addCategory(String category){
44 | if(this.categories == null)
45 | this.categories = new LinkedList();
46 | this.categories.add(category);
47 | }
48 | public void addTag(String tag){
49 | if(this.tags == null)
50 | this.tags = new LinkedList();
51 |
52 | this.tags.add(tag);
53 | }
54 | @Override
55 | public String toString() {
56 | return "Article [title=" + title + ", url=" + url + ", categories="
57 | + categories + ", tags=" + tags + "]";
58 | }
59 |
60 |
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/xstream-java-xml/src/main/java/com/hmkcode/App.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 |
4 | import com.hmkcode.vo.Article;
5 | import com.thoughtworks.xstream.XStream;
6 |
7 |
8 | public class App
9 | {
10 | public static void main( String[] args )
11 | {
12 |
13 | XStream xs = new XStream();
14 | xs.autodetectAnnotations(true);
15 |
16 | // -->
17 | //xs.alias("article", Article.class);
18 | // -->
19 | // xs.aliasField("address", Article.class, "url");
20 |
21 | // OBJECT --> XML
22 | String xml = xs.toXML(createArticle());
23 |
24 | System.out.println("OBJECT --> XML");
25 | System.out.println(xml);
26 |
27 | System.out.println("\n--------------------------------\n");
28 |
29 | // XML --> OBJECT
30 | Article article = (Article) xs.fromXML(xml);
31 |
32 | System.out.println("XML --> OBJECT");
33 | System.out.println(article);
34 | }
35 |
36 | private static Article createArticle(){
37 |
38 | Article article = new Article();
39 |
40 | article.setTitle("XStream - Java Object to XML & XML to Object Mapping");
41 | article.setUrl("http://hmkcode.com/xstream-java-object-xml");
42 | article.setPublished(true);
43 |
44 | article.addCategory("Java");
45 | article.addTag("Java");
46 | article.addTag("Xstream");
47 | article.addTag("XML");
48 | article.addTag("Marshalling");
49 | article.addTag("Unmarshalling");
50 |
51 | return article;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/gson-json-java/src/main/java/com/hmkcode/App.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.lang.reflect.Type;
4 | import java.util.LinkedList;
5 | import java.util.List;
6 |
7 | import com.google.gson.Gson;
8 | import com.google.gson.reflect.TypeToken;
9 | import com.hmkcode.vo.Article;
10 |
11 |
12 | public class App
13 | {
14 | public static void main( String[] args )
15 | {
16 | Gson gson = new Gson();
17 |
18 |
19 | List articles = new LinkedList();
20 |
21 | articles.add(createArticle());
22 | articles.add(createArticle());
23 |
24 | // Java --> JSON
25 | String json = gson.toJson(articles);
26 | System.out.println("toJson: "+json);
27 |
28 |
29 | // JSON --> Java
30 | List list = gson.fromJson(json, List.class);
31 | System.out.println("fromJson: "+list);
32 | System.out.println("Class Type: "+list.get(0).getClass());
33 |
34 | // JSON --> Java "Get the actual type"
35 | Type type = new TypeToken>(){}.getType();
36 | list = gson.fromJson(json, type);
37 | System.out.println("fromJson: "+list);
38 | System.out.println("Class Type: "+list.get(0).getClass());
39 |
40 |
41 | }
42 | private static Article createArticle(){
43 |
44 | Article article = new Article();
45 |
46 | article.setTitle("GSON - Java JSON Library");
47 | article.setUrl("http://hmkcode.com/gson-json-java");
48 | article.addCategory("Java");
49 | article.addTag("Java");
50 | article.addTag("GSON");
51 | article.addTag("JSON");
52 |
53 | return article;
54 | }
55 | }
--------------------------------------------------------------------------------
/websocket-java-api/websocket-app-client/src/main/java/com/hmkcode/App.java:
--------------------------------------------------------------------------------
1 |
2 | package com.hmkcode;
3 |
4 | import java.io.BufferedReader;
5 | import java.io.IOException;
6 | import java.io.InputStreamReader;
7 | import java.net.URI;
8 | import javax.websocket.ContainerProvider;
9 | import javax.websocket.DeploymentException;
10 | import javax.websocket.Session;
11 | import javax.websocket.WebSocketContainer;
12 |
13 | public class App {
14 |
15 | public Session session;
16 |
17 | protected void start()
18 | {
19 |
20 | WebSocketContainer container = ContainerProvider.getWebSocketContainer();
21 |
22 | String uri = "ws://localhost:8080/websocket-glassfish-server/websocket/desktop-client";
23 | System.out.println("Connecting to " + uri);
24 | try {
25 | session = container.connectToServer(MyClient.class, URI.create(uri));
26 | } catch (DeploymentException e) {
27 | e.printStackTrace();
28 | } catch (IOException e) {
29 | e.printStackTrace();
30 | }
31 |
32 | }
33 | public static void main(String args[]){
34 | App client = new App();
35 | client.start();
36 |
37 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
38 | String input = "";
39 | try {
40 | do{
41 | input = br.readLine();
42 | if(!input.equals("exit"))
43 | client.session.getBasicRemote().sendText(input);
44 |
45 | }while(!input.equals("exit"));
46 |
47 | } catch (IOException e) {
48 | // TODO Auto-generated catch block
49 | e.printStackTrace();
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/java-servlet-json/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.hmkcode
6 | java-servlet-json
7 | 1.0-SNAPSHOT
8 | war
9 |
10 | java-servlet-json
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | javax.servlet
20 | javax.servlet-api
21 | 3.1.0
22 | provided
23 |
24 |
25 |
26 |
27 | com.fasterxml.jackson.core
28 | jackson-core
29 | 2.9.6
30 |
31 |
32 | com.fasterxml.jackson.core
33 | jackson-databind
34 | 2.9.6
35 |
36 |
37 | com.fasterxml.jackson.core
38 | jackson-annotations
39 | 2.9.6
40 |
41 |
42 |
43 |
44 | java-servlet-json
45 |
46 |
47 | org.eclipse.jetty
48 | jetty-maven-plugin
49 | 9.4.11.v20180605
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/castor-xml-object/src/main/java/com/hmkcode/App.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.io.FileReader;
4 | import java.io.FileWriter;
5 | import java.io.IOException;
6 | import java.util.LinkedList;
7 |
8 | import org.exolab.castor.xml.MarshalException;
9 | import org.exolab.castor.xml.Marshaller;
10 | import org.exolab.castor.xml.Unmarshaller;
11 | import org.exolab.castor.xml.ValidationException;
12 |
13 | import com.hmkcode.vo.Article;
14 |
15 | public class App
16 | {
17 | public static void main( String[] args )
18 | {
19 |
20 | try {
21 |
22 | //( 1 ) OBJECT --> XML
23 | FileWriter writer = new FileWriter("article.xml");
24 | Marshaller.marshal(createArticle(), writer);
25 | writer.close();
26 |
27 |
28 | //( 2 ) XML --> OBJECT
29 | FileReader reader = new FileReader("article.xml");
30 | Article article = (Article) Unmarshaller.unmarshal(Article.class, reader);
31 |
32 | System.out.println(article);
33 |
34 |
35 | } catch (IOException e) {
36 | e.printStackTrace();
37 | } catch (MarshalException e) {
38 | e.printStackTrace();
39 | } catch (ValidationException e) {
40 | e.printStackTrace();
41 | }
42 |
43 | }
44 |
45 | public static Article createArticle(){
46 | Article article = new Article();
47 |
48 | article.setTitle("Castor - Java Object to XML & XML to Object Mapping");
49 | article.setUrl("http://hmkcode.com/castor-java-object-xml");
50 | article.addCategory("Java");
51 | article.addTag("Java");
52 | article.addTag("Castor");
53 | article.addTag("XML");
54 | article.addTag("Marshalling");
55 | article.addTag("Unmarshalling");
56 |
57 | return article;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/simple-junit/src/test/java/com/hmkcode/junit/MathTest.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode.junit;
2 |
3 | import static org.junit.Assert.assertThat;
4 |
5 | import org.junit.Rule;
6 | import org.junit.Test;
7 | import org.junit.Ignore;
8 | import org.junit.rules.Timeout;
9 | import org.junit.runner.RunWith;
10 | import org.junit.runners.JUnit4;
11 | import static org.hamcrest.CoreMatchers.not;
12 | import static org.hamcrest.CoreMatchers.is;
13 |
14 |
15 | /**
16 | * Tests for {@link Math}.
17 | *
18 | * @author hmkcode@gmail.com (Hani HMK)
19 | */
20 | @RunWith(JUnit4.class)
21 | public class MathTest {
22 |
23 | @Rule
24 | public Timeout globalTimeout = new Timeout(3000); // 3 seconds max per method tested
25 |
26 |
27 | com.hmkcode.junit.Math math = new com.hmkcode.junit.Math();
28 |
29 |
30 | @Test
31 | @Ignore
32 | public void testAssertNotNull() {
33 | org.junit.Assert.assertNotNull("should not be null", math);
34 | }
35 |
36 | @Test
37 | public void testSum(){
38 | org.junit.Assert.assertTrue("failure - not equal", math.sum(3, 2) == 5);
39 |
40 | //to test timeout
41 | /*for (;;) {
42 | }*/
43 | }
44 |
45 | @Test
46 | public void testMultiply(){
47 | org.junit.Assert.assertTrue("failure - not equal", math.multiply(3, 2) == 6);
48 | }
49 |
50 | @Test
51 | public void testDivide(){
52 | double x = 3,y = 2;
53 | assertThat("failure - can't divide by 0",y, is(not(0.0)));
54 | org.junit.Assert.assertTrue("failure - not equal", math.divide(x, y) == 1.5);
55 | }
56 |
57 | @Test
58 | public void testSubtract(){
59 | org.junit.Assert.assertTrue("failure - not equal", math.subtract(3, 2) == 1);
60 | }
61 |
62 |
63 | }
--------------------------------------------------------------------------------
/servlet-file-upload/src/main/webapp/css/style.css:
--------------------------------------------------------------------------------
1 | #header{
2 | height:95px;
3 | min-width:720px;
4 | border-bottom:1px #E5E5E5 solid;
5 | /*background-color:#F1F1F1; */
6 | background:white url('../img/tech-stack.jpg') repeat-x;
7 | margin-left:180px;
8 |
9 | }
10 | #site-title-content{
11 | background-color:#333;
12 | display:inline-block;
13 | float:left;
14 | width:180px;
15 | height:76px;
16 | padding:0px;
17 | padding-top:20px;
18 |
19 | }
20 | #site-title-content:hover{
21 | background-color:#333;
22 |
23 | }
24 |
25 | h2.latest-post-title{
26 | font-family: 'Didact Gothic', sans-serif;
27 | }
28 |
29 | h3.site-header {
30 | margin:0;
31 | padding:0;
32 | text-align:center;
33 |
34 |
35 | }
36 | h3.site-header a{
37 | color:#fff;
38 | text-decoration: none;
39 |
40 | }
41 | h3.site-header a:hover {
42 | color: rgb(33, 117, 155);
43 | text-decoration: none;
44 | }
45 |
46 | h4.site-description{
47 | font-weight: normal;
48 | font-size: 12px;
49 | line-height: 1.84615;
50 | color: #ccc;
51 | margin:0;
52 | padding:0;
53 | text-align:center;
54 | font-family: "Open Sans",Helvetica,Arial,sans-serif;
55 | }
56 | .social-button{
57 | padding:10px;
58 | text-align:right;
59 | border-bottom:1px solid rgb(235, 235, 235);
60 | background:rgb(242, 242, 242);
61 | }
62 | .icon img{
63 | width: 32px;
64 | }
65 | #icon-bar{
66 | height:40px;
67 | }
68 | .tech-icons {
69 | padding:5px;
70 | border-bottom:1px solid rgb(235, 235, 235);
71 | text-align:center;
72 | }
73 | .tech-icons span{
74 | padding:2px;
75 | display:inline-block;
76 | width:110px;
77 | border:1px rgb(235, 235, 235) solid;
78 | border-radius:15px;
79 | }
80 | .tech-icons span:hover{
81 |
82 | border:1px rgb(33, 117, 155) solid;
83 | cursor:pointer;
84 | }
--------------------------------------------------------------------------------
/java-servlet-json/src/main/webapp/js/myfunctions.js:
--------------------------------------------------------------------------------
1 | function sendAjax() {
2 |
3 | // get inputs
4 | var article = new Object();
5 | article.title = $('#title').val();
6 | article.url = $('#url').val();
7 | article.categories = $('#categories').val().split(";");
8 | article.tags = $('#tags').val().split(";");
9 |
10 | $.ajax({
11 | url: "jsonservlet",
12 | type: 'POST',
13 | dataType: 'json',
14 | data: JSON.stringify(article),
15 | contentType: 'application/json',
16 | mimeType: 'application/json',
17 |
18 | success: function (data) {
19 | $("tr:has(td)").remove();
20 |
21 | $.each(data, function (index, article) {
22 |
23 | var td_categories = $(" | ");
24 | $.each(article.categories, function (i, tag) {
25 | var span = $("");
26 | span.text(tag);
27 | td_categories.append(span);
28 | });
29 |
30 | var td_tags = $(" | ");
31 | $.each(article.tags, function (i, tag) {
32 | var span = $("");
33 | span.text(tag);
34 | td_tags.append(span);
35 | });
36 |
37 | $("#added-articles").append($('
')
38 | .append($(' | ').html(""+article.title+""))
39 | .append(td_categories)
40 | .append(td_tags)
41 | );
42 |
43 |
44 | });
45 | },
46 | error:function(data,status,er) {
47 | alert("error: "+data+" status: "+status+" er:"+er);
48 | }
49 | });
50 | }
--------------------------------------------------------------------------------
/junit-exception/src/test/java/com/hmkcode/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.hmkcode;
2 |
3 | import java.util.LinkedList;
4 |
5 | import org.junit.Rule;
6 | import org.junit.Test;
7 | import org.junit.rules.ExpectedException;
8 | import org.junit.runner.RunWith;
9 | import org.junit.runners.JUnit4;
10 |
11 | import static org.junit.Assert.assertThat;
12 | import static org.junit.Assert.fail;
13 | import static org.hamcrest.CoreMatchers.is;
14 |
15 |
16 |
17 | @RunWith(JUnit4.class)
18 | public class AppTest
19 | {
20 |
21 | // ( 1 ) Simple way to test exception
22 | @Test(expected= NullPointerException.class)
23 | public void testNull() {
24 | String str = null;
25 | str.toUpperCase();
26 | }
27 |
28 | // ( 2 ) Test by tyr/catch (test exception message)
29 | @Test
30 | public void testExceptionMessage(){
31 | try{
32 | new LinkedList