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;

Thursday, July 05, 2007

Unix Commands

  1. To see the disk usage use df -ks .
  2. To see the disk usage in gb use df -gs .
  3. To see which ports are in use or see available ports use these commands
    netstat -an find /i "listening"