Thursday, August 3, 2017

How to Read XML in Java – (DOM Parser)

In this Example I will demonstrate how to read and modify xml file using DOM parser:

Step 1. Read an xml file from disk or project directory
Step 2. Build an xml document form the xml file
Step 3. Retrive and update xml element and attribute

Course.xml file

       


<?xml version="1.0" encoding="UTF-8"?>  
<courses>     
   <course category="JAVA">  
      <title lang="en">Learn Java in 3 Months.</title>  
      <trainer>Sonoo Jaiswal</trainer>  
      <year>2008</year>  
      <fees>10000.00</fees>  
   </course> 
    <course category="XML">  
      <title lang="en">Learn XML in 2 Months.</title>  
      <trainer>Ajeet Kumar</trainer>  
      <year>2015</year>  
      <fees>4000.00</fees>  
   </course>    
</courses> 
       
 




           import java.io.File;  
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException; 

/**
 * @author Md. Shariful Islam
 
*/
public class XMLDOMTester{

 /**
  * @param args
  */
 public static void main(String[] args) {
  
  //String filepath = "c:\\Course.xml"; 
  
  File xmlFile = new File("Course.xml");
  boolean exist = xmlFile.exists();
  System.out.println(exist);
  
  
  DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
  DocumentBuilder docBuilder;
  try {
   docBuilder = docFactory.newDocumentBuilder();
   Document xmlDocument = docBuilder.parse(xmlFile);
   
   //optional, but recommended
   //read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
   xmlDocument.getDocumentElement().normalize();
   
   String rootElement =  xmlDocument.getDocumentElement().getNodeName();
   System.out.println("Root element :" +rootElement);
   
   NodeList nList = xmlDocument.getDocumentElement().getChildNodes();
   
   for (int i = 0; i < nList.getLength(); i++) {
    
    Node node = nList.item(i);
    
    if (node.getNodeType() == node.ELEMENT_NODE) {
     
     String nodeName = node.getNodeName();
     System.out.println(nodeName);
     
    }
   }
   
   
   
  } catch (ParserConfigurationException | SAXException | IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  

       
 

For modifying XML file Please read the follwing blog

how-to-modify-xml-file-in-java-dom-parser


Friday, April 21, 2017

Basic linux commands

I this blog post i am going to write some basic Linux command that every Linux user should know :

but before digging in to the commands it is important that we know about the basic directory structure of Linux OS . following article has the details linux-directory-structure-explained


1. pwd2. ls3. cd4.cp5. rm6. mkdir7. rmdir8.clear9. man command10. Check current OS version 11. Check memory usage12. Create an empty file (touch command)13. Which (shows the installation path of a program or command)14. Search text in a file (grep command)15. Zip a directory16.UnZip a directory




1. pwd
The first command i am going to talk about is "pwd" . pwd command stand for "print working directory". so if i write pwd in a terminal and press enter it will show which directory i am currently located at.


As you can see i am currently located at centos directory which is insdse root home directory.

2. ls
The second command I want to show you is the  "ls" command. ls stand for list. 
as you can see above the "pwd" shows where i am currently in and the ls command shows what i have inside my current directory.

 

so as you can see , inside my current working directory  i have the following item Desktop, Documents, Downloads, Music, Pictures, Public, Templates and Videos.

3. cd
The next command I want to show is "cd" command . cd stands for change directory. cd is a navigational command. so let's i want to go to the "Downloads" folder. how do i do that ? i have use cd command . 




4.cp
cp stand for copy. I can use the cp command to copy file or directory and past it to another directory


5. rm
rm stands for remove. i can use rm command to remove an file or directory.

6. mkdir
mkdir stands for make directory. i can use the mkdir command to create a new directory.

7. rmdir
rmdir stands for remove directory. i can use the rmdir command to remove a directory. one thing to remember here is if we can something inside the directory I can not remove the directory using the rmdir command. i that case i have to use rm command 

rm -r mydirectory

8.clear
clear command clear the terminal screen.


9. man command
man stand for manuals

10. Check current OS version 
using the following two commands we can check current OS info .
$ uname -a

$ cat /etc/*release*

11. Check memory usage

The free command is the most simple and easy to use command to check memory usage on linux . Here is a quick example:

$ free -m
             total       used       free     shared    buffers     cached
Mem:          7976       6459       1517          0        865       2248
-/+ buffers/cache:       3344       4631
Swap:         1951          0       1951

The m option displays all data in MBs. The total os 7976 MB is the total amount of RAM installed on the system, that is 8GB. The used column shows the amount of RAM that has been used by linux, in this case around 6.4 GB. The output is pretty self explanatory. The catch over here is the cached and buffers column. The second line tells that 4.6 GB is free. This is the free memory in first line added with the buffers and cached amount of memory.

Linux has the habit of caching lots of things for faster performance, so that memory can be freed and used if needed.
The last line is the swap memory, which in this case is lying entirely free.

12. Create an empty file (touch command)

One easy way to create an empty file is with touch.
touch my_file_name.txt 

The above command will create a file with the name my_file_name.txt 

13. Which (shows the installation path of a program or command)

[centos@localost ~]$ which git
/usr/bin/git

The above command shows the installation location of git.

14. Search text in a file (grep command)

15. $ zip -r myfiles.zip mydir

16. unzip myzip.zip

$  grep "text_to_search" filename




More usefull command can be found here





Tuesday, March 7, 2017

Standard Operating Procedures (SOP)

Standard Operating Procedures (SOP)



Agile Standard Operating Procedures

1. Create product backlog with User Stories

2. Designate the following roles:
        Product Owner
        Scrum Master
        Team Members

3. Conduct Sprint Planning Meeting

4. Daily Scrum with available team members

5. Weekly Code Review meeting including
        Storytime to groom Pivotal Tracker
        Retrospective “Inspect & Adapt” for team

6. Weekly Sprint Review with product owner

7. Developer Best Practices
  • Every new idea => document user story => vote number of points
  • Only choose work from voted upon features or chores
  • Be accountable for delivering story. Pair program on a problem you can't solve on your own
  • Person submitting pull request is different from person approving the request
  • If you are pairing, ping pong code
  • If you are working on a feature that does not need a pull request, when finished with tasks/chores:
               Check off each task finished in Pivotal Tracker as soon as completed.
                Mark feature finished when ALL TASKS it contains are finished.
               Team will check work at next scrum mtng.


http://www.agileventures.org/projects/codealia/documents/standard-operating-procedures-sop

Tag a user in Jira

I want to tag a user in Jira how can i do that ?



You can tag a user in Jira using "@" sign. but in order to do that you need to have "Browse User" Permission in the "Global Permissions"




So if you are unable to tag a user in jira or confluence ask the jira admin to allow the "Browse User" permission for you !

Friday, February 24, 2017

StarUML


StarUML is an open source software modeling tool that supports UML (Unified Modeling Language).  StarUML is one of the most popular UML tools in the world. It has been downloaded over than 5 millions and used in more than 150 countries.




http://staruml.io/

I have tried this tools and very happy with the features and performance.  Enjoy !

Saturday, February 18, 2017

Software Architecture AntiPatterns

Good software architecture is crucial for developing successful and scalable systems.
Architecture-driven approaches to software development have proven to be a lot more effective than approaches driven by methodology, documentation, or requirements, and thus more popular.
Just because architecture-driven approaches are more effective, however, doesn’t mean they’re foolproof. It’s important to make sure you’re not undermining your project by employing counterproductive techniques in the creation, implementation, and management of software architecture.
With that in mind, we bring you a list of the 7 most common software architecture AntiPatterns that will lay your project to waste:

1. God Object

Let’s imagine that you’ve created a number of string methods – one capitalizes the first letter of every new sentence, another one substitutes multiple spaces with a single space, and so on. Now let’s imagine you put all of them in a class called StringUtils.
And now let’s say you write another set of methods that allows you to generate PDF, TXT, and DOC reports. You aren’t really sure where to put them, so you just add them to the StringUtils and rename the whole thing to DocUtils.
Later, you develop a bunch of methods to draw simple geometric shapes. Where do you put them? Since you already have that utility class, you might as well keep them there.
All these methods keep piling up until eventually you end up with a god object – a class that can do nearly anything. Unfortunately, you can no longer tell what does what

2. Warm Bodies

This antipattern seems, at first, to have more to do with the structure of your company than the structure of your software. That being said, problems with the former can have unfortunate consequences for the latter. “Warm bodies” are people who work for your company, but aren’t deeply invested in its success.
Because they don’t have a stake in the ultimate success or failure of your product, they can slack off on the job or give less than 100%. Freelancers and contractors working for third-party outsourcing vendors are a good example of how the warm bodies antipattern can make its way into your development process (find out why our model works better than IT outsourcing).

3. Reinvent the Wheel

The speed at which technology moves today leads to substantial reinvention as many tech workers feel tempted to put on the inventor’s hat instead of working with available solutions.

4. Vendor Lock-in

Vendor lock-in occurs when a software project becomes entirely dependent upon technologies provided by a single vendor either due to company policy or out of habit.
As a result, you’re unable to use solutions provided by other vendors, which leads to employing outdated or inconvenient tools for problem solving.

5. Cover Your Assets

When we say software engineers are “covering their assets,” what we mean is that they insist on using the technologies they know best even when they aren’t the best choice for the task at hand just because they don’t want to invest the time and energy into learning new tools.
This may result in extended development times and poor software performance.

6. Stovepipe System

You’ve been working on a system for ten sprints but you still feel there are plenty of blank spaces you don’t fully understand? Congratulations, you’ve been working on a stovepipe system – that is a system with a wide range of functions that are used improperly or aren’t used at all due to the team’s incomplete knowledge.

7. Design by Committee

This antipattern occurs when everyone, from the company founder to the security guy, takes part in architectural decision making.
Make sure that the only people influencing software architecture are the ones who are actually experts in the field.

5 Strategies for Getting More Work Done in Less Time

Summary.    You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...