Commonly commands in Git

Here are some of the commonly used in Git:

git status – displays modified files and staged files.
git commit – commits all staged files to current remote branch
git log – history of commits in the current branch
git show <commit-number> – displays commit information for a particular commit.
git show-branch – one line summary of current branch
git diff <commit-number1> <commit-number2> – difference of two commits
git mv old-file-name new-file-name – renames a file / directory, retains all commit history.
git clone <repository_name> <workspace_name> – makes a full copy of a repository

Posted in Uncategorized | Tagged , | Leave a comment

3n+1 path

While reading Programming Challenges I thought of implementing the path of 3n+1 for a given number. Here is my first stab in Java. I am not trying to solve the problem, however I thought it is interesting to print the sequence for a given number.

public class ThreeNPlusOne {

public static void main(String[] args) {

ThreeNPlusOne driver = new ThreeNPlusOne();
int counter = 0;
int i = 9;
while (i > 0) {
System.out.print(i + " ");
++counter;
if (i == 1)
break;
i = driver.getNextNumber(i);
}
System.out.println("\nMaxmimum cycle length: " +counter);
}

private boolean isEven(int n) {
return n % 2 == 0;
}

private int getNextNumber(int n) {

if (isEven(n)) {
return n / 2;
}
return (n * 3) + 1;
}
}

Posted in Uncategorized | Tagged , | Leave a comment

Ant war task

Many of us build war files as part of the project, however some projects stilll use jar and copy ant tasks to assemble war file. However ant has a built-in war task which takes care of web.xml, classes, libraries etc.,

Here is sample of ant war task.

<war destfile=”myapp.war” webxml=”myapp/web.xml”>

<classes dir=”myapp/classes” />

<lib dir=”myapp/lib”>

<exclude name=”whatever you need to exclude” />

</lib>

<fileset dir=”myapp/jsp” />

<fileset dir=”myapp/html” />

</war>

Posted in Uncategorized | Tagged | Leave a comment

Validation and erroror reporting in Struts 1.1

One of the benefits of using Struts framework is declarative validation mechanism and error reporting. Struts provides validation hook so that you can implement your own validation logic in action classes. The validation can be turned on/off in action mapping using validate property.

In action class you can override validate() and it’s signature is:

public  ActionErrors validate(ActionMapping mapping, HttpServletRequest request)

Typically you validate presentation related information such as missing text or wrong format etc., If a validation error occurred for an input field, you can create an ActionError class  with message key (for internationalization purposes ) and the name of the input field. In the JSP you can use Struts <html:errors /> tag to display these errors.

Sometimes you need to validate business validation such as ‘check user alredy existed in the system’, these should be performed in actions’ perform(), I will post the details in my next blog.

Posted in Uncategorized | Tagged , , | Leave a comment

Internationalization in Struts 1.1

How do you internationalize your struts 1.1 application?  Here are simple steps:

  1. Prepare you language speicific resource bundles.
  2. Provide default resource bundle in struts-config.xml using message-resources
  3. Include struts bean tag lib in your web.xml using taglib
  4. In JSP,  include your struts bean tag lib directive
  5. In JSP,  replace all hard-coded string … values with interntaionalized property keys using message property of bean tag
Posted in Uncategorized | Tagged , | 1 Comment

Implicit objects in JavaServer Pages.

In JSP you can get access to the following implicit objects:

  1. request – HttpServletRequest
  2. response  – HttpServletResponse
  3. Session – HttpSession
  4. out – JspWriter
  5. application – ServletContext
  6. config – ServletConfig
  7. pageContext
  8. page
  9. exception (available only to error pages).
Posted in Uncategorized | Tagged , , | 1 Comment

Scopes in JSP

In JSP you can create attributes in four scopes: page, request, session and application. If you need to access them Expression Language such as c:out tag, you can specify the scope explicitly.

Here are some examples:
<c:out value=”${pageScope.maxAttempts}” />
<c:out value=”${requestScope.maxAttempts}” />
<c:out value=”${sessionScope.maxAttempts}” />
<c:out value=”${applicationScope.maxAttempts}” />

If you try to display a value without specifying a scope, it first looks the value in the pageScope, requestScope, sessionScope and finally applicationScope. If it finds a value it displays otherwise it display ‘empty‘. Remember you won’t see null in the expression language.

Posted in Uncategorized | Tagged , | 1 Comment