Showing posts with label Interview. Show all posts
Showing posts with label Interview. Show all posts

Sunday, May 1, 2011

Servlet Interview Question | Latest Servlet/JSP Interview Question


Q) What is the difference between JSP and Servlets ?
A)JSP is used mainly for presentation only. A JSP can only be HttpServlet that means the only supported protocol in JSP is HTTP. But a servlet can support any protocol like HTTP, FTP, SMTP etc.

Q )What is difference between custom JSP tags and beans?
A)Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body are interpreted, and then group your tags into collections called tag libraries that can be used in any number of JSP files. To use custom JSP tags, you need to define three separate components: the tag handler class that defines the tag’s behavior ,the tag library descriptor file that maps the XML element names to the tag implementations and the JSP file that uses the tag library
JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. You use tags
Custom tags and beans accomplish the same goals — encapsulating complex behavior into simple and accessible forms. There are several differences:
Custom tags can manipulate JSP content; beans cannot. Complex operations can be reduced to a significantly simpler form with custom tags than with beans. Custom tags require quite a bit more work to set up than do beans. Custom tags usually define relatively self-contained behavior, whereas beans are often defined in one servlet and used in a different servlet or JSP page. Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.

Q) What are the different ways for session tracking?
A)Cookies, URL rewriting, HttpSession, Hidden form fields

Q) What mechanisms are used by a Servlet Container to maintain session information?
A)Cookies, URL rewriting, and HTTPS protocol information are used to maintain session information

Q) Difference between GET and POST
A)In GET your entire form submission can be encapsulated in one URL, like a hyperlink. query length is limited to 255 characters, not secure, faster, quick and easy. The data is submitted as part of URL.
In POST data is submitted inside body of the HTTP request. The data is not visible on the URL and it is more secure.

Q) What is session?
A)The session is an object used by a servlet to track a user’s interaction with a Web application across multiple HTTP requests. The session is stored on the server.

Q) What is servlet mapping?
A)The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to Servlets.

Q) What is servlet context ?
A)The servlet context is an object that contains a information about the Web application and container. Using the context, a servlet can log events, obtain URL references to resources, and set and store attributes that other servlets in the context can use.

Q) What is a servlet ?
A)servlet is a java program that runs inside a web container.

Q) Can we use the constructor, instead of init(), to initialize servlet?
A)Yes. But you will not get the servlet specific things from constructor. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructor a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.

Q) How many JSP scripting elements are there and what are they?
A)There are three scripting language elements: declarations, scriptlets, expressions.

Q) How do I include static files within a JSP page?
A)Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase.

Q) How can I implement a thread-safe JSP page?
A)You can make your JSPs thread-safe adding the directive <%@ page isThreadSafe=”false” % > within your JSP page.

Q) What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?
A)In request.getRequestDispatcher(path) in order to create it we need to give the relative path of the resource. But in resourcecontext.getRequestDispatcher(path) in order to create it we need to give the absolute path of the resource.

Q) What are the lifecycle of JSP?
A)When presented with JSP page the JSP engine does the following 7 phases.
Page translation: -page is parsed, and a java file which is a servlet is created.
Page compilation: page is compiled into a class file
Page loading : This class file is loaded.
Create an instance :- Instance of servlet is created
jspInit() method is called
_jspService is called to handle service calls
_jspDestroy is called to destroy it when the servlet is not required.

Q) What are context initialization parameters?
A)Context initialization parameters are specified by the <context-param> in the web.xml file, these are initialization parameter for the whole application.

Q) What is a Expression?
A)Expressions are act as place holders for language expression, expression is evaluated each time the page is accessed. This will be included in the service method of the generated servlet.

Q) What is a Declaration?
A)It declares one or more variables or methods for use later in the JSP source file. A declaration must contain at least one complete declarative statement. You can declare any number of variables or methods within one declaration tag, as long as semicolons separate them. The declaration must be valid in the scripting language used in the JSP file. This will be included in the declaration section of the generated servlet.

Q) What is a Scriptlet?
A)A scriptlet can contain any number of language statements, variable or expressions that are valid in the page scripting language. Within scriptlet tags, you can declare variables to use later in the file, write expressions valid in the page scripting language, use any of the JSP implicit objects or any object declared with a <jsp:useBean>. Generally a scriptlet can contain any java code that are valid inside a normal java method. This will become the part of generated servlet’s service method.

SBI Exam Practice paper | Latest SBI exam Sample papers with answers


Q)Study each of the following table and choose the alternative which can best replace the question mark (?)
*1 2 3 2 10 12
*2 5 12 10 16 13
*1 2 1 ? 10 24

options :

(a) 5   (b) 11   (c) 13   (d) 8
Ans (c)

Q)Study each of the following table and choose the alternative which can best replace the question mark (?)
*3 8 10 2 ? 1
*6 56 90 2 20 0
options:
(a) 0 (b) 3 (c) 5 (d) 7
Ans (c)

Q)In the following question one term in the number series is wrong. Find out the wrong term.*11, 5, 20, 12, 40, 26, 74, 54
options:
(a) 5 (b) 20 (c) 40 (d) 26
Ans (c)

Q)In the following question one term in the number series is wrong. Find out the wrong term.
*8, 14, 26, 48, 98, 194, 386
options:
(a) 14 (b) 48 (c) 98 (d) 194
Ans (b)

Q)Calculate value of each word by the following formula:
Consonants = (2 × Position of the letter in alphabet) – 1
Vowels = (3 × Position in alphabet) + 1
CHANGE
options:
(a) 77 (b) 79 (c) 83 (d) 80
Ans (d)

Q)Calculate value of each word by the following formula:
Consonants = (2 × Position of the letter in alphabet) – 1
Vowels = (3 × Position in alphabet) + 1
FLUTE
options:
(a) 153 (b) 157 (c) 151 (d) 149
Ans (a)

Q)Calculate value of each word by the following formula:Consonants = (2 × Position of the letter in alphabet) – 1
Vowels = (3 × Position in alphabet) + 1
BREAD
options:
(a) 67 (b) 62 (c) 59 (d) 65
Ans (d)

Q) In a certain code language, ‘3a, 2b, 7c’ means ‘Truth is Eternal’; ‘7c, 9a, 8b, 3a’ means ‘Enmity is not Eternal’ and 6a, 4d, 2b, 8b’ means ‘Truth does not perish’. Which of the following means ‘enmity’ in that language?
options:
(a) 3a (b) 7c (c) 8b (d) 9a
Ans (d)

Q)In a certain code language, ‘po ki top ma’ means ‘Usha is playing cards’; ‘Kop ja ki ma’ means ‘Asha is playing tennis’; ki top sop ho’ means ‘they are playing football’; and ‘po sur kop’ means ‘cards and tennis’. Which word in that language means ‘Asha’?
options:
(a) ja (b) ma (c) kop (d) top
Ans (a)

Q)A girl was born on September 6, 1970, which happened to be a Sunday. Her birthday has again fall on Sunday in
options:
(a) 1975 (b) 1976 (c) 1977 (d) 1981
Ans (d)

Q)A long rope has to be cut to make 23 small pieces. If it is double folded to start with how many times does it need to be cut?
options:
(a) 9 (b) 23 (c) 11 (d) 12
Ans (c)

Q)There are 19 hockey players in a club. On a particular day 14 were wearing the hockey shirts prescribed, while 11 were wearing the prescribed hockey pants. None of them was without either hockey pants or hockey shirts. How many were in complete hockey uniform?
options:
(a) 8 (b) 6 (c) 9 (d) 7
Ans (b)

Q)In a class room three fourth of the boys are above 160 cm in height and they are 18 in number. Also out of the total strength, the boys form only two third and the rest are girls. The total number of girls in the class is
options:(a) 18 (b) 24 (c) 12 (d) 30
Ans (c)

Q)A is east of B and west of C. H is South-West of C, B is South-East of X. which is farthest West?
options:
(a) C (b) A (c) X (d) B
Ans (c)

Q)A girl earns twice as much in December as in each of the other months. What part of her entire year’s earning does she earn in December?
options:
(a) 2/11 (b) 2/13 (c) 3/14 (d) 1/6
Ans (b)

Q)One watch is 1 minute slow at 1 pm on Tuesday and 2 minutes fast at 1 pm on Thursday. When did it show the correct time?
options:
(a) 1.00 am on Wednesday (b) 5.00 am on Wednesday (c) 1.00 pm on Wednesday (d) 5.00 pm on Wednesday

Latest PHP Interview Question Answers | Basic & Most asked Question of PHP


Q 1)Which function in PHP gives us absolute path of a file on the server?
< ?php $p = getcwd(); echo $p; ?> Ans: getcwd() Here I have stored my files under httdocs (using php5,i haven’t checked under php4) so I get the output as C:\apache2triad\htdocs you may get your path information while runnings the above code.

Q 2)what is the php solution to dynamic caching ?
www.w3answers.com PHP offers an extremely simple solution to dynamic caching in the form of output buffering.

Q 3)What is the difference between strstr() and stristr()?
strstr — Find first occurrence of a string strstr() example < ?php$email = 'user@example.com';$domain = strstr($email, '@');echo $domain; // prints @example.com?> stristr — Case-insensitive strstr() stristr() example < ?php$email = 'USER@EXAMPLE.com';echo stristr($email, 'e');// outputs ER@EXAMPLE. ....!
Is it possible to set a time expire page in PHP.?
Yes it is Using header("Expires: Mon, 26 Jul 2007 05:00:00 GMT"); .

Q 4)What is MIME?
MIME is Multipurpose Internet Mail Extensions is an internet standard for the format of e-mail. Howewer browsers also uses MIME standart to transmit files. MIME has a header wich is added to a begining of the data. When browser sees such header it shows the data as it would be a file (for example image) some mimes:audio/x-ms-wmpimage/pngaplication/x-shockwave-flash .
5)What is the maximum length of a table name, a database name, or a field name in MySQL?
Ans: Database name: 64 characters Table name: 64 characters Column name: 64 characters ….!
php supports following database
a) Solid & oracle b) mysql c) None of the above d) All of the above All of the above ….!
what are the ‘function problems’ you have met in php?
1)Call to undefined function we_w3answers() ***************************************** PHP is trying to call the function we_w3answers(), which has not been because you misspelled the name of a function (built-in or user-defined) simply omitted the function definition. If you use include/require functions, make sure that you are loading the appropriate files. 2)Call to undefined function array() *********************************** This problem has a cause that i….!

Q 6)What is meant by Exceptional Handling?
Exceptions PHP 5 has an exception model similar to that of other programming languages. An exception can be thrown, try and caught within PHP. A Try block must include at least one catch block. Multiple catch blocks can be used to catch different classtypes; execution will continue after that last catch block defined in sequence. Exceptions can be thrown within catch blocks. When an exception is thrown, code following the statement will not be executed and PHP will attempt to find the first matching catch block. ….!
Q 7)what is the output here?
< ?php var_dump(0 == "a"); ?>
a) false
b) true
c) error
d) declaration error ANS : true ….!

Q 8)What will be the following script output?
< ?php$a = 1;$a = $a— + 1;echo $a;?>
A. 2
B. 1
C. 3
D. 0
E. Null Answer : B is correct. ….!

Q 9)What are the different functions in sorting an array?
Ans: asort() arsort() ksort() krsort() uksort() sort() natsort() rsort() ….!

Q 10)What is the difference between the functions unlink() and unset()?
unlink is a function for file system handling. It will simply delete the file in context unset will set UNSET the variable ….!

Q 11)What will be the following script output?
< ?php$x = 3 - 5 % 3;echo $x;?>
A. 2
B. 1
C. Null
D. True
E. 3 Answer A is correct. Because of operator precedence, the modulus operation isperformed first, yielding a result of 2 (the remainder of the division of 5 by 2).Then, the result of this operation is subtracted from the integer 3. ….!

Q 12)< ?php
$x = 3 - 5 % 3;
echo $x;
?>
A. 2
B. 1
C. Null
D. True
E. 3 Answer A is correct.
Because of operator precedence, the modulus operation is
performed first, yielding a result of 2 (the remainder of the division of 5 by 2).
Then, the result of this operation is subtracted from the integer 3.
….!

Basic MySql Database Questions with Answers | MySql Mostly Asked Question in Interview


Q 1 how to do login in mysql with unix shell
A: By below method if password is pass and user name is root
A# [mysql dir]/bin/mysql -h hostname -u root -p pass

Q 2 how you will Create a database on the mysql server with unix shell
A: mysql> create database databasename;

Q 3 how to list or view all databases from the mysql server.
A: mysql> show databases;

Q4 How Switch (select or use) to a database.
A: mysql> use databasename;

Q 5 How To see all the tables from a database of mysql server.
A: mysql> show tables;

Q 6 How to see table’s field formats or description of table .
A: mysql> describe tablename;

Q7 How to delete a database from mysql server.
A : mysql> drop database databasename;

Q 8 How we get Sum of column
A : mysql> SELECT SUM(*) FROM [table name];

Q9 How to delete a table
A : mysql> drop table tablename;

Q 10 How you will Show all data from a table.
A : mysql> SELECT * FROM tablename;

Q 11 How to returns the columns and column information pertaining to the designated table
A: mysql> show columns from tablename;

Q12 How to Show certain selected rows with the value “pcds”
A : mysql> SELECT * FROM tablename WHERE fieldname = “pcds”;

Q13 How will Show all records containing the name “sonia” AND the phone number ’9876543210′
A: mysql> SELECT * FROM tablename WHERE name = “sonia” AND phone_number = ’9876543210′;

Q 14 How you will Show all records not containing the name “sonia” AND the phone number ’9876543210′ order by the phone_number field.
A: mysql> SELECT * FROM tablename WHERE name != “sonia” AND phone_number = ’9876543210′ order by phone_number;

Q 15 How to Show all records starting with the letters ‘sonia’ AND the phone number ’9876543210′
A : mysql> SELECT * FROM tablename WHERE name like “sonia%” AND phone_number = ’9876543210′;

Q16 How to show all records starting with the letters ‘sonia’ AND the phone number ’9876543210′ limit to records 1 through 5.
A: mysql> SELECT * FROM tablename WHERE name like “sonia%” AND phone_number = ’9876543210′ limit 1,5;

Q 17 Use a regular expression to find records. Use “REGEXP BINARY” to force case-sensitivity. This finds any record beginning with r.
A :mysql> SELECT * FROM tablename WHERE rec RLIKE “^r”;

Q 18How you will Show unique records.
A: mysql> SELECT DISTINCT columnname FROM tablename;

Q 19 how we will Show selected records sorted in an ascending (asc) or descending (desc)
A : mysql> SELECT col1,col2 FROM tablename ORDER BY col2 DESC;
mysql> SELECT col1,col2 FROM tablename ORDER BY col2 ASC;

Q20 how to Return total number of rows.
A: mysql> SELECT COUNT(*) FROM tablename;

Q21 How to Join tables on common columns.
A: mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id