17 June, 2014

Accenture Java Interview Questions & Answers

Accenture interview question for Java 3-8 year experience .

  




Q1. Why do you want to work in this industry / company?


Ans: First you should try to convince that this company gives huge opportunity in many aspect i.e. new technologies implementation, the policy of company suits you like professionalism.   Also you can mention that you are big fan of this company and its your dream company. Basically show your all positive attitude towards company.


Q2. Which location do you want to work in and why?


Ans : Give your own choice. Also mention a valid reason for why you are interested for that location. The reason should be always positive and clear. Example :- you can support your family from this location,

Q3. Describe a problem you faced and how you deal with it ?


Ans : You can describe any issue you faced during your project work in the organization. And what the solution you have implemented for that issue.

Q4. What are the types of class loaders in Java?


Ans  :  As per my knowledge there are basically 3 types of class loader like bootstarp classloader,extension class loader and system class loader.
  • Bootstrap Class Loader
    Bootstrap class loader loads java’s core classes like java.lang, java.util etc. These are classes that are part of java runtime environment. Bootstrap class loader is native implementation and so they may differ across different JVMs.
  •  Extensions Class Loader
    JAVA_HOME/jre/lib/ext contains jar packages that are extensions of standard core java classes. Extensions class loader loads classes from this ext folder. Using the system environment propery java.ext.dirs you can add ‘ext’ folders and jar files to be loaded using extensions class loader
  • System Class Loader
                  Java classes that are available in the java classpath are loaded using System class loader

Q5. Write your own ArrayList in Java ?

      Your own code here .

Q6. How to read and write image from a file ?


Ans : You can use ImageIo.read() and ImageIO.write()  method of javax.imageio package.

Q7. What is difference between static and init block in java.


Q8. How ConcurrentHashMap works?


Ans : The basic design of ConcurrentHashMap is to handling threading. Basically it locks each of the box (by default 16) which can be locked independently and thread safe for operation. And it does not expose the internal lock process.

Q9. Can a static block throw exception?


Ans : Yes. We can throw checked exception.

Q10. What is difference between iterator access and index access?


Ans : Basically iterator access process the traverse operation through each element, where index access process access direct the element by using the index.

Q11. Why character array is better than string for storing password in java?


Ans : Because, character array stores data in encrypted format which is not readable by human. But,the string stores the data in human readable format which is not secure.

Q12. what is daemon thread in java ?


Ans : A daemon thread is normally runs on background. And it does not prevent the JVM from exiting when the program finishes but the thread is still running.

Q13. What is Java Reflection API?


Ans  : Reflection is one of the most powerful api which help to work with classes, methods and variables  dynamically. Basically it inspect the class attributes at runtime. Also we can say it provides a metadata about the class. 

Q14. What is the difference between Serializable and Externalizable interfaces? 


Ans : Both interfaces are used for implement serialization. But, the basic difference is Serializable interface does not have any method (it’s a marker interface ) and Externalizable interface having 2 methods such as readExternal() and writeExternal(). Serializable interface is the super interface for Externalizable interface. 

08 March, 2014

How to stop windows 8 maintenance in progress ?

How to stop windows 8 maintenance in progress ?


This is always a ridiculous task. Just I want get rid of this, because its troubling me. Apparently you need to changes few settings.

Follow the steps for settings :-


Click the lower left corner to open the Start screen.

Type Schedule tasks in the Start screen

1. Click Settings

2. Click Schedule tasks

3. Go to Task Scheduler Library\Microsoft\Windows\TaskScheduler

4. Right Click Regular Maintenance

5. Click Properties

6. Click the Settings tab

7. Mark check in the box to Allow task to be run on demand

8. Click OK

9. Right Click Regular Maintenance again for testing whether its running or not and click on Run.

10. Again Right Click Regular Maintenance and click on End  for end this process.



Now your maintenance icon from task bar removed.
Its working NOW.WOW !!!

06 August, 2013

Why Interface methods are Public ?


Do you know why methods are Public in Interface ?

/*
 * @Author Manoj
 * Interface with two method
 */

interface IMyInterFace{
    public void display();
    public void calculate();
}



//Implementation Class
class MyImplClass implements IMyInterFace{   
   
   
    //Interface Method
    public void display(){
        System.out.println("Hi: Override-Display");
    }
   
    //private void display(){
    //    System.out.println("Hi: Override-Display with Private");
    //If you run this method then, Error Weaker Access Privileges
    //}
   
    //Interface method
    public void calculate(){
        System.out.println("Hi: Override-calculate");
    }
   
    //Class Method
    public void show(){
        System.out.println("Hi: I am Own Method");
    }
   
    public static void main(String str[]){
        IMyInterFace f=new MyImplClass();
        f.display();
    }
}


Output:- Hi: Override-Display




Explanation :-

In the above example , Interface methods are public means extremely strong access.When , you try to access those public method with private or protected (weak access privilege than public) then, you will face error.So, I override those two interface methods with same strong access privilege (public).
Please know more about strong/weak access privilege.

As you know ,objects define their interaction with the outside world through the methods that they expose. Methods form the object's interface with the outside world.So, the most common form, an interface is a group of related methods with empty bodies.

When you are creating an Interface, you must have to declare the methods as Public inside the interface.When you are creating an Interface , it means you are creating a common schema/structure and you are going to implement over any class (Known as Implementation Class). If you need more interesting points about Interface then , Click.


But , our point is why all methods are public in interface.Because of  weaker access privileges.Interface means you are going to implement those methods in implementation classes.So, that interface method can accessed by any where , only require to implementing that Interface.When you are declaring a method(Without body) inside interface  , by default you are making that method with the most strong access privileges (public).

  1. Do you really know , what is weaker access privilege ?
  2. Are you really interested on Interface ?
  3. What is Access Specifier when Overriding ?







Hope it will help you.
Any suggestions or comments will appreciated.

31 July, 2013

Attempting to assign weaker access privileges - Error in Java

As per the rule in overriding , you cannot apply weaker access specifier over a stronger access specifier.Suppose , your parent class has a method Display() with stronger access specifier like Public, then you cannot use weaker access specifier like private or public when you are overriding the Display() method.

Note :-

 Public is the 1st stronger access specifier
 Protected is the 2nd stronger access specifier
 Default is the 3rd stronger access specifier
 Private is the most weaker access specifier

 Always keep in mind about the access specifiers has vital role in inheritance (OOPS concept).

 Example :-

 /*
 * @Author Manoj
 *
 */


class AccessTest{
    protected void display(){ //Stronger Access specifier
        System.out.println("Hello AccessTest:Display");
    }
}

class TestWithMain extends AccessTest{
    // I am trying to override with weaker specifier , it show error
    // You can use public or protected (higher or same level of access specifier)
    private void display(){
        System.out.println("Hello TestWithMain:display");
    }   
    public static void main(String str[]){       
        AccessTest acObj=new TestWithMain();
        acObj.display();
    }   
}

 
 Error :-

 TestWithMain.java:8: display() in TestWithMain cannot override display() in AccessTest;
 attempting to assign weaker access privileges; was protected
    private void display(){

   

So, now if you change the access specifier to protected or public then it will work properly.

Changed executable code :-

    public void display(){
        System.out.println("Hello TestWithMain:display");
    }

   
    OR
   
    protected void display(){
        System.out.println("Hello TestWithMain:display");
    }

   

Hope it will help you.

Access Specifier in Method Overriding

As per the rule in overriding , you cannot apply weaker access specifier over a stronger access specifier.Suppose , your parent class has a method Display() with stronger access specifier like Public, then you cannot use weaker access specifier like private or public when you are overriding the Display() method.

Note :-

 Public is the 1st stronger access specifier
 Protected is the 2nd stronger access specifier
 Default is the 3rd stronger access specifier
 Private is the most weaker access specifier

 Always keep in mind about the access specifiers has vital role in inheritance (OOPS concept).

 Example :-

 /*
 * @Author Manoj
 *
 */


class AccessTest{
    protected void display(){ //Stronger Access specifier
        System.out.println("Hello AccessTest:Display");
    }
}

class TestWithMain extends AccessTest{
    // I am trying to override with weaker specifier , it show error
    // You can use public or protected (higher or same level of access specifier)
    private void display(){
        System.out.println("Hello TestWithMain:display");
    }   
    public static void main(String str[]){       
        AccessTest acObj=new TestWithMain();
        acObj.display();
    }   
}

 
 Error :-

 TestWithMain.java:8: display() in TestWithMain cannot override display() in AccessTest;
 attempting to assign weaker access privileges; was protected
    private void display(){

   

So, now if you change the access specifier to protected or public then it will work properly.

Changed executable code :-

    public void display(){
        System.out.println("Hello TestWithMain:display");
    }

   
    OR
   
    protected void display(){
        System.out.println("Hello TestWithMain:display");
    }

   

Hope it will help you.

29 July, 2013

How to inherit a constructor in JAVA

First of all when we are talking about the inheritance , Java does not inherit the construtor from super class.As we know constructor is one of the member of a , but we cannot inherit it for sub class (child class).Yes, we can invoke a super class (parent class) constructor from sub class by using the keyword "super".

Few Points about 'super' Keyword :-

1. Its a reserved keyword by Java API.
2. It is used to invoke or call super class (parent class) members .
3. When 'super' keyword is used inside the sub class (child class) constructor , 'super' keyword
     is the first line inside the constructor.

Example :-

/*
 * @Author Manoj
 * 29/07/2013
 */

class SUP{
    public SUP(String s){
        System.out.println("Hi Super: "+s);
    }
}


//SUB class extending SUP class
class SUB extends SUP{
    public SUB(String p){
        // Explicitly call the super class argument constructor
        // super is the first line inside the constructor
        super(p);
        System.out.println("Hi SUB: "+p);   
    }
   
    public static  void main(String str[]){
        new SUB("Manoj Kumar");
    }
}





OutPut :-



Hi Super: Manoj Kumar
Hi SUB: Manoj Kumar

Note :- If super class(parent class) constructor is a no-argument constructor the no need to call that constructor by using 'super'
keyword inside the sub class (child class) constructor .

When you invoke sub class (child class) constructor with no-argument, automatically super class (parent class) no-argument constructor
called or invoked.

Hope it will help you.

26 July, 2013

How do I default printer service in java ?


Code :


package experiment.java.printing;

import javax.print.PrintService;
import javax.print.PrintServiceLookup;

public class getDefaultPrinter{
    public static void main(String str[]){
        try{
        //Get print server as your local setting ( Printer)
        PrintService services = PrintServiceLookup.lookupDefaultPrintService();          
        System.out.println("Default Printer Name ::"+services.getName());
       
    }catch(Exception e){
        System.out.println("Error in get Default Printer service::"+e);
       
    }
       
    }
   
}


Example of Enumeration in java

import java.util.Enumeration;
import java.util.Vector;

/*
    Example of Enumaration with Vector
    @Author Manoj
*/

class MyEnumaration{
    public static void main(String str[]){
        Vector<String> vtr=new Vector<String>();
        vtr.add("Hi");
        vtr.add("Tester");
        vtr.add("How");
        vtr.add("Are");
        vtr.add("You?");
        Enumeration enumobj=vtr.elements();
        while(enumobj.hasMoreElements()){
        System.out.println(enumobj.nextElement());
           
        }
       
    }
}

OUTPUT:-


Hi
Tester
How
Are
You?


Read more about Enumeration.

02 July, 2013

hashCode() in Java

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable. The general contract of hashCode is:
  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

23 April, 2013

Experienced Java/J2EE interview questions by MNC

Experienced Java/J2ee Interview questions asked by MNC.



1. Why main() in java is declared as public static void main? What if the main method is declared as
private?


Ans : Because, every program start exucution from main function.The static method can directly call without createing the object of the class.So, before createing object the main function runs and then it creates object.

And, public in main method due to access by JVM. If the method is private then JVM cannot call that function.The program will compile but never run.It show the message  "Main method not public."


2.What is Externalizable?

Ans : This interface is used for serialization.To save the state of an object in file. It provides two method
readExternal() and writeExternal().

3.What modifiers are allowed for methods in an Interface?
Ans : abstract and public

4.What are the different identifier states of a Thread?

Ans :
R- Running or Runnable
S- Suspended
MS- Thread Suspended on Moniter lock
MW- Thread waiting on moniter
CW- Thread waiting on condition variable


5.What are some alternatives to inheritance?

Ans : Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).

6.Why isn’t there operator overloading?

Ans : Because C++ has proven by example that operator overloading makes code almost impossible to maintain.

7.What does it mean that a method or field is “static”?

Ans : Static method or field are member of class.They do not need any object for call or access . We can directly call the static method and fields without using the object.





07 March, 2013

How to find days difference between two given dates ?

Find number of days between two given dates:-

public class FindDays {

    /**
     * @param args
     */
    public static void main(String[] args) {
        String str1="20/01/2013";
        String str2="28/03/2013";       
        Calendar cal=Calendar.getInstance();
        cal.set(Integer.parseInt(str1.substring(6)),Integer.parseInt(str1.substring(3,5))-1,Integer.parseInt(str1.substring(0,2)));
        long xTime=cal.getTimeInMillis();
        cal.set(Integer.parseInt(str2.substring(6)),Integer.parseInt(str2.substring(3,5))-1,Integer.parseInt(str2.substring(0,2)));
        long xTime2=cal.getTimeInMillis();
        System.out.println("Final Days...."+((xTime2-xTime)/(1000*60*60*24)));

    }

}


//Out put- Final Days.... 8

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
     */
    static{
        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

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 :-

 SELECT 'INSERT INTO DUAL VALUES ('''||dummy||''');' FROM DUAL;

output :
INSERT INTO DUAL VALUES ('X');

Example 2 :-

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


output:
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 .

06 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. 

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 : -

http://www.favicon.cc/


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



08 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);
           sos=resp.getOutputStream();
            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");
            exporterXLS.exportReport();
            resp.setContentType("application/vnd.ms-excel");
            resp.setHeader("Content-Disposition", "attachment; filename="+OutputFileName+".xls");
            sos.write(baos.toByteArray());
            sos.flush();
            sos.close();

 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.

01 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

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-config.xml 
struts-extra-config.xml
  

 struts-config.xml 

 










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










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

MainactionAction.java
ExtrastrutsfileAction.java


MainactionAction.java














ExtrastrutsfileAction.java 














Finally create 3 jsp file for mapping forword .

index.jsp
main_struts_config_jsp.jsp
extra_struts_config_jsp.jsp

index.jsp


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.



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.

Example:-
You,are,a,programmer.

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)




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 :- xLoop.java

public class xLoop{     public static void main(String str[])
{     
       boolean x=true;             
       while(x)
{       
  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.



HTTP GET Method

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()"/>
    </form>

Note-

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 :-

MyServletTest.java

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

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

   

}

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="http://java.sun.com/j2ee?myval=I am Testing">Click here for

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


OR

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

here for GET method Request</a>


Note-

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

13 July, 2012

GROUP_CONCAT() Function in MYSQL

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.

Suppose:-

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

Output:-

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


02 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
}

OR


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;
        //fobj.symbolAdd();
        impobj=fobj;
        impobj.symbolAdd();
        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.




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:- https://docs.google.com/open?id=0B29rcw3_bbOqRzVSWlliQkI3NHc


By Manoj.