Tuesday, January 12, 2010

Interview Questions

Interview Questions

I have been on interview mode for past few weeks and attended some interviews. Here are some sample question asked by interviewers. I am posting only the questions, Google for best answers.

  1. Can I pass HTTPSession object to EJB?

  2. Explain some J2EE design patterns

  3. In struts, can we add some preprocessing code before action gets executed? (Request processor)

  4. Can I print a string in a program without using main method? (static block)

  5. How do you set up cluster in Websphere

  6. Can you explain struts life cycle?

  7. Are you exposed to Ajile methodology? Can you explain the cycle

  8. Do you have any experiences with Ajax

  9. Can you explain the life cycle of session beans?

  10. I have two tables with 10 and 2 rows, How many rows will select * from table1, tabl2 fetch
    (10?or 12 rows – hint cartesian – 10*2 rows)

  11. What is the difference between HashTable vs HashMap

  12. What is the difference between Vector and Arraylist

  13. What is synchronized block and where do you use it

  14. What is the difference between Union vs Join
    Answer: For Union the column name and datatypes must match. Union eliminates duplicate row

  15. What is the difference between interface and abstract

  16. difference between java & j2ee

  17. explain value object pattern & where do you use?

  18. Difference between ibatis & hibernate

  19. Difference between servlets and JSP


SQL Notes

SQL Notes


True or false: You must also use theGROUP BYclause when using theHAVINGclause.

False – having clause can be used without group by

Group by vs Order by

In group by all non aggregate columns must be selected.

Group by is used to group identical data

order by is designed merely to put a data in a specific order.

It is generally not necessary unless using aggregate functions like sum, avg,count.

SELECT COUNT(EMPLOYEE_ID), SALARY FROM EMPLOYEE_PAY_TBL;

The result will display the first salary along with count.

AVGfunction does not consider null values

INSTR

The INSTR function is used to search a string of characters for a specific set of characters

and report the position of those characters. The syntax is as follows:

INSTR( COLUMN NAME, ‘ SET’,

[ START POSITION[ , OCCURRENCE] ]);

LTRIM(CHARACTER STRING[ ,set’])

DECODE(COLUMN NAME,SEARCH1’,RETURN1’,[SEARCH2’,RETURN2’,DEFAULTVALUE’])

Coalesce:Function to check null in specified order and return not null values if any found

coalesce(column1,column2,column3... so on)

ASCII – returns acii set

Conversion functions

TO_NUMBER

CAST – Operator to convert datatypes into other data types.

Convert date to string

to_char(date_column,'month yy dd')

Natural join vs Inner join

Natural join – no need to specify column name

Inner join – column name in join is required

Not equal join,

If table a has 6 rows and table b has 8 rows then non equal join produces

6*(8-1) rows since it excludes the current row in the join instead of 6*8 rows

Subqueries

1.Order by clause cannot be used in subquery where as group by can be used to get achieve the same.

2. Between operator cannot be used with subquery

Correlated subquery – a subquery that depends on information specified from main query

Union vs Union ALL – former eliminates duplicate, later includes it.

Oracle – select random rows – use sample(10) where 10 is 10% of total rows.

Views – insert/update – the underlying data cannot involve joins or group by clause or union statement.

Create view cannot have order by clause – use group by instead.


Thursday, December 24, 2009

webservices overview

XML:

NMTOKENS . A single word; otherwise a list of them separated by whitespace. (e.g, “hello world” is invalid where as “hello” is valid)

WSDL:

WSDL document essentially has four parts

definition

  • message

    • part ^name ^type

  • portType

    • Operation

      • input *

      • output

  • binding

    • ^name ^type (portType)

    • soap | http

    • <soap

      • operation

        • input

          • soap:body use=”encoded|literal”

        • output

          • soap:body use=”encoded|literal”

  • service

    • ^name

    • documentation

    • port ^name ^binding


Friday, December 04, 2009

Java training notes

Some of my notes from Java training. Some may be of interests to you.

  1. Java final attribute - A blank final attribute must be set in every constructor. Otherwise compiler reports error. -- Legal -- private final int customerId; public Blank(){ customerId=2; }

  1. Overridden method in child class may throw fewer or no exceptions than the exception in parent class

  2. To create an unchecked exception class, extend your exception class from RuntimeException. For checked exception, extend from Exception.

  3. Do not use assertion to check the parameters of a public method.

  4. To enable assertions, use ea or enableassertions control flag in java command java -ea MyApp java -enableassertions MyApp

  5. Java Arrays are objects and cannot grow in size after you declare

  6. Generics eliminate the need for cast

  7. Primitives cannot be stored in EJB component environment.

  8. Which methods are invoked to transition an entity bean from a state of non-existence to a pooled state 1.The EJB Constructor 2.setEntityContext(EntityContext ec)

  9. Only stateless session beans can be implemented as webservice

  10. Instance variables must be explicitly initialized before you use. Otherwise it is a compile error

  11. In subclasses constructors are never inherited. But you can override them.

  12. POJO vs JavaBeans – JavaBeans mandate no argument constructor and getter/setters.

Difference between Message Driven Beans and others

  1. MDB has only bean class

  2. Clients do not access MDB through interface

  3. Most part MDB's are stateless session beans

  4. onMessage is the method called by container for MDB

  5. Mainly used with JMS for async messaging.

EJB

  1. Remote Interface declare business methods

  2. Home Interface declares EJB lifecycle ejbCreate and ejbRemove


Wednesday, August 27, 2008

Unix Commands

Command to print file path

To print the file name prefix with path, use this command

find `pwd` -type f

Command to search for text in specific files

find . -type f -name "MSG0710*.xml" -exec grep "Email Confirmation" '{}' \; -print

Command to find files and delete it with confirmation

$ find $HOME/. -name *.txt -ok rm {} \;

Thursday, July 10, 2008

Build materials

Combine all SQL scripts from CVS links into one

I was asked to create a single SQL script from a document that has cvs links for each sql. Here is what I did,
  1. Download DAP a.ka. Download accelerator
  2. Copy all the CVS links into a text file
  3. Replace "&view=markup" and "&view=auto" with blanks
  4. Open Download accelerator and import the text file (File -> Import -> Plan text file)
  5. Download all
  6. exeute dos2unix command in downloaded directory
  7. execute this command in unix (or cygwin for windows)
    find . -type f -iname "*.prc" -exec cat {} >> ../sp_implementation_script.txt \;
  8. execute this command to generate list of file names included with number of files
    $ echo -e "Number of files \n---------------\n`ls -1 | wc -l`\n\nFile Name\n---------" > ../sp_implementation_script_list.txt
    find . -type f -iname "*.prc" -exec ls {} >> ../sp_implementation_script_list.txt \;
  9. execute this command in unix (or cygwin for windows)
    find . -type f -iname "*.prc" -exec cat {} >> ../sp_rollback_script.txt \;

  10. execute this command to generate list of file names included with number of files
    $ echo -e "Number of files \n---------------\n`ls -1 | wc -l`\n\nFile Name\n---------" > ../sp_rollback_script_list.txt
    find . -type f -iname "*.prc" -exec ls {} >> ../sp_rollback_script_list.txt \;

Thursday, July 26, 2007

Unix Commands

Command option to print line number with grep

grep -n pattern filename

With the line number use tail + file | more to see the content of the file from that line onwards.

Command option to print the number of occurences

grep -c pattern filename

or

grep pattern filename | wc -l

To see the last occurrences

tail -1000 filename | grep pattern

Tuesday, July 24, 2007

DB2 Syntax

To specify date in where clause for db2, use this format.
'2007-07-24-12.19.47'

To Print Date in mm/dd/yyyy format use

select char(date(current_timestamp),USA) from sysibm.sysdummy1;