Thursday, November 21, 2013

Car Driving - L01

Lesson 1

Pre trip inspection 
Exterior inspection
starting from anti clockwise.

How to start car

Key on engine
check parking brake is on and gear should be neutral.
press full clutch by foot
change gear to  1st
make parking brake off
release clutch slowly halfway 



How to stop a car from above position

press clutch fully 
Bring back gear to neutral
make parking brake on
press foot brake slowly


End of lesson - Confidence level .05 %

Tuesday, March 5, 2013

Query Optimization ...........1

  • ----- This post is excerpt of Pinal Dave 's article published on www.sqlauthority.com ----
  • ----- Try to get causes of each sentence  -----
  •  
  • Notes prepared for “Good, Better and Best Programming Techniques” meeting
  • Do not prefix stored procedure with SP_ prefix. As they are first searched in master database, before it is searched in any other database.
  • Always install latest server packs and security packs.
  • Make sure your SQL Server runs on optimal hardware. If your operating system supports 64 bit SQL Server, install 64 bit SQL Server on it. Raid 10 Array.
  • Reduce Network Traffic by using Stored Procedure. Return only required result set from database. If application needs paging it should have done in SQL Server instead of at application level.
  • After running query check Actual Execution Plan for cost of the query. Query can be analyzed in Database Engine Tuning Advisor.
  • Use User Defined Functions sparsely, use Stored Procedures instead.
  • Stored Procedure can achieve all the tasks UDF can do. SP provides much more features than UDFs.
  • Test system with realistic data rather than sample data. Realistic data provides better scenario for testing and reveals problems with real system before it goes to production.
  • Do not use SELECT *, use proper column names to decrease network traffic and fewer locks on table.
  • Avoid Cursors as it results in performance degradation. Sub Query, derived tables, CTE can perform same operation.
  • Reduces the use of nullable columns.
  • NULL columns consumes an extra byte on each column used as well as adds overhead in queries. Also NULL is not good for logic development for programmers.
  • Reduce deadlocks using query hints and proper logic of order in columns.
  • Normalized database always increases scalability and stability of the system. Do not go over 3rd normal form as it will adversely affect performance.
  • Use WHERE clauses to compare assertive logic. Use IN rather than NOT IN even though IN will require more value to specify in clause.
  • BLOBS must be stored filesystem and database should have path to them only. If path is common stored them in application variable and append with filename from the BLOBColumnName.
  • Always perform referential integrity checks and data validations using constraints such as the foreign key and check constraints.
  • SQL Server optimizer will use an index scan if the ORDER BY clause is on an indexed column.
  • Stored Procedure should return same numbers of resultset and same columns in any input parameters. Result Set of Stored Procedure should be deterministic.
  • Index should be created on highly selective columns, which are used in JOINS, WHERE and ORDER BY clause.
  • Format SQL Code. Make it readable. Wrap it.
  • Use Column name in ORDER BY clause instead of numbers.
  • Do not use TEXT or NTEXT if possible. In SQL Server 2005 use VARCHAR(MAX) or NVARCHAR(MAX).
  • Join tables in order that they always perform the most restrictive search first to filter out the maximum number of rows in the early phases of a multiple table join.
  • Remember to SET NOCOUNT ON at the beginning of your SQL bataches, stored procedures, triggers to avoid network traffic. This will also reduct the chances of error on linked server.
  • Do not use temp tables use CTE or Derived tables instead.
  • Always take backup of all the data.
  • Never ever work on production server.
  • Ask someone for help if you need it. We all need to learn.

Saturday, March 2, 2013

What is JNDI

The Java Naming and Directory Interface (JNDI) is an application programming interface (API) for accessing different kinds of naming and directory services. JNDI is not specific to a particular naming or directory service, it can be used to access many different kinds of systems including file systems; distributed objects systems like CORBA, Java RMI, and EJB; and directory services like LDAP, Novell NetWare, and NIS+.
JNDI is similar to JDBC in that they are both Object-Oriented Java APIs that provide a common abstraction for accessing services from different vendors. While JDBC can be used to access a variety of relational databases, JNDI can be used to access a variety of of naming and directory services.
check http://www.jguru.com/faq/view.jsp?EID=10852

To know JNDI one should know first what is Naming and Directory Service.

Tuesday, January 22, 2013

Servlet 3.0 ( Tidbits ) ......2

  • Difference between response.sendRedirect("path" ) & req.getRequestDispatcher("path").forward(req,resp);

In former method a fresh request will be directed to url hence loosing all req level attributes and param in the redirected page . client will be notified that req is being redirected. In later  the current req attributes and params will be preserved  & client wont be  intimated that it is being taken to another page .

  • Difference between RequestURI /URL

http://localhost:8080/myWebapp/FirstServlet/second.jsp?blogname=thevoid

reqURL = http://localhost:8080/myWebapp/FirstServlet/second.jsp ( except Qry String)
reqURI = /FirstServlet/second.jsp ( excluding context and qey string )
path info = /second.jsp ( between urlPattern for servlet  and Qry string  ) 
Qry String  =  blogname=thevoid ( after  ? )

  • Difference between req.getReader() req.getInputStream()

getReader() returens Buffered Reader  & givers character data of req body  .
getInputStream() returns ServletInputStream & gives binary Data of req body .
** body doesnt include  headers


Servlet 3.0 ( Tidbits ) ......1

Different between RequestDispatcher  in context and request .

RequestDispatcher can be obtained either from ServletContext or from ServletRequest.

An object implementing the RequestDispatcher interface may be obtained from the ServletContext via the following methods:
■ getRequestDispatcher(String Path)
■ getNamedDispatcher(String Servletname)

The getRequestDispatcher method takes a String argument path. This path must be relative to the root of the
ServletContext and begin with a ‘/’, or be empty. The method uses the path to look up a servlet, using the servlet path matching rules,and wraps it with a RequestDispatcher object, and returns the resulting object. If no servlet can be resolved based on the given path, a RequestDispatcher is provided that returns the content for that path.

The getNamedDispatcher method takes a String argument indicating the name of a servlet known to the ServletContext. If a servlet is found, it is wrapped with a RequestDispatcher object and the object is returned. If no servlet is associated with the given name, the method must return null.

To allow RequestDispatcher objects to be obtained using relative paths that are relative to the path of the current request (not relative to the root of the ServletContext) (if omitting the / slash ), the  getRequestDispatcher method is provided in the ServletRequest interface.
The servlet container uses information in the request object to transform the given relative path against the current servlet to a complete path. For example,
 in a context rooted at ’/’ and a request to /garden/tools.html, a request dispatcher obtained via ServletRequest.getRequestDispatcher("header.html") will behave exactly like a call to ServletContext.getRequestDispatcher("/garden/header.html").

Query Strings in Request Dispatcher Paths

The ServletContext and ServletRequest methods that create RequestDispatcher objects using path information allow the optional attachment of query string information to the path. For example, a Developer may obtain a RequestDispatcher by using the following code:

String path = “/raisins.jsp?orderno=5”;
RequestDispatcher rd = context.getRequestDispatcher(path);
rd.include(request, response);


Parameters specified in the query string used to create the RequestDispatcher take precedence over other parameters of the same name passed to the included servlet.
The parameters associated with a RequestDispatcher are scoped to apply only for the duration of the include or forward call.

Saturday, January 19, 2013

Servlet 3.0 ( Asynchronous Support for Web )



In Servlet 3.0 one can create Asynchronous servlets /Filters . Detach request/response from thread.

3 ways to set asyn servlets support

  • < async-supported > true < async-supported >
  • or by annotations @WebServlet(asyncSupported = true,name = "HelloAnnotationServlet", urlPatterns = {"/helloanno"})
  • or by configuring dynamically while registering servlet .. ServletRegistration.Dynamic.setAsyncSupported(true);


see an example here  https://blogs.oracle.com/enterprisetechtips/entry/asynchronous_support_in_servlet_3 
 Important interfaces for Async web apps are 

1 . interface AsyncContext 
An AsyncContext is created and initialized by a call to ServletRequest.startAsync() or ServletRequest.startAsync(ServletRequest, ServletResponse). Repeated invocations of these methods will return the same AsyncContext instance, reinitialized as appropriate.
In the event that an asynchronous operation has timed out, the container must run through these steps:
  1. Invoke, at their onTimeout method, all AsyncListener instances registered with the ServletRequest on which the asynchronous operation was initiated.
  2. If none of the listeners called complete() or any of the dispatch() methods, perform an error dispatch with a status code equal to HttpServletResponse.SC_INTERNAL_SERVER_ERROR.
  3. If no matching error page was found, or the error page did not call complete() or any of the dispatch() methods, call complete().
  4. There are 3 flavors of dispatch() for AsyncContext.
 void dispatch()
          Dispatches the request and response objects of this AsyncContext to the servlet container.
 void dispatch(ServletContext context, java.lang.String path)
          Dispatches the request and response objects of this AsyncContext to the given path scoped to the given context.
 void dispatch(java.lang.String path)
          Dispatches the request and response objects of this AsyncContext to the given path.