Friday, December 29, 2017
Wednesday, December 27, 2017
Friday, December 22, 2017
Meet with Mercury1 geek person
Phil Haigh - Founder
Climber. Coder. Chief-geek.
A few facts:
- Phil loves solving complex problems. Even as a kid he was competing in international chess competitions.
- Graduated from Leicester with a degree in Physics and Space Science in 2000 (our own Rocket Scientist!).
- Initially worked for an IT consultancy and was then poached into the mobile industry where he became a lead architect for a company who was a leader in the launch of 3G mobile.
- He left the world of big business to escape his dislike of fluorescent strip lights and corporate politics.
- He's not a typical geek. He loves being outside rock climbing and is pretty good at most sports (except golf!).
- Mostly though he’s a really nice, honest guy who believes it’s important to be the best you can be.
Find out more:
Natalie Haigh - Director
Creative, gregarious techie. They exist!
A few facts:
- Natalie enthusiastically facilitates solutions to problems with a can do attitude.
- She is not afraid to make tough decisions, has the willingness to get stuck in and the intelligence to select the right things to focus on.
- She has experience of how many different businesses operate and likes to use this knowledge to help others.
- Her degree in Management and Information Systems at Royal Holloway lead her into the world of international IT consulting.
- Then at P&G she helped save over 1 million by implementing innovation projects.
- She says if you can take on a leadership role at a German manufacturing plant without speaking any German then you can do anything.
- Smart, friendly, innovative and helpful. She loves working with charities or worthy causes.
Find out more:
Thursday, December 21, 2017
Wednesday, December 20, 2017
KDiff3 best installation and configuration procedure for git in Windows/Ubuntu/MacOS
The installation procedure of KDiff3:
For Windows users:
Download from https://sourceforge.net/projects/kdiff3/ and then install
git config --global --add merge.tool kdiff3
git config --global --add mergetool.kdiff3.path "C:/Program Files/KDiff3/kdiff3.exe"
git config --global --add mergetool.kdiff3.trustExitCode false
git config --global --add diff.guitool kdiff3
git config --global --add difftool.kdiff3.path "C:/Program Files/KDiff3/kdiff3.exe"
git config --global --add difftool.kdiff3.trustExitCode false
For Ubuntu/Linux users: Installation:
sudo apt-get update
sudo apt-get install kdiff3
Then configure:
git config --global merge.tool kdiff3
git config --global mergetool.kdiff3.cmd "/usr/bin/kdiff3 --merge --result=\$MERGED \$LOCAL \$BASE \$REMOTE"
git config --global mergetool.keepBackup false
git config --global diff.tool kdiff3
git config --global difftool.kdiff3.cmd "/usr/bin/kdiff3 \$LOCAL \$REMOTE"
For MacOS users: Installation:
sudo apt-get update
sudo apt-get install kdiff3
Then configure,
git config --global merge.tool kdiff3Then run
git config --global mergetool.kdiff3.cmd "/Applications/kdiff3.app/Contents/MacOS/kdiff3 --merge --result=\$MERGED \$LOCAL \$BASE \$REMOTE"
git config --global mergetool.keepBackup false
git config --global diff.tool kdiff3
git config --global difftool.kdiff3.cmd "/Applications/kdiff3.app/Contents/MacOS/kdiff3 \$LOCAL \$REMOTE"
$ kdiff3or
$ git mergetoolor
$ git mergetool --tool=kdiff3
Tuesday, December 19, 2017
A Step by Step Guide for Learning Git without Pain
Git: Best Version Control System(VCS)
Why we use git?
- It can track changes in your files.
- It simplifies working on files and projects with multiple people(developers).
- It can help to get involved in open source.
Who are giving support and free repository service to keep your project?
- github: https://github.com/
- bitbucket: https://bitbucket.org/
- gitlab: https://about.gitlab.com/
Wednesday, December 13, 2017
How to export a local project to github repo?
Locally I have created a project and developed for few days. Now I want to add this project to my github arena.
Local Project Name: TestIt
Now I have to create a repo with same name. Please check the following:
Then go to my project directory and initialize like the following
HP@Al-Fateh MINGW64 /f/workspace/TestIt
$ git init
Initialized empty Git repository in F:/workspace/TestIt/.git/
HP@Al-Fateh MINGW64 /f/workspace/TestIt (master)
$ git remote add origin https://github.com/rizvi/TestIt
HP@Al-Fateh MINGW64 /f/workspace/TestIt (master)
$ git pull origin master
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/rizvi/TestIt
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
HP@Al-Fateh MINGW64 /f/workspace/TestIt (master)
$ git checkout -b br#201721 origin/master
Switched to a new branch 'br#201721'
Branch br#201721 set up to track remote branch master from origin.
HP@Al-Fateh MINGW64 /f/workspace/TestIt (br#201721)
$ git add .
HP@Al-Fateh MINGW64 /f/workspace/TestIt (br#201721)
$ git gui
Commit Message is also given here.
HP@Al-Fateh MINGW64 /f/workspace/TestIt (br#201721)
$ git push origin HEAD:br#201721
fatal: TaskCanceledException encountered.
A task was canceled.
Username for 'https://github.com': rizvi
Counting objects: 31, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (31/31), 5.08 KiB | 578.00 KiB/s, done.
Total 31 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), done.
To https://github.com/rizvi/TestIt
* [new branch] HEAD -> br#201721
HP@Al-Fateh MINGW64 /f/workspace/TestIt (br#201721)
Local Project Name: TestIt
Now I have to create a repo with same name. Please check the following:
Then go to my project directory and initialize like the following
HP@Al-Fateh MINGW64 /f/workspace/TestIt
$ git init
Initialized empty Git repository in F:/workspace/TestIt/.git/
HP@Al-Fateh MINGW64 /f/workspace/TestIt (master)
$ git remote add origin https://github.com/rizvi/TestIt
HP@Al-Fateh MINGW64 /f/workspace/TestIt (master)
$ git pull origin master
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/rizvi/TestIt
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
HP@Al-Fateh MINGW64 /f/workspace/TestIt (master)
$ git checkout -b br#201721 origin/master
Switched to a new branch 'br#201721'
Branch br#201721 set up to track remote branch master from origin.
HP@Al-Fateh MINGW64 /f/workspace/TestIt (br#201721)
$ git add .
HP@Al-Fateh MINGW64 /f/workspace/TestIt (br#201721)
$ git gui
Commit Message is also given here.
HP@Al-Fateh MINGW64 /f/workspace/TestIt (br#201721)
$ git push origin HEAD:br#201721
fatal: TaskCanceledException encountered.
A task was canceled.
Username for 'https://github.com': rizvi
Counting objects: 31, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (31/31), 5.08 KiB | 578.00 KiB/s, done.
Total 31 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), done.
To https://github.com/rizvi/TestIt
* [new branch] HEAD -> br#201721
HP@Al-Fateh MINGW64 /f/workspace/TestIt (br#201721)
Read a file from resources folder with getResource() for static and non-static context
Read a file from resources folder with getResource() for static and non-static context:
File Location:
src/main/resources
|--->mock-response/monga-response.json
Method implementation for non-static context:
public String readResponseFromFile(String fileName) throws URISyntaxException, IOException {
File inputFile = new File(this.getClass().getResource("/" + fileName).toURI());
return FileUtils.readFileToString(inputFile);
}
If you want to load a file from the resources folder from a static context you must use the class name.
Method Implementation for static context:
public static String readResponseFromFile(String fileName) throws URISyntaxException, IOException {
File inputFile = new File(MockingUtil.class.getClassLoader().getResource(fileName).getFile());
return FileUtils.readFileToString(inputFile);
}
Method Call:
dataFetcher.setHttpClient(MockingUtil.getMockHttpClient(MockingUtil.readResponseFromFile("mock-response/monga-response.json")));
Resource Link:
https://memorynotfound.com/load-file-resources-folder-java/
File Location:
src/main/resources
|--->mock-response/monga-response.json
Method implementation for non-static context:
public String readResponseFromFile(String fileName) throws URISyntaxException, IOException {
File inputFile = new File(this.getClass().getResource("/" + fileName).toURI());
return FileUtils.readFileToString(inputFile);
}
If you want to load a file from the resources folder from a static context you must use the class name.
Method Implementation for static context:
public static String readResponseFromFile(String fileName) throws URISyntaxException, IOException {
File inputFile = new File(MockingUtil.class.getClassLoader().getResource(fileName).getFile());
return FileUtils.readFileToString(inputFile);
}
Method Call:
dataFetcher.setHttpClient(MockingUtil.getMockHttpClient(MockingUtil.readResponseFromFile("mock-response/monga-response.json")));
Resource Link:
https://memorynotfound.com/load-file-resources-folder-java/
Tuesday, December 12, 2017
Why we use TestNG instead of JUnit?
Why we use TestNG instead of JUnit?
- The declaration of
@BeforeClass
and@AfterClass
method has to be static in JUnit whereas, there is more flexibility in TestNG in the method declaration, it does not have these constraints. - In TestNG, we can parametrize tests using 2 ways. @Parameter or @DataProvider annotation.i) @Parameter for simple cases, where key value mapping is required.(data is provided through xml file)ii) @DataProvider for complex cases. Using 2 dimensional array, It can provide data.
- In TestNG, since @DataProvider method need not be static, we can use multiple data provider methods in the same test class.
- Dependency Testing: In TestNG, if the initial test fails, then all subsequent dependent tests will be skipped, not marked as failed. But JUnit marked it failed.
- Grouping: Single tests can belong to multiple groups and then run in different contexts (like slow or fast tests). A similar feature exists in JUnit Categories but lacks the @BeforeGroups / @AfterGroups TestNG annotations that allow initializing the test / tearing it down.
- Parallelism: If you’d like to run the same test in parallel on multiple threads, TestNG has you covered with a simple to use annotation while JUnit doesn’t offer a simple way to do so out of the box.
- TestNG @DataProvider can also support XML for feeding in data, CSVs, or even plain text files.
- TestNG allows you to declare dependencies between tests, and skip them if the dependency test didn’t pass.
@Test(dependsOnMethods = { "dependOnSomething" })
This functionality doesn’t exist in JUnit
- Reporting:
TestNG reports are generated by default to a test-output folder that includes HTML reports with all of the test data, passed/failed/skipped, how long did they run, which input was used and the complete test logs. In addition, it also exports everything to an XML file which can be used to construct your own report template.
On the JUnit front, all of this data is also available via XML, but there’s no out of the box report and you need to rely on plugins.
Resource Link:
A good difference is given in this tutorial side by side: TestNG Vs JUnit: What's the Difference?
Friday, December 8, 2017
Thursday, December 7, 2017
Java8 Tutorial learning for beginner
https://www.callicoder.com/java-callable-and-future-tutorial/
https://github.com/callicoder/java-concurrency-examples
https://github.com/callicoder/algorhythm
Lambda Expression: Good Example is available here:
https://www.boraji.com/java-8-lambda-expression-hello-world-example
https://www.boraji.com/index.php/java-8-bifunction-interface-example
https://dzone.com/articles/java-8-definitive-guide
https://github.com/callicoder/java-concurrency-examples
https://github.com/callicoder/algorhythm
Lambda Expression: Good Example is available here:
https://www.boraji.com/java-8-lambda-expression-hello-world-example
https://www.boraji.com/index.php/java-8-bifunction-interface-example
https://dzone.com/articles/java-8-definitive-guide
Wednesday, December 6, 2017
Monday, December 4, 2017
Java Enterprise Edition(J2EE) Study Step by Step
First I believe that you know Java Standard Edition(SE) well. So I am trying to provide you some suggestions and tutorials for learning Java Enterprise Edition(J2EE).
So we can learn in 3 phases.
i) Basic Level
ii) Mid Level
iii) Standard Level
In Basic Level, we will learn JSP, Servlet and JSTL.
In Mid Level, we will learn Spring, Spring Boot
In Standard Level, we will do some project and learn design patterns
ii) For better understanding: http://tutorials.jenkov.com/java-servlets/index.html
iii) Koushik's JSP and Servlet video: http://freevideolectures.com/Course/3312/JSPs-and-Servlets/1
ii) Full tutorial with example: https://beginnersbook.com/jsp-tutorial-for-beginners/
ii) https://www.javatpoint.com/jstl
Spring Boot: https://www.youtube.com/watch?v=msXL2oDexqw&list=PLqq-6Pq4lTTbx8p2oCgcAQGQyqN8XeA1x
So we can learn in 3 phases.
i) Basic Level
ii) Mid Level
iii) Standard Level
In Basic Level, we will learn JSP, Servlet and JSTL.
In Mid Level, we will learn Spring, Spring Boot
In Standard Level, we will do some project and learn design patterns
For Basic Level,
we will try to give you some tutorials that may be video or website links with a full example.
1. For Servlet:
i) Full tutorial with example: https://beginnersbook.com/2013/05/servlet-tutorial/ii) For better understanding: http://tutorials.jenkov.com/java-servlets/index.html
iii) Koushik's JSP and Servlet video: http://freevideolectures.com/Course/3312/JSPs-and-Servlets/1
2. For JSP:
i) Full tutorial with example: https://www.guru99.com/jsp-tutorial.htmlii) Full tutorial with example: https://beginnersbook.com/jsp-tutorial-for-beginners/
3. For JSTL:
i) Full tutorial with example: https://beginnersbook.com/jsp-jstl-tutorial-jstl-functions-and-core-tags/ii) https://www.javatpoint.com/jstl
For Mid Level:
Spring: https://www.youtube.com/watch?v=GB8k2-Egfv0&list=PLC97BDEFDCDD169D7Spring Boot: https://www.youtube.com/watch?v=msXL2oDexqw&list=PLqq-6Pq4lTTbx8p2oCgcAQGQyqN8XeA1x
Sunday, December 3, 2017
Difference between Spring Data JPA's findFirst and findTop?
Limiting query results
The results of query methods can be limited via the keywords
first
or top
, which can be used interchangeably. An optional numeric value can be appended to top/first
to specify the maximum result size to be returned. If the number is left out, a result size of 1 is assumed.Limiting the result size of a query with Top and First
User findFirstByOrderByLastnameAsc();
User findTopByOrderByAgeDesc();
Page<User> queryFirst10ByLastname(String lastname, Pageable pageable);
Slice<User> findTop3ByLastname(String lastname, Pageable pageable);
List<User> findFirst10ByLastname(String lastname, Sort sort);
List<User> findTop10ByLastname(String lastname, Pageable pageable);
The limiting expressions also support the
Distinct
keyword. Also, for the queries limiting the result set to one instance, wrapping the result into an Optional is supported.Set vs List: When to use Set instead of List?
A Set cannot contain duplicate elements while a List can. A List (in Java) also implies order. Conceptually we usually refer to an unordered grouping that allows duplicates as a Bag and doesn't allow duplicates is a Set. List is used for the collection of elements with duplicates.
For more, you can go through this link: What is the difference between Set and List?
When to use List, Set and Map in Java?
1) If you do not want to have duplicate values in the database then Set should be your first choice as all of its classes do not allow duplicates.
2) If there is a need for frequent search operations based on the index values then List (ArrayList) is a better choice.
3) If there is a need of maintaining the insertion order then also the List is a preferred collection interface.
4) If the requirement is to have the key & value mappings in the database then Map is your best bet.
Resource Link: What is the use of set when we can use list?
What is the best way to communicate between doGet method and JSP page?
For Servlet section for doGet()
@WebServlet("/products")
public class ProductsServlet extends HttpServlet {
@EJB
private ProductService productService;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Product> products = productService.list();
request.setAttribute("products", products); // Will be available as ${products} in JSP
request.getRequestDispatcher("/WEB-INF/products.jsp").forward(request, response);
}
}
For JSP:
<table>
<c:forEach items="${products}" var="product">
<tr>
<td>${product.name}</td>
<td><a href="product?id=${product.id}">detail</a></td>
</tr>
</c:forEach>
</table>
Resource Link:
UPDATE1 for AJAX:
Returning Map as JSON
Here's another example which displays
Map<String, String>
as <option>
:@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Map<String, String> options = new LinkedHashMap<>();
options.put("value1", "label1");
options.put("value2", "label2");
options.put("value3", "label3");
String json = new Gson().toJson(options);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json);
}
And the JSP:
$(document).on("click", "#somebutton", function() { // When HTML DOM "click" event is invoked on element with ID "somebutton", execute the following function...
$.get("someservlet", function(responseJson) { // Execute Ajax GET request on URL of "someservlet" and execute the following function with Ajax response JSON...
var $select = $("#someselect"); // Locate HTML DOM element with ID "someselect".
$select.find("option").remove(); // Find all child elements with tag name "option" and remove them (just to prevent duplicate options when button is pressed again).
$.each(responseJson, function(key, value) { // Iterate over the JSON object.
$("<option>").val(key).text(value).appendTo($select); // Create HTML <option> element, set its value with currently iterated key and its text content with currently iterated item and finally append it to the <select>.
});
});
});
with
<select id="someselect"></select>
Resource Link:
Subscribe to:
Posts (Atom)