Skip to main content


Showing posts from February, 2013

JEE : Java Server Page (JSP) life cycle

All the JSP run under supervising of web server. They do not receive requests from client and they do not send the response to client. All the JSP pages pass through the Server side processing. And result of sever side processing is sent to client. That is why they called dynamic pages. In the case of static page there is no server processing, web server returns them as they are. Dotted line showing that, When client sends the request for static page , server returns the requested page without processing and solid line showing that when client sends the request for dynamic page, server process it and the response generated is returned to client. How the JSP executes 1. A request for a JSP pages is made by the client. 2. The request is handled by the web server. 3. Then the request is delegated to the JSP container 4. Container will check whether JSP to be invoked is changed or not 5. If there are some changes or its new JSP page then engine translates the contents of

Popular Logics for implementation to check basic skills of fresher

Factorial long Factorial( int n ) { if ( n>0 ) return( n * Factorial(n-1) ); else return( 1 ); } Fibonacci int Fibonacci( int n ) { if ( n==1 || n==2 ) return( 1 ); else return( Fibonacci(n-1) + Fibonacci(n-2) ); } GCD int GCD( int a, int b ) { if ( a>=b && a%b==0 ) return( b ); else if ( a<b ) return( GCD( b, a ) ); else return( GCD( b, a%b ) ); } Power double Power( double x, int n ) { if ( n==0 ) return( 1 ); else if ( n>0 ) return( x * Power( x, n-1 ) ); else return( (1/x) * Power( x, n+1 ) ); } Reverse Printing void ReverseChar( void ) { char ch; if ( (ch=getchar( ))!='n' ) ReverseChar( ); putchar( ch ); } Decimal to binary conversion void ToBin( int n ) /* { if (n>1) ToBin( n/2 ); printf( "%d", n%2 ); } Decimal to hexadecimal conversion void ToHex( int n ) { char *htab[ ] = { "0", "1", "2", "3", "4", "5", "6", "7&quo


Expression tag ( <%= %>) This tag is used to sent the output of the expression to the output stream like method println(). This tag allows the developer to embed any Java expression and is short for out.println(). This tag starts with <%= and ends with %>. A semicolon ( ; ) does not appear at the end of the code inside the tag. For example,to show the current date and time. <HTML> <HEAD> <TITLE>MCA</TITLE> </HEAD> <BODY> Date : <%= new java.util.Date() %> </BODY> </HTML> Declaration tag ( <%! %> ) This tag allows the developer to declare variables or methods. Before the declaration you must have <%! At the end of the declaration, the developer must have %> Code placed in this tag must end in a semicolon ( ; ). Declarations do not generate output so are used with JSP expressions or scriptlets. For Example, <%! S

JSP : Predifined variables | implicit objects

There are following implicit objects those become available to programmer to use in JSP page.   out The out implicit object is an instance of a javax.servlet.jsp.JspWriter object and is used to send content in a response. The JspWriter object emulates some of the functionality found in the and objects to provide a convenient method of writing text in a buffered fashion. The out implicit object can be configured on a per JSP basis by the page directive. Example : <HTML> <HEAD> <TITLE>JSP Demo</TITLE> </HEAD> <BODY> <% out.write("Server Date is: "); %> <% out.write(new java.util.Date().toString()); %> </BODY> </HTML>   request The request implicit object is an instance of a javax.servlet.http.HttpServletRequest object. The request implicit object represents a client's request and is a reference to the HttpServletRequest object passed

@AttributeOverrides annotation in hibernate/JPA

@AttributeOverrides annotation is used in hibernate/JPA to rename the column(s) name of the embadable class while it is being embedded in other class. Suppose A class is embedded in class B, then if A entity contains the column name of any property "phone", then B entity can override the column name to "mobileNumber". So, in the table, column name will be "mobileNumber". package  entity; import Serializable ; import  javax.persistence.Column; import  javax.persistence.Embeddable; @Embeddable public   class  ContactKey  implements   Serializable   {      private   int  roll;      private   String  sem;      private   String  branch;      public   int   getRoll ()   {          return  roll;      }      public   void   setRoll ( int  roll )   {          this .roll  =  roll;      }     @ Column ( name  =   "sem" )      public   String   getSem ()   {          return  sem;      }      public   void   setSem ( Str

Hibernate (or JPA) - Using "mappedBy" attribute of mapping annotations(like @OneToOne, @OneToMany, @ManyToMany)

Using " mappedBy " attribute of mapping annotations(like @OneToOne, @OneToMany, @ManyToMany) for bi-directional relationship. This attribute allows you to refer the associated entities from both sides. If "X" has association with "Y" then you can get X from Y and Y from X. For example, If you have "Book" entity and "Author" entity those are associated to each other in the way that Book has a Author and Author associated with a Book. Now if you retrieve the Book Object from hibernate session, then you can get the Author entity from Book entity. Or if you get the Author entity then you can get the Book entity from Author entity. So you require the bidirectional navigation relationships between Book and Author entities. This is achieved in the Hibernate using the  @OneToOne relationship provided that child entity must have property type of parent and marked with annotation @OneToOne(mappedBy="parent") where parent is the Ow