Thursday, 25 October 2012

Initialization Block Vs Static Block in Java

Static does not need any object to execute. Before creating any object the static block can execute as we are using in static method. So, here the static block is call at the time of JVM execution , means before creating the object( when first time JVM execute ). But Initialization block is   call/loaded every time when object is created.Whenever the object is created at that time the Initialization block is loaded.

Example :- Sample Code

package manoj.experiment;
  * @author MANOJ
public class InitBlockStaticBlock {

     * Static block
        System.out.println("I am here in static");
     * INIT block
        System.out.println("I am here in INIT ");
     * @param args
    public static void main(String[] args) {
        InitBlockStaticBlock obj1=new InitBlockStaticBlock();
        InitBlockStaticBlock obj2=new InitBlockStaticBlock();
        InitBlockStaticBlock obj4=new InitBlockStaticBlock();



Out put :-
I am here in static
I am here in INIT
I am here in INIT
I am here in INIT

Tuesday, 16 October 2012

Oracle Script Generate for insert data into table

Use this following format/query for generate script for insert data into database (Table) .When you export data or migrate data from one database to other database it may help you.With out creating the dumps you can export data from one database to other database.But it is table wise.

You can simply generate script for insert  and then run the generated script on command line.

Example 1 :-


output :

Example 2 :-

SELECT 'INSERT INTO EMP_DETAILS VALUES (',''''||EMP_NAME||'''',',',''''||EMP_SEX||'''',',',''''||EMP_JOIN_DT||'''',');' FROM M_EMPLOYEE;

INSERT INTO EMP_DETAILS VALUES (    'Rakesh'  ,  'M'  ,  '03-APR-05'    );
INSERT INTO EMP_DETAILS VALUES (    'Manoj Kumar' ,   'M' ,   '06-APR-05'    );
INSERT INTO EMP_DETAILS VALUES (    'Santosh Kumar'  ,  'M'  ,  '02-JAN-05'    );
INSERT INTO EMP_DETAILS VALUES (    'Rakesh Kumar'  ,  'M'  ,  '05-JAN-05'    );
INSERT INTO EMP_DETAILS VALUES (    'Sunil Dev'  ,  'M'  ,  '01-APR-05'    );
INSERT INTO EMP_DETAILS VALUES (    'Sheeba'  ,  'F'  ,  '01-JAN-05'    );

Use the generated output in command line and execute .

Thursday, 6 September 2012

JDK not found - Netbean Intallation Error

I faced this problem when i was trying to install Netbean IDE 6  on my office PC. But my system has only JDK 5. Suddenly I got this error message for JDK required.

I have tried to search on many forum,blog and other resources of internet but failure. 

Saturday, 11 August 2012

Create a favicon for your website

It is one of the short cut icon for an website or web page.The format for this icon is .ico. Normally 16x16 pixel icon is associated with a particular web site or web page.Other than .ico format it can support few other formats like .png,.gif. But it may not support all browser. So, .ico format is compatiable to every popular browser.Few other sizes can be used like 16×16, 32×32, 48×48, or 64×64 but , it depends on browser .

You can generate the favicon icon online also. Go for google search you can find some suggestion for creating favicon.

Example : -

Its simple. You just need a link tag on your page. Just put this tag under <HEAD></HEAD> tag of your Page. The tag like :-

<link rel="shortcut icon" href="path/location of your favicon" type="image/x-icon" /> 

Read more from wiki

Wednesday, 8 August 2012

Generate Excel file with single sheet in JasperReport

Yes, its quite easy to generate a excel report using Ireport . There are many blog guru's ,authors, developers has posted ample of solutions on this topic. But , still some time we are facing this problem.

Generating excel report is easy , but our requirement was all report should be come on a single sheet (not multiple sheet). We had few existing codes. But the problem was we were not about to find our exact solution. Finally after lots of testing & research got the solution.I hope it will help you.

The program code for generating Excel file from Ireport :-

JRResultSetDataSource jrds = new JRResultSetDataSource(rs);
JasperPrint print = JasperFillManager.fillReport(rptPath, hmp, jrds);
            ByteArrayOutputStream baos=new ByteArrayOutputStream();
            JRXlsExporter exporterXLS = new JRXlsExporter();
            exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, print);
            exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, baos);
            //exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
            exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE , Boolean.TRUE);
            exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
            exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
            //exporterXLS.setParameter(JRXlsExporterParameter.CHARACTER_ENCODING, "UTF-8");
            resp.setHeader("Content-Disposition", "attachment; filename="+OutputFileName+".xls");

 Now , you just simple remove the below line which has setParameter().When you are setting parameter for your JRXLSReporter.

The Parameter is JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE

The line i removed is //exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);

Hope it will helpfull.

Wednesday, 1 August 2012

Find day name from an Input Date in Java

There are many ways to find the day name from a given date. But here I have used simple one.Really its so easy but sometimes we hang on it .We never found the solutions.Today its happening with me, because I always prefer  less search on Google.

Below the code for finding the day name from an input date.

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
class myDay{
public static void main(){
                String inputDate="01/08/2012";
                SimpleDateFormat format1=new SimpleDateFormat("dd/MM/yyyy");
                Date dt1=format1.parse(dt);
                DateFormat format2=new SimpleDateFormat("EEEE");
                String finalDay=format2.format(dt1);
                System.out.println("My Day is: "+finalDay);

Output:- Wednesday

Explanation :- 

First I prepare a date by using SimpleDateFormat . Then Prepare a DateFormat by using that before SimpleDateFormat(format1).

EEEE is the date Format Suffix for Day.More

Wednesday, 25 July 2012

More struts-config.xml file in your Project

Is it possible to have multiple struts-config.xml in a single project ?

Answer:- YES

Yes,  its a new flavor for developers. In today's it is one of the most FAQ from most of the prominent IT/Software companies.

Yes, it is not too hard to implement struts-config.xml file more than one in your project. But , it may hazardous in case of proper settings.

Basically as per my experience multiple number of struts-config.xml file is not required always but in few cases when the project flow has many modules/sections and the development team want to maintain a separation layer for all module including struts fetures at that time we may require it.Here is the easy steps you can follow :-

Steps to Follow :-

 First few changes in WEB-INF/web.xml

Now, create 2 ( any number of xml file you can do) xml file as mentioned inside the web.xml file.



struts-extra-config.xml ( This is 2nd struts config file)

Now create 2 action file (Action Servlet) as per our example :-


Finally create 3 jsp file for mapping forword .



This file is first file from which we will send request to action.

Now your project structure like below :- 

Now run your project & Enjoy your multiple struts-config.xml file in a single project . Any doubt ping me.

Tuesday, 24 July 2012

Find a sub string from as string splited by delimiter in MYSQL

String operation with MYSQL database is quite simple. But some times it found very ridiculous to find a expected result.That exactly happens with me. Actually I was expecting the result like below :-

But when I run my query it generates the out put like below:-

But i want only the name before the first comma(,) occurrence like :-

 Jon kumar Pattnaik from first row.

To find the expected result from database I have used SUBSTRING_INDEX(str,delim,index count) method.A string operation method .

Query :-

select SUBSTRING_INDEX(GROUP_CONCAT(s.vchSName,' ',vchMidName,' ',vchLastName),',',1) as nam,vchSGudian,vchSGRelation  from t_emp_details ;

Now its running fine with a good expected result.

SUBSTRING_INDEX(str,delim,index count)

Notes :- Parameters

str- is the main string from which we need to find the substring.
delim- is the separator of main string.
index count- is the number of separator you want to find.


select SUBSTRING_INDEX( 'You,are,a,programmer',',',1) from myTable;

Out put:- You

Here in the above query :-

You,are,a,programmer.--( Main String)
comma (,) -- (Separator or delim)
1 --(Index Count)

Thursday, 19 July 2012

What is Thread Dump and how to create a Thread Dump

Thread Dump basically helps to track a activity of each thread.What are the job/task each thread is doing at a particular point of time we can get by thread dump.

To Create a thread dump in console Press Ctrl+Break from Key board.

Create a java program with infinite loop , at the time of running press Ctrl+Break key from key board and see the Full Thread dump is printed on console ( Now write that into a file).

Program :-

public class xLoop{     public static void main(String str[])
       boolean x=true;             
  System.out.println("Hello Manoj ");    
 }  } }

Now run this program on console and at the run time press Ctrl+Break , now the Full Thread Dump like below :-

Note- If any body find complex to find the Full Thread Dump message in the console , do some primary setup with your console window (command prompt). Change the CMD property-->Layout-->Height , set height to 2000 and CMD property-->options-->Buffer Size , set buffer size to 200.Now it will work and you can see this Dump messages.


In the area of web application request & response are two major keys.The property of HTTP will remains universal over any programming language & platform, but here i mainly focus on Java/J2EE development.It means the response are related to each other.Normally the request is sent by client machine( browser ) and the response is revert back (sent back) to the client .Again for the response we need a clear idea about the content type ( MIME Type, Please read MIME TYPE in other post for more about content Type).

Key Points to remember about GET-

1. It has no Body, where as POST has Body.

2. It is Idempotent.

3. It is the default method in HttpServlet.In the Http servlet life cycle it is the default method.i.e. doGet().

4. It is not secure, because the data send by request line (URL) will visible on the rowser.

5. The amount of data for send with request using get method  is very limited.

Below a HTML form like :-

<form action="servlet/MyServletTest" name="frmMyServlet" method="get">
        <input type="text" name="txtValue" />
        <input type="submit" value="Send Value" onclick="FunSendValue()"/>


If method name will not mentioned then bydefault it will take GET method as default.But be aware about your servlet , there must be a doGet() method for your operation/request you are sending. The doGet() must be there inside your resource servlet.If no doGet() method found then it will generate an error - HTTP method GET is not Supported.

The doGet() method inside the servlet like below :-

public class MyServletTest extends HttpServlet {      
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        PrintWriter out = response.getWriter();
        String paramVal=request.getParameter("txtValue");
        out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
        out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
        out.println("  <BODY>");
        out.print("    This is ");
        out.println(", using the GET method");
        out.println("<h3> Your Value from JSP="+paramVal+"</h3>");       
        out.println("  </BODY>");



Like doGet() , there is doPost(),doPut(),doTrace(),doDelete() method for HTTP Servlet.The doGet() and doPost() methods are call by server ( via service method) for handling HTTP GET and POST requests.By extending HttpServlet ,here i have overrides the doGet() method for handle the request with GET method.
One more things to know is all Links,URL are the type GET in nature.

By default all links are handled by GET Method.Example :-

 <a href=" am Testing">Click here for

GET method Request</a> is a link with request type GET.


 <a href="servlet/MyServletTest?txtValue=I am a Programmer">Click

here for GET method Request</a>


The term Idempotent ! It means GET can safely repeated.No need to change the request link but keep in mind that the HTTP GET and servlet doGet() methods are quite different.Let me clear that HTTP GET is
idempotent as per HTTP 1.1 Specification but servlet doGet() method is non-idempotent. It means you repeate the link again and again without changes inside servlet doGet() method, then it may generate error like "Bad Request".And one thing about idempotent is that , it does not mean that the same request has always same response/output and we donot mean that request has no side-effect.

Read more from sun/oracle

Friday, 13 July 2012


GROUP_CONCAT() is one the most essential function over many areas of software development.The basic purpose of this function is to concatinate all records/rows/tuples of a single column/field into a single string.MYSQL library provides huge amount of function with huge requirement of clients.


select vchDay from m_days_list

A column has these following records

After use GROUP_CONCAT() the output like below-

Query :-
select GROUP_CONCAT(vchDay) from m_days_list

GROUP_CONCAT() not only working on single column , but it also working on multiple column/field.And the results are also similar as single column.It gives higher operating value than GROUP BY clause.

select GROUP_CONCAT(vchDay,vchMonth) from m_days_list


FridayJanuary,MondayFebruary,SaturDayMarch     .................... Like this .

Monday, 2 July 2012

A Moment with Marker Interface in Java Development, What is Marker Interface

Under editing..........

What is Interface ? The face value of Interface.

As there are ample of technology in the area of Computer science, that has many contribution to mankind.When I was a student of computer science, I had many doubts about my future .On which platform or language I should work ? What will be my profession? Out of all I choose Java as soul of my profession.

Rally java has many features and scopes.But when I go for the interface ( like an important organ in the java body) , really I can not calculate the face value of interface.How much essential it is for java followers?The face value of interface is undefined.As we know that interface makes java popular.

The Term  "Interface"

And it is a reference type, similar to a class, that can contain only constants, method signatures, and nested types. There are no method bodies inside interface. Interfaces cannot be instantiated and interfaces can only be implemented by classes or extended by other interfaces.Its a protocol of communication between objects.

How to Define an Interface ?

It is quite simple to define an interface. The modifier 'interface' is used to define an interface.The naming convention shall be follows like declaring a class.A class can implement more than one interface separated by comma.And also an interface can extends more than one interface separated by comma.And it contains only signature of the method , no implementation.

public interface SymbolInterface extends int_face1, int_face2, int_face3,int_face4 {
//Declare your member here


public class ImplementSymbolInterface implements SymbolInterface,OtherInterfaces {
//Declare your member here

It is recommended to make your interface public, so that it can be used by other packages, or it can only visible to that implemented class.And you quite sure that the body of the  interface is always having any number method (without method body) or closing with semicolon.Those method has no implementation inside that interface. For implementing that you may need implementation class.

Except, method an interface can contain constant declaration with few modifiers public,static and final. These method & constant declarations are completely optional, i.e. you can declare an interface without any method or any constants. And when an interface does not contain any method or constants that interface is called Marker Interface.

Note:- Yes, Marker interface is good question asked by major MNC .You can find more details about marker interface from the post A Moment with with Marker Interface in Java Development, What is Marker Interface.

How to Implement an Interface ?

Yes, this is the point that you need in your real life program. Before going to implement you have some brief idea about the term interface & its usage.

Use, implements keyword for implement the interface over a class . Follow few code below :-

Declare an interface :

public interface InterfaceSymbol {

    public void symbolAdd();
    public void symbolDiv();
    public void symbolMul();
    public void symbolSub();

Implement the above interface for a class :

public class SymbolImplementa implements InterfaceSymbol{

    public void symbolAdd(){
        System.out.println("I am In Add");
    public void symbolSub(){
        System.out.println("I am In Sub");
    public void symbolMul(){
        System.out.println("I am In Mul");
    public void symbolDiv(){
        System.out.println("I am In Div");

As per the rule you must have to override the methods of interface in the implementation class. But , remember it is not mandatory , you can avoid it by using :

1--- Adapter Class
2--- Make that implementation class as Final. ( Final is a keyword)

Here I am not describing how to avoid for overriding all methods of interface.This is beyond of this post.You follow other posts related to interface.

Also , like a class one interface can extend ( defined keyword) another interface.And the behavior of that interface will remains same.When you define a new interface, you are defining a new reference data type. You can use interface names anywhere you can use any other data type name. If you define a reference variable whose type is an interface, any object you assign to it must be an instance of a class that implements the interface.

This is main function where the implementation is done.

public  class MainImplementationClass  extends SymbolImplementa implements InterfaceSymbol{

     * @param args
    public void symbolAdd(){
        System.out.println("inside ");
    public static void main(String[] args) {
        testf fobj=new testf();
        SymbolImplementa impobj;
        System.out.println("I am in Main.........");


The word of Caution.

Then you need to rewrite an interface, be careful about the pitfall. In the above example  InterfaceSymbol interface is implemented by the class SymbolImplementa , but  If you make few changes in the old interface , all classes that implement the old InterfaceSymbol interface will break because they don't implement the interface anymore. Programmers relying on this interface will oppose deeply.So, enjoy the flavor of interface in java programming.

By Manoj.

Monday, 25 June 2012

MS-Office a short notes & step by step process for word with few tips

Welcome to this Mini Technical Reference tutorial. This tutorial gives you a very quick
way of learning in step-by-step manner as your concerned faculty discussed with
you. These contents only for those who are working in some where as a corporate
employee coming for the training at NIIT, ELS.

This is for officials & corporate people for office management, letter writing  & other activities on word processor.

Download the Tutorial/Book:-

By Manoj.

Friday, 22 June 2012

JSTL a rich Web solution for JSP ! Kick your scriptlet over JSP.

By our traditional web development with J2EE is quite deprecated.Now-a-days there are ample of technology provided by different vendors like sun, oracle, micro soft , etc. Out of all JSTL(Java Standard Tag Library) a tech of sun has supreme power to optimize    and encapsulate the core functionality that common to many JSP applications. Instead of mixing tags from numerous vendors in your JSP applications, JSTL allows you to employ a single, standard set of tags.The sun has provides enormous benefits through JSTL.

  I am really disappointed; I am not using JSTL in my current project. Although I know it has many benefits over JSP scriptlet tags. I really want to kick out the scriptlet tags from my jsp. Scriptlets are difficult to maintain & execute by container also.It is a complete solution for web developers/front end developer , no need of prior knowledge of java/j2ee.It support full tag syntax, no need of jsp scriptlet tags.It has following major tag areas :-
         -- Core Tags
         -- Formatting Tags
         -- SQL Tags
         -- XML Tags
         -- Function Tags ( JSTL Functions)

There are many advantages of JSTL over JSP. 

         -- It is easy to use, ( avoid scriptlet tags)
         -- We can create our own custom tags
         -- These tags are standardize by sun.
         -- More functionality with easy iteration support tags
         -- XML supports
         -- It uses EL (Expression Language )  

You can get more about these from below given link from sun.

But, its quite simple to use JSTL with your jsp.I have posted here an easy example of JSTL below:-

Before go to the example, you need certain setups & resources like jstl.jar and  standard.jar.

1. You can Download the binary distribution from Apache Standard Taglib and unpack the compressed jar file.
2. Extract those files , and copy all extracted files ( .tld and other files) into WEB-INF\lib .

3. set some necessary tag-lib inside web.xml & enjoy the flavor of JSTL.

Simple Example-

web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"

jsp file

<%@ taglib uri="/WEB-INF/lib/c.tld"  prefix="c" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">   
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <c:forEach var="i"  begin="1" end="10" step="1">
        <c:forEach var="k" begin="1" end="5" step="1">
            <td><c:out value="${k}"></c:out></td>

Now start the tomcat and run from browser. The out put of the program will be like below :-

I have only used core tag in this example. But there are so many tags including other tag sections discuss above. Also you can develop you own .tld file and own custom tags. 

Read all about JSTL from sun.

By Manoj.

Wednesday, 20 June 2012

Arbic Data/Text in mySql Database Table

Some time we need this type of requirement as per the client given. I have faced this one. But need not to worry there are lots of way by which we can insert data/text into mysql table. Create a table with following steps:-

1. Create a table with Collation - utf8- utf8-bin
2. Then , set all columns datatype should be varchar and  Collation - utf8- utf8-bin
3. And now Apply changes. Ok

This above image setting for table.

This image for setting column . (utf-8-to-column.jpg)

This image , finally data inside the table. (data-in-table.jpg)

Or by using  query

column_name varchar(50) character set utf8 collate utf8_bin ----set for individual column
CHARSET=utf8 ---------Set on  table

Below one dummy query for better understanding-

ALTER TABLE `admin_kairali`.`t_report_language` CHANGE COLUMN `vchBeing` `vchBeing` VARCHAR(200) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NULL DEFAULT NULL  , CHANGE COLUMN `vchScrtry` `vchScrtry` VARCHAR(200) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NULL DEFAULT NULL  , CHANGE COLUMN `vchAccount` `vchAccount` VARCHAR(200) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NULL DEFAULT NULL  , CHANGE COLUMN `vchReceiversign` `vchReceiversign` VARCHAR(4000) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NULL DEFAULT NULL  ;

Now enjoy this read.

By Manoj.( مانوج بواسطة

Tuesday, 19 June 2012

John Yeary: When Do I Use CSS?

John Yeary: When Do I Use CSS?: Image via Wikipedia I have been looking at a number of articles on web technologies, and HTML . One of the things I noticed on a lot of the ...

Monday, 18 June 2012

SDLC:- Waterfall Model ( A Leaner Apporach for Designing )

As per our prior knowledge , Software development Life Cycle (SDLC) is the backbone of software development.Its part of systems engineering, information systems and software engineering, is a process of creating or altering information systems, and the models and methodologies that people use to develop these systems , means the every process involves with software development must follow SDLC for every organization.

On the other hand PCL,for project management defined both with a project life cycle (PLC) and an SDLC. According to Taylor (2004) "the project life cycle encompasses all the activities of the project, while the systems development life cycle focuses on realizing the product requirements"

As per my view SDLC is the best fundamental for software development.
There may be so many methodologies are there, but out of all there are finger count methodologies like Prototype Approach, Waterfall Approach,etc. The waterfall apporach is a linear approach. This approach or model has many advantages & Disadvantages, but it is quite popular & acceptable.The initial startup name of this model was Process Model and it has been accepted by many software engineering firms & authors. It ensure the software development process with different phases :-

1. Conception
2. Initiation
3. Analysis
4. Design
5. Coding
6. Testing
7. Implementation and Maintenance.
These all stages/phases are the vital part of this model. And these stages are the key concept of the entire software development.
The word conception , is self meaning word. An idea for create a project/application.
To implement your ideas or to initialize your Ideas/Conception for start up.
To analysis the data/requirements for the project/application.
To build the concrete of the above points to make an application/project.
Applying your construction code/logic for physical structure.
Test the application/project for make it accurate or bug free.( ie. unit test,inte. test)
To implement  the final product and keep maintenance for that product.Its a long term process .

There are so many development process we are following now-a-days. Because, we need fast & quick delivery, so that we a accepting so many techniques like AGILE,xp,SCRUM etc. Many authors argue on this waterfall model due to lack of fastness or other few disadvantages.
But still its the parent of all design & development models are used now-a-days. For more about Agile  read other posts.

By Manoj

Friday, 15 June 2012

J2EE: What is a Struts in our Life ? Struts.

We need to  our life with a easy & smooth track. Now-a-days our technology runs above of the sky with new vision. But , can we feel struts is one of the necessary part of software development , basically on the footprint of JAVA/J2EE.

When I was new to software development ( java/j2ee) at that time struts was new to me & I always afraid about what is that. But, after the span of time slowly slowly deeply I rushed into that struts garden.

Struts framework is an open-source framework for developing the web applications in Java EE, based on MVC-2 architecture. It uses and extends the Java Servlet API. Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java. The term Framework, is way we find to easy developing environment with all possible features for that environment. Its a complete 3rd party(in other way).

Struts components can be categorize into Model, View and Controller:
  • Model: Components like business logic /business processes and data are the part of model.
  • View: HTML, JSP are the view components.
  • Controller: Action Servlet of Struts is part of Controller components which works as front controller to handle all the requests.
Also Struts is a set of cooperating classes, servlets, and JSP tags that make up a reusable MVC 2 design.
  • JavaBeans components for managing application state and behavior.
  • Event-driven development (via listeners as in traditional GUI development).
  • Pages that represent MVC-style views; pages reference view roots via the JSF component tree.

But the major role in struts is ActionServlet. ActionServlet is a simple servlet which is the backbone of all Struts applications. It is the main Controller component that handles client requests and determines which Action will process each received request. It serves as an Action factory – creating specific Action classes based on user’s request.It has following roles:
  • Process user requests
  • Determine what the user is trying to achieve according to the request
  • Pull data from the model (if necessary) to be given to the appropriate view,
  • Select the proper view to respond to the user
  • Delegates most of this grunt work to Action classes
  • Is responsible for initialization and clean-up of resources

Except ActionServlet , there is one ActionForm, which may lead you to represent data(Usable component) . ActionForm is javabean which represents the form inputs containing the request parameters from the View referencing the Action bean.It has  2 major methods validate() and reset(). These methods are used by struts framework.

Also ActionMapping, ActionForward,Dispatch Action are play major roles in struts. Follow other reads/posts.

To make your application faster & easy , I follow struts.

Tuesday, 12 June 2012

MySQL : Find all Foreign Keys Constraints in a database (MySql)

I was really Unpleasant when I  failed to find out all foreign keys inside my database. Really, that was a great movement when I did it.My project manager was asking again and again , really I was so happy after the solution.

I can do it in MS SQL Server 2000/2008  , but in mysql its not quite easy.So, I share this in this blog, for help other developers to achive the goal.Below the query you can use it in mysql query editor :-

f.table_schema as 'schema',
f.table_name as 'table' ,
f.column_name as 'column',
f.constraint_name as 'constraint_name'
FROM `information_schema`.`KEY_COLUMN_USAGE` f
f.table_schema='admin_kairali' and f.referenced_column_name  is not null

--Above for a single given table.

f.table_schema as 'schema',
f.table_name as 'table' ,
f.column_name as 'column',
f.constraint_name as 'constraint_name'
FROM `information_schema`.`KEY_COLUMN_USAGE` f
 f.referenced_column_name  is not null

--For all table.

MySQL: Find Number of Engines and their description in Mysql Database System, Like (InnoDB)

I faced this problem to find the information about engines inside Mysql DB. Its quite easy to work with mysql, but the engine inside mysql are so pretty and the information about the engines can be found by using following commands in query editor/console :-

show engine innodb status;

This above  query /command will help you to find the information about a perticular database.Here I used in this query is innodb engine.

show engines;

This above query /command will help you to find following output ( all engines inside your db and some information about those).


1--'MyISAM', 'YES', 'Default engine as of MySQL 3.23 with great performance'
2--'MEMORY', 'YES', 'Hash based, stored in memory, useful for temporary tables'
3--'InnoDB', 'DEFAULT', 'Supports transactions, row-level locking, and foreign keys'
4--'BerkeleyDB', 'NO', 'Supports transactions and page-level locking'
5--'BLACKHOLE', 'YES', '/dev/null storage engine (anything you write to it disappears)'
6--'EXAMPLE', 'NO', 'Example storage engine'
7--'ARCHIVE', 'YES', 'Archive storage engine'
8--'CSV', 'NO', 'CSV storage engine'
9--'ndbcluster', 'NO', 'Clustered, fault-tolerant, memory-based tables'
10--'FEDERATED', 'YES', 'Federated MySQL storage engine'
11--'MRG_MYISAM', 'YES', 'Collection of identical MyISAM tables'
12--'ISAM', 'NO', 'Obsolete storage engine'

Read more about this system internal commands from mysql.

Monday, 11 June 2012

Manoj.Blog: Java Struts: The flavor of DispatchAction. Leave A...

Manoj.Blog: Java Struts: The flavor of DispatchAction. Leave A...: Its really good to know that struts has so many features which provides the programmer/developer easy life.Out of all the good thing the ac...

Java Struts: The flavor of DispatchAction. Leave Action and Love DispatchAction .

Its really good to know that struts has so many features which provides the programmer/developer easy life.Out of all the good thing the action part of struts frame work is superb. As you know there are 5 type of action , provided by struts.

But the Dispatch action make your job function centric. Struts DispatchAction from (org.apache.struts.actions.DispatchAction) is one of the Built-in Actions provided along with the struts framework.It works on a single action with multiple function . No need of create multiple action type for operating any task. It gather all related methods into a single.

An abstract Action that dispatches to a public method that is named by the request parameter whose name is specified by the parameter property of the corresponding ActionMapping. This Action is useful for developers who prefer to combine many similar actions into a single Action class, in order to simplify their application design. Read more on this Dispatch Action.

public class MyDispatch_Action extends DispatchAction


public ActionForward add-data(
  ActionMapping mapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response) throws Exception{
  System.out.println("You are inside add");
  return mapping.findForward("addmydata");


public ActionForward edit-data(
  ActionMapping mapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response) throws Exception


  System.out.println("You are inside edit");
    return mapping.findForward("editmydata");


return null;


The rest are same flavor as other struts.Just enjoy new flavor.

Monday, 28 May 2012

Java : JVM Inside. The Story behind JVM. Continue......

In , the previous post , we have discussed some points about JVM in Java platform. Including JVM, java has its own Run time environment(JRE). There are many versions available for JRE, download here.Being byte codes are binary format, Programs intended to run on a JVM must be compiled into a standardized portable binary format, which typically comes in the form of .class files. A program may consist of many classes in different files. For easier distribution of large programs, multiple class files may be packaged together in a .jar (Java Archive file ) file.

The Java application launcher, java, offers a standard way of executing Java code. The JVM runtime executes .class or .jar files, emulating the JVM instruction set by interpreting it, or using a just-in-time compiler (JIT) such as Oracle's HotSpot. JIT compiling, not interpreting, is used in most JVMs today to achieve greater speed. There are also ahead-of-time compilers that enable developers to precompile class files into native code for particular platforms.

Almost virtual machines are similar and the Java virtual machine has a stack-based architecture akin to a microcontroller/microprocessor. However, the JVM also has low-level support for Java-like classes and methods.

JVM have following inside paradigm :- 

1. Bytecode verifier
2. Stack
3. Garbage Collected Heap
4. Method Area

Bytecode Verifier :

It helps to jvm to verifies all bytecode before it is executed. This verification consists basic of three types of checks:-
       1. Branches are always to valid locations
       2. Data is always initialized and references are always type-safe
       3. Access to private or package private data and methods is rigidly controlled.


Stack in Java virtual machine stores various method arguments as well as the local variables of any method. Stack also keep track of each an every method invocation. This is called Stack Frame. There are three registers thats help in stack manipulation. They are vars ( local variable), frame (Execution environment), optop ( Operand Stack ). This registers points to different parts of current Stack.

Method Area:

The byte codes are here. The program counter (PC) points to some byte in the method area. It always keep tracks of the current instruction which is being executed (interpreted). After execution of an instruction, the JVM sets the PC to next instruction ( As we know in ASM language). Method area is shared among all the threads of a process. Hence if more then one threads are accessing any specific method or any instructions, synchorization is needed. Synchronization in JVM is acheived through Monitors (Read this post).

Garbage Collected Heap:

This is one of the main part of java/jvm .This is the place where the objects in Java programs are stored. Whenever we allocate an object using new operator, the heap comes into picture and memory is allocated from there. Unlike C++, Java does not have free operator to free any previously allocated memory. Java does this automatically using Garbage collection mechanism.The garbage collection logic for make memory free and available the resource for more development.

Point to Remember: The local object reference resides on Stack but the actual object resides in Heap only. Also, arrays in Java are objects, hence they also resides in Garbage-collected Heap.

Java: JVM Inside .A story behind JVM.

The word JVM is the core heart of java programming language. It stands for Java Virtual Machine , a simple virtual machine inside your physical computer/system. The virtual refers to not physically it is conceptual.So, it is a virtual machine which can understand byte code.

It is the code execution component of java software platform.A Java virtual machine is software that is implemented on virtual and non-virtual hardware and on standard operating systems. A JVM provides an environment in which Java byte code can be executed, enabling such features as automated exception handling, which provides root-cause debugging information for every software error (exception), independent of the source code. A JVM is distributed along with a set of standard class libraries that implement the Java application programming interface (API). Appropriate APIs bundled together with JVM form the Java Runtime Environment (JRE). 

The term WORA (Write Once and Run Anywhere) make java popular & easy . JVM understand byte code which is the intermediate language between programming and system.The WORA  and   write once, compile anywhere,(WOCA)  which describes cross-platform compiled languages Thus, the JVM is a vital component of the java platform. Typically , we can say JVM makes java platform independent. 

                                                 Java Source File (.java)
                                                   Java Compiler ( javac)     
                                       Byte code ( .class file, secure code)    
                                        |                         |                         |
                                        |                         |                         |
                                     JVM                   JVM                  JVM
                                       |                          |                         |
                                       |                          |                         |
                                Windows                Linux                   Mac

                                                                                                         Continue to read this in next post

Thursday, 24 May 2012

MYSQL: Password security problem with mysql Database,Be Aware about secure your Password

Yes , it is true in mysql your password may not secure . It happens with any developer those are using mysql as database. Normally developers are not aware about the password hacking and apply normal query for retrieving  data from database.

Anyone using MySQL on a computer connected to the Internet should read this section to avoid the most common security mistakes.
In discussing security, it is necessary to consider fully protecting your password when login. Commonly we are using such below where clause for comparison for login or validation . But, it is completely not safe.

where binary pass='yourpassword'

But, this above code is not secure and it can be overlapped by using '=' . In place of you password you can use '=' , and see it will hack your password. Your condition is going to true and login success. So, Be careful if you are a responsible developer for your organization.

Your data can be fetch if your condition is '=', it is hacked or checked true. So, follow the process below.

Always use password security mechanism for secure your password.Always follow mysql manual for security before applying security on mysql password.

But when retrive data , you can  use HEX() function from convert it to Hexa decimal format .
As below :

HEX(vchadmin_pass)=HEX('YOur password')

Or use

MD5() other function mentioned below table.

So, Always follow the password security for secure. You can encrypt or decrypt the password when store using the following table :-

AES_DECRYPT()Decrypt using AES
AES_ENCRYPT()Encrypt using AES
COMPRESS()Return result as a binary string
DECODE()Decodes a string encrypted using ENCODE()
DES_DECRYPT()Decrypt a string
DES_ENCRYPT()Encrypt a string
ENCODE()Encode a string
ENCRYPT()Encrypt a string
MD5()Calculate MD5 checksum
OLD_PASSWORD()Return the value of the pre-4.1 implementation of PASSWORD
PASSWORD()Calculate and return a password string
SHA1(), SHA()Calculate an SHA-1 160-bit checksum
SHA2()Calculate an SHA-2 checksum
UNCOMPRESS()Uncompress a string compressed
UNCOMPRESSED_LENGTH()Return the length of a string before compression

Wednesday, 23 May 2012

JAVA: Implementing Singleton design patten for creating single instance with example.

As per the old post related to singleton design patten , here the example of implementation.For implementing the singleton design patten for creating single instance of a class , below one example for better understanding:

//Class with Main function for calling singleton class
public class TestSingleTon {

     * @param args

    public static void main(String[] args) {
    SingleTonClass classinstance=SingleTonClass.getInstance();
    System.out.println("My SingleTon member value is="+classinstance.testval);


//Singleton class 
public class SingleTonClass {

    //create an instance
    private static SingleTonClass my_instance=new SingleTonClass();
    private SingleTonClass(){
        //Private Constructor here
        //Not allow to create an object out side
    //method to access the instance
    public static SingleTonClass getInstance(){
        return my_instance;
    //Member variable
    int testval=10;

     //if remove comment from below line , the program will not execute.
    //SingleTonClass s1=new SingleTonClass();

The output of this program is :-

My SingleTon member value is=10

This is the simple implementation & ensuring one object creation of singleton design patten.Also there are so many other methods are there for implementing signleton ( lazy loading, multiple jvm, etc ).

Thank you
Good Reading.

Friday, 18 May 2012

HTML/JAVASCRIPT: Creating a window in Javascript

Some times its an useful job to create a window with a new requirement. But , when we are in development room/area , we always remember any search engine to fine the solutions for any type of problem. Even I , also  following some of the search engine. But, it is a fact that I am always try to avoid this type of habits. Be , traceable  for finding any solution. This article is one of the mail memory & also my teaching my myself , that don't guess any coding is normal and easy , so don't remember.

So, below the topic:- code line put inside script tag'','','left=0,top=0,width=1000,height=780,toolbar=0,scrollbars=0,status=0');

All parameters are not mandatory  to put with values. If you donot need any scrollbar,toolbar,status bar then you can put 0 as the value here, either put 1.

See more in :- other links

Hope it will help you