<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8829103433621523357</id><updated>2024-11-01T00:31:22.800-07:00</updated><category term="COREJAVA INTERVIEW QUESTIONS1"/><category term="COREJAVA INTERVIEW QUESTIONS2"/><category term="COREJAVA INTERVIEW QUESTIONS3"/><category term="COREJAVA INTERVIEW QUESTIONS4"/><category term="COREJAVA INTERVIEW QUESTIONS5"/><category term="COREJAVA INTERVIEW QUESTIONS6"/><category term="DATABASE QUESTIONS"/><category term="EJB FAQS"/><category term="JDBC"/><category term="JSP QUESTIONS"/><category term="SERVLETS"/><category term="STRUTS"/><title type='text'>ItJobsFaqs</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://itjobsfaqs.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://itjobsfaqs.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Tiru Reddy</name><uri>http://www.blogger.com/profile/13152630017999545653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8829103433621523357.post-3890246266483110982</id><published>2010-08-02T22:50:00.000-07:00</published><updated>2010-08-02T22:54:34.013-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DATABASE QUESTIONS"/><title type='text'>DATABASE QUESTIONS</title><content type='html'>&lt;strong&gt;&lt;FONT COLOR=&quot;RED&quot;&gt;Database Questions&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=&quot;BLACK&quot;&gt;&lt;br /&gt;Q) DML  insert, update, delete&lt;br /&gt;&lt;br /&gt;     DDL  create, alter, drop, truncate, rename.&lt;br /&gt;&lt;br /&gt;     DQL  select&lt;br /&gt;&lt;br /&gt;     DCL  grant, revoke.&lt;br /&gt;&lt;br /&gt;     TCL  commit, rollback, savepoint.&lt;br /&gt;   &lt;br /&gt;Q) Normalization&lt;br /&gt; Normalization is the process of simplifying the relationship between data elements in a record.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q) Normal forms&lt;br /&gt;&lt;br /&gt;(i) 1st normal form : - 1st N.F is achieved when all repeating groups are removed, and P.K should be defined.&lt;br /&gt;&lt;br /&gt;(ii) 2nd  normal form : - Eliminate any non full dependence of data item on record keys.&lt;br /&gt;&lt;br /&gt;(iii) 3rd  normal form : - Eliminate any transitive dependence of  data items on P.K’s.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q) Diff Primary key and a Unique key? What is foreign key?&lt;br /&gt;A) Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn&#39;t allow NULLs, but unique key allows one NULL only.&lt;br /&gt;&lt;br /&gt;Foreign key constraint prevents any actions that would destroy link between tables with the corresponding data values. A foreign key in one table points to a primary key in another table. Foreign keys prevent actions that would leave rows with foreign key values when there are no primary keys with that value. The foreign key constraints are used to enforce referential integrity.&lt;br /&gt;CHECK constraint is used to limit the values that can be placed in a column. The check constraints are used to enforce domain integrity.&lt;br /&gt;NOT NULL constraint enforces that the column will not accept null values. The not null constraints are used to enforce domain integrity, as the check constraints.&lt;br /&gt;&lt;br /&gt;Q) Diff Delete &amp; Truncate? &lt;br /&gt;A) Rollback is possible after DELETE but TRUNCATE remove the table permanently and can’t rollback. Truncate will remove the data permanently we cannot rollback the deleted data. &lt;br /&gt;&lt;br /&gt;Dropping  :  (Table structure  + Data are deleted), Invalidates the dependent objects, Drops the indexes &lt;br /&gt;Truncating :  (Data alone deleted), Performs an automatic commit, Faster than delete&lt;br /&gt;Delete        : (Data alone deleted), Doesn’t perform automatic commit&lt;br /&gt; &lt;br /&gt;Q) Diff Varchar and Varchar2?&lt;br /&gt;A) The difference between Varchar and Varchar2 is both are variable length but only 2000 bytes of character of data can be store in varchar where as 4000 bytes of character of data can be store in varchar2.&lt;br /&gt;&lt;br /&gt;Q) Diff LONG &amp; LONG RAW?&lt;br /&gt;A) You use the LONG datatype to store variable-length character strings. The LONG datatype is like the VARCHAR2 datatype, except that the maximum length of a LONG value is 32760 bytes.&lt;br /&gt;     You use the LONG RAW datatype to store binary data (or) byte strings. LONG RAW data is like LONG data, except that LONG RAW data is not interpreted by PL/SQL. The maximum length of a LONG RAW value is 32760 bytes.&lt;br /&gt;&lt;br /&gt;Q) Diff Function &amp; Procedure &lt;br /&gt; Function is a self contained program segment, function will return a value but procedure not.&lt;br /&gt; Procedure is sub program will perform some specific actions.&lt;br /&gt;&lt;br /&gt;Q) How to find out duplicate rows &amp; delete duplicate rows in a table?&lt;br /&gt;A)&lt;br /&gt;   MPID EMPNAME EMPSSN&lt;br /&gt;-------  --------------- ----------------&lt;br /&gt;    1  Jack         555-55-5555&lt;br /&gt;    2       Mike         555-58-5555&lt;br /&gt;    3       Jack         555-55-5555&lt;br /&gt;    4       Mike         555-58-5555&lt;br /&gt;SQL&gt; select count (empssn), empssn from employee group by empssn having count (empssn) &gt; 1;&lt;br /&gt;&lt;br /&gt;COUNT (EMPSSN) EMPSSN&lt;br /&gt;-------------            -----------&lt;br /&gt;            2 555-55-5555&lt;br /&gt;            2 555-58-5555&lt;br /&gt;&lt;br /&gt;SQL&gt; delete from employee where (empid, empssn) &lt;br /&gt;                           not in (select min (empid), empssn from employee group by empssn);&lt;br /&gt;Good approach&lt;br /&gt;SQL&gt; delete ename from emp a where rowid &lt; (select min(rowid) from emp b where a.ename = b.ename);&lt;br /&gt;&lt;br /&gt;Matrix Report &lt;br /&gt;Select * from (select job,sum(decode (deptno,10,sal)) DEPT10,&lt;br /&gt;   sum(decode (deptno,20,sal)) DEPT20,&lt;br /&gt;   sum(decode (deptno,30,sal)) DEPT30 from &lt;br /&gt;emp group by job);&lt;br /&gt;&lt;br /&gt;Q) Select the nth highest rank from the table?&lt;br /&gt;A) Select * from tab t1 where 2=(select count (distinct (t2.sal)) from tab t2 where t1.sal&lt;=t2.sal)&lt;br /&gt;&lt;br /&gt;Q) a) Emp table where fields empName, empId, address&lt;br /&gt;   b) Salary table where fields EmpId, month, Amount&lt;br /&gt;these 2 tables he wants EmpId, empName and salary for month November?&lt;br /&gt;A) Select emp.empId, empName, Amount from emp, salary where emp.empId=salary.empId and month=November;&lt;br /&gt;&lt;br /&gt;Q) Oracle/PLSQL: Synonyms?&lt;br /&gt;A) A synonym is an alternative name for objects such as tables, views, sequences, stored procedures, and other database objects&lt;br /&gt;&lt;br /&gt;Syntax: -&lt;br /&gt;Create [or replace]  [public] synonym [schema.] synonym_name for [schema.] object_name;&lt;br /&gt;&lt;br /&gt;or replace -- allows you to recreate the synonym (if it already exists) without having to issue a DROP synonym command.&lt;br /&gt;Public -- means that the synonym is a public synonym and is accessible to all users. &lt;br /&gt;Schema -- is the appropriate schema.  If this phrase is omitted, Oracle assumes that you are referring to your own schema.&lt;br /&gt;object_name -- is the name of the object for which you are creating the synonym. It can be one of the following:&lt;br /&gt;Table Package&lt;br /&gt;View materialized view&lt;br /&gt;sequence java class schema object&lt;br /&gt;stored procedure user-defined object&lt;br /&gt;Function Synonym&lt;br /&gt; &lt;br /&gt;Example: &lt;br /&gt;Create public synonym suppliers for app. suppliers;&lt;br /&gt;Example demonstrates how to create a synonym called suppliers.  Now, users of other schemas can reference the table called suppliers without having to prefix the table name with the schema named app.  For example:&lt;br /&gt;Select * from suppliers;&lt;br /&gt;&lt;br /&gt;If this synonym already existed and you wanted to redefine it, you could always use the or replace phrase as follows:&lt;br /&gt;Create or replace public synonym suppliers for app. suppliers;&lt;br /&gt;Dropping a synonym&lt;br /&gt;It is also possible to drop a synonym.&lt;br /&gt;drop [public]  synonym  [schema .]  synonym_name [force];&lt;br /&gt;public -- phrase allows you to drop a public synonym.  If you have specified public, then you don&#39;t specify a schema.&lt;br /&gt;Force -- phrase will force Oracle to drop the synonym even if it has dependencies.  It is probably not a good idea to use the force phrase as it can cause invalidation of Oracle objects.&lt;br /&gt; &lt;br /&gt;example:&lt;br /&gt;Drop public synonym suppliers;&lt;br /&gt;This drop statement would drop the synonym called suppliers that we defined earlier.&lt;br /&gt;&lt;br /&gt;Q) What is an alias and how does it differ from a synonym? &lt;br /&gt;A) An alias is an alternative to a synonym, designed for a distributed environment to avoid having to use the location qualifier of a table or view.  The alias is not dropped when the table is dropped.&lt;br /&gt;&lt;br /&gt;Q) What are joins? Inner join &amp; outer join?&lt;br /&gt;A) By using joins, you can retrieve data from two or more tables based on logical relationships between the tables&lt;br /&gt;&lt;br /&gt;Inner Join: - returns all rows from both tables where there is a match&lt;br /&gt;Outer Join: - outer join includes rows from tables when there are no matching values in the tables. &lt;br /&gt;&lt;br /&gt;• LEFT JOIN or LEFT OUTER JOIN &lt;br /&gt;The result set of a left outer join includes all the rows from the left table specified in the LEFT OUTER clause, not just the ones in which the joined columns match. When a row in the left table has no matching rows in the right table, the associated result set row contains null values for all select list columns coming from the right table.&lt;br /&gt;&lt;br /&gt;• RIGHT JOIN or RIGHT OUTER JOIN. &lt;br /&gt;A right outer join is the reverse of a left outer join. All rows from the right table are returned. Null values are returned for the left table any time a right table row has no matching row in the left table.&lt;br /&gt;&lt;br /&gt;• FULL JOIN or FULL OUTER JOIN. &lt;br /&gt;A full outer join returns all rows in both the left and right tables. Any time a row has no match in the other table, the select list columns from the other table contain null values. When there is a match between the tables, the entire result set row contains data values from the base tables.&lt;br /&gt;&lt;br /&gt;Q. Diff join and a Union? &lt;br /&gt;A) A join selects columns from 2 or more tables. A union selects rows.  &lt;br /&gt;when using the UNION command all selected columns need to be of the same data type. The UNION command eliminate duplicate values.&lt;br /&gt;&lt;br /&gt;Q. Union &amp; Union All?&lt;br /&gt;A) The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values. It cannot eliminate duplicate values.&lt;br /&gt; &gt; SELECT E_Name FROM Employees_Norway&lt;br /&gt;UNION ALL&lt;br /&gt;    SELECT E_Name FROM Employees_USA&lt;br /&gt;&lt;br /&gt;Q) Is the foreign key is unique in the primary table? &lt;br /&gt;A) Not necessary&lt;br /&gt;&lt;br /&gt;Q) Table mentioned below named employee&lt;br /&gt;ID NAME MID&lt;br /&gt;1 CEO Null&lt;br /&gt;2 VP CEO&lt;br /&gt;3 Director VP&lt;br /&gt;&lt;br /&gt;Asked to write a query to obtain the following output&lt;br /&gt;CEO  Null&lt;br /&gt;VP CEO&lt;br /&gt;Director VP&lt;br /&gt;&lt;br /&gt;A) SQL&gt; Select a.name, b.name from employee a, employee b where a.mid=b.id(+).&lt;br /&gt;&lt;br /&gt;Q) Explain a scenario when you don’t go for normalization?&lt;br /&gt;A) If we r sure that there wont be much data redundancy then don’t go for normalization.&lt;br /&gt;&lt;br /&gt;Q) What is Referential integrity? &lt;br /&gt;A) R.I refers to the consistency that must be maintained between primary and foreign keys, i.e. every foreign key value must have a corresponding primary key value. &lt;br /&gt;&lt;br /&gt;Q) What is Normalization? Explain in details?&lt;br /&gt;A)  Normalization is the process of simplifying the relation ship between data elements in a record.&lt;br /&gt;     &lt;br /&gt;     1st N.F -- the big table is broken into many small tables, such that each table has a primary key.&lt;br /&gt;     2nd N.F – Removes partial dependency. Ie The columns in a table which is not completely dependant on   the primary key are taken to a separate table&lt;br /&gt;     3rd N.F – Removes Transitive dependency. Ie If X is the primary key in a table. Y &amp; Z are columns in the same table. Suppose Z depends only on Y and Y depends on X. Then Z does not depend directly on primary key. So remove Z from the table to a look up table.&lt;br /&gt;&lt;br /&gt;Q) What techniques are used to retrieve data from more than one table in a single SQL statement? &lt;br /&gt;A) Joins, unions and nested selects are used to retrieve data. &lt;br /&gt;&lt;br /&gt;Q) What is a view? Why use it? &lt;br /&gt;A) A view is a virtual table made up of data from base tables and other views, but not stored separately. &lt;br /&gt;&lt;br /&gt;Q) SELECT statement syntax?&lt;br /&gt;A) SELECT [ DISTINCT | ALL ]  column_expression1, column_expression2, ....&lt;br /&gt;  [ FROM from_clause ]&lt;br /&gt;  [ WHERE where_expression ]&lt;br /&gt;  [ GROUP BY expression1, expression2, .... ]&lt;br /&gt;  [ HAVING having_expression ]&lt;br /&gt;  [ ORDER BY order_column_expr1, order_column_expr2, .... ]&lt;br /&gt;&lt;br /&gt;column_expression ::= expression [ AS ] [ column_alias ]&lt;br /&gt;from_clause ::= select_table1, select_table2, ...&lt;br /&gt;from_clause ::= select_table1 LEFT [OUTER] JOIN select_table2 ON expr  ...&lt;br /&gt;from_clause ::= select_table1 RIGHT [OUTER] JOIN select_table2 ON expr  ...&lt;br /&gt;from_clause ::= select_table1 [INNER] JOIN select_table2  ...&lt;br /&gt;select_table ::= table_name [ AS ] [ table_alias ]&lt;br /&gt;select_table ::= ( sub_select_statement ) [ AS ] [ table_alias ]&lt;br /&gt;order_column_expr ::= expression [ ASC | DESC ]&lt;br /&gt;&lt;br /&gt;Q) DISTINCT clause?&lt;br /&gt;A) The DISTINCT clause allows you to remove duplicates from the result set.&lt;br /&gt;      &gt; SELECT DISTINCT city FROM supplier;&lt;br /&gt;&lt;br /&gt;Q) COUNT function?&lt;br /&gt;A) The COUNT function returns the number of rows in a query&lt;br /&gt;       &gt; SELECT COUNT (*) as &quot;No of emps” FROM employees WHERE salary &gt; 25000;&lt;br /&gt;&lt;br /&gt;Q) Diff HAVING CLAUSE &amp; WHERE CLAUSE?  &lt;br /&gt;A) Having Clause is basically used only with the GROUP BY function in a query. &lt;br /&gt;WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.&lt;br /&gt;&lt;br /&gt;Q) Diff GROUP BY &amp; ORDER BY? &lt;br /&gt;A) Group by controls the presentation of the rows; order by controls the presentation of the columns for the results of the SELECT statement. &lt;br /&gt;&lt;br /&gt;&gt; SELECT &quot;col_nam1&quot;, SUM (&quot;col_nam2&quot;) FROM &quot;tab_name&quot; GROUP BY &quot;col_nam1&quot;&lt;br /&gt;&gt; SELECT &quot;col_nam&quot; FROM &quot;tab_nam&quot; [WHERE &quot;condition&quot;] ORDER BY &quot;col_nam&quot; [ASC, DESC] &lt;br /&gt;&lt;br /&gt;Q) What keyword does an SQL SELECT statement use for a string search? &lt;br /&gt;A) The LIKE keyword allows for string searches.  The % sign is used as a wildcard. &lt;br /&gt;&lt;br /&gt;Q) What is a NULL value?  What are the pros and cons of using NULLS? &lt;br /&gt;A) NULL value takes up one byte of storage and indicates that a value is not present as opposed to a space or zero value. A NULL in a column means no entry has been made in that column. A data value for the column is &quot;unknown&quot; or &quot;not available.&quot; &lt;br /&gt;&lt;br /&gt;Q) Index? Types of indexes?&lt;br /&gt;A) Locate rows more quickly and efficiently. It is possible to create an index on one (or) more columns of a table, and each index is given a name. The users cannot see the indexes, they are just used to speed up queries. &lt;br /&gt;&lt;br /&gt;Unique Index: -&lt;br /&gt;A unique index means that two rows cannot have the same index value.&lt;br /&gt;   &gt;CREATE UNIQUE INDEX index_name ON table_name (column_name)&lt;br /&gt;&lt;br /&gt;When the UNIQUE keyword is omitted, duplicate values are allowed. If you want to index the values in a column in descending order, you can add the reserved word DESC after the column name:&lt;br /&gt;   &gt;CREATE INDEX PersonIndex ON Person (LastName DESC)&lt;br /&gt; &lt;br /&gt;If you want to index more than one column you can list the column names within the parentheses. &lt;br /&gt;   &gt;CREATE INDEX PersonIndex ON Person (LastName, FirstName)&lt;br /&gt;&lt;br /&gt;Q) Diff subqueries &amp; Correlated subqueries?&lt;br /&gt;A) subqueries are self-contained. None of them have used a reference from outside the subquery.&lt;br /&gt;Correlated subquery cannot be evaluated as an independent query, but can reference columns in a table listed in the from list of the outer query.&lt;br /&gt;&lt;br /&gt;Q) Predicates IN, ANY, ALL, EXISTS?&lt;br /&gt;A) Sbquery can return a subset of zero to n values. According to the conditions which one wants to express, one can use the predicates IN, ANY, ALL or EXISTS. &lt;br /&gt;&lt;br /&gt;IN  The comparison operator is the equality and the logical operation between values is OR.&lt;br /&gt;ANY  Allows to check if at least a value of the list satisfies condition. &lt;br /&gt;ALL  Allows to check if condition is realized for all the values of the list.&lt;br /&gt;EXISTS  If the subquery returns a result, the value returned is True otherwise the value returned is False. &lt;br /&gt;&lt;br /&gt;Q) What are some sql Aggregates and other Built-in functions? &lt;br /&gt;A) AVG, SUM, MIN, MAX, COUNT and DISTINCT. &lt;/FONT&gt;&lt;/strong&gt;</content><link rel='replies' type='application/atom+xml' href='http://itjobsfaqs.blogspot.com/feeds/3890246266483110982/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/database-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/3890246266483110982'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/3890246266483110982'/><link rel='alternate' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/database-questions.html' title='DATABASE QUESTIONS'/><author><name>Tiru Reddy</name><uri>http://www.blogger.com/profile/13152630017999545653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8829103433621523357.post-7048072925202735497</id><published>2010-08-02T22:48:00.000-07:00</published><updated>2010-08-02T22:50:40.713-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="STRUTS"/><title type='text'>STRUTS</title><content type='html'>&lt;strong&gt;&lt;FONT COLOR=&quot;RED&quot;&gt;Struts Questions&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=&quot;BLACK&quot;&gt;&lt;br /&gt;Q) Diff Struts1.0 &amp; 1.1?&lt;br /&gt;A) 1.RequestProcessor class, 2.Method perform() replaced by execute() in Struts base Action Class&lt;br /&gt;3. Changes to web.xml and struts-config.xml, 4. Declarative exception handling, 5.Dynamic ActionForms, 6.Plug-ins, 7.Multiple Application Modules, 8.Nested Tags, 9.The Struts Validator&lt;br /&gt;Change to the ORO package, 10.Change to Commons logging, 11. Removal of Admin actions, 12.Deprecation of the GenericDataSource&lt;br /&gt;&lt;br /&gt;Q) Struts Validator Framework?&lt;br /&gt;A) Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side. Struts Framework emits the java scripts and it can be used validate the form data on the client browser&lt;br /&gt;   &lt;br /&gt;Q) ActionServlet:- &lt;br /&gt;The class org.apache.struts.action.ActionServlet is the called the ActionServlet. In the Jakarta Struts Framework this class plays the role of controller. All the requests to the server goes through the controller. Controller is responsible for handling all the requests.&lt;br /&gt;&lt;br /&gt;Q) Action Class:- &lt;br /&gt;The Action Class is part of the Model and is a wrapper around the business logic. The purpose of Action Class is to translate the HttpServletRequest to the business logic. To use the Action, we need to  Subclass and overwrite the execute()  method. In the Action Class all the database/business processing are done. It is advisable to perform all the database related stuffs in the Action Class. The ActionServlet (commad) passes the parameterized class to Action Form using the execute() method. The return type of the execute method is ActionForward which is used by the Struts Framework to forward the request to the file as per the value of the returned ActionForward object.&lt;br /&gt;&lt;br /&gt;import javax.servlet.http.HttpServletRequest;&lt;br /&gt;import javax.servlet.http.HttpServletResponse;&lt;br /&gt;&lt;br /&gt;import org.apache.struts.action.Action;&lt;br /&gt;import org.apache.struts.action.ActionForm;&lt;br /&gt;import org.apache.struts.action.ActionForward;&lt;br /&gt;import org.apache.struts.action.ActionMapping;&lt;br /&gt;&lt;br /&gt;public class TestAction extends Action&lt;br /&gt;{&lt;br /&gt;  public ActionForward execute(&lt;br /&gt;    ActionMapping mapping,&lt;br /&gt;    ActionForm form,&lt;br /&gt;    HttpServletRequest request,&lt;br /&gt;    HttpServletResponse response) throws Exception{&lt;br /&gt;      return mapping.findForward(&quot;testAction&quot;);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Q) Action Form:-  &lt;br /&gt;An ActionForm is a JavaBean that extends org.apache.struts.action.ActionForm. ActionForm maintains the session state for web application and the ActionForm object is automatically populated on the server side with data entered from a form on the client side&lt;br /&gt;&lt;br /&gt;Q) Message Resource Definition file:-&lt;br /&gt; M.D.R file are simple .properties file these files contains the messages that can be used in struts project. The M.D.R can be added in struts-config.xml file through &lt;message-resource&gt; tag ex: &lt;message-resource parameter=”MessageResource”&gt;&lt;br /&gt;&lt;br /&gt;Q) Reset:- &lt;br /&gt;This is called by the struts framework with each request, purpose of this method is to reset all of the forms data members and allow the object to be pooled for rescue.&lt;br /&gt;&lt;br /&gt;public class TestAction extends ActionForm{&lt;br /&gt;  public void reset(ActionMapping mapping, HttpServletRequest request request)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Q) execute:- &lt;br /&gt;is called by the controller when a request is received from a client. The controller creates an instance of the Action class if one do not already exist. The frame work will create only a single instance of each Action class.&lt;br /&gt;&lt;br /&gt;  public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request,    HttpServletResponse response)&lt;br /&gt;&lt;br /&gt;Q) Validate:- &lt;br /&gt;This method is called by the controller after the values from the request has been inserted into the ActionForm. The ActionForm should perform any input validation that can be done and return any detected errors to the controller.&lt;br /&gt;&lt;br /&gt;public ActionErrors validate(ActionMapping mapping,  HttpServletRequest request)&lt;br /&gt;&lt;br /&gt;Q) Struts-config.xml&lt;br /&gt;&lt;br /&gt;&lt;struts-config&gt;&lt;br /&gt;&lt;br /&gt;    &lt;data-sources&gt;&lt;br /&gt;        &lt;data-sources&gt; &lt;br /&gt;               &lt;set-property property=”key” value=”   ” url=”” maxcount=”” mincount=””   user=”” pwd=”” &gt;                  &lt;br /&gt;        &lt;/data-sources&gt;&lt;br /&gt;    &lt;data-sources&gt;&lt;br /&gt;&lt;br /&gt;    &lt;!— describe the instance of the form bean-- &gt;&lt;br /&gt;    &lt;form-beans&gt;&lt;br /&gt;        &lt;form-bean name=&quot;employeeForm&quot; type=&quot;net.reumann.EmployeeForm&quot;/&gt; &lt;br /&gt;    &lt;/form-beans&gt;&lt;br /&gt; &lt;br /&gt;    &lt;!— to identify the target of an action class when it returns results -- &gt;&lt;br /&gt;    &lt;global-forwards&gt;&lt;br /&gt;        &lt;forward name=&quot;error&quot; path=&quot;/error.jsp&quot;/&gt;&lt;br /&gt;    &lt;/global-forwards&gt;&lt;br /&gt;&lt;br /&gt;    &lt;!— describe an action instance to the action servlet-- &gt;&lt;br /&gt;    &lt;action-mappings&gt;&lt;br /&gt;        &lt;action path=&quot;/setUpEmployeeForm&quot; type=&quot;net.reumann.SetUpEmployeeAction&quot;&lt;br /&gt;            name=&quot;employeeForm&quot; scope=&quot;request&quot; validate=&quot;false&quot;&gt;&lt;br /&gt;          &lt;forward name=&quot;continue&quot; path=&quot;/employeeForm.jsp&quot;/&gt;&lt;br /&gt;        &lt;/action&gt;&lt;br /&gt;&lt;br /&gt;        &lt;action path=&quot;/insertEmployee&quot; type=&quot;net.reumann.InsertEmployeeAction&quot;&lt;br /&gt;            name=&quot;employeeForm&quot; scope=&quot;request&quot; validate=&quot;true&quot;&lt;br /&gt;            input=&quot;/employeeForm.jsp&quot;&gt;&lt;br /&gt;         &lt;forward name=&quot;success&quot; path=&quot;/confirmation.jsp&quot;/&gt;&lt;br /&gt;        &lt;/action&gt;&lt;br /&gt;    &lt;/action-mappings&gt;&lt;br /&gt;    &lt;br /&gt;     &lt;!— to modify the default behaviour of the struts controller-- &gt; &lt;br /&gt;    &lt;controller processorClass=”” bufferSize=” ” contentType=””  noCache=””   maxFileSize=””/&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;!—define the collection of messages for this application -- &gt;&lt;br /&gt;    &lt;message-resources parameter=&quot;ApplicationResources&quot; null=&quot;false&quot; /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;plug-in className=””/&gt;&lt;br /&gt;&lt;br /&gt;&lt;/struts-config&gt;&lt;br /&gt;&lt;br /&gt;Q) web.xml :-&lt;br /&gt; Is a configuration file describing the deployment elements.&lt;br /&gt;&lt;br /&gt;&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;&lt;br /&gt;&lt;web-app&gt;&lt;br /&gt;  &lt;display-name&gt;Struts rr lesson 2&lt;/display-name&gt;&lt;br /&gt;&lt;br /&gt;  &lt;servlet&gt;&lt;br /&gt;    &lt;servlet-name&gt;action&lt;/servlet-name&gt;&lt;br /&gt;    &lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt;&lt;br /&gt;    &lt;init-param&gt;&lt;br /&gt;      &lt;param-name&gt;debug&lt;/param-name&gt;&lt;br /&gt;      &lt;param-value&gt;3&lt;/param-value&gt;&lt;br /&gt;    &lt;/init-param&gt;&lt;br /&gt;    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;&lt;br /&gt;  &lt;/servlet&gt;&lt;br /&gt;&lt;br /&gt;  &lt;! -- Action Servlet Mapping --&gt;&lt;br /&gt;  &lt;servlet-mapping&gt;&lt;br /&gt;    &lt;servlet-name&gt;action&lt;/servlet-name&gt;&lt;br /&gt;    &lt;url-pattern&gt;/do/*&lt;/url-pattern&gt;&lt;br /&gt;  &lt;/servlet-mapping&gt;&lt;br /&gt;&lt;br /&gt;  &lt;!-- The Welcome File List --&gt;&lt;br /&gt;  &lt;welcome-file-list&gt;&lt;br /&gt;    &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;&lt;br /&gt;  &lt;/welcome-file-list&gt;&lt;br /&gt;&lt;br /&gt;  &lt;!-- tag libs --&gt;&lt;br /&gt;  &lt;taglib&gt;&lt;br /&gt;    &lt;taglib-uri&gt;struts/bean-el&lt;/taglib-uri&gt;&lt;br /&gt;    &lt;taglib-location&gt;/WEB-INF/struts-bean-el.tld&lt;/taglib-location&gt;&lt;br /&gt;  &lt;/taglib&gt;&lt;br /&gt;&lt;br /&gt;  &lt;taglib&gt;&lt;br /&gt;    &lt;taglib-uri&gt;struts/html-el&lt;/taglib-uri&gt;&lt;br /&gt;    &lt;taglib-location&gt;/WEB-INF/struts-html-el.tld&lt;/taglib-location&gt;&lt;br /&gt;  &lt;/taglib&gt;&lt;br /&gt;&lt;br /&gt;  &lt;taglib&gt;&lt;br /&gt;    &lt;taglib-uri&gt;struts/logic-el&lt;/taglib-uri&gt;&lt;br /&gt;    &lt;taglib-location&gt;/WEB-INF/struts-logic-el.tld&lt;/taglib-location&gt;&lt;br /&gt;  &lt;/taglib&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/web-app&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Design Patterns Questions&lt;br /&gt;&lt;br /&gt;Service Locator&lt;br /&gt;To access different resources/services, J2EE compatible server binds these resources/services to the JNDI server so that the clients can lookup those resources/services through JNDI lookup process from anywhere in the network. The resources/services can be &lt;br /&gt;                1. EJBHome objects&lt;br /&gt;                2. DataSource objects&lt;br /&gt;                3. JMS ConnectionFactory&lt;br /&gt;                4. JMS Topic/Queue etc.&lt;br /&gt;EJB Client needs to initially get EJBHome object from JNDI to manage life cycle of EJBObjects. JMS clients need to get ConnectionFactory and Topic/Queue from JNDI for processing messages. JDBC clients need to get DataSource object in order to get database connection. All these services need to bind to the JNDI services and the clients need to lookup JNDI to get those services. Clients have to go through JNDI lookup process every time to work with these services. JNDI lookup process is expensive because clients need to get network connection to the JNDI server if the JNDI server is located on a different machine and need to go through lookup process every time, this is redundant and expensive. &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;The solution for the redundant and expensive JNDI lookup process problem is to cache those service objects when the client performs JNDI lookup first time and reuse that service object from the cache second time onwards for other clients. This technique maintains a cache of service objects and looks up the JNDI only first time for a service object. This technique reduces redundant and expensive JNDI lookup process thus increasing performance significantly. Service Locator Pattern implements this technique by having a class to cache service objects, methods for JNDI lookup and methods for getting service objects from the cache.&lt;br /&gt;The figure below shows the ServiceLocator class intercepting the client request and accessing JNDI once and only once for a service object.&lt;br /&gt; &lt;br /&gt;Here the clients call ServiceLocator class to get a service object rather than calling JNDI directly. ServiceLocator acts as interceptor between client and JNDI. For source code and different flavors of implementation of this Pattern, see the following links.&lt;br /&gt;&lt;br /&gt;Session Facade&lt;br /&gt;EJB clients (swing, servlets, jsps etc) can access entity beans directly. If EJB clients access entity beans directly over the network, it takes more network calls and imposes network overhead.   &lt;br /&gt;Here the servlet calls multiple entity beans directly to accomplish a business process, thereby increasing the number of network calls. &lt;br /&gt;The solution for avoiding number of network calls due to directly accessing multiple entity beans is to wrap entity beans with session bean (Facade). The EJB client accesses session bean (Facade) instead of entity beans through coarse grained method call to accomplish a business process.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Message Facade&lt;br /&gt;Session bean and entity bean methods execute synchronously that means the method caller has to wait till a value is returned. In some situations like sending hundred&#39;s of mails or firing a batch process or updating processes, the client does not have to bother about return value. If you use synchronous session and entity beans in such situations, they take a long time to process methods and clients have to wait till the method returns a value.&lt;br /&gt; &lt;br /&gt;The client has to wait till all the eight synchronous steps complete. This synchronous execution takes a long time and has an impact on performance when the method process is huge.&lt;br /&gt;&lt;br /&gt;To avoid blocking of a client, use asynchronous message driven beans, so that client does not have to wait for a return value. If a client uses asynchronous messaging then the client need not wait for a return value but can continue its flow of execution after sending the message. &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Value Object&lt;br /&gt;&lt;br /&gt;When a client calls a remote method there will be process of marshalling, network calls and unmarshalling involved for the remote method invocation. If you choose fine grained approach when calling methods remotely, there will be a significant network overhead involved. For example if you call fine grained method like this,&lt;br /&gt;        remoteObject.getName();&lt;br /&gt;        remoteObject.getCity();&lt;br /&gt;        remoteObject.getState();&lt;br /&gt;        remoteObject.getZipCode();&lt;br /&gt;Here, there are four network calls from client to the remote object because every method call is remote method call. &lt;br /&gt; &lt;br /&gt;The solution for avoiding many network calls due to fine grained method calls is to use coarse grained approach. For example :&lt;br /&gt;        // create an Value Object and fill that object locally &lt;br /&gt;        PersonInfo person = new PersonInfo();&lt;br /&gt;        person.setName(&quot;Ravi&quot;);&lt;br /&gt;        person.setCity(&quot;Austin&quot;);&lt;br /&gt;        person.setState(&quot;TX&quot;);&lt;br /&gt;        person.zipCode(&quot;78749&quot;);  &lt;br /&gt;        // send Value Object through network&lt;br /&gt;        remoteObject.getPersonInfo(person); &lt;br /&gt;Here, there is only one network call instead of three network calls and PersonInfo object is a Value Object. The following figure illustrates the coarse grained approach that is passing a Value Object through network.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;Value Object is an object that is passed over the network rather than passing each attributes separately thus increasing performance by reducing network calls.&lt;br /&gt;&lt;br /&gt;ValueObjectFactory&lt;br /&gt;For a single request, a client might need to access multiple server side components such as different session beans and entity beans. In such situations  the client accesses multiple components over the network, this increases the network traffic and has an impact on the performance. &lt;br /&gt; &lt;br /&gt; &lt;br /&gt;To reduce the network traffic due to accessing multiple components by a client for a single request, let ValueObjectFactory hold different ValueObjects as place holders and respond with a single ValueObject for a client request. Here ValueObjectFactory holds creation and delegation logic of ValueObjects for different client requests. &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Value List Handler&lt;br /&gt;J2EE applications generally have the search facility and have to search huge data and retrieve results. If an application returns huge queried data to the client, the client takes long time to retrieve that large data and If that application uses entity bean to search data, it has an impact on. &lt;br /&gt;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;1. Use Data Access Objects (DAO) rather than Entity beans&lt;br /&gt;2. Return small quantity of data multiple times iteratively rather than returning large amount of data at once to the client. &lt;br /&gt;Data Access Object encapsulates JDBC access logic. ValueListHandler caches list of Value objects that are retrieved through DAO. When client wants to search data, It calls ValueListHandler that is in turn responsible for caching data and returning data to the client iteratively.  &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Singleton&lt;br /&gt; There will be only one instance for the entire JVM. You can achieve this by having the private constructor in the class.&lt;br /&gt;Singleton is probably the most widely used design pattern. Its intent is to ensure that a class has only one instance, and to provide a global point of access to it. There are many situations in which a singleton object is necessary: a GUI application must have a single mouse, an active modem needs one and only one telephone line, an operating system can only have one window manager, and a PC is connected to a single keyboard &lt;br /&gt;&lt;br /&gt;     Public class Singleton{&lt;br /&gt;Private static final Singleton s = new Singleton();&lt;br /&gt;Private Singleton(){}&lt;br /&gt;Public static Singleton getInstance(){ return s;}&lt;br /&gt;     } &lt;br /&gt;&lt;br /&gt;Business Delegate&lt;br /&gt;The Business Delegate hides the underlying implementation details of the business service, such as lookup &amp; access details of the EJB architecture. The business delegates acts as a client-side business abstraction and hides the implementation of the business services.&lt;br /&gt;The delegate may cache results and references to remote business services. Caching can significantly improve performance, because it limits unnecessary and potentially costly round trips over the network.&lt;br /&gt;A Business Delegate uses a component called the Lookup Service. The Lookup Service is responsible for hiding the underlying implementation details of the business service lookup code. The Lookup Service may be written as part of the Delegate, but we recommend that it be implemented as a separate component, as outlined in the Service Locator pattern&lt;br /&gt;Figure shows the class diagram representing the Business Delegate pattern. The client requests the BusinessDelegate to provide access to the underlying business service. The BusinessDelegate uses a LookupService to locate the required BusinessService component.&lt;br /&gt;&lt;br /&gt; &lt;/FONT&gt;&lt;/strong&gt;</content><link rel='replies' type='application/atom+xml' href='http://itjobsfaqs.blogspot.com/feeds/7048072925202735497/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/struts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/7048072925202735497'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/7048072925202735497'/><link rel='alternate' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/struts.html' title='STRUTS'/><author><name>Tiru Reddy</name><uri>http://www.blogger.com/profile/13152630017999545653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8829103433621523357.post-2241892465432893113</id><published>2010-08-02T22:47:00.001-07:00</published><updated>2010-08-02T22:48:52.354-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="EJB FAQS"/><title type='text'>EJB FAQS</title><content type='html'>&lt;strong&gt;&lt;FONT COLR=&quot;RED&quot;&gt;EJB Questions&lt;/FONT&gt;&lt;br /&gt;&lt;H4&gt;&lt;FONT COLOR=&quot;BLACK&quot;&gt;&lt;br /&gt;Q) Application server &amp; Web server&lt;br /&gt; Application server is a generalized server for running more than one application  like ejb, rmi, jsp, servlets.&lt;br /&gt; webserver is for request, response paradigm. It takes the client request and send response back to the client and the connection is closed.&lt;br /&gt; A.S cannot process Http request, but takes the forwarded request from W.S and process the business logic and send the output to the W.S which it turns send to the client.&lt;br /&gt; A.S manage transactions, security, persistence and lot more, but W.S cannot help in this regards. W.S takes only the Http request.&lt;br /&gt; A.S provides runtime environment for server side components, they provide middleware services such as resource pooling and network.&lt;br /&gt;&lt;br /&gt;Q) Diff Bean &amp; Ejb&lt;br /&gt;&lt;br /&gt;Q) SessionBeans &lt;br /&gt; Session beans are not persistence there are short lived beans. S.B can perform database operations but S.B it self is not a persistence objects. S.B are business process objects they implements business logic, business rules and workflow. &lt;br /&gt;&lt;br /&gt;Statefull Session Bean &amp; Stateless Session Bean &lt;br /&gt;&lt;br /&gt; Statefull session bean is a bean that is designed to service business process that span multiple methods request/transaction, S.S.B can retain their state on the behalf of individual client. All S.S.B can exposes only a single ejbCreate() method it does not take any parameters.&lt;br /&gt; Stateless session bean these are single request business process is one that does not require state to be maintained across method invocation. S.S.B cannot hold the state.&lt;br /&gt; Statefull session bean do not have pooling concept&lt;br /&gt; Stateless session bean instance can be pooled.&lt;br /&gt; If the business process span multiple invocations there by requiring a conversational then S.S.B will be ideal choice.&lt;br /&gt; If the business last only for a single method call, S.S.B are suitable.&lt;br /&gt;&lt;br /&gt;Q) Entity Bean&lt;br /&gt; Entity beans are permanent business entities because their state is saved in permanent data storage. E.B are persistence objects, E.B contain data related logic. E.B are permanent so if any machine crashes, the E.B can be reconstructed in memory again by simple reading the data back in from the database. &lt;br /&gt;&lt;br /&gt;Bean managed Persistence &amp; Container managed Persistence&lt;br /&gt; B.P is an entity bean that must be persisted by hand, other words component developer must write the code to translate your in-memory fields into an underlying data store. You handle these persist operations your self, you place your data base calls in ejbLoad() and ejbStore(). Finder methods only for B.M.P for C.M.P your ejb container will implement the finder methods. In this commit, rollback, begin are transactions In B.M.P findByPK() return a reference to the actual bean object.&lt;br /&gt; You do not have to do anything to synchronize with data base. In entity bean deployment descriptor you specify which fields that the container should manage. The transaction in C.M.P are TX-Support, TX-NotSupport, TX-require. He findByPK() in C.M.P return void because the method is internally implemented.&lt;br /&gt;&lt;br /&gt;Q) Message Driven Bean&lt;br /&gt; M.D.B process messages asynchronously are deliver via JMS. M.D.B’s are stateless, server side, transaction aware components used for asynchronous JMS messages. It acts as a JMS message listener which JMS messages, the  messages may be sent by any J2ee component, an application client, another enterprise bean, or by a JMS application.&lt;br /&gt;     When Ejb application server starts it parse the D.D and then loads and initializes declared beans. In case of M.D.B container establish a connection with the message provide(MOM server), client access message beans through the beans JMS interface (java.JMS.messageListerner) which exposes a single method.&lt;br /&gt;Public void onmessage(javax.JMS.message message)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q) When to use container managed and bean managed persistence?&lt;br /&gt;Container managed persistance is used when the persistant data store is a relational database and there is one to one mapping between a data represented in a table in the relational database and the ejb object.&lt;br /&gt;Bean managed persistance in used when there is no one to one mapping of the table and a complex query reteriving data from several tables needs to be performed to construct an ejb object. Bean managed is also used when the persistence data storage is not a relational database.&lt;br /&gt;&lt;br /&gt;Q) When to choose Statefull &amp; Stateless Session bean?&lt;br /&gt;A) Does the business process span multiple method invocations, requiring a conversational state if so the state full model fits very nicely. If your business process last for a single method call the stateless paradigm will better suite needed.&lt;br /&gt;&lt;br /&gt;Q) Diff Statefull Session &amp; Entity Bean&lt;br /&gt; Both S.S.B &amp; E.B undergo passivation and activation. The E.B have a separate ejbStore() callback for saving state during passivation &amp; a separate ejbLoad() callback for loading state during activation. We do not need these callbacks for S.S.B because the container is simply uses object serialization to persist S.S.B fields. &lt;br /&gt;&lt;br /&gt;Q) Object-Relational Mapping&lt;br /&gt; Mapping of objects to relational database is a technology called O.R.M. O.R.M is a persistence mechanism of persistence objects than simple object serialization.&lt;br /&gt;&lt;br /&gt;Q) When to use which bean Session Bean &amp; Entity Bean?&lt;br /&gt; E.B are effective when application want to access one row at a time, if many rows needed to be fetched using session bean can be better alternative.&lt;br /&gt; E.B are effective when working with one row at a time cause of lot of N.W traffic. S.B are efficient when client wants to access database directly, fetching, updating multiple rows from data base.&lt;br /&gt; S.B for application logic.&lt;br /&gt;&lt;br /&gt;Q) Deployment Descriptor &lt;br /&gt;D.D contains information for all the beans in the “ejb.jar” file. D.D enables ejb container to provide implicit services to enterprise bean components, these services can gain your bean with out coding. D.D is a XML file.&lt;br /&gt;&lt;br /&gt;Q) ejbCreate()&lt;br /&gt; In stateless session bean can have only one ejbCreate() method it must take no arguments. Remember that ejbCreate() is essentially analogous to a constructor for ejb; it initializes an instance internal state variable. Because the stateless session bean has no client specific variables.&lt;br /&gt;&lt;br /&gt;Q) Can a Session Bean be defined without ejbCreate() method?&lt;br /&gt;A) The ejbCreate() methods is part of the bean&#39;s lifecycle, so, the compiler will not return an error because there is no ejbCreate() method. &lt;br /&gt;&lt;br /&gt;- The home interface of a Stateless Session Bean must have a single create() method with no arguments, while the session bean class must contain exactly one ejbCreate() method, also without arguments. &lt;br /&gt;- Stateful Session Beans can have arguments (more than one create method) &lt;br /&gt;- Stateful beans can contain multiple ejbCreate() as long as they match with the home interface definition&lt;br /&gt;&lt;br /&gt;Q) Can i call remove() on a Stateless Session bean?&lt;br /&gt;A) Yes, The life of a Stateless Session bean for a client is just till the execution of the method that the client would have called on the bean…after the execution of that method if the client calls another method, then a different bean is taken from the pool. so the container very well knows that a bean has finished its life for a client and can put it back in the pool.&lt;br /&gt;&lt;br /&gt;Q) Can a Stateless Session Bean maintain state?&lt;br /&gt;A) Yes, A Stateless Session bean can contain no-client specific state across client invoked methods. For ex states such as socket connection, dbase connection, references to an EJBObject and so on can be maintained.&lt;br /&gt;&lt;br /&gt;Q) How can I map a single Entity Bean to multiple tables?&lt;br /&gt;A) If u use Bean-Managed Persistence(BMP), map the bean to tables manually. Consider applying the DAO design pattern to accomplish this,.&lt;br /&gt;     If u choose Container-Managed persistence(CMP), use the vendors object/relational mapping tool to specify the mapping between your object state and the persistence schema.&lt;br /&gt;&lt;br /&gt;Q) Can EJB handle transaction across multiple databases?&lt;br /&gt;A) The transaction manager in EJB handling transaction across multiple databases. This is accomplished with multiple Entity beans handling to each database and a single session bean to manage a transaction with the Entity bean.&lt;br /&gt;&lt;br /&gt;Q) Session Bean CallBack methods?&lt;br /&gt;public interface javax.ejb.SessionBean extends javax.ejb.EnterpriseBean&lt;br /&gt;{&lt;br /&gt;    public abstract void ejbActivate();&lt;br /&gt;    public abstract void ejbCreate();&lt;br /&gt;    public abstract void ejbPassivate();&lt;br /&gt;    public abstract void ejbRemove();&lt;br /&gt;    public abstract void setSessionContext(SessionyContext ctx);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;SessionContext  S.C is your beans gateway to interact with the container, S.C query the container about your current transactional state, your security state.&lt;br /&gt;&lt;br /&gt;ejbCreate() &lt;br /&gt;&lt;br /&gt;ejbPassivate( )   If too many beans are instantiated, the container can passivate some of them .ie write the bean to some temp storage. The container should release all resources held by the bean. Just before passivating, the container calls the ejbPassivate() method. So release all resources here, ie,close socket connections..etc. &lt;br /&gt;&lt;br /&gt;ejbActivate( )  When a passiavted bean is called, its said to be activated. The container then calls the ejbActivate() method. Acquire all the required resources for the bean in this method. ie get socket connection&lt;br /&gt;&lt;br /&gt;ejbRemove() container wants to remove your bean instance it will call this method.&lt;br /&gt;&lt;br /&gt;Q) Entity Bean CallBack methods?&lt;br /&gt;public interface javax.ejb.EntityBean extends javax.ejb.EnterpriseBean&lt;br /&gt;{&lt;br /&gt;    public abstract void ejbActivate();&lt;br /&gt;    public abstract void ejbLoad();&lt;br /&gt;    public abstract void ejbPassivate();&lt;br /&gt;    public abstract void ejbRemove();&lt;br /&gt;    public abstract void ejbStore();&lt;br /&gt;    public abstract void setEntityContext(EntityContext ctx);&lt;br /&gt;    public abstract void unsetEntityContext();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Q) EJBContext Rollback Methods &lt;br /&gt;&lt;br /&gt;EJBContext interface provides the methods setRollbackOnly() &amp; getRollbackOnly().&lt;br /&gt;setRollbackOnly( )Once a bean invokes the setRollbackOnly() method, the current transaction is marked for rollback and cannot be committed by any other participant in the transaction--including the container.&lt;br /&gt;getRollbackOnly( )  method returns true if the current transaction has been marked for rollback. This can be used to avoid executing work that wouldn&#39;t be committed anyway.&lt;br /&gt;&lt;br /&gt;Q) How can I call one EJB from inside of another EJB?&lt;br /&gt;A) EJB can be clients of another EJB’s. it just works. Use JNDI to locate the Home Interface of the other bean, then acquire an instance.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q) Conversational &amp; Non-conversational&lt;br /&gt; Conversational is an interaction between the bean and client, stateless session bean is a bean that do not hold multi method conversation with clients. Stateless.S.B cannot hold state, Statefull.S.B can hold conversational with client that may span multiple method request.  &lt;br /&gt;&lt;br /&gt;Q) JNDI to locate Home Objects&lt;br /&gt;H.O are physically located some where  on the N.W, perhaps in the address space of the Ejb Container. For client to locate H.O, you must provide nick name for your beans H.O. Client will use this nick name to identify the H.O it wants, we will specify the nice name in the Deployment descriptor. Container will use this nick name, JNDI goes over the N.W to some directory service to look for the H.O.&lt;br /&gt; &lt;br /&gt;Properties props = System.getProperties();&lt;br /&gt;Context ctx = new InitialContext(props);&lt;br /&gt;MyHome home = (MyHome)ctx.lookup(“MyHome”);&lt;br /&gt;MyRemoteInterface remote = home.create();&lt;br /&gt;&lt;br /&gt;Q) Diff servlet/jsp session &amp; EJB session&lt;br /&gt; logical point of view a servlet/jsp session is similar to an ejb session. A session in servlet is maintained by the servlet container through Http session object.. That is acquiring through the request object. You cannot instantiate Http session object.&lt;br /&gt; A session in Ejb is maintained using S.B, you design bean that can maintain business logic. You can have 2 types of beans 1. Stateless 2. Stateful.&lt;br /&gt;&lt;br /&gt;Q) ejbCretae( ) &amp; ejbPostCreate( )&lt;br /&gt; ejbCreate() is called just before the state of the bean is written to the persistence storage. After this method is completed a new record is created and written.&lt;br /&gt; ejbPostCreate() is called after the bean has been written to  the database and the bean data has been assigned to an Ejb object.&lt;br /&gt;&lt;br /&gt;Q) Can map Entity bean to more than one table?&lt;br /&gt;A) &lt;br /&gt;&lt;br /&gt;Q) EAR, WAR, JAR&lt;br /&gt; All EJB classes should package in a JAR file, All web components pages, servlets, gif, html, applets, beans, ejb modules, classes should be packaged into WAR file. EAR file contain all the JAR &amp; WAR files. Note that each JAR, WAR, EAR file will contain D.D&lt;br /&gt;&lt;br /&gt;Q) Life cycle &lt;br /&gt;&lt;br /&gt;Life cycle of a Stateful Session Bean&lt;br /&gt;&lt;br /&gt;- Stateful session bean has 3 states Does Not Exist, Method Ready Pool and Passivated states.&lt;br /&gt;- A bean has not yet instantiated when it is in the Does Not Exist Sate.&lt;br /&gt;- Once a container creates one are more instance of a Stateful Session bean it sets them in a Method Ready State. In this state it can serve requests from its clients. Like Stateless beans, a new instance is created(Class.newInstance()), the context is passed (setSessionContext()) and finally the bean is created with the ejbCreate().&lt;br /&gt;- ejbPassivate( )  If too many beans are instantiated, the container can passivate some of them .ie write the bean to some temp storage. The container should release all resources held by the bean. Just before passivating, the container calls the ejbPassivate() method. So release all resources here,ie,close socket connections..etc. &lt;br /&gt;- ejbActivate( )  When a passiavted bean is called, its said to be activated. The container then calls the ejbActivate() method. Acquire all the required resources for the bean in this method. ie get socket connection&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Life cycle of a Stateless Session Bean : -&lt;br /&gt;&lt;br /&gt;- A  S.S.B has only two states: Does Not Exist and Method Ready Pool.&lt;br /&gt;- A bean has not yet instantiated when it is in the Does Not Exist Sate.&lt;br /&gt;- When the EJB container needs one are more beans, it creates and set then in the Method Ready Pool Sate. This happens through the creation of a new instance(Class.newInstance()), then it is set its context (setSessionContext()) and finally calls the ejbCreate() method.&lt;br /&gt;- The ejbRemove() method is called to move a bean from the Method Ready Pool back to Does Not Exist State.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Life cycle of Entity bean&lt;br /&gt;- Bean instance “Dose not exist” state represent entity bean instance that has not been instantiated yet. &lt;br /&gt;- To create a new instance container calls the newInstance() on entity bean class.&lt;br /&gt;- After step 2 E.B is in a pool of other E.Bs. At this point your E&gt;b does not have any E.B data base data loaded into it and it does not hold any bean specific resources (socket &amp; database connections) .If the container wants to reduce it’s pool size it can destroy your bean by calling unsetEntityContext() on your bean.&lt;br /&gt;- When the client wants to create some new data base data it calls a create() method on entity beans HomeObject. The container grabs the beans instance from the pool  and the instance ejbCreate() method is called.&lt;br /&gt;- E.B to be kicked back to pool, if a client call ejbremove() method.&lt;br /&gt;- ejbPassivate( )  If too many beans are instantiated, the container can passivate some of them .ie write the bean to some temp storage. The container should release all resources held by the bean. Just before passivating, the container calls the ejbPassivate() method. So release all resources here, ie,close socket connections..etc. &lt;br /&gt;- ejbActivate( )  When a passiavted bean is called, its said to be activated. The container then calls the ejbActivate() method. Acquire all the required resources for the bean in this method. ie get socket connection&lt;br /&gt;- &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Life cycle of M.D.B&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;Does Not Exist&lt;br /&gt;When an MDB instance is in the Does Not Exist state, it is not an instance in the memory of the system. In other words, it has not been instantiated yet.&lt;br /&gt;&lt;br /&gt;The Method-Ready Pool&lt;br /&gt;MDB instances enter the Method-Ready Pool as the container needs them. When the EJB server is first started, it may create a number of MDB instances and enter them into the Method-Ready Pool. (The actual behavior of the server depends on the implementation.) When the number of MDB instances handling incoming messages is insufficient, more can be created and added to the pool.&lt;br /&gt;&lt;br /&gt;Transitioning to the Method-Ready Pool&lt;br /&gt;When an instance transitions from the Does Not Exist state to the Method-Ready Pool, three operations are performed on it. First, the bean instance is instantiated when the container invokes the Class.newInstance() method on the MDB class. Second, the setMessageDrivenContext() method is invoked by the container providing the MDB instance with a reference to its EJBContext. The MessageDrivenContext reference may be stored in an instance field of the MDB.&lt;br /&gt;Finally, the no-argument ejbCreate() method is invoked by the container on the bean instance. The MDB has only one ejbCreate() method, which takes no arguments. The ejbCreate() method is invoked only once in the life cycle of the MDB.&lt;br /&gt;&lt;br /&gt;Q) EJB Resources?&lt;br /&gt;  &lt;ejb-ref&gt;&lt;br /&gt;     &lt;description&gt; text  &lt;/description&gt;&lt;br /&gt;     &lt;ejb-ref-name&gt; name  &lt;/ejb-ref-name&gt;&lt;br /&gt;     &lt;ejb-ref-type&gt; Java type  &lt;/ejb-ref-type&gt;&lt;br /&gt;     &lt;home&gt; mycom.ejb.AccountHome  &lt;/home&gt;&lt;br /&gt;     &lt;remote&gt; mycom.ejb.Account  &lt;/remote&gt;&lt;br /&gt;     &lt;ejb-link&gt; ejb.name &lt;/ejb-link&gt;&lt;br /&gt;     &lt;run-as&gt;  security role &lt;/run-as&gt;&lt;br /&gt;   &lt;/ejb-ref&gt;&lt;br /&gt;&lt;br /&gt;Q How to deploy in J2EE (i.e Jar, War file) ?&lt;br /&gt; &lt;br /&gt;Each web application should be contained in a war (web archive) file. War files are nothing but a jar file containing atleast one descriptor called web.xml. The file structure of war file is:&lt;br /&gt; &lt;br /&gt;  /--&lt;br /&gt;    |&lt;br /&gt;    | WEB-INF&lt;br /&gt;    |   |&lt;br /&gt;    |   |-- WEB.XML (Deployment descriptor)&lt;br /&gt;    |   |-- classes (Folder containing servlets and JSPs&lt;br /&gt;    |&lt;br /&gt;    | META-INF&lt;br /&gt;    |   |&lt;br /&gt;    |   |-- MANIFEST.MF&lt;br /&gt;    |&lt;br /&gt;    | all utility files and resources like error pages etc.&lt;br /&gt; &lt;br /&gt;Each enterprise bean is stored in a jar file. The jar file contains all standard files like manifest and atleast one additional file called ejb-jar.xml. The structure of a jar file is:&lt;br /&gt; &lt;br /&gt;  /--&lt;br /&gt;    |&lt;br /&gt;    | META-INF&lt;br /&gt;    |   |&lt;br /&gt;    |   |-- MANIFEST.MF&lt;br /&gt;    |   |-- ejb-jar.xml&lt;br /&gt;    |&lt;br /&gt;    | all classes as in a normal jar file.&lt;br /&gt; &lt;br /&gt;Both jar and war files are placed inside a ear (enterprise archive) file. The structure of an ear file is&lt;br /&gt; &lt;br /&gt;  /--&lt;br /&gt;    |&lt;br /&gt;    | META-INF&lt;br /&gt;    |   |&lt;br /&gt;    |   |-- MANIFEST.MF&lt;br /&gt;    |   |-- application.xml&lt;br /&gt;    |&lt;br /&gt;    | jar and war files.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q) Deployment descriptor of EJB&lt;br /&gt;&lt;br /&gt;&lt;?xml version=&quot;1.0&quot;?&gt;&lt;br /&gt;&lt;!DOCTYPE ejb-jar PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Enterprise&lt;br /&gt;JavaBeans 1.1//EN&quot; &quot;http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;ejb-jar&gt;&lt;br /&gt; &lt;description&gt;&lt;br /&gt;    This Deployment includes all the beans needed to make a reservation:&lt;br /&gt;    TravelAgent, ProcessPayment, Reservation, Customer, Cruise, and Cabin.&lt;br /&gt; &lt;/description&gt;&lt;br /&gt; &lt;enterprise-beans&gt;&lt;br /&gt;   &lt;session&gt;&lt;br /&gt;      &lt;ejb-name&gt;TravelAgentBean&lt;/ejb-name&gt;&lt;br /&gt;      &lt;remote&gt;com.titan.travelagent.TravelAgent&lt;/remote&gt;&lt;br /&gt;      ...&lt;br /&gt;   &lt;/session&gt;&lt;br /&gt;   &lt;entity&gt;&lt;br /&gt;      &lt;ejb-name&gt;CustomerBean&lt;/ejb-name&gt;&lt;br /&gt;      &lt;remote&gt;com.titan.customer.Customer&lt;/remote&gt;      &lt;br /&gt;      ...&lt;br /&gt;   &lt;/entity&gt;&lt;br /&gt;   &lt;session&gt;&lt;br /&gt;      &lt;ejb-name&gt;ProcessPaymentBean&lt;/ejb-name&gt;&lt;br /&gt;      &lt;remote&gt;com.titan.processpayment.ProcessPayment&lt;/remote&gt;&lt;br /&gt;      ...&lt;br /&gt;   &lt;/session&gt;&lt;br /&gt;   ...&lt;br /&gt; &lt;/enterprise-beans&gt;&lt;br /&gt; &lt;assembly-descriptor&gt;&lt;br /&gt; ...&lt;br /&gt; &lt;/assembly-descriptor&gt;&lt;br /&gt; ...&lt;br /&gt;&lt;/ejb-jar&gt;&lt;br /&gt;&lt;br /&gt;Q) &lt;br /&gt;  Remote Interface &lt;br /&gt;  &lt;br /&gt;   public interface Hello extends javax.ejb.EJBObject&lt;br /&gt;      {&lt;br /&gt; public String hello() throws java.rmi.RemoteException; &lt;br /&gt;      }&lt;br /&gt; &lt;br /&gt;  Home Interface&lt;br /&gt;&lt;br /&gt;    public interface HelloHome extends javax.ejb.EJBHome&lt;br /&gt;      {&lt;br /&gt; Hello create() throws java.rmi.RemoteException; javax.ejb.CreateException; &lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt; Bean Class &lt;br /&gt;&lt;br /&gt;     public class HelloBean implements javax.ejb.SessionBean&lt;br /&gt;      {&lt;br /&gt; private SessionContex ctx;&lt;br /&gt;public void ejbCreate();&lt;br /&gt; public abstract void ejbRemove();&lt;br /&gt;public abstract void ejbActivate();&lt;br /&gt;public abstract void ejbPassivate();&lt;br /&gt; public abstract void setSessionContext(SessionyContext ctx);&lt;br /&gt; &lt;br /&gt; public String hello(){&lt;br /&gt; System.out.println(“hello());&lt;br /&gt; Return “hello world”;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;  Client      &lt;br /&gt;   &lt;br /&gt;     public class HelloClient&lt;br /&gt;      {&lt;br /&gt; public static void main(String args[ ])&lt;br /&gt;properties props = system.getProperties();&lt;br /&gt; Context ctx =  new InitialContext(props);&lt;br /&gt;Object obj = ctx.lookup(“HelloHome”);&lt;br /&gt;HelloHome home = (HelloHome) &lt;br /&gt;javax.rmi.protableRemoteObject.narrow(obj, HelloHome.class);&lt;br /&gt; Hello hello = home.create();&lt;br /&gt; System.out.println(hello.hello());&lt;br /&gt; Hello.remove();&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;Q) Transaction Isolation levels &lt;br /&gt;&lt;br /&gt;TRANSACTION_READ_UNCOMMITTED&lt;br /&gt;The transaction can read uncommitted data. Dirty reads, nonrepeatable reads, and phantom reads can occur. Bean methods with this isolation level can read uncommitted change. &lt;br /&gt;&lt;br /&gt;TRANSACTION_READ_COMMITTED&lt;br /&gt;The transaction cannot read uncommitted data; data that is being changed by a different transaction cannot be read. Dirty-reads are prevented; nonrepeatable reads and phantom reads can occur. Bean methods with this isolation level cannot read uncommitted data. &lt;br /&gt;&lt;br /&gt;TRANSACTION_REPEATABLE_READ&lt;br /&gt;The transaction cannot change data that is being read by a different transaction. &lt;br /&gt;Dirty reads and nonrepeatable reads are prevented; phantom reads can occur. Bean methods with this isolation level have the same restrictions as Read Committed and can only execute repeatable reads. &lt;br /&gt;&lt;br /&gt;TRANSACTION_SERIALIZABLE&lt;br /&gt;The transaction has exclusive read and update privileges to data; different transactions can neither read nor write the same data. Dirty reads, nonrepeatable reads, and phantom reads are prevented. This isolation level is the most restrictive. &lt;br /&gt;&lt;br /&gt;Dirty-read  When your application reads data from a database that has not been committed to permanent storage yet.&lt;br /&gt;&lt;br /&gt;Un-repeatable read  When a component reads some data from a database, but upon reading the data, the data has been changed. This can arise when another concurrently executing transaction modifies the data being read.&lt;br /&gt;&lt;br /&gt;Phantom-read  A phantom is a new set of data that magically appears in a database between two database read operations.&lt;br /&gt;&lt;br /&gt;Q) Diff Phantom  &amp; Un-repeatable &lt;br /&gt; Un-repeatable occurs when existing data is changed, where as phantom read occurs when new data is inserted that does not exist before.&lt;br /&gt;&lt;br /&gt;Q) Transaction Attributes &lt;br /&gt;&lt;br /&gt;TX_BEAN_MANAGED  Then your bean programmatically controls its own transaction boundaries. When you using programmatically transaction, you issue the begin, commit &amp; abort statements.&lt;br /&gt;&lt;br /&gt;TX_NOT_SUPPORTED  If you set this your bean cannot be involved in a transaction at all.&lt;br /&gt;&lt;br /&gt;TX_REQUIRED  If you want your bean to always run in a transaction. If there is a transaction already running your bean joins in on that transaction. If there is no transaction running, the container starts one for you.&lt;br /&gt;&lt;br /&gt;TX_REQUIRES_NEW  If you always want a new transaction to begin when your bean is called we should use this. If there is a transaction already underway when your bean called, that transaction is suspended during the bean invocation. The container then launches a new transaction and delegate the call to the bean.&lt;br /&gt;&lt;br /&gt;TX_SUPPORTS   When a client call this it runs only in a transaction if the client had one running already; it then joins that transaction. If no transaction =, the bean runs with no transaction at all.&lt;br /&gt;&lt;br /&gt;TX_MANDATORY  Is a safe transaction attribute to use. It guarantees that your bean should run in a transaction. There is no way your  bean can be called if there is not a transaction already running.&lt;br /&gt;&lt;br /&gt;Q) ACID Properties&lt;br /&gt; When you properly use transaction your operations will execute ACID properties.&lt;br /&gt;&lt;br /&gt;(i) Atomicity  Guarantees that many operations are bundled together and appears as one contiguous unit of work.&lt;br /&gt;Ex:- When you transfer money from one bank account to another you want to add funds to one account and remove funds from the other transaction and you want both operations to occur or neither to occur.&lt;br /&gt;&lt;br /&gt;(ii) Consistency  Guarantees that a transaction will leave the system state to be consistent after a transaction completes.&lt;br /&gt;Ex:- A bank system state could be consist if the rule “bank account balance must  always be +ve”.&lt;br /&gt;&lt;br /&gt;(iii) Isolation  Protect concurrently executing transaction from seeing each other incomplete results.&lt;br /&gt;Ex:- If you write a bank account data to a database, the transaction may obtain locks on the bank account record (or) table. The lock guarantee that no other updates can interfere.&lt;br /&gt;&lt;br /&gt;(iv) Durability   Resources keep a transactional log  for resources crashes, the permanent data can be reconstructed by reapplying the steps in the log.&lt;br /&gt;&lt;br /&gt;Q) Diff Sax &amp; DOM&lt;br /&gt; &lt;br /&gt;DOM SAX&lt;br /&gt;1. Tree of nodes&lt;br /&gt;2. Occupies more memory preferred for small XML documents&lt;br /&gt;3. Slower at runtime&lt;br /&gt;4. Stored as objects&lt;br /&gt;5. Programmatically easy, since objects&lt;br /&gt;6. Easy of navigation&lt;br /&gt;7. DOM creates a tree structure in memory 1.Sequence of events&lt;br /&gt;2.Does not use any memory preferred for large documents.&lt;br /&gt;3.Faster at runtime&lt;br /&gt;4.Objects are to be created&lt;br /&gt;5.Need to write code for creating objects are to referred&lt;br /&gt;6.backward navigation is not possible&lt;br /&gt;&lt;br /&gt;Q) Hot deployment &lt;br /&gt;Hot Deployment in Web Logic is he act of deploying, re-deploying and un-deploying EJBs while the server is still running.&lt;br /&gt;&lt;br /&gt;Q) When should I use TxDataSource instead of Datasource?&lt;br /&gt;  If your  application  (or) environment meet the following criteria you should use &lt;br /&gt;- uses JTA&lt;br /&gt;- uses EJB container in web logic  server to manage transactions.&lt;br /&gt;- Includes multiple database updates with single transaction.&lt;br /&gt;- Access multiple resources, such as database &amp; JMS during transactions.&lt;br /&gt;- Use same connection pool on multiple servers.&lt;br /&gt;&lt;br /&gt;Q) Clustering &lt;br /&gt; In J2ee container can be distributed, a distributed container consist of number of JVM’s running on one are more host machines. In this setup, application components can be deployed on a number of JVM’s. Subject to the type of loading strategy and the type of the component the container can distributed the load of incoming request to one of  these JVM’s.&lt;/FONT&gt;&lt;/H4&gt;&lt;/strong&gt;</content><link rel='replies' type='application/atom+xml' href='http://itjobsfaqs.blogspot.com/feeds/2241892465432893113/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/ejb-faqs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/2241892465432893113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/2241892465432893113'/><link rel='alternate' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/ejb-faqs.html' title='EJB FAQS'/><author><name>Tiru Reddy</name><uri>http://www.blogger.com/profile/13152630017999545653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8829103433621523357.post-2348654912675724260</id><published>2010-08-02T22:45:00.000-07:00</published><updated>2010-08-02T22:46:55.468-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JDBC"/><title type='text'>JDBC</title><content type='html'>&lt;strong&gt;&lt;FONT COLOR=&quot;RED&quot;&gt;JDBC Questions&lt;/FONT&gt;&lt;br /&gt;&lt;H4&gt;&lt;FONT COLOR=&quot;BLACK&quot;&gt;&lt;br /&gt;&lt;br /&gt;Q) What Class.forName will do while loading drivers?&lt;br /&gt;A) It is used to create an instance of the driver and register with the DriverManager.&lt;br /&gt;&lt;br /&gt;Q) JDBC connection&lt;br /&gt;&lt;br /&gt;import java.sql.*;&lt;br /&gt;public class JDBCSample {&lt;br /&gt;  public static void main(java.lang.String[] args) {&lt;br /&gt;    try {&lt;br /&gt;      Class.forName(&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;);&lt;br /&gt;    } catch (ClassNotFoundException e) {&lt;br /&gt;      System.out.println(&quot;Unable to load Driver Class&quot;);&lt;br /&gt;      return;&lt;br /&gt;    }&lt;br /&gt;    try {&lt;br /&gt;      Connection con = DriverManager.getConnection(&quot;jdbc:odbc:companydb&quot;,&quot;&quot;, &quot;&quot;);&lt;br /&gt;      Statement stmt = con.createStatement();&lt;br /&gt;      ResultSet rs = stmt.executeQuery(&quot;SELECT FIRST_NAME FROM EMPLOYEES&quot;);	&lt;br /&gt;      while(rs.next()) {&lt;br /&gt;      System.out.println(rs.getString(&quot;FIRST_NAME&quot;));&lt;br /&gt;      }&lt;br /&gt;      rs.close();&lt;br /&gt;      stmt.close();&lt;br /&gt;      con.close();&lt;br /&gt;    } &lt;br /&gt;    catch (SQLException se) {&lt;br /&gt;      System.out.println(&quot;SQL Exception: &quot; + se.getMessage());&lt;br /&gt;    } &lt;br /&gt;  } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q) 4th type driver&lt;br /&gt;&lt;br /&gt;class.forName(“oracle.jdbcdriver.oracledriver”);&lt;br /&gt;//DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());&lt;br /&gt;// com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource for Initial Context&lt;br /&gt;// &lt;br /&gt;connection con = driverManager.getConnection(“jdbc:oracle:thin:@hostname:portno:oracleservice”,”uid”, “pwd”);&lt;br /&gt;&lt;br /&gt;Q) Steps to connect to JDBC?&lt;br /&gt;A) 1. First thing is using jdbc you have to establish a connection to the data base this is 2 steps process (i) you must load the jdbc driver (ii) then make a connection, to do this we can call the getConnection() method of driver manager class.&lt;br /&gt;2. To execute any sql commands using jdbc connection you must first create a statement object to create this call statement st = con.createSteatement().&lt;br /&gt;This is done by calling the createStatement () method in connection interface. Once the statement is created you can executed it by calling execute () method of the statement interface.&lt;br /&gt;&lt;br /&gt;Q) JDBC connection pool&lt;br /&gt; 	When you are going to create a pool of connection to the data base. This will give access to a collection of already opened data base connections, which will reduce the time it takes to service the request and you can service “n” number of request at once.&lt;br /&gt;&lt;br /&gt;Q) Why you need JDBC if ODBC is available?&lt;br /&gt;A)  ODBC is purely written in “c” so we cannot directly connect with java. JDBC is a low level pure java API used to execute SQL statements. (i) ODBC is not appropriate for direct use from java because it uses “c” interfaces. A call from java to native “c” code has number of drawbacks in the security, implementation and robustness.&lt;br /&gt;&lt;br /&gt;Q) Can we establish the connection with ODBC itself?&lt;br /&gt;A) Yes, using java native classes we have to write a program.&lt;br /&gt;&lt;br /&gt;Q) What is necessity of JDBC in JDBC-ODBC Bridge?&lt;br /&gt;A) The purpose of JDBC is to link java API to the ODBC, ODBC return high level “c” API so the JDBC converts “c” level API to java API.&lt;br /&gt;&lt;br /&gt;Q) JDBC Drivers&lt;br /&gt;o	JDBC-ODBC Bridge Driver &lt;br /&gt;o	Native API - Partly Java Driver &lt;br /&gt;o	Network protocol – All Java Driver &lt;br /&gt;o	Native Protocol - Pure Java Driver &lt;br /&gt;Tier	Driver mechanism	Description&lt;br /&gt;Two	JDBC-ODBC 	JDBC access via most ODBC drivers, some ODBC binary code and client code must be loaded on each client machine. This driver is commonly used for prototyping. The JDBC-ODBC Bridge is JDBC driver which implements JDBC operations by translating them to JDBC operations.&lt;br /&gt;Two	Native API - Partly - Java driver 	This driver converts JDBC calls to database specific native calls. Client requires database specific libraries. &lt;br /&gt;Three	JDBC - Net -All Java driver	This driver converts JDBC calls into DBMS independent network protocol that is sent to the middleware server. This will translate this DBMS independent network protocol into DBMS specific protocol, which is sent to a particular database. The results are again rooted back to middleware server and sent back to client.      &lt;br /&gt;Two	Native protocol - All - Java driver	They are pure java driver, they communicate directly with the vendor database. They convert JDBC commands.&lt;br /&gt;&lt;br /&gt;Q) Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection?&lt;br /&gt;A) No. You can open only one Statement object per connection when you are using the JDBC-ODBC Bridge.&lt;br /&gt;&lt;br /&gt;Q) Is the JDBC-ODBC Bridge multi-threaded?&lt;br /&gt;A) No. The JDBC-ODBC Bridge does not support concurrent access from different threads. The JDBC-ODBC Bridge uses synchronized methods to serialize all of the calls that it makes to ODBC&lt;br /&gt;Q) Dynamically creating Tables &lt;br /&gt;	Statement st = con.cretaeStatement ();&lt;br /&gt;	Int n = st.executeUpdate (“create table “+ uname+ “(sno int, sentby varchar (10), subject varchar (15)”);&lt;br /&gt;&lt;br /&gt;Q) Statements in JDBC&lt;br /&gt;&lt;br /&gt;Statement    Does not take any arguments; in this statement it will check syntax error and execute it every time.&lt;br /&gt;                          &lt;br /&gt;Prepare statement  P.S is precompiled statements once we compile the statements and send it to the server for later use. P.S are partially compiled statements placed at server side with place holders. Before execution of these statements user has to supply values for place holders, it will increase performance of application.&lt;br /&gt;&lt;br /&gt;PreparedStatement pst = con.prepareStatement(&quot;SELECT * FROM EMP WHERE deptno=?&quot;);&lt;br /&gt;DataInputStream dis = new DataInputStream(“System.in”);&lt;br /&gt;Int dno = Integer.ParseInt(dis.readLine());&lt;br /&gt;pst.setInt(1, dno);&lt;br /&gt;ResultSet rs = pst.executeQuery();&lt;br /&gt;&lt;br /&gt;execute () return type boolean and executeUpdate () return type  is int.&lt;br /&gt;&lt;br /&gt;Callable statement  C.S used to retrieve data by invoking stored procedures, stored procedure are program units placed at data base server side for reusability. These are used by n-number of clients. Stored procedures are precompiled in RDBMS, so they can run faster than the dynamic sql.&lt;br /&gt;Callable statement will call a single stored procedure, they perform multiple queries and updates without net work traffic.&lt;br /&gt;&lt;br /&gt;callableStatement cst = con.prepareCall(“{CALL procedure-name(??)} ”);&lt;br /&gt;DataInputStream dis = new DataInputStream(“System.in”);&lt;br /&gt;Int enum = Integer.ParseInt(dis.readLine());&lt;br /&gt;cst.setInt(1, enum);&lt;br /&gt;cst.registerOutParameter(2, types.VARCHAR)&lt;br /&gt;resultset rs = cst.execute();&lt;br /&gt;&lt;br /&gt;In        used to send information to the procedure.&lt;br /&gt;Out     used to retrieve information from data base.&lt;br /&gt;InOut  both.&lt;br /&gt;&lt;br /&gt;Q) Retrieving very large values from database?&lt;br /&gt;A) getASSCIISteram()  read values which are character in nature.&lt;br /&gt;     GetBinaryStream()   used to read images.&lt;br /&gt;&lt;br /&gt;Q) ResultSetMetaData&lt;br /&gt;      It is used to find out the information of a table in a data base.&lt;br /&gt;      ResultSet rs = stmt.executeQuery(&quot;SELECT * FROM &quot;+ table);&lt;br /&gt;      ResultSetMetaData rsmd = rs.getMetaData();&lt;br /&gt;&lt;br /&gt;Methods in ResultSetMetaData  getColumnCount(), getColumnName(), getColumnLabel(), getColumnType(), getTableName(),&lt;br /&gt;&lt;br /&gt;Q) Database MetaData&lt;br /&gt;You need some information about the “data base” &amp; “dictionary” we use this .To find out tables, stored procedure names, columns in a table, primary key of a table we use this, this is the largest interface in java.sql package&lt;br /&gt;&lt;br /&gt;Connection con = DriverManager.getConnection(jdbcURL, &quot;&quot;, &quot;&quot;);&lt;br /&gt;DatabaseMetaData dbmd = con.getMetaData();&lt;br /&gt;ResultSet rs= dbmd.getxxx();&lt;br /&gt;&lt;br /&gt;Methods in DatabaseMetaData  getColumns(), getTableTypes(), getTables(), getDriverName(), getMajorVersion(), get MinorVersion(), getProcedures(), getProcedureColumns(), getTables().&lt;br /&gt;&lt;br /&gt;Q) Procedure&lt;br /&gt;	Procedure is a subprogram will perform some specific action; sub programs are naming PL/SQL blocks that can take parameters to be invoked.&lt;br /&gt;&lt;br /&gt;create or replace procedure procedure-name (id IN INTEGER , bal IN OUT FLOAT) IS&lt;br /&gt;  BEGIN&lt;br /&gt;select balance into bal from accounts where account_id = id;&lt;br /&gt;             bal := bal + bal * 0.03;&lt;br /&gt;             update accounts set balance = bal where account_id = id;&lt;br /&gt;  END;&lt;br /&gt;&lt;br /&gt;Q) Trigger&lt;br /&gt;	Trigger is a stored PL/SQL block associated with a specific database table. Oracle executes triggers automatically when ever a given SQL operation effects the table, we can associate 12 data base triggers with in a given table.&lt;br /&gt;&lt;br /&gt;Create/Replace trigger before Insert (or) Delete (or) Update on emp for each row&lt;br /&gt;Begin&lt;br /&gt; Insert into table-name values(:empno; :name)&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q) Stored Images into a table&lt;br /&gt; &lt;br /&gt;Public class img&lt;br /&gt;{&lt;br /&gt;   Public static void main(String args[]){&lt;br /&gt;   Class.forName();&lt;br /&gt;   Connection con = DriverManager.getConnection();&lt;br /&gt;   Preparestatement pst = con.prepareStatement(“insert into image value(?));&lt;br /&gt;   FileInputStream fis = new FileInputStream(“a.gif”);&lt;br /&gt;   Pst.setBinaryStream(1, fis, fis.available);&lt;br /&gt;   Int I = pst.executeUpadate();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Retrieve Image&lt;br /&gt;&lt;br /&gt;Statement st = con.CreateStatement();&lt;br /&gt;ResultSet rs = st.executeQuery(“select * from img”);&lt;br /&gt;rs.next();&lt;br /&gt;InputStream is = rs.getBinaryStream(1);&lt;br /&gt;FileOutPutStream fos = new FileOutPutStream(“g2.gif”);&lt;br /&gt;Int ch;&lt;br /&gt;While((ch=is.read(1))!=!-1)&lt;br /&gt;{&lt;br /&gt;	fos.write(ch);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q) Resultset Types&lt;br /&gt;rs.beforeFirst()  goto 1st record&lt;br /&gt;rs.afterLast()  goto last record&lt;br /&gt;res.absolute(4)  will got 4th record in result set.&lt;br /&gt;rs.first(), rs.last()&lt;br /&gt;rs.deleteRow()&lt;br /&gt;rs.updateRow(), rs.updateRow(3,88)  value in column 3 of resultset is set to 88.&lt;/FONT&gt;&lt;/H4&gt;&lt;/strong&gt;</content><link rel='replies' type='application/atom+xml' href='http://itjobsfaqs.blogspot.com/feeds/2348654912675724260/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/jdbc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/2348654912675724260'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/2348654912675724260'/><link rel='alternate' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/jdbc.html' title='JDBC'/><author><name>Tiru Reddy</name><uri>http://www.blogger.com/profile/13152630017999545653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8829103433621523357.post-6527650926753132726</id><published>2010-08-02T22:42:00.000-07:00</published><updated>2010-08-02T22:44:31.408-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JSP QUESTIONS"/><title type='text'>JSP QUESTIONS</title><content type='html'>&lt;strong&gt;&lt;FONT COLOR=&quot;BLACK&quot;&gt;JSP Questions&lt;br /&gt;&lt;br /&gt;Directives&lt;br /&gt;Page Directive	&lt;%@ Page language=&quot;java&quot; extends=&quot;className&quot; import=&quot;className&quot; session=&quot;true|false&quot; buffer=&quot;8KB&quot; autoFlush=&quot;true/false&quot; isThreadSafe=&quot;true/false&quot; info=&quot;text&quot; errorPage=&quot;jspUrl&quot; isErrorPage=&quot;true/false&quot; contentType=&quot;mimeType” %&gt;	Page directive defines information that will be globally available for that page&lt;br /&gt;Include Directive	&lt;%@ include file=&quot;relative URL&quot; %&gt; 	Include JSP are Servlet at compile time meaning that only once parsed by the compiler, it will act as a “C” &quot;#include&quot; pulling in the text of the included file and compiling it as if it were part of the including file. We can also include “Static” files using this directive.&lt;br /&gt;Taglib Directive	&lt;%@ taglib uri=&quot;uriToTagLibrary&quot; prefix=&quot;prefixString&quot; %&gt;	Taglib directive enables you to create your own custom tags.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Actions&lt;br /&gt;&lt;Jsp: useBean&gt;	&lt;Jsp: useBean id=&quot;beanInstanceName&quot; scope=&quot;page|request|session|application” class=&quot;&quot; &lt;br /&gt;type=&quot;&quot; bean Name=&quot;&quot; type=&quot;&quot; &lt;/jsp: useBean&gt; &lt;br /&gt;	UseBean tag is used to associate a java bean with jsp.&lt;br /&gt;&lt;Jsp: setProperty&gt;&lt;br /&gt;	&lt;Jsp: setProperty name=&quot;beanInstanceName” property=&quot;*&quot; |&quot;propertyName” param=&quot;paramName&quot; value=&quot;{string | &lt;%= expression %&gt;}&quot;  /&gt;&lt;br /&gt;	Sets a property value or values in a bean.&lt;br /&gt;&lt;br /&gt;&lt;Jsp: getProperty&gt;	&lt;Jsp: getProperty name=&quot;beanInstanceName&quot; property=&quot;propertyName&quot; /&gt;	Gets the value of a bean property so that you can display it in a result page.&lt;br /&gt;&lt;Jsp: param&gt;	&lt;Jsp: param name=&quot;beanInstanceName&quot; value=&quot; parameterValue &quot; /&gt;	It is used to provide other tags with additional information in the form of name, value pairs. This is used to conjunction with jsp:include, jsp:forward, jsp:plugin.&lt;br /&gt;&lt;Jsp: include&gt;&lt;br /&gt;	&lt;br /&gt;	&lt;Jsp: include page=&quot;relativeURL &quot; flush=&quot;true&quot; &gt; &lt;br /&gt;        &lt;Jsp: param name=&quot;username&quot; value=&quot;jsmith&quot; /&gt; &lt;br /&gt;&lt;/jsp: include&gt;&lt;br /&gt;	Jsp Include includes the JSP are Servlet at request time, it is not parsed by the compiler, and it Includes a static file or sends a request to a dynamic file.&lt;br /&gt;&lt;br /&gt;&lt;Jsp: forward&gt;&lt;br /&gt;	&lt;Jsp: forward page=&quot;{relativeURL|&lt;%=expression %&gt;}&quot; &gt; &lt;br /&gt;   &lt;jsp: param name=&quot;paramName&quot; value=&quot;paramValue&quot;/&gt;&lt;br /&gt;&lt;/jsp: forward&gt;&lt;br /&gt;	When ever the client request will come it will take the request and process the request and the request to be forward to another page and it will also forward the http parameters of the previous page to the destination page. It will work at server side.&lt;br /&gt;&lt;Jsp: plugin&gt;	&lt;Jsp: plugin type=&quot;bean/applet&quot; code=&quot;classFileName&quot; codebase=&quot;classFileDirectoryName&quot; name=&quot;instanceName&quot; archive=&quot;” align=&quot;&quot; height=&quot; &quot; width=&quot; &quot; hspace=&quot; &quot; vspace=&quot; &lt;/jsp: plugin&gt;&lt;br /&gt;	This action is used to generate client browser specific html tags that ensures the java plug in software is available, followed by execution of applet or java bean component specified in tag.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q) Implicit Objects&lt;br /&gt; &lt;br /&gt;Implicit objects	Type	Scope	Sum useful methods&lt;br /&gt;request	Subclass of javax.servlet.ServletRequest	Request	getAttribute, getParameter, getParameterNames, getParameterValues, setAttribute&lt;br /&gt;response	Subclass of javax.servlet.ServletResponse	Page	Not typically used by JSP page authors&lt;br /&gt;pageContext&lt;br /&gt;	javax.servlet.jsp.PageContext&lt;br /&gt;	Page	findAttribute, getAttribute, getAttributesScope, getAttributeNamesInScope, setAttribute.&lt;br /&gt;session	javax.servlet.http.HttpSession	Session	getAttribute, getId, setAttribute.&lt;br /&gt;application	javax.servlet.ServletContext	Application	getAttribute, getMimeType, getRealPath, setAttribute&lt;br /&gt;out	javax.servlet.jsp.JspWriter	Page	clear, clearBuffer, flush, getBufferSize, getRemaining&lt;br /&gt;config	javax.servlet.ServletConfig	Page	getInitParameter, getInitParameterNames&lt;br /&gt;page	java.lang.Object	Page	Not typically used by JSP page authors&lt;br /&gt;exception	java.lang.Throwable	Page	getMessage, getLocalizedMessage, printStackTrace, toString&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Q) Declaration&lt;br /&gt;A declaration declares one or more variables or methods for use later in the JSP source file. &lt;br /&gt;    	Ex: &lt;%! int a, b, c; %&gt;&lt;br /&gt;      &lt;%! int accountnumber=2346883; %&gt;&lt;br /&gt;      &lt;%! String accountname=&quot;Thomas&quot;; %&gt;&lt;br /&gt;      &lt;%! private void processAmount () { ... } %&gt;&lt;br /&gt;&lt;br /&gt;    XML syntax for JSP declaration is &lt;jsp: declaration&gt;int x; &lt;/jsp: declaration&gt;&lt;br /&gt;&lt;br /&gt;Q) Expressions&lt;br /&gt;An expression tag contains a scripting language expression that is evaluated, converted to a String, and inserted where the expression appears in the JSP file. &lt;br /&gt;          Ex: &lt;%= (new java.util.Date ()).toLocaleString() %&gt;&lt;br /&gt;&lt;br /&gt;    XML syntax for JSP expression is &lt;jsp: expression&gt;Java expression&lt;/jsp: expression&gt; &lt;br /&gt;&lt;br /&gt;Q) Scriptlet&lt;br /&gt;	A scriptlet can contain variable or method declarations, or expressions that are valid in the page scripting language. Within scriptlet tags, you can &lt;br /&gt;1.Declare variables or methods to use later in the file &lt;br /&gt;2.Write expressions valid in the page scripting language&lt;br /&gt;3.Use any of the JSP implicit objects or any object declared with a &lt;jsp: useBean&gt; tag. &lt;br /&gt;Scriptlets are executed at request time, when the JSP engine processes the client request. If the scriptlet produces output, the output is stored in the out object, from which you can display it.&lt;br /&gt;&lt;br /&gt;    XML syntax for JSP scriptlets is &lt;jsp: scriptlet&gt;Java code&lt;/jsp: scriptlet&gt;&lt;br /&gt;&lt;br /&gt;Q) Comments&lt;br /&gt;     Html comment  Creates a comment that is sent to the client in the viewable page source. &lt;br /&gt;Ex: &lt;! -- comment [ &lt;%= expression %&gt; ] --&gt;&lt;br /&gt;&lt;br /&gt;     Hidden Comment  Documents the JSP file, but is not sent to the client. &lt;br /&gt;Ex: &lt;%-- comment --%&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q) MVC &lt;br /&gt; &lt;br /&gt;Model: - model is java bean/entity beans that represent the data being transmitted are received.&lt;br /&gt;Controller: - Controller is a servlet that performs necessary manipulations to the model.&lt;br /&gt;View: - is a screen representation of the model. &lt;br /&gt;&lt;br /&gt; Major benefits of using the MVC design pattern is separate the view &amp; model this make it is possible to create are change views with out having to change the model.&lt;br /&gt; 1) The browser makes a request to the controller servlet 2) Servlet performs necessary actions to the java bean model and forward the result to the jsp view. 3) The jsp formats the model for display and send the html results back top the web browser.&lt;br /&gt;&lt;br /&gt;Q) Life-cycle of JSP&lt;br /&gt;jspInit ()            container calls the jspInit() to initialize to servlet instance. It is called before any other method, and is called only once for a servlet instance.&lt;br /&gt;_jspservice ()  container calls _jspservice () for each request, passing it the request and the response objects.&lt;br /&gt;jspDestroy ()   container calls this when it decides take the instance out of service. It is the last method called n the servlet instance.&lt;br /&gt; jspInit () &amp; jspDestroy () called only once so we cannot override these methods.&lt;br /&gt;&lt;br /&gt;Q) Diff RequestDispatcher.forward(req, res) &amp; RequestDispatcher.include(req, res) &amp; &lt;jsp:forward&gt; &amp; res.sendRedirect( url)&lt;br /&gt;&lt;br /&gt;	RequestDispatcher.include(req, res) RequestDispatcher.include() and &lt;jsp:include&gt; both include content. The included page is inserted into the current page or output stream at the indicated point.&lt;br /&gt;&lt;br /&gt;	RequestDispatcher.forward(req, res) in forward req, res would be passed to the destination url and the control will return back to the same method, It will execute at “server side”. (Or) RequestDispatcher.forward(), the servlet engine transfers control of this HTTP request internally from your current servlet or JSP to another servlet or JSP or static file.&lt;br /&gt;&lt;br /&gt;	&lt;Jsp: forward&gt; Forwards a client request to an HTML file, JSP file, or servlet for processing. When ever the client request will come it will take the request and process the request and the request to be forward to another page, it will also forward the http parameters of the previous page to the destination page. It will execute at “server side” so the browser unaware of the changes. If page1.jsp redirects to page2.jsp, the browser address bar will still show page1.jsp.&lt;br /&gt;	&lt;br /&gt;res.sendRedirect(url) when ever the client request will come just it will take the request and the request to be forwarded to another page. It cannot forward the http parameters of the previous page. This will work at client side.&lt;br /&gt;&lt;br /&gt;Q) Diff res.sendRedirect( ) &amp; req.forward( )&lt;br /&gt;&lt;br /&gt; 	sendRedirect()  sends a redirect response back to the client&#39;s browser. The browser will normally interpret this response by initiating a new request to the redirect URL given in the response. &lt;br /&gt;forward()  does not involve the client&#39;s browser. It just takes browser&#39;s current request, and hands it off to another servlet/jsp to handle. The client doesn&#39;t know that they&#39;re request is being handled by a different servlet/jsp than they originally called. &lt;br /&gt;For ex, if you want to hide the fact that you&#39;re handling the browser request with multiple servlets/jsp, and all of the servlets/jsp are in the same web application, use forward() or include(). If you want the browser to initiate a new request to a different servlet/jsp, or if the servlet/jsp you want to forward to is not in the same web application, use sendRedirect (). &lt;br /&gt;&lt;br /&gt;Q) Diff &lt;%@ include file=&quot;file&quot; %&gt; &amp; &lt;jsp:include page=”abc.jsp” %&gt;&lt;br /&gt;&lt;br /&gt;  	 &lt;%@include file=&quot;abc.jsp&quot;%&gt; directive acts like C &quot;#include&quot;, pulling in the text of the included file and compiling it as if it were part of the including file. The included file can be any type (including HTML or text). (Or) includes a jsp/servlet at compile time meaning only once parsed by the compiler.&lt;br /&gt;&lt;br /&gt;&lt;jsp:include page=&quot;abc.jsp&quot;&gt; include a jsp/servlet at request time it is not parsed by the compiler.&lt;br /&gt;&lt;br /&gt;Q) Diff Jsp &amp; Servlet&lt;br /&gt;	&lt;br /&gt;Internally when jsp is executed by the server it get converted into the servlet so the way jsp &amp; servlet work is almost similar.&lt;br /&gt; In jsp we can easily separate the P.L with B.L, but in servlet both are combined.&lt;br /&gt; One servlet object is communicated with many numbers of objects, but jsp it is not possible.&lt;br /&gt;&lt;br /&gt;Q) Can JSP be multi-threaded? How can I implement a thread-safe JSP page?&lt;br /&gt;A) By default the service() method of all the JSP execute in a multithreaded fashion. You can make a page “thread-safe” and have it serve client requests in a single-threaded fashion by setting the page tag’s is Thread Safe attribute to false:	&lt;br /&gt;&lt;%@ page is ThreadSafe=”false” %&gt;&lt;br /&gt;&lt;br /&gt;Q) How does JSP handle runtime exceptions?&lt;br /&gt;A) You can use the errorPage attribute of the page directive to have uncaught run-time exceptions automatically forwarded to an error processing page. For example:&lt;br /&gt;        	&lt;%@ page errorPage=\&quot;error.jsp\&quot; %&gt; &lt;br /&gt;redirects the browser to the JSP page error.jsp if an uncaught exception is encountered during request &lt;br /&gt;&lt;br /&gt;processing. Within error.jsp, if you indicate that it is an error-processing page, via the directive: &lt;br /&gt;&lt;%@ page isErrorPage=\&quot;true\&quot; %&gt;.&lt;br /&gt;&lt;br /&gt;Q) How do I prevent the output of my JSP or Servlet pages from being cached by the Web browser? And Proxy server?&lt;br /&gt;&lt;br /&gt;    Web browser caching&lt;br /&gt;    &lt;%response.setHeader(&quot;Cache-Control&quot;,&quot;no-store&quot;); &lt;br /&gt;          response.setHeader(&quot;Pragma&quot;,&quot;no-cache&quot;); &lt;br /&gt;          response.setDateHeader (&quot;Expires&quot;, 0); &lt;br /&gt;     %&gt;&lt;br /&gt;&lt;br /&gt;   Proxy server caching&lt;br /&gt;      response.setHeader(&quot;Cache-Control&quot;,&quot;private&quot;);&lt;br /&gt;&lt;br /&gt;Q) What&#39;s a better approach for enabling thread-safe servlets &amp; JSPs? SingleThreadModel Interface or Synchronization?&lt;br /&gt;A) SingleThreadModel technique is easy to use, and works well for low volume sites. If your users to increase in the future, you may be better off implementing explicit synchronization for your shared data &lt;br /&gt;     Also, note that SingleThreadModel is pretty resource intensive from the server&#39;s perspective. The most serious issue however is when the number of concurrent requests exhausts the servlet instance pool. In that case, all the unserviced requests are queued until something becomes free. &lt;br /&gt;&lt;br /&gt;Q) Servlet – to- JSP communicate? &lt;br /&gt;    public void doPost(HttpServletRequest req, &lt;br /&gt;                                   HttpServletResponse res)&lt;br /&gt;{&lt;br /&gt;    Try{&lt;br /&gt;	govi.FormBean f = new govi.formBean();&lt;br /&gt;             string id = req.getParameter(“id”);&lt;br /&gt;             f.setName(req.getParameter(“name”)); &lt;br /&gt;             f.setName(req.getParameter(“addr”)); &lt;br /&gt;             f.setPersonalizationInfo(info);&lt;br /&gt;             req.setAttribute(“fBean”,f);&lt;br /&gt;             getServletConfig().getServletContext().getRequestDispatcher(“/jsp/Bean1.jsp”).forward(req, res);&lt;br /&gt;       } catch(Exception ex);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The jsp page Bean1.jsp can then process fBean,&lt;br /&gt;&lt;br /&gt;&lt;jsp:useBean id=”fBean” class=”govi.formBean” scope=”request” /&gt;&lt;br /&gt;&lt;jsp:getProprety name=”fBean” property=”name” /&gt;&lt;br /&gt;&lt;jsp:getProprety name=”fBean” property=”addr” /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q) JSP- to-EJB Session Bean communicate? &lt;br /&gt;&lt;%@ page import=&quot;javax.naming.*, javax.rmi.PortableRemoteObject, foo.AccountHome, foo.Account&quot; %&gt;&lt;br /&gt;&lt;%!&lt;br /&gt;     AccountHome accHome=null;&lt;br /&gt;     public void jspInit() {&lt;br /&gt;     InitialContext cntxt = new InitialContext( );&lt;br /&gt;     Object ref= cntxt.lookup(&quot;java:comp/env/ejb/AccountEJB&quot;);&lt;br /&gt;     accHome = (AccountHome)PortableRemoteObject.narrow(ref,AccountHome.class);&lt;br /&gt;   }&lt;br /&gt;%&gt;&lt;br /&gt;&lt;%&lt;br /&gt;     Account acct = accHome.create();&lt;br /&gt;     acct.doWhatever(...);&lt;br /&gt; %&gt;&lt;br /&gt;&lt;br /&gt;Q) Servlet output -  to - another Servlet?&lt;br /&gt;     &lt;br /&gt;Servlet1&lt;br /&gt;     ServletContext sc = getServletContext();&lt;br /&gt;     RequestDispatcher rd = sc.getRequestDispatcher(“/../srevlet2”) ;&lt;br /&gt;     rd.forward(req, res);&lt;br /&gt;    &lt;br /&gt;Servlet2&lt;br /&gt;&lt;br /&gt;Public void service(servletRequest req, servletResponse res)&lt;br /&gt;{&lt;br /&gt;     ServletContext sc = getServletContext();&lt;br /&gt;     RequestDispatcher rd = sc.getRequestDispatcher(“/../srevlet1”) ;&lt;br /&gt;     rd.include(req, res);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Q) How do you pass an InitParameter to a JSP?&lt;br /&gt;&lt;%! &lt;br /&gt;ServletConfig cfg =null;&lt;br /&gt;	public void jspInit(){&lt;br /&gt;            	ServletConfig  cfg=getServletConfig();&lt;br /&gt;           	for (Enumeration e=cfg.getInitParameterNames(); e.hasMoreElements();)&lt;br /&gt; {&lt;br /&gt;           		String name=(String)e.nextElement();&lt;br /&gt;           	String value = cfg.getInitParameter(name);&lt;br /&gt;           		System.out.println(name+&quot;=&quot;+value); &lt;br /&gt;       	}&lt;br /&gt;           }&lt;br /&gt;%&gt;&lt;br /&gt;&lt;br /&gt;Q) How to view an image stored on database with JSP?&lt;br /&gt;&lt;%@ page language=&quot;java&quot; import=&quot;java.sql.*,java.util.*&quot;%&gt;&lt;br /&gt;&lt;%&lt;br /&gt;          String image_id = (String) request.getParameter(&quot;ID&quot;);&lt;br /&gt;          if (image_id != null){&lt;br /&gt;          try &lt;br /&gt;          {&lt;br /&gt;            Class.forName(&quot;interbase.interclient.Driver&quot;);&lt;br /&gt;Connection con = DriverManager.getConnection(&quot;jdbc:interbase://localhost/D:/InterBase/examples/Database/employee.gdb&quot;,&quot;java&quot;,&quot;java&quot;);&lt;br /&gt;   	Statement stmt = con.createStatement();&lt;br /&gt;ResultSet rs = stmt.executeQuery(&quot;SELECT * FROM IMMAGINE WHERE IMMAGINE_ID = &quot; + image_id);&lt;br /&gt;	if (rs.next())&lt;br /&gt;            {&lt;br /&gt;		String dim_image = rs.getString(&quot;IMMAGINE_DIMENSIONE&quot;);&lt;br /&gt;		byte [] blocco = rs.getBytes(&quot;IMMAGINE_IMMAGINE&quot;);&lt;br /&gt;		response.setContentType(&quot;image/jpeg&quot;);&lt;br /&gt;		ServletOutputStream op = response.getOutputStream();&lt;br /&gt;		for(int i=0;i&lt;Integer.parseInt(dim_image);i++)&lt;br /&gt;		{&lt;br /&gt;			op.write(blocco[i]);&lt;br /&gt;		}&lt;br /&gt;  	   } &lt;br /&gt;	   rs.close();&lt;br /&gt;	   stmt.close();&lt;br /&gt;	   con.close();&lt;br /&gt;	 } catch(Exception e) {&lt;br /&gt;		out.println(&quot;An error occurs : &quot; + e.toString());				&lt;br /&gt;         }			&lt;br /&gt;	}&lt;br /&gt;%&gt;&lt;br /&gt;&lt;br /&gt;Q) How do I pass values from a list box (with multiple selects) to a Java Bean?&lt;br /&gt;Consider the following HTML, which basically allows the user to select multiple values by means of a checkbox: &lt;br /&gt;&lt;br /&gt;What&#39;s your favorite movie?&lt;br /&gt;&lt;form method=post action=Movies.jsp&gt;&lt;br /&gt;&lt;input type=checkbox name=faveMovies   value=&quot;2001: A Space Odyssey&quot;&gt;  2001: A Space Odyssey&lt;br /&gt;&lt;input type=checkbox name=faveMovies   value=&quot;The Waterboy&quot;&gt;  The Waterboy&lt;br /&gt;&lt;input type=checkbox name=faveMovies   value=&quot;The Tin Drum&quot;&gt;   The Tin Drum&lt;br /&gt;&lt;input type=checkbox name=faveMovies   value=&quot;Being John    &quot;&gt;  Being John Malkovich&lt;br /&gt;&lt;input type=submit&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;To handle HTML elements like checkboxes and lists which can be used to select multiple values, you need to use a bean with indexed properties (arrays). The following bean can be used to store the data selected from the above check box, since it contains an indexed property movies: &lt;br /&gt;&lt;br /&gt;package foo;&lt;br /&gt;public class MovieBean {&lt;br /&gt;    private String[] movies;&lt;br /&gt;    public MovieBean() {&lt;br /&gt;     String movies[] = new String[0];&lt;br /&gt;    }&lt;br /&gt;    public String[] getMovies() {&lt;br /&gt;       return movies;&lt;br /&gt;    }&lt;br /&gt;    public void setMovies(String[] m) {&lt;br /&gt;     this.movies = m;&lt;br /&gt;    }   &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Although a good design pattern would be to have the names of the bean properties match those of the HTML input form elements, it need not always be the case, as indicated within this example. The JSP code to process the posted form data is as follows: &lt;br /&gt;&lt;br /&gt;&lt;html&gt; &lt;body&gt;&lt;br /&gt;&lt;%! String[] movies; %&gt;&lt;br /&gt;&lt;br /&gt;&lt;jsp:useBean id=&quot;movieBean&quot; class=&quot;foo.MovieBean&quot;&gt;&lt;br /&gt;  &lt;jsp:setProperty name=&quot;movieBean&quot;     property=&quot;movies&quot;      param=&quot;faveMovies&quot; /&gt;&lt;br /&gt;&lt;/jsp:useBean&gt;&lt;br /&gt;&lt;br /&gt;&lt;%   movies = movieBean.getMovies();&lt;br /&gt;   if (movies != null) {&lt;br /&gt;      out.println(&quot;You selected: &lt;br&gt;&quot;);&lt;br /&gt;      out.println(&quot;&lt;ul&gt;&quot;);&lt;br /&gt;      for (int i = 0; i &lt; movies.length; i++) {&lt;br /&gt;        out.println (&quot;&lt;li&gt;&quot;+movies[i]+&quot;&lt;/li&gt;&quot;);&lt;br /&gt;      }&lt;br /&gt;      out.println(&quot;&lt;/ul&gt;&quot;);&lt;br /&gt;    } else &lt;br /&gt;      out.println (&quot;Don&#39;t you watch any movies?!&quot;);&lt;br /&gt;%&gt;&lt;br /&gt;&lt;/body&gt;&lt;/html&gt;&lt;/FONT&gt;&lt;/strong&gt;</content><link rel='replies' type='application/atom+xml' href='http://itjobsfaqs.blogspot.com/feeds/6527650926753132726/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/jsp-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/6527650926753132726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/6527650926753132726'/><link rel='alternate' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/jsp-questions.html' title='JSP QUESTIONS'/><author><name>Tiru Reddy</name><uri>http://www.blogger.com/profile/13152630017999545653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8829103433621523357.post-3425535685253589751</id><published>2010-08-02T22:40:00.000-07:00</published><updated>2010-08-02T22:41:29.643-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SERVLETS"/><title type='text'>SERVLETS</title><content type='html'>&lt;strong&gt;&lt;FONT COLOR=&quot;BLACK&quot;&gt;Q) Servlet&lt;br /&gt; Servlet is server side component, a servlet is small plug gable extension to the server and servlets are used to extend the functionality of the java-enabled server. Servlets are durable objects means that they remain in memory specially instructed to be destroyed.&lt;br /&gt;&lt;br /&gt;Q) Servlet Life cycle&lt;br /&gt;&lt;br /&gt;Public void init (ServletConfig config) throws ServletException&lt;br /&gt;public void service (ServletRequest req, ServletResponse res) throws ServletException, IOException&lt;br /&gt;public void destroy ()&lt;br /&gt;&lt;br /&gt;First the servlet is constructed and then initialized with the init () method, this will call only once.&lt;br /&gt;Any request from client is handled initially by the service () method before delegating to the doXxx () methods in the case of HttpServlet.&lt;br /&gt;The servlet is removed from service, destroyed with the destroy () method, then garbaged collected and finalized. This will call only once. When your application is stopped (or) Servlet Container shuts down, your Servlet&#39;s destroy () method will be called. This allows you to free any resources you may have got hold of in your Servlet&#39;s init () method.&lt;br /&gt;&lt;br /&gt;Q) ServletConfig &amp; ServletContext&lt;br /&gt;ServletConfig  ServletConfig object is used to obtain configuration data when it is loaded.&lt;br /&gt;ServletContext ServletContext is used to obtain information about environment on which a servlet is running.&lt;br /&gt;&lt;br /&gt;Q) Where the servlets will be loaded?&lt;br /&gt;A) Address space of webserver.&lt;br /&gt;&lt;br /&gt;Q) Are Servlets multithread?&lt;br /&gt;A) Yes, the servlet container allocates a thread for each new request for a single servlet. Each thread of your servlet runs as if a single user were accessing using it alone, but u can use static variable to store and present information that is common to all threads, like a hit counter for instance.&lt;br /&gt;&lt;br /&gt;Q) What happens to System.out &amp; System.err output in a Servlet?&lt;br /&gt;A) System.out goes to &#39;client side&#39; and is seen in browser, while System.err goes to &#39;server side&#39; and is visible in error logs and/or on console.&lt;br /&gt;&lt;br /&gt;Q) Session Tracking&lt;br /&gt; Session tracking is the capability of the server to maintain the single client sequential list.&lt;br /&gt;&lt;br /&gt;Q) Servlet chaining&lt;br /&gt; Is a technique in which two are more servlets cooperating in servicing a single client sequential request, where one servlet output is piped to the next servlet output. The are 2 ways (i) Servlet Aliasing (ii) HttpRequest&lt;br /&gt;&lt;br /&gt;Servlet Aliasing  allows you to setup a single alias name for a comma delimited list of servlets. To make a servlet chain opens your browser and give the alias name in URL.&lt;br /&gt;&lt;br /&gt;HttpRequest construct a URL string and append a comma delimited list of servlets to the end.&lt;br /&gt;&lt;br /&gt;Q) HttpTunnelling&lt;br /&gt; Is a method used to reading and writing serializes objects using a http connection. You are creating a sub protocol inside http protocol that is tunneling inside another protocol.&lt;br /&gt;&lt;br /&gt;Q) Diff CGI &amp; Servlet &lt;br /&gt; Servlet  is thread based but CGI is not&lt;br /&gt; CGI allow separate process for every client request, CGI is platform dependent and servlet is platform independent.&lt;br /&gt;&lt;br /&gt;Q) Diff GET &amp; POST&lt;br /&gt; GET &amp; POST are used to process request and response of a client. &lt;br /&gt; Get method is the part of URL, we send less amount of data through Get. The amount of information limited is 240-255 characters.&lt;br /&gt; Using POST we can send large amount of data through hidden fields.&lt;br /&gt; Get is to get the posted html data; POST is to post the html data.&lt;br /&gt;&lt;br /&gt;Q) Diff Http &amp; Generic Servlet&lt;br /&gt; HttpServlet class extends Generic servlet, so Generic servlet is parent and HttpServlet is child.&lt;br /&gt; Generic is from javax.servlet package, HttpServlet is from javax.servlet.Http package.&lt;br /&gt; Http implements all Http protocols, Generic servlet will implements all networking protocol&lt;br /&gt; Http is stateless protocol, which means each request is independent of previous one; In generic we cannot maintain the state of next page only main state of current page.&lt;br /&gt; A protocol is said to be stateless if it has n memory of prior connection.&lt;br /&gt; Http servlet extra functionality is capable of retrieving Http header information.&lt;br /&gt; Http servlet can override doGet (), doDelete (), doGet (), doPost (), doTrace (), generic servlet will override Service () method only.&lt;br /&gt;&lt;br /&gt;Q) The Structure and Deployment of Modern Servlet Web Applications&lt;br /&gt;A) /WEB-INF/web.xml&lt;br /&gt;     /WEB-INF/lib/ [any required jar files]&lt;br /&gt;     /WEB-INF/classes/ [all class files]&lt;br /&gt;    &lt;br /&gt;     WAR-&gt; WARfile can be placed in a server’s webapps directory&lt;br /&gt;&lt;br /&gt;Q) Servlet mapping?&lt;br /&gt;A)   &lt;servlet&gt;&lt;br /&gt;   &lt;servlet-name&gt;watermelon&lt;/servlet-name&gt;&lt;br /&gt;   &lt;servlet-class&gt;myservlets.watermelon&lt;/servlet-class&gt;&lt;br /&gt;      &lt;/servlet&gt;&lt;br /&gt;      &lt;servlet-mapping&gt;&lt;br /&gt;&lt;servlet-name&gt;watermelon&lt;/servlet-name&gt;&lt;br /&gt;&lt;url-pattern&gt;/fruit/summer/*&lt;/url-pattern&gt;&lt;br /&gt;      &lt;/servlet-mapping&gt;&lt;br /&gt;&lt;br /&gt;Q) Timeoutcan be overridden in web.xml?&lt;br /&gt;A) &lt;session-config&gt;&lt;br /&gt;        &lt;session-timeout&gt;e.g.60&lt;/session-timeout&gt;&lt;br /&gt;     &lt;/session-config&gt; &lt;br /&gt;&lt;br /&gt;Q) Init parameter / Define context parameters?&lt;br /&gt;   &lt;servlet&gt;&lt;br /&gt;       &lt;servlet-name&gt;HelloWorld2&lt;/servlet-name&gt; &lt;br /&gt;       &lt;servlet-class&gt;examples.servlets.HelloWorld2&lt;/servlet-class&gt;&lt;br /&gt;   &lt;init-param&gt;&lt;br /&gt;        &lt;param-name&gt;greeting&lt;/param-name&gt; &lt;br /&gt;        &lt;param-value&gt;Welcome&lt;/param-value&gt; &lt;br /&gt;  &lt;/init-param&gt;&lt;br /&gt; &lt;/servlet&gt;&lt;br /&gt;&lt;br /&gt;Q) Tag Libraries?&lt;br /&gt;A) &lt;taglib&gt;&lt;br /&gt;        &lt;taglib-uri&gt;myTaglib&lt;/taglib-uri&gt;&lt;br /&gt;        &lt;tablig-location&gt;WEB-INF/myTLD.tld&lt;/taglib-location&gt;&lt;br /&gt;    &lt;/taglib&gt;&lt;br /&gt;&lt;br /&gt;Q) How many ways we can instantiate a class.?&lt;br /&gt;A) Class.forName().newInstance() and new keyword&lt;br /&gt;&lt;br /&gt;Q) Client pull &amp; Server push?&lt;br /&gt; Client pull &lt;br /&gt;Client pull is similar to redirection, with one major difference: the browser actually displays the content from the first page and waits some specified amount of time before retrieving and displaying the content from the next page. It&#39;s called client pull because the client is responsible for pulling the content from the next page. &lt;br /&gt;Client pull information is sent to the client using the Refresh HTTP header. This header&#39;s value specifies the number of seconds to display the page before pulling the next one, and it optionally includes a URL string that specifies the URL from which to pull. If no URL is given, the same URL is used. Here&#39;s a call to setHeader() that tells the client to reload this same servlet after showing its current content for three seconds: setHeader(&quot;Refresh&quot;, &quot;3&quot;);&lt;br /&gt;And here&#39;s a call that tells the client to display Netscape&#39;s home page after the three seconds: &lt;br /&gt;setHeader(&quot;Refresh&quot;, &quot;3; URL=http://home.netscape.com&quot;);&lt;br /&gt;&lt;br /&gt;Server push&lt;br /&gt;server push because the server sends, or pushes, a sequence of response pages to the client.With server push, the socket connection between the client and the server remains open until the last page has been sent.&lt;br /&gt;&lt;br /&gt;Q) How can a servlet refresh automatically if some new data has entered the database?&lt;br /&gt;A) you can use client side refresh are server push&lt;br /&gt;&lt;br /&gt;Q) Session Tracking techniques&lt;br /&gt;     &lt;br /&gt;(i) URL Rewriting&lt;br /&gt;(ii) Hidden form Field&lt;br /&gt;(iii) Persistence Cookies&lt;br /&gt;(iv) Session Tracking API&lt;br /&gt;(v) User Authorization&lt;br /&gt;&lt;br /&gt;URL Rewriting&lt;br /&gt;URL rewriting is a technique in which the requested URL is modified with the session id.&lt;br /&gt;URL rewriting is another way to support anonymous session tracking. With URL rewriting, every local URL the user might click on is dynamically modified, or rewritten, to include extra information.&lt;br /&gt;http://server:port/servlet/Rewritten?sessionid=123   added parameter&lt;br /&gt;&lt;br /&gt;Hidden form Field&lt;br /&gt; Hidden form fields are HTML input type that are not displayed when read by the browser. They are sent back to the server when the form that contains them is submitted. You include hidden form fields with HTML like this: &lt;br /&gt;&lt;br /&gt;&lt;FORM ACTION=&quot;/servlet/MovieFinder&quot; METHOD=&quot;POST&quot;&gt;&lt;br /&gt;   &lt;INPUT TYPE=hidden NAME=&quot;zip&quot; VALUE=&quot;94040&quot;&gt;&lt;br /&gt;   &lt;INPUT TYPE=hidden NAME=&quot;level&quot; VALUE=&quot;expert&quot;&gt;&lt;br /&gt;&lt;/FORM&gt;&lt;br /&gt;In a sense, hidden form fields define constant variables for a form. To a servlet receiving a submitted form, there is no difference between a hidden field and a visible field. &lt;br /&gt;&lt;br /&gt;Persistence Cookie  &lt;br /&gt;A cookie is a bit of information sent by a web server to a browser that can later be read back from that browser. When a browser receives a cookie, it saves the cookie and thereafter sends the cookie back to the server each time it accesses a page on that server, subject to certain rules. Because a cookie&#39;s value can uniquely identify a client, cookies are often used for session tracking. Because cookies are sent using HTTP headers, they should be added to the response before you send any content. Browsers are only required to accept 20 cookies per site, 300 total per user, and they can limit each cookie&#39;s size to 4096 bytes. &lt;br /&gt;&lt;br /&gt;Sending cookies from a servlet&lt;br /&gt;&lt;br /&gt;Cookie cookie = new Cookie (&quot;ID&quot;, &quot;123&quot;);&lt;br /&gt;res.addCookie (cookie);&lt;br /&gt;&lt;br /&gt;A servlet retrieves cookies by calling the getCookies () method of HttpServlet- Request: &lt;br /&gt;public Cookie[] HttpServletRequest.getCookies()&lt;br /&gt;This method returns an array of Cookie objects that contains all the cookies sent by the browser as part of the request or null if no cookies were sent. The code to fetch cookies looks like this: &lt;br /&gt;&lt;br /&gt;Reading browser cookies from a Servlet&lt;br /&gt;&lt;br /&gt;Cookie [] cookies = req. getCookies();&lt;br /&gt;if (cookies != null) {&lt;br /&gt;  for (int i = 0; i &lt; cookies.length; i++) {&lt;br /&gt;    String name = cookies [i]. getName ();&lt;br /&gt;    String value = cookies [i]. getValue();&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;A cookie, mycookie, can be Deleted using the following scriptlet: &lt;br /&gt;&lt;%&lt;br /&gt;     Cookie killMyCookie = new Cookie(&quot;mycookie&quot;, null);&lt;br /&gt;     killMyCookie.setMaxAge(0);&lt;br /&gt;     killMyCookie.setPath(&quot;/&quot;);&lt;br /&gt;     response.addCookie(killMyCookie);&lt;br /&gt;%&gt;&lt;br /&gt;&lt;br /&gt;You can set the maximum age of a cookie with the cookie.setMaxAge(int seconds) method: &lt;br /&gt; Zero means to delete the cookie &lt;br /&gt; + value is the maximum number of seconds the cookie will live, before it expires &lt;br /&gt; - value means the cookie will not be stored beyond this browser session (deleted on browser close)&lt;br /&gt;&lt;br /&gt;Session Tracking API&lt;br /&gt;In Java the javax.servlet.http.HttpSession API handles many of the details of session tracking. It allows a session object to be created for each user session, then allows for values to be stored and retrieved for each session. A session object is created through the HttpServletRequest using the getSession() method: &lt;br /&gt;&lt;br /&gt;HttpSession session = request.getSession(true); &lt;br /&gt;&lt;br /&gt;This will return the session for this user or create one if one does not already exist. &lt;br /&gt;Values can be stored for a user session using the HttpSession method putValue(): &lt;br /&gt;&lt;br /&gt;session.putValue(&quot;valueName&quot;, valueObject); &lt;br /&gt;&lt;br /&gt;Session objects can be retrieved using getValue(String name), while a array of all value names can be retrieved using getValueNames(). Values can also be removed using removeValue(String valueName) &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;User Authorization&lt;br /&gt; Servers can be set up to restrict access to HTML pages (and servlets). The user is required to enter a user name and password. Once they are verified the client re-sends the authorisation with requests for documents to that site in the http header. &lt;br /&gt;Servlets can use the username authorisation sent with request to keep track of user data. For example, a hashtable can be set up to contain all the data for a particular user. When a user makes another request the user name can be used to add new items to their cart using the hashtable. &lt;br /&gt;&lt;br /&gt;Q) Session&lt;br /&gt;Session is a persistence network connection between client and server that facilitate the exchange of information between client and server. A session object created for each user persists on the server side, either until user closes the browser or user remains idle for the session expiration time.&lt;br /&gt; &lt;br /&gt;As such there is no limit on the amount of information that can be saved in a Session Object. Only the RAM available on the server machine is the limitation. The only limit is the Session ID length(Identifier) , which should not exceed more than 4K. If the data to be store is very huge, then it&#39;s preferred to save it to a temporary file onto hard disk, rather than saving it in session. Internally if the amount of data being saved in Session exceeds the predefined limit, most of the servers write it to a temporary cache on Hard disk.&lt;br /&gt;&lt;br /&gt;HttpSession session = req.getSession(true); //Creating a Session instance&lt;br /&gt;session.putValue (&quot;MyIdentifier1&quot;, count1);  // Storing Value into session Object&lt;br /&gt;session.putValue (&quot;MyIdentifier2&quot;, count2);  &lt;br /&gt;session.getValue(MyIdentifier1); // Prints value of Count&lt;br /&gt;session.removeValue(MyIdentifier1); // Removing Valuefrom Session Object&lt;br /&gt;&lt;br /&gt;Q) Cookie advantages &amp; Disadvantages&lt;br /&gt;Advantages Persistence offer efficient way to implement session tracking for each client request a cookie can be automatically provide a clients session id.&lt;br /&gt;Disadvantage The biggest problem with cookies is that browser do not always accept cookies. Some times browser does not accept cookies. Browser only requires accepting 20 cookies per page and they can limit the cookie size to 4096 bytes. It cannot work if the security level set too high in browser. Cookies are stored in a plain text format so every one can view and modify them. We can put maximum 300 cookies for entire application.&lt;br /&gt;&lt;br /&gt;Q) Advantages of Sessions over Cookies &amp; URLRewriting?&lt;br /&gt; Sessions are more secure and fast because they are stored at server side. But sessions has to be used combindly with cookies (or) URLRewriting for maintaining client id that is session id at client side.&lt;br /&gt; Cookies are store at client side so some clients may disable cookies so we may not sure that the cookies which we are maintaining may work or not, if cookies are disable also we can maintain sessions using URLRewriting.&lt;br /&gt; In URLRewriting we cannot maintain large data because it leads to network traffic and access may be become slow. Where in sessions will not maintain the data which we have to maintain instead we will maintain only the session id.&lt;br /&gt;&lt;br /&gt;Q) encodeURL &amp; encodeRedirectURL&lt;br /&gt;   These are methods of HttpResponse object,  “encodeURL” is for normal links inside your HTML pages, “encodeRedirectURL” is for a link your passing to response.sendRedirect().&lt;br /&gt;&lt;br /&gt;Q) SingleThread model&lt;br /&gt; SingleThreadModel is a tag interface with no methods. In this model no two threads will execute concurrently the service method of the servlet, to accomplish this each thread uses a free servlet instance from the servlet pool. So any servlet implementing this can be considered thread safe and it is not required synchronize access to its variables.&lt;br /&gt;(or)&lt;br /&gt;If a servlet implements this interface, the server ensures that each instance of the servlet handles only one service request at a time. Servers implement this functionality by maintaining a pool of servlet instances and dispatching incoming requests to free servlets within the pool. SingleThreadModel provides easy thread safety, but at the cost of increased resource requirements as more servlet instances are loaded at any given time. &lt;br /&gt;&lt;br /&gt;public interface SingleThreadModel { &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Q) Request Headers&lt;br /&gt;User-agent: - Gives the information about client software, browser name, version and information about the machine on which it is running.&lt;br /&gt;request.getHeader(“user-agent”);&lt;br /&gt;&lt;br /&gt;Q) Why there is no constructor in servlet?&lt;br /&gt;A) A servlet is just like an applet in the respect that it has an init() method that acts as a constructor, an initialization code you need to run should e place in the init(), since it get called when the servlet is first loaded.&lt;br /&gt;&lt;br /&gt;Q) Why do you need both GET &amp; POST methods in servlets?&lt;br /&gt;A) A single servlet can be called from different HTML pages, so different method calls can be possible.&lt;br /&gt;  &lt;/FONT&gt;&lt;/strong&gt;</content><link rel='replies' type='application/atom+xml' href='http://itjobsfaqs.blogspot.com/feeds/3425535685253589751/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/servlets.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/3425535685253589751'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/3425535685253589751'/><link rel='alternate' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/servlets.html' title='SERVLETS'/><author><name>Tiru Reddy</name><uri>http://www.blogger.com/profile/13152630017999545653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8829103433621523357.post-3833130472254382884</id><published>2010-08-02T22:34:00.000-07:00</published><updated>2010-08-02T22:37:40.091-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="COREJAVA INTERVIEW QUESTIONS6"/><title type='text'>COREJAVA INTERVIEW QUESTIONS6</title><content type='html'>&lt;strong&gt;&lt;font color=&quot;black&quot;&gt;Collections Frame Work&lt;br /&gt;&lt;br /&gt;Q) &lt;br /&gt;Collection classes Collection Interfaces Legacy classes Legacy interface&lt;br /&gt;Abstract collection Collection  Dictionary Enumerator&lt;br /&gt;Abstract List List Hash Table &lt;br /&gt;Abstract Set Set Stack &lt;br /&gt;Array List Sorted Set Vector &lt;br /&gt;Linked List Map Properties &lt;br /&gt;Hash set Iterator  &lt;br /&gt;Tree Set   &lt;br /&gt;Hash Map   &lt;br /&gt;Tree Map   &lt;br /&gt; &lt;br /&gt;Collection Classes&lt;br /&gt;&lt;br /&gt; Abstract collection  &lt;br /&gt; &lt;br /&gt; Abstract List &lt;br /&gt;&lt;br /&gt; Abstract Set &lt;br /&gt;&lt;br /&gt;Array List  Array List extends AbstractList and implements the List interface. ArrayList is a variable length    of array of object references, ArrayList support dynamic array that grow as needed. A.L allows rapid random access to element but slow for insertion and deletion from the middle of the list.&lt;br /&gt; &lt;br /&gt;  ArrayList is a replacement for Vector.&lt;br /&gt;&lt;br /&gt;Linked List  Extends AbstactSequentialList and implements List interface. L.L provides optimal sequence access, in expensive insertion and deletion from the middle of the list, relatively slow for random access. &lt;br /&gt; &lt;br /&gt; Methods&gt;&gt; void addFirst (Object obj), addLast (Object obj), Object getFirst (), Object getLast ().&lt;br /&gt;&lt;br /&gt;Hash Set  HashSet extends AbstractSet implements Set interface, it creates a collection that uses HashTable for storage, H.S does not guarantee the order of its elements, if u need storage go for TreeSet&lt;br /&gt; &lt;br /&gt; Methods&gt;&gt; add (), remove (), size ().&lt;br /&gt;&lt;br /&gt;Tree Set  Extends Abstract Set implements Set interface. Objects are stored in sorted, ascending order. Access and retrial times are quite fast.&lt;br /&gt; &lt;br /&gt;Hash Map  Extends Abstract Map and implements Map interface. H.P does not guarantee the order of elements, so the order in which the elements are added to a H.P is not necessary the order in which they are ready by the iterate.&lt;br /&gt; &lt;br /&gt;  HashMap is similar to Hashtable.&lt;br /&gt; &lt;br /&gt;Tree Map  implements Map interface, a TreeMap provides an efficient means of storing key/value pairs in sorted order and allows rapid retrieval.&lt;br /&gt;     &lt;br /&gt;Collection Interfaces&lt;br /&gt; &lt;br /&gt; Collection  Collection is a group of objects, collection does not allow duplicate elements.&lt;br /&gt; &lt;br /&gt; Methods&gt;&gt; boolean add (Object obj), boolean addAll (Collection c), Iterator iterator (), &lt;br /&gt; boolean remove(Object obj), boolean removeAll(Collection c).&lt;br /&gt;&lt;br /&gt;List   List will extend collection, List stores a sequence of elements that can contain duplicates, elements can be accessed their position in the list using a zero based index.&lt;br /&gt;&lt;br /&gt;Methods&gt;&gt; void add(int index, Object obj), boolean addAll(int index, Collection c), Object get(int index), int indexOf(Object obj), int lastIndexOf(Object obj), ListIterator  iterator(), Object remove(int index).&lt;br /&gt; &lt;br /&gt; Set   Set will extend collection, Set cannot contain duplicate elements.&lt;br /&gt; &lt;br /&gt; Sorted Set   Extends Set to handle Sorted Sets.&lt;br /&gt; Methods&gt;&gt; Object last (), Object first ().&lt;br /&gt;&lt;br /&gt; Map  Map maps unique key to value in a map for every key there is a corresponding value and you will lookup the values using keys. Map cannot contain duplicate “key” and “value”. In map both the “key” &amp; “value” are objects.&lt;br /&gt;      &lt;br /&gt;Methods&gt;&gt; Object get (Object k), Object put (Object k, Object v).&lt;br /&gt;&lt;br /&gt;Iterator  Before accessing a collection through an iterator you must obtain one if the collection classes provide an iterator () method that returns an iterator to the start of the collection. By using iterator object you can access each element in the collection, one element at a time.&lt;br /&gt;Ex: - ArayList arr = new ArrayList ();&lt;br /&gt;  Arr.add (“c”);&lt;br /&gt;     Iterator itr = arr.iterator ();&lt;br /&gt;  While (itr.hashNext ())&lt;br /&gt;  {&lt;br /&gt;  Object element = itr.next ();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;       List Iterator  List Iterator gives the ability to access the collection, either forward/backward direction  &lt;br /&gt;&lt;br /&gt;Legacy Classes&lt;br /&gt; &lt;br /&gt;Dictionary  is an abstract class that represent key/value storage repository and operates much like “Map” once the value is stored you can retrieve it by using key.&lt;br /&gt; &lt;br /&gt;Hash Table  HashTable stores key/value pairs in hash table, HashTable is Synchronized when using hash table you have to specify an object that is used as a key, and the value that you want to linked to that key. The key is then hashed, and the resulting hash code is used as the index at which the value is stored with the table. Use H.T to store large amount of data, it will search as fast as vector.&lt;br /&gt;&lt;br /&gt;Methods&gt;&gt; boolean containsKey(Object key), boolean containsValue(Object value), Object get(Object key), Object put(Object key, Object value)&lt;br /&gt;&lt;br /&gt;Stack  is a sub class of vector, stack includes all the methods defined by vector and adds several of its own.&lt;br /&gt; &lt;br /&gt;Vector  vector holds any type of objects, it is not fixed length and vector is synchronized. We can store primitive data types as well as objects. Default length of vector is up to 10.&lt;br /&gt;&lt;br /&gt;Methods&gt;&gt; final void addElement(Object element), final int size(), final int capacity(), final boolean removeElementAt(int index), final void removeAllElements().&lt;br /&gt;&lt;br /&gt;Properties  is a subclass of HashTable, it is used to maintain the list of values in which the “key/value”  is String.&lt;br /&gt; &lt;br /&gt;Legacy Interfaces&lt;br /&gt;&lt;br /&gt;      Enumeration  Define methods by which you can enumerate the elements in a collection of objects. Enumeration is synchronized it having 2 methods hasMoreElements(), nextElement().&lt;br /&gt; &lt;br /&gt;Q) Array&lt;br /&gt; Array of fixed length of same data type, we can store primitive data types as well as class objects.&lt;br /&gt; Arrays are initialized to the default value of their type when they are created, not declared, even if they are local variables&lt;br /&gt;&lt;br /&gt;Q) Diff Iterator &amp; Enumeration&lt;br /&gt; Iterator is not synchronized and enumeration is synchronized. Both are interface, Iterator is collection interface which extends from ‘List’ interface. Enumeration is a legacy interface, Enumeration having 2 methods ‘Boolean hasMoreElements()’ &amp; ‘Object NextElement()’. Iterator having 3 methods ‘boolean hasNext()’, ‘object next()’, ‘void remove()’.&lt;br /&gt;&lt;br /&gt;Q) List Iterator&lt;br /&gt; It is an interface, List Iterator extends Iterator to allow bi-directional traversal of a list and modification of the elements. Methods are ‘hasNext()’, ‘ hasPrevious()’.&lt;br /&gt;&lt;br /&gt;Q) Diff HashTable &amp; HashMap&lt;br /&gt; Both provide key/value to access the data. The H.T is one of the original collection class in java. H.M is part of new collection frame work.&lt;br /&gt; H.T is synchronized and H.M is not.&lt;br /&gt; H.M permits null values in it while H.T does not.&lt;br /&gt; Iterator in the H.M is fail safe while the enumerator for the H.T is not.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Exception Handling&lt;br /&gt;&lt;br /&gt;     Object&lt;br /&gt;&lt;br /&gt;          &lt;br /&gt;               Throwable&lt;br /&gt;    &lt;br /&gt;      Error                    Exception      &lt;br /&gt;&lt;br /&gt;   AWT Error     Virtual Machine Error         &lt;br /&gt;                Compile time.Ex                 Runtime Exception&lt;br /&gt;      (checked)        (Unchecked)&lt;br /&gt;&lt;br /&gt;  OutOfMemory.E   StackOverFlow.E             EOF.E             FilenotFound.E&lt;br /&gt;          Arithmetic.E     NullPointer.E   Indexoutof&lt;br /&gt;                                      Bound.E                   &lt;br /&gt;                         ArrayIndexoutOfBound.E         StirngIndexoutOfBound&lt;br /&gt;&lt;br /&gt;Q) Diff Exception &amp; Error&lt;br /&gt; Exception and Error both are subclasses of the Throwable class.&lt;br /&gt; &lt;br /&gt;ExceptionException is generated by java runtime system (or) by manually. An exception is a abnormal condition that transfer program execution from a thrower to catcher.&lt;br /&gt;Error        Will stop the program execution, Error is a abnormal system condition we cannot handled   these.&lt;br /&gt; &lt;br /&gt;Q) try, catch, throw, throws&lt;br /&gt;&lt;br /&gt;Try           This is used to fix up the error, to prevent the program from automatically terminating, try-catch is used to catching an exception that are thrown by the java runtime system. &lt;br /&gt;&lt;br /&gt;Throw    is used to throw an exception explicitly.&lt;br /&gt;&lt;br /&gt;Throws  A Throws clause list the type of exceptions that a methods might through.&lt;br /&gt;&lt;br /&gt;Q) Checked &amp; UnChecked Exception :-&lt;br /&gt;Checked exception is some subclass of Exception. Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream&#39;s read() method•&lt;br /&gt;             &lt;br /&gt;Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn&#39;t force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String&#39;s charAt() method• Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Checked Exceptions Un checked exception&lt;br /&gt;ClassNotFoundException ArithmeticException&lt;br /&gt;NoSuchMethodException ArrayIndexOutOfBoundException&lt;br /&gt;NoSuchFieldException ClasscastException&lt;br /&gt;InterruptedException IllegalArgumentException &lt;br /&gt;IllegalAccessException IllegalMonitorSateException&lt;br /&gt;CloneNotSupportedException IllegalThreadStateException&lt;br /&gt; IndexOutOfBoundException&lt;br /&gt; NullPointerException&lt;br /&gt; NumberFormatException&lt;br /&gt; StringIndexOutOfBounds&lt;br /&gt;&lt;br /&gt;OutOfMemoryError --&gt; Signals that JVM has run out of memory and that the garbage collector is unable to claim any more free memory.&lt;br /&gt;StackOverFlow --&gt; Signals that a stack O.F in the interpreter.&lt;br /&gt;ArrayIndexOutOfbound --&gt; For accessing an array element by providing an index values &lt;0 or &gt; or equal to the array size.&lt;br /&gt;StringIndexOutOfbound --&gt; For accessing character of a string or string buffer with index values &lt;0 or &gt; or equal to the array size.&lt;br /&gt;Arithmetic Exception --&gt; such as divide by zero.&lt;br /&gt;ArrayStore Exception --&gt; Assignment to an array element of incompatible types.&lt;br /&gt;ClasscastException --&gt; Invalid casting.&lt;br /&gt;IllegalArgument Exception --&gt; Illegal argument is used to invoke a method.&lt;br /&gt;Nullpointer Exception --&gt; If attempt to made to use a null object.&lt;br /&gt;NumberFormat Exception --&gt; Invalid conversition of string to numeric format.&lt;br /&gt;ClassNotfound Exception --&gt; class not found.&lt;br /&gt;Instantion Exception --&gt; Attempt to create an object of an Abstract class or Interface.&lt;br /&gt;NosuchField Exception --&gt; A request field does not exist.&lt;br /&gt;NosuchMethod Exception --&gt; A request method does not exist.&lt;br /&gt;&lt;br /&gt;Q) Can I catch an exception and give my own error message? &lt;br /&gt;A) Yes, you can catch servlet errors and give custom error pages for them, but if there are exceptional conditions you can anticipate, it would be better for your application to address these directly and try to avoid them in the first place. If a servlet relies upon system or network resources that may not be available for unexpected reasons, you can use a RequestDispatcher to forward the request to an error page. &lt;br /&gt;&lt;br /&gt;RequestDispatcher dispatcher = null;&lt;br /&gt;request.getRequestDispatcher (/err/SQL.jsp);&lt;br /&gt;try {&lt;br /&gt; // SQL operation&lt;br /&gt;}&lt;br /&gt;catch (SQLException se) {&lt;br /&gt; dispatcher.forward (request, response);&lt;br /&gt;}        &lt;br /&gt;Web.xml:-&lt;br /&gt;&lt;error-page&gt;&lt;br /&gt; &lt;error-code&gt;&lt;br /&gt;    HTTP error code&lt;br /&gt; &lt;error-code&gt;&lt;br /&gt;  &lt;exception-type&gt;&lt;br /&gt;    java.lang.RuntimeException&lt;br /&gt;  &lt;/exception-type&gt;&lt;br /&gt;  &lt;location&gt;&lt;br /&gt;    /err/RuntimeException.jsp&lt;br /&gt;  &lt;/location&gt;&lt;br /&gt;&lt;/error-page&gt;&lt;br /&gt;&lt;br /&gt;Q) Methods in Exceptions?&lt;br /&gt;A) getMessage (), toString(), printStackTrace(), getLocalizedMessage(),&lt;br /&gt;&lt;br /&gt;Q) Primitive multi tasking&lt;br /&gt;  If the thread of different priorities shifting the control depends on the priority .i.e; a thread with higher priority is executed first than the thread with lower priority. This process of shifting control is known as primitive multi tasking.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;All Packages&lt;br /&gt;&lt;br /&gt;Q) Thread Class&lt;br /&gt;Methods: -&lt;br /&gt;&lt;br /&gt;getName() run()&lt;br /&gt;getPriority() Sleep()&lt;br /&gt;isAlive() Start()&lt;br /&gt;join() &lt;br /&gt;&lt;br /&gt;Q) Object class&lt;br /&gt; All other classes are sub classes of object class; Object class is a super class of all other class.&lt;br /&gt;Methods: -&lt;br /&gt;void notify() void notifyAll()&lt;br /&gt;Object Clone() Sting toString()&lt;br /&gt;Boolean equals(Object object) Void wait()&lt;br /&gt;void finalize() void wait(long milliseconds, int nanoseconds)&lt;br /&gt;&lt;br /&gt;Q) throwable class&lt;br /&gt;&lt;br /&gt;Methods: -&lt;br /&gt;String getMessage() Void printStackTrace()&lt;br /&gt;String toString() Throwable fillInStackTrace()&lt;br /&gt;&lt;br /&gt;Q) Javax.servlet Package&lt;br /&gt;&lt;br /&gt;Interfaces Classes Exceptions&lt;br /&gt;Servlet GenericServlet ServletException&lt;br /&gt;ServletConfig ServletInputStream UnavaliableException&lt;br /&gt;ServletContext ServletOutputStream &lt;br /&gt;ServletRequest  &lt;br /&gt;ServletResponse  &lt;br /&gt;SingleThreadModel  &lt;br /&gt;&lt;br /&gt;GenericServlet (C) public void destroy ();&lt;br /&gt;public String getInitParameter(String name);&lt;br /&gt;public Enumeration getInitParameterNames();&lt;br /&gt;public ServletConfig getServletConfig();&lt;br /&gt;public ServletContext getServletContext();&lt;br /&gt;public String getServletInfo();&lt;br /&gt;public void init(ServletConfig config) throws ServletException;&lt;br /&gt;public void log(String msg);&lt;br /&gt;public abstract void service(ServletRequest req, ServletResponse res)&lt;br /&gt;&lt;br /&gt;ServletInputStream (C)      public int readLine (byte b [], int off, int len) &lt;br /&gt;&lt;br /&gt;ServletOutputStream (C)   public void print (String s) throws IOException;&lt;br /&gt;          public void println() throws IOException;&lt;br /&gt;&lt;br /&gt;Servlet (I)     public abstract void destroy ();&lt;br /&gt;  public abstract ServletConfig getServletConfig();&lt;br /&gt;  public abstract String getServletInfo();&lt;br /&gt;  public abstract void init(ServletConfig config) throws ServletException;&lt;br /&gt;  public abstract void service(ServletRequest req, ServletResponse res)&lt;br /&gt;&lt;br /&gt;ServletConfig (I)   public abstract String getInitParameter (String name);&lt;br /&gt;        public abstract Enumeration getInitParameterNames();&lt;br /&gt;                                  public abstract ServletContext getServletContext();&lt;br /&gt;&lt;br /&gt;ServletContext (I)  public abstract Object getAttribute (String name);&lt;br /&gt;public abstract String getRealPath(String path);&lt;br /&gt;public abstract String getServerInfo();&lt;br /&gt;public abstract Servlet getServlet(String name) throws ServletException;&lt;br /&gt;public abstract Enumeration getServletNames();            &lt;br /&gt;public abstract Enumeration getServlets();                 &lt;br /&gt;public abstract void log(Exception exception, String msg); &lt;br /&gt;&lt;br /&gt;ServletRequest (I)  public abstract Object getAttribute (String name);&lt;br /&gt; public abstract String getParameter(String name);&lt;br /&gt; public abstract Enumeration getParameterNames();&lt;br /&gt; public abstract String[] getParameterValues(String name);&lt;br /&gt; public abstract String getRealPath(String path);&lt;br /&gt; public abstract String getRemoteAddr();&lt;br /&gt; public abstract String getRemoteHost();&lt;br /&gt; public abstract String getServerName();&lt;br /&gt; public abstract int getServerPort();&lt;br /&gt;&lt;br /&gt;ServletResponse (I)  public abstract String getCharacterEncoding ();               &lt;br /&gt; public abstract PrintWriter getWriter() throws IOException;&lt;br /&gt; public abstract void setContentLength(int len);&lt;br /&gt; public abstract void setContentType(String type);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q) Javax.servlet.Http Package&lt;br /&gt;&lt;br /&gt;Interfaces Classes Exceptions&lt;br /&gt;HttpServletRequest Cookies  ServletException&lt;br /&gt;HttpServletResponse HttpServlet UnavaliableException&lt;br /&gt;HttpSession HttpUtils &lt;br /&gt;HttpSessionContext HttpSessionbindingEvent &lt;br /&gt;HttpSessionBindingListener  &lt;br /&gt;&lt;br /&gt;Cookies (C)  public Object clone ();&lt;br /&gt;public int getMaxAge();&lt;br /&gt;public String getName();&lt;br /&gt;public String getPath();&lt;br /&gt;public String getValue();&lt;br /&gt;public int getVersion();&lt;br /&gt;public void setMaxAge(int expiry);&lt;br /&gt;public void setPath(String uri);&lt;br /&gt;public void setValue(String newValue);&lt;br /&gt;public void setVersion(int v);&lt;br /&gt;&lt;br /&gt;HttpServlet (C)  public void service(ServletRequest req, ServletResponse res) &lt;br /&gt;     protected void doDelete (HttpServletRequest req, HttpServletResponse res) &lt;br /&gt;     protected void doGet (HttpServletRequest req, HttpServletResponse res) &lt;br /&gt;     protected void doOptions(HttpServletRequest req, HttpServletResponse res)&lt;br /&gt;     protected void doPost(HttpServletRequest req,  HttpServletResponse res) &lt;br /&gt;     protected void doPut(HttpServletRequest req, HttpServletResponse res) &lt;br /&gt;     protected void doTrace(HttpServletRequest req, HttpServletResponse res) &lt;br /&gt;     protected long getLastModified(HttpServletRequest req);&lt;br /&gt;     protected void service(HttpServletRequest req, HttpServletResponse res) &lt;br /&gt;&lt;br /&gt;HttpSessionbindingEvent (I)  public String getName();&lt;br /&gt;  public HttpSession getSession();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;HttpServletRequest (I)   public abstract Cookie[] getCookies();                &lt;br /&gt;  public abstract String getHeader(String name);&lt;br /&gt;  public abstract Enumeration getHeaderNames();&lt;br /&gt;  public abstract String getQueryString();&lt;br /&gt;  public abstract String getRemoteUser();&lt;br /&gt;  public abstract String getRequestedSessionId();&lt;br /&gt;  public abstract String getRequestURI();&lt;br /&gt;  public abstract String getServletPath();&lt;br /&gt;  public abstract HttpSession getSession(boolean create);&lt;br /&gt;  public abstract boolean isRequestedSessionIdFromCookie();&lt;br /&gt;  public abstract boolean isRequestedSessionIdFromUrl();    &lt;br /&gt;  public abstract boolean isRequestedSessionIdValid();&lt;br /&gt;&lt;br /&gt;HttpServletResponse (I)  public abstract void addCookie(Cookie cookie);            &lt;br /&gt; public abstract String encodeRedirectUrl(String url);     &lt;br /&gt; public abstract String encodeUrl(String url);             &lt;br /&gt; public abstract void sendError(int sc, String msg) throws IOException;&lt;br /&gt; public abstract void sendRedirect(String location) throws IOException;&lt;br /&gt; public abstract void setHeader(String name, String value);&lt;br /&gt;&lt;br /&gt;HttpSession (I)  public abstract long getCreationTime();&lt;br /&gt;  public abstract String getId();&lt;br /&gt;  public abstract long getLastAccessedTime();&lt;br /&gt;  public abstract HttpSessionContext getSessionContext();&lt;br /&gt;  public abstract Object getValue(String name);&lt;br /&gt;  public abstract String[] getValueNames();&lt;br /&gt;  public abstract void invalidate();&lt;br /&gt;  public abstract boolean isNew();&lt;br /&gt;  public abstract void putValue(String name, Object value);&lt;br /&gt;  public abstract void removeValue(String name);&lt;br /&gt;&lt;br /&gt;HttpSessionContext (I)   public abstract Enumeration getIds();&lt;br /&gt;           public abstract HttpSession getSession(String sessionId);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q) java.sql Package&lt;br /&gt;&lt;br /&gt;Interfaces Classes Exceptions&lt;br /&gt;Statement DriverManager SQL Exception&lt;br /&gt;PreparedStatement Time ClassNotFoundException&lt;br /&gt;CallableStatement TimeStamp Instantiation Exception&lt;br /&gt;ResultSet  &lt;br /&gt;ResultSetMetaData  &lt;br /&gt;Connection  &lt;br /&gt;Driver  &lt;br /&gt;&lt;br /&gt;Q) java.lang Package&lt;br /&gt;&lt;br /&gt;Interfaces Classes Exceptions&lt;br /&gt;Cloneable Double, Float, Long, Integer, Short, Byte, Boolean, Character, ArithmeticException, ArrayIndexOutOfBoundOf.E, ClassCast.E, ClassNotFound.E&lt;br /&gt;Runnable Class, ClassLoader IlleAcess.E, IllegalArgument.E&lt;br /&gt;Comparable Process, RunTime, Void IllegalSate.E, NullPointer.E&lt;br /&gt; String, StringBuffer NoSuchField.E, NoSuchMethod.E&lt;br /&gt; Thread, ThreadGroup NumberFormat.E&lt;br /&gt;&lt;br /&gt;Q) java.IO Package&lt;br /&gt;&lt;br /&gt;Interfaces Classes Exceptions&lt;br /&gt;DataInputstream BufferInputstream, BufferOutputStream &lt;br /&gt;DataOutputstream BufferReader, BufferWriter &lt;br /&gt;ObjectInputStream ByteArrayInputStream, ByteArrayOutputstream &lt;br /&gt;ObjectOutputstream CharacterarrayReader, CharacterArayWriter &lt;br /&gt;Serializable DataInputStream, DataOutputStream &lt;br /&gt;Externializable Filereader, FileWriter &lt;br /&gt; ObjectInputStream, ObjectOutputStream &lt;/font&gt;&lt;/strong&gt;</content><link rel='replies' type='application/atom+xml' href='http://itjobsfaqs.blogspot.com/feeds/3833130472254382884/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/corejava-interview-questions6.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/3833130472254382884'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/3833130472254382884'/><link rel='alternate' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/corejava-interview-questions6.html' title='COREJAVA INTERVIEW QUESTIONS6'/><author><name>Tiru Reddy</name><uri>http://www.blogger.com/profile/13152630017999545653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8829103433621523357.post-7065454808119190112</id><published>2010-08-02T22:30:00.000-07:00</published><updated>2010-08-02T22:34:11.400-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="COREJAVA INTERVIEW QUESTIONS5"/><title type='text'>COREJAVA INTERVIEW QUESTIONS5</title><content type='html'>&lt;strong&gt;&lt;strong&gt;&lt;font color=&quot;black&quot;&gt;Method Overriding (Runtime polymorphism)&lt;br /&gt;When a method in a subclass has the same name, return type and parameters as the method in the super class then the method in the subclass is override the method in the super class.&lt;br /&gt;&lt;br /&gt; The access modifier for the overriding method may not be more restrictive than the access modifier of the superclass method &lt;br /&gt;&lt;br /&gt;• If the super class method is public, the overriding method must be public &lt;br /&gt;• If the superclass method is protected, the overriding method may be protected or public &lt;br /&gt;• If the superclass method is package, the overriding method may be packagage, protected, or public &lt;br /&gt;• If the superclass methods is private, it is not inherited and overriding is not an issue &lt;br /&gt;• Methods declared as final cannot be overridden.&lt;br /&gt;&lt;br /&gt; The throws clause of the overriding method may only include exceptions that can be thrown by the           superclass method, including it&#39;s subclasses &lt;br /&gt;   &lt;br /&gt; Only member method can be overriden, not member variable &lt;br /&gt; class Parent{ &lt;br /&gt;     int i = 0; &lt;br /&gt;     void amethod(){&lt;br /&gt;           System.out.println(&quot;in Parent&quot;);&lt;br /&gt;          } &lt;br /&gt;             }  &lt;br /&gt;class Child extends Parent{ &lt;br /&gt;      int i = 10; &lt;br /&gt;      void amethod(){&lt;br /&gt;            System.out.println(&quot;in Child&quot;);&lt;br /&gt;      } &lt;br /&gt;}  &lt;br /&gt;class Test{ &lt;br /&gt;public static void main(String[] args){ &lt;br /&gt;Parent p = new Child (); &lt;br /&gt;Child c = new Child (); &lt;br /&gt;System.out.print(&quot;i=&quot;+p.i+&quot; &quot;); &lt;br /&gt;p.amethod(); &lt;br /&gt;System.out.print(&quot;i=&quot;+c.i+&quot; &quot;); &lt;br /&gt;c.amethod(); &lt;br /&gt;} &lt;br /&gt;}&lt;br /&gt;O/p: - i=0 in Child&lt;br /&gt;        i=10 in Child&lt;br /&gt;&lt;br /&gt;Q) Static&lt;br /&gt;Static variables and methods are instantiated only once per class. In other words they are class variables,   not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class.&lt;br /&gt;&lt;br /&gt; When a member is declared a static it can be accessed before any object of its class are created.&lt;br /&gt; Instance variables declared as static are essentially global variables.&lt;br /&gt; If you do not specify an initial value to an instance &amp; Static variable a default value will be assigned    automatically.&lt;br /&gt; Methods declared as static have some restrictions they can access only static data, they can only call other            static data, they cannot refer this or super.&lt;br /&gt; Static methods can’t be overriden to non-static methods.&lt;br /&gt; Static methods are called by the static methods only, an ordinary method can call the static methods, but static methods cannot call ordinary methods.&lt;br /&gt; Static methods are implicitly &quot;final&quot;, because overriding is only done based on the type of the objects&lt;br /&gt; They cannot refer “this” or “super” in any way.&lt;br /&gt;&lt;br /&gt;Q) Class variable &amp; Instance variable &amp; Instance methods &amp; class methods&lt;br /&gt;&lt;br /&gt;Instance variable  variables defined inside a class are called instance variables with multiple instance of class; each instance has a variable stored in separate memory location.&lt;br /&gt;&lt;br /&gt;Class variables  you want a variable to be common to all classes then we crate class variables. To create a class variable put the “static” keyword before the variable name.&lt;br /&gt;&lt;br /&gt;Class methods  we create class methods to allow us to call a method without creating a instance of the class. To declare a class method uses the “static” key word.&lt;br /&gt;&lt;br /&gt;Instance methods  we define a method in a class, in order to use that methods we need to first create objects of the class. &lt;br /&gt;&lt;br /&gt;Q) Static block&lt;br /&gt; Static block which exactly executed exactly once when the class is first loaded into JVM. Before going to the main method the static block will execute.&lt;br /&gt;&lt;br /&gt;Q) Static methods cannot access instance variables why?&lt;br /&gt;A)  Static methods can be invoked before the object is created, Instance variables are created only when the new object is created. Since there is no possibility to the static method to access the instance variables. Instance variables are called called as non-static variables.&lt;br /&gt;&lt;br /&gt;Q) String &amp; StringBuffer&lt;br /&gt; String is a fixed length of sequence of characters, String is immutable.&lt;br /&gt; &lt;br /&gt; StringBuffer represent growable and writeable character sequence, StringBuffer is mutable which means that its value can be changed. It allocates room for 16 addition character space when no specific length is specified. Java.lang.StringBuffer is also a final class hence it cannot be sub classed. StringBuffer cannot be overridden the equals () method.&lt;br /&gt;&lt;br /&gt;Q) Conversions&lt;br /&gt;   &lt;br /&gt;    String to Int Conversion:- &lt;br /&gt;   int I   = integer.valueOf(“24”).intValue();&lt;br /&gt;         int x  = integer.parseInt(“433”);&lt;br /&gt;                            float f = float.valueOf(23.9).floatValue();&lt;br /&gt; &lt;br /&gt;    Int to String Conversion:-&lt;br /&gt;   String arg = String.valueOf (10);&lt;br /&gt;&lt;br /&gt;Q) Super ()&lt;br /&gt; super () always calling the constructor of immediate super class, super () must always be the first statements executed inside a subclass constructor.&lt;br /&gt;&lt;br /&gt;Q) How will u implement 1) polymorphism 2) multiple inheritance 3) multilevel inheritance in java?&lt;br /&gt;A) Polymorphism           – overloading and overriding &lt;br /&gt;    Multiple inheritances   – interfaces.&lt;br /&gt;    Multilevel inheritance – extending class.&lt;br /&gt;&lt;br /&gt;Q) What are different types of inner classes?&lt;br /&gt;A) Nested top-level classes- If you declare a class within a class and specify the static modifier, the compiler treats the class just like any other top-level class. Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. e.g., outer.inner. Top-level inner classes implicitly have access only to static variables. There can also be inner interfaces. All of these are of the nested top-level variety.&lt;br /&gt;&lt;br /&gt;Member classes - Member inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables. This means public member class acts similarly to a nested top-level class. The primary difference between member classes and nested top-level classes is that member classes have access to the specific instance of the enclosing class.&lt;br /&gt;&lt;br /&gt;Local classes - Local classes are like local variables, specific to a block of code. Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement a more publicly available interface. Because local classes are not members the modifiers public, protected, private and static are not usable.&lt;br /&gt;&lt;br /&gt;Anonymous classes - Anonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor.&lt;br /&gt;&lt;br /&gt; Inner class inside method cannot have static members or blocks&lt;br /&gt;&lt;br /&gt;Q) Which circumstances you use Abstract Class &amp; Interface?&lt;br /&gt;--&gt; If you need to change your design make it an interface.&lt;br /&gt;--&gt; Abstract class provide some default behaviour, A.C are excellent candidates inside of application frame work. A.C allow single inheritance model which should be very faster.&lt;br /&gt;&lt;br /&gt;Q) Abstract Class &lt;br /&gt;Any class that contain one are more abstract methods must also be declared as an abstract, there can be no object of an abstract class, we cannot directly instantiate the abstract classes. A.C can contain concrete methods. &lt;br /&gt;Any sub class of an Abstract class must either implement all the abstract methods in the super class or be declared itself as Abstract.&lt;br /&gt;&lt;br /&gt; Compile time error occur if an attempt to create an instance of an Abstract class.&lt;br /&gt; You cannot declare “abstract constructor” and “abstract static method”.&lt;br /&gt; Abstract class can have static, final method.&lt;br /&gt; An abstract method also declared private, native, final, synchronized, or strictfp.&lt;br /&gt; An abstract method declared in a non-abstract class&lt;br /&gt; A class can be declared abstract even if it does not actually have any abstract methods. Declaring such a class abstract indicates that the implementation is somehow incomplete and is meant to serve as a super class for one or more subclasses that will complete the implementation.&lt;br /&gt;&lt;br /&gt;Abstract class A {&lt;br /&gt; Public abstract callme ();&lt;br /&gt; void callmetoo () {&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class B extends A(&lt;br /&gt; void callme(){&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class AbstractDemo{&lt;br /&gt;public static void main(string args[]){&lt;br /&gt; B b = new B();&lt;br /&gt; b.callme();&lt;br /&gt; b.callmetoo();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Q) Interface &lt;br /&gt; Interface is similar to class but they lack instance variable, their methods are declared with out any body. Interfaces are designed to support dynamic method resolution at run time. All methods in interface are implicitly abstract, even if the abstract modifier is omitted. Interface methods have no implementation; &lt;br /&gt;&lt;br /&gt; Interface can be extended, Interface can be implemented.&lt;br /&gt; An interface body may contain constant declarations, abstract method declarations, inner classes and inner interfaces.&lt;br /&gt; All methods of an interface are implicitly abstract, public, even if the public modifier is omitted.&lt;br /&gt; Interface methods cannot be declared protected, private, strictfp, native or synchronized. &lt;br /&gt; All Variables are implicitly final, public, static fields&lt;br /&gt; A compile time error occurs if an interface has a simple name the same as any of it&#39;s enclosing classes or interfaces.&lt;br /&gt; top-level interfaces may only be declared public, inner interfaces may be declared private and protected but only if they are defined in a class.&lt;br /&gt;&lt;br /&gt; A class can only extend one other class.&lt;br /&gt; A class may implements more than one interface.&lt;br /&gt; Interface can extend more than one interface.&lt;br /&gt;&lt;br /&gt;Interface A&lt;br /&gt;{&lt;br /&gt;final static float pi = 3.14f;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class B implements A&lt;br /&gt;{&lt;br /&gt; public float compute(float x, float y)&lt;br /&gt; {&lt;br /&gt;  return(x*y);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class test{&lt;br /&gt;public static void main(String args[])&lt;br /&gt;{&lt;br /&gt; A a = new B();&lt;br /&gt; a.compute();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;Q) Diff Interface &amp; Abstract Class?&lt;br /&gt; Abstract classes may have some executable methods and methods left unimplemented. Interface contains no implementation code.&lt;br /&gt; An abstract class can have nonabstract methods. All methods of an Interface are abstract.&lt;br /&gt; An abstract class can have instance variables. An Interface cannot.&lt;br /&gt; An abstract class can define constructor. An Interface cannot.&lt;br /&gt; An abstract class can have any visibility: public, private, protected. An Interface visibility must be public (or) none.&lt;br /&gt;&lt;br /&gt;Q) What are some alternatives to inheritance? &lt;br /&gt;A) Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass). &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q) When we use Abstract class?&lt;br /&gt;A) Let us take the behaviour of animals, animals are capable of doing different things like flying, digging, &lt;br /&gt;Walking. But these are some common operations performed by all animals, but in a different way as well. When an operation is performed in a different way it is a good candidate for an abstract method.&lt;br /&gt;&lt;br /&gt;Public Abstarctclass Animal{&lt;br /&gt;  Public void eat(food food)&lt;br /&gt;  {&lt;br /&gt;  }&lt;br /&gt;  public void sleep(int hours)&lt;br /&gt;  {&lt;br /&gt;  }&lt;br /&gt;  public abstract void makeNoise()&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public Dog extends Animal&lt;br /&gt;{&lt;br /&gt;   public void makeNoise()&lt;br /&gt;    {&lt;br /&gt;  System.out.println(“Bark! Bark”);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public Cow extends Animal&lt;br /&gt;{&lt;br /&gt;   public void makeNoise()&lt;br /&gt;    {&lt;br /&gt;  System.out.println(“moo! moo”);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Q) Serializable &amp; Externalizable&lt;br /&gt;Serializable --&gt; is an interface that extends serializable interface and sends data into streams in compressed format. It has 2 methods writeExternal (objectOutput out), readExternal (objectInput in).&lt;br /&gt;&lt;br /&gt;Externalizable  is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal (ObjectOuput out) and readExternal (ObjectInput in). &lt;br /&gt;&lt;br /&gt;Q) Internalisation &amp; Localization&lt;br /&gt; Internalisation -- Making a programme to flexible to run in any locale called internalisation.&lt;br /&gt; Localization    -- Making a programme to flexible to run in a specific locale called Localization.&lt;br /&gt;&lt;br /&gt;Q) Serialization&lt;br /&gt; Serialization is the process of writing the state of the object to a byte stream; this is useful when ever you want to save the state of your programme to a persistence storage area. &lt;br /&gt;&lt;br /&gt;Q) Synchronization&lt;br /&gt; Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. (Or) When 2 are more threads need to access the shared resources they need to some way ensure that the resources will be used by only one thread at a time. This process which is achieved is called synchronization.&lt;br /&gt;&lt;br /&gt;(i) Ex: - Synchronizing a function: &lt;br /&gt;public synchronized void Method1 () {&lt;br /&gt;     // Appropriate method-related code.&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;(ii) Ex: - Synchronizing a block of code inside a function: &lt;br /&gt;public myFunction () {&lt;br /&gt; synchronized (this) {&lt;br /&gt;            // Synchronized code here.&lt;br /&gt;         }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;(iii) Ex: - public Synchronized void main (String args [])&lt;br /&gt;      But this is not the right approach because it means servlet can handle one request at a time.&lt;br /&gt;&lt;br /&gt;Q) Different level of locking using Synchronization?&lt;br /&gt;A) Class level, Object level, Method level, Block level&lt;br /&gt;&lt;br /&gt;Q) Monitor&lt;br /&gt; A monitor is a mutex, once a thread enters a monitor, all other threads must wait until that thread exist the monitor. &lt;br /&gt;&lt;br /&gt;Q) Diff = = and .equals ()?&lt;br /&gt;A)   ==           Compare object references whether they refer to the same instance are not.&lt;br /&gt;      equals ()  method compare the characters in the string object.&lt;br /&gt;&lt;br /&gt;Q) Marker Interfaces (or) Tagged Interfaces :- &lt;br /&gt;An Interface with no methods. Is called marker Interfaces, eg., Serializable, SingleThread Model, Cloneable.&lt;br /&gt;&lt;br /&gt;Q) URL Encoding &amp; URL Decoding&lt;br /&gt;  URL Encoding is the method of replacing all the spaces and other extra characters into their corresponding Hex Characters and URL Decoding is the reverse process converting all Hex Characters back their normal form.&lt;br /&gt;&lt;br /&gt;Q) URL &amp; URLConection&lt;br /&gt;&lt;br /&gt;URL is to identify a resource in a network, is only used to read something from the network.&lt;br /&gt;URL url = new URL (protocol name, host name, port, url specifier)&lt;br /&gt;&lt;br /&gt;URLConnection can establish communication between two programs in the network.&lt;br /&gt; URL hp = new URL (“www.yahoo.com”);&lt;br /&gt; URLConnection con = hp.openConnection ();&lt;br /&gt;&lt;br /&gt;Q) Runtime class &lt;br /&gt; Runtime class encapsulate the run-time environment. You cannot instantiate a Runtime object. You can get a reference to the current Runtime object by calling the static method Runtime.getRuntime () &lt;br /&gt;&lt;br /&gt;Runtime r = Runtime.getRuntime ()&lt;br /&gt;Long mem1;&lt;br /&gt;mem1 = r.freeMemory ();&lt;br /&gt;mem1 = r.totalMemory ();&lt;br /&gt;&lt;br /&gt;Q) Execute other programs&lt;br /&gt; You can use java to execute other heavy weight process on your multi tasking operating system, several form of exec () method allows you to name the programme you want to run.&lt;br /&gt; Runtime r = Runtime.getRuntime ();&lt;br /&gt; Process p = null;&lt;br /&gt; try{&lt;br /&gt;  p = r.exce (“notepad”);&lt;br /&gt;  p.waiFor ()&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;Q) System class &lt;br /&gt; System class hold a collection of static methods and variables. The standard input, output, error output of the java runtime are stored in the in, out, err variables.&lt;br /&gt;&lt;br /&gt;Q) Class&lt;br /&gt; Class encapsulate the run-time state of an object or interface. Methods in this class are &lt;br /&gt;&lt;br /&gt;static Class forName(String name) throws ClassNotFoundException getClass()&lt;br /&gt;getClassLoader() getConstructor()&lt;br /&gt;getField() getDeclaredFields()&lt;br /&gt;getMethods() getDeclearedMethods()&lt;br /&gt;getInterface() getSuperClass()&lt;br /&gt;&lt;br /&gt;Q) Native Methods&lt;br /&gt; Native methods are used to call subroutine that is written in a language other than java, this subroutine exist as executable code for the CPU.&lt;br /&gt;&lt;br /&gt;Q) Cloneable Interface&lt;br /&gt; Any class that implements the cloneable interface can be cloned, this interface defines no methods. It is used to indicate that a class allow a bit wise copy of an object to be made.&lt;br /&gt;&lt;br /&gt;Q) Clone&lt;br /&gt; Generate a duplicate copy of the object on which it is called. Cloning is a dangerous action.&lt;br /&gt;&lt;br /&gt;Q) Comparable Interface&lt;br /&gt; Classes that implements comparable contain objects that can be compared in some meaningful manner. This interface having one method compare () the invoking object with the object. For sorting comparable interface will be used.&lt;br /&gt;Ex: - int compareTo (Object obj)&lt;br /&gt; &lt;br /&gt;Q) Class&lt;br /&gt; Encapsulate the run time state of an object (or) interface. You cannot explicitly declare a class object, by using getClass () method you can do that.&lt;br /&gt; Class a = x.getClass ();&lt;br /&gt;&lt;br /&gt;Methods&gt;&gt; getClasses (), getConstructor (), getInterface (), getMethods (), getSuperclass (), getName ().&lt;br /&gt;&lt;br /&gt;Q) java.lang.Reflect (package)&lt;br /&gt; Reflection is the ability of software to analyse it self, to obtain information about the field, constructor, methods &amp; modifier of class. You need this information to build software tools that enables you to work with java beans components.&lt;br /&gt;&lt;br /&gt;Q) InstanceOf&lt;br /&gt; Instanceof means by which your program can obtain run time type information about an object.&lt;br /&gt;Ex: - A a = new A ();&lt;br /&gt;       a instanceof A;&lt;br /&gt;&lt;br /&gt;Q) java pass arguments by value are by reference?&lt;br /&gt;A) by value&lt;br /&gt;&lt;br /&gt;Q) java lack pointers how do I implements classic pointer structures like linked list?&lt;br /&gt;A) using object reference.&lt;br /&gt;&lt;br /&gt;Q) java.Exe&lt;br /&gt; Micro soft provided sdk for java, which includes “jexegentool”. This converts class file into an “.Exec” form. Only disadvantage is user needs a M.S java V.M installed.&lt;br /&gt;&lt;br /&gt;Q) bin &amp; Lib in jdk?&lt;br /&gt;bin contains all tools such as javac, appletviewer and awt tool.&lt;br /&gt;lib contains API and all packages.&lt;br /&gt;   &lt;/font&gt;&lt;/strong&gt;&lt;/strong&gt;</content><link rel='replies' type='application/atom+xml' href='http://itjobsfaqs.blogspot.com/feeds/7065454808119190112/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/corejava-interview-questions5.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/7065454808119190112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/7065454808119190112'/><link rel='alternate' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/corejava-interview-questions5.html' title='COREJAVA INTERVIEW QUESTIONS5'/><author><name>Tiru Reddy</name><uri>http://www.blogger.com/profile/13152630017999545653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8829103433621523357.post-5713949013418805307</id><published>2010-08-02T22:26:00.000-07:00</published><updated>2010-08-02T22:30:37.850-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="COREJAVA INTERVIEW QUESTIONS4"/><title type='text'>COREJAVA INTERVIEW QUESTIONS4</title><content type='html'>&lt;strong&gt;&lt;h4&gt;&lt;font color=&quot;black&quot;&gt;&lt;br /&gt;      Core Java&lt;br /&gt;Java Material Interview Reference&lt;br /&gt;&lt;br /&gt;Q) OOPS concepts&lt;br /&gt;&lt;br /&gt;Polymorphism&lt;br /&gt; Ability to take more than one form, In java we achieve this using Method Overloading (compile time polymorphism), Method overriding (runtime polymorphism)&lt;br /&gt;&lt;br /&gt;Inheritance&lt;br /&gt; Is the process by which one object acquires the properties of another object.&lt;br /&gt; &lt;br /&gt;Encapsulation&lt;br /&gt; Wrapping of data and function into a single unit called encapsulation. Ex:- all java programs.&lt;br /&gt;&lt;br /&gt;Abstraction&lt;br /&gt; Nothing but representing the essential futures without including background details.&lt;br /&gt;&lt;br /&gt;Dynamicbinding&lt;br /&gt; Code associated with a given procedural call is not known until the time of the call at runtime. Dynamic binding is nothing but late binding.&lt;br /&gt;&lt;br /&gt;Q) class &amp; object?&lt;br /&gt;    class   &lt;br /&gt;  &lt;br /&gt; class is a Template that describes the Kind of State(The Instance Variables) and Behavior (Methods)   &lt;br /&gt;    class is a blue print of an object                            component means u can use a piece of code like an&lt;br /&gt;                                                                                       independent piece.like servlet,EJB...etc&lt;br /&gt; Object   instance of class                                u can reuse it in any application &lt;br /&gt;&lt;br /&gt;Q) System.out.println()&lt;br /&gt;      println() is a methd of java.io.printWriter.&lt;br /&gt;      “out” is an instance variable of java.lang.System class.&lt;br /&gt;&lt;br /&gt;Q) Transient &amp; volatile&lt;br /&gt;&lt;br /&gt;    Transient --&gt; the object or variable will not persist.&lt;br /&gt;     Volatile --&gt; value will be changed unexpectedly by the other part of the program.&lt;br /&gt;&lt;br /&gt;Q) Access Specifiers &amp; Access modifiers?&lt;br /&gt;Access Specifiers  A.S gives access privileges to outside of application (or) others; they are Public, Protected, Private, Defaults   &lt;br /&gt;Access Modifiers  A.M which gives additional meaning to data, methods and classes, final cannot be modified at any point of time.&lt;br /&gt;&lt;br /&gt; Private Public Protected No modifier&lt;br /&gt;Same class No Yes Yes Yes&lt;br /&gt;Same package Subclass No Yes Yes Yes&lt;br /&gt;Same package non-subclass No Yes Yes Yes&lt;br /&gt;Different package subclass No Yes Yes No&lt;br /&gt;Different package non-subclass No Yes No NO&lt;br /&gt;&lt;br /&gt;Q)                                               Default Values&lt;br /&gt;     long      -2^63 to 2^63 –1   0L&lt;br /&gt;     Int         -2^31 to 2^31 –1   0&lt;br /&gt;     Short    -2^15 to 2^15 –1   0&lt;br /&gt;     Byte     -2^7 to 2^7 –1       0&lt;br /&gt;     char      0 to 2^7 –1           null character (or) ‘\u 0000’&lt;br /&gt;     double      0.0d&lt;br /&gt;     float          0.0f&lt;br /&gt;     Boolean       false&lt;br /&gt;     Character     ‘\u0000’&lt;br /&gt;&lt;br /&gt;Q) Byte code &amp; JIT compiler&lt;br /&gt; Byte code is a highly optimized set of instructions. JVM is an interpreter  for byte code. Translating a java program into byte code helps makes it much easier to run a program in a wide variety of environment.&lt;br /&gt;&lt;br /&gt;  JIT is a part of JVM, it compiles byte code into executable code in real time, will increase the performance of the interpretations.&lt;br /&gt;&lt;br /&gt;Q) Diff Access Specifier &amp; Access Modifiers&lt;br /&gt;&lt;br /&gt;Access Specifier&lt;br /&gt;&lt;br /&gt;Access Modifiers&lt;br /&gt;&lt;br /&gt;Q) Wrapper classes&lt;br /&gt; &lt;br /&gt;Primitive data types can be converted into objects by using wrapper classes. These are java.lang.package.&lt;br /&gt;&lt;br /&gt;Q) Does Java pass method arguments by value or by reference?&lt;br /&gt;A) Java passes all arguments by value, not by reference&lt;br /&gt; &lt;br /&gt;Q) Arguments &amp; Parameters&lt;br /&gt;While defining method, variable passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.&lt;br /&gt;&lt;br /&gt;Q) Public static void main (String [] args)&lt;br /&gt;&lt;br /&gt; What if the main method is declared as private?&lt;br /&gt;    The program compiles properly but at runtime it will give &quot;Main method not public.&quot; Message&lt;br /&gt;&lt;br /&gt; What if the static modifier is removed from the signature of the main method?&lt;br /&gt;    Program compiles. But at runtime throws an error &quot;NoSuchMethodError&quot;.&lt;br /&gt;&lt;br /&gt; We can write “static public void” instead of “public static void” but not “public void static”.&lt;br /&gt;&lt;br /&gt; If I do not provide the String array as the argument to the method?&lt;br /&gt;    Program compiles but throws a runtime error &quot;NoSuchMethodError&quot;.&lt;br /&gt;&lt;br /&gt; If no arguments on the command line, String array of Main method will be empty of null?&lt;br /&gt;    It is empty. But not null.&lt;br /&gt; Variables can have the same name as a method or a class&lt;br /&gt;&lt;br /&gt;Q) Can an application have multiple classes having main method?&lt;br /&gt;A) Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.&lt;br /&gt;&lt;br /&gt;Q) Can I have multiple main methods in the same class?&lt;br /&gt;A) No the program fails to compile. The compiler says that the main method is already defined in the class.&lt;br /&gt;&lt;br /&gt;Q) Constructor&lt;br /&gt; &lt;br /&gt;The automatic initialization is performed through the constructor, constructor has same name has class name. Constructor has no return type not even void. We can pass the parameters to the constructor. this () is used to invoke a constructor of the same class. Super () is used to invoke a super class constructor. Constructor is called immediately after the object is created before the new operator completes.&lt;br /&gt;&lt;br /&gt; Constructor can use the access specifiers public, protected or private or have no access modifier (package access)&lt;br /&gt; Constructor can not use the modifiers abstract, static, final, native, synchronized or strictfp&lt;br /&gt; Constructor can be overloaded, we cannot override.&lt;br /&gt; You cannot use this() and Super() in the same constructor.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Class A(&lt;br /&gt;A(){&lt;br /&gt;     System.out.println(“hello”);&lt;br /&gt;}}&lt;br /&gt;&lt;br /&gt;Class B extends A {&lt;br /&gt;B(){&lt;br /&gt;     System.out.println(“friend”);&lt;br /&gt;}}&lt;br /&gt;&lt;br /&gt;Class print {&lt;br /&gt;Public static void main (String args []){&lt;br /&gt;B b = new B();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;o/p:- Hello&lt;br /&gt;        friend&lt;br /&gt;&lt;br /&gt;Q) Diff Constructor &amp; Method&lt;br /&gt;&lt;br /&gt;Constructor Method&lt;br /&gt;Use to instance of a class Grouping java statement&lt;br /&gt;No return type Void (or) valid return type&lt;br /&gt;Same name as class name As a name except the class method name, begin with lower case.&lt;br /&gt;“This” refer to another constructor in the same class Refers to instance of class&lt;br /&gt;“Super” to invoke the super class constructor Execute an overridden method in the super class&lt;br /&gt;“Inheritance” cannot be inherited Can be inherited&lt;br /&gt;We can overload but we cannot overridden Can be inherited&lt;br /&gt;Will automatically invoke when an object is created Method has called explicitly&lt;br /&gt;&lt;br /&gt;Q) Garbage collection &lt;br /&gt;&lt;br /&gt;G.C is also called automatic memory management as JVM automatically removes the unused variables/objects (value is null) from the memory. User program cann&#39;t directly free the object from memory, instead it is the job of the garbage collector to automatically free the objects that are no longer referenced by a program. Every class inherits finalize () method from java.lang.Object, the finalize () method is called by garbage collector when it determines no more references to the object exists. In Java, it is good idea to explicitly assign null into a variable when no more in use. In Java on calling System.gc () and Runtime.gc (), JVM tries to recycle the unused objects, but there is no guarantee when all the objects will garbage collected. &lt;br /&gt;&lt;br /&gt;Q) Final, Finally, Finalize&lt;br /&gt;&lt;br /&gt;Final: - When we declare a sub class a final the compiler will give error as “cannot subclass final class” Final to prevent inheritance and method overriding. Once to declare a variable as final it cannot occupy memory per instance basis. &lt;br /&gt;   &lt;br /&gt;       Final class cannot have static methods &lt;br /&gt;       Final class cannot have abstract methods&lt;br /&gt;       Final class can have only a final method.&lt;br /&gt;&lt;br /&gt;Finally: - Finally create a block of code that will be executed after try catch block has completed. Finally block will execute whether or not an exception is thrown. If an exception is thrown, the finally block will execute even if no catch statement match the exception. Any time a method is about to return to the caller from inside try/catch block, via an uncaught exception or an explicit return statement, the finally clause is also execute.&lt;br /&gt;  &lt;br /&gt;    Using System.exit (); in try block will not allow finally code to execute&lt;br /&gt;&lt;br /&gt;Finalize: - some times an object need to perform some actions when it is going to destroy, if an object holding some non-java resource such as file handle (or) window character font, these resources are freed before the object is going to destroy any cleanup processing before the object is garbage collected.&lt;br /&gt;&lt;br /&gt;Q) Superclass &amp; Subclass&lt;br /&gt; A super class is a class that is inherited whereas subclass is a class that does the inheriting&lt;br /&gt;&lt;br /&gt;Q) Diff forms of Polymorphism? Method overloading, Method overriding?&lt;br /&gt;A) Method overloading, Method overriding through inheritance &lt;br /&gt;&lt;br /&gt;Q) Method Overloading &amp; Method Overriding?&lt;br /&gt;&lt;br /&gt;Method Overloading (Compile time polymorphism)&lt;br /&gt; Define two or more methods within the same class (or) subclass that share the same name and their parameter declarations are different then the methods are said to be overloaded. Overloaded methods must differ in number of parameters &amp; return type.&lt;br /&gt;&lt;br /&gt;• Overloaded methods are not required to have the same return type or the list of thrown exceptions. &lt;br /&gt;• Overloading is particularly used while implementing several methods that implement similar behavior but for    different data types.&lt;br /&gt;&lt;br /&gt;Method Overriding (Runtime polymorphism)&lt;br /&gt;When a method in a subclass has the same name, return type and parameters as the method in the super class then the method in the subclass is override the method in the super class.&lt;/h4&gt;&lt;/font&gt;&lt;/strong&gt;</content><link rel='replies' type='application/atom+xml' href='http://itjobsfaqs.blogspot.com/feeds/5713949013418805307/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/corejava-interview-questions4.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/5713949013418805307'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/5713949013418805307'/><link rel='alternate' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/corejava-interview-questions4.html' title='COREJAVA INTERVIEW QUESTIONS4'/><author><name>Tiru Reddy</name><uri>http://www.blogger.com/profile/13152630017999545653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8829103433621523357.post-268817742010035689</id><published>2010-08-02T22:24:00.000-07:00</published><updated>2010-08-02T22:26:01.867-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="COREJAVA INTERVIEW QUESTIONS3"/><title type='text'>COREJAVA INTERVIEW QUESTIONS3</title><content type='html'>&lt;strong&gt;&lt;H4&gt;&lt;FONT COLOR=&quot;BLACK&quot;&gt;101. Can an abstract class be final?&lt;br /&gt;An abstract class may not be declared as final.&lt;br /&gt;102. What is numeric promotion?&lt;br /&gt;Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required.&lt;br /&gt;103. What is the difference between a public and a non-public class?&lt;br /&gt;A public class may be accessed outside of its package. A non-public class may not be accessed outside of its package.&lt;br /&gt;104. To what value is a variable of the boolean type automatically initialized?&lt;br /&gt;The default value of the boolean type is false.&lt;br /&gt;105. What is the difference between the prefix and postfix forms of the ++ operator?&lt;br /&gt;The prefix form performs the increment operation and returns the value of the increment operation. The postfix form returns the current value all of the expression and then performs the increment operation on that value.&lt;br /&gt;106. What restrictions are placed on method overriding?&lt;br /&gt;Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method.&lt;br /&gt;107. What is a Java package and how is it used?&lt;br /&gt;A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces.&lt;br /&gt;108. What modifiers may be used with a top-level class?&lt;br /&gt;A top-level class may be public, abstract, or final.&lt;br /&gt;109. What is the difference between an if statement and a switch statement?&lt;br /&gt;The if statement is used to select among two alternatives. It uses a boolean expression to decide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternative should be executed.&lt;br /&gt;110. What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. import java.net.* versus import java.net.Socket)?&lt;br /&gt;It makes no difference in the generated class files since only the classes that are actually used are referenced by the generated class file. There is another practical benefit to importing single classes, and this arises when two (or more) packages have classes with the same name. Take java.util.Timer and javax.swing.Timer, for example. If Iimport java.util.* and javax.swing.* and then try to use &quot;Timer&quot;, I get an error while compiling (the class name is ambiguous between both packages). Let&#39;s say what you really wanted was the javax.swing.Timer class, and the only classes you plan on using in java.util are Collection and HashMap. In this case, some people will prefer to import java.util.Collection and import java.util.HashMap instead of importing java.util.*. This will now allow them to use Timer, Collection, HashMap, and other javax.swing classes without using fully qualified class names in.&lt;br /&gt;111. Can a method be overloaded based on different return type but same argument type ?&lt;br /&gt;No, because the methods can be called without using their return type in which case there is ambiquity for the compiler.&lt;br /&gt;112. What happens to a static variable that is defined within a method of a class ?&lt;br /&gt;Can&#39;t do it. You&#39;ll get a compilation error.&lt;br /&gt;113. How many static initializers can you have ?&lt;br /&gt;As many as you want, but the static initializers and class variable initializers are executed in textual order and may not refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope.&lt;br /&gt;114. What is the difference between method overriding and overloading?&lt;br /&gt;Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments&lt;br /&gt;115. What is constructor chaining and how is it achieved in Java ?&lt;br /&gt;A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java it is done via an implicit call to the no-args constructor as the first statement.&lt;br /&gt;116. What is the difference between the Boolean &amp; operator and the &amp;&amp; operator?&lt;br /&gt;If an expression involving the Boolean &amp; operator is evaluated, both operands are evaluated. Then the &amp; operator is applied to the operand. When an expression involving the &amp;&amp; operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The &amp;&amp; operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.&lt;br /&gt;117. Which Java operator is right associative?&lt;br /&gt;The = operator is right associative.&lt;br /&gt;118. Can a double value be cast to a byte?&lt;br /&gt;Yes, a double value can be cast to a byte.&lt;br /&gt;119. What is the difference between a break statement and a continue statement?&lt;br /&gt;A break statement results in the termination of the statement to which it applies (switch, for, do, or while). Acontinue statement is used to end the current loop iteration and return control to the loop statement.&lt;br /&gt;120. Can a for statement loop indefinitely?&lt;br /&gt;Yes, a for statement can loop indefinitely. For example, consider the following: for(;;);&lt;br /&gt;121. To what value is a variable of the String type automatically initialized?&lt;br /&gt;The default value of an String type is null.&lt;br /&gt;122. What is the difference between a field variable and a local variable?&lt;br /&gt;A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.&lt;br /&gt;123. How are this() and super() used with constructors?&lt;br /&gt;this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.&lt;br /&gt;124. What does it mean that a class or member is final?&lt;br /&gt;A final class cannot be inherited. A final method cannot be overridden in a subclass. A final field cannot be changed after it&#39;s initialized, and it must include an initializer statement where it&#39;s declared.&lt;br /&gt;125. What does it mean that a method or class is abstract?&lt;br /&gt;An abstract class cannot be instantiated. Abstract methods may only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do. Each subclass of an abstract class must override the abstract methods of its superclasses or it also should be declared abstract.&lt;br /&gt;126. What is a transient variable?&lt;br /&gt;Transient variable is a variable that may not be serialized.&lt;br /&gt;127. How does Java handle integer overflows and underflows?&lt;br /&gt;It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.&lt;br /&gt;128. What is the difference between the &gt;&gt; and &gt;&gt;&gt; operators?&lt;br /&gt;The &gt;&gt; operator carries the sign bit when shifting right. The &gt;&gt;&gt; zero-fills bits that have been shifted out.&lt;br /&gt;129. Is sizeof a keyword?&lt;br /&gt;The sizeof operator is not a keyword.&lt;/FONT&gt;&lt;/H4&gt;&lt;/strong&gt;</content><link rel='replies' type='application/atom+xml' href='http://itjobsfaqs.blogspot.com/feeds/268817742010035689/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/corejava-interview-questions3.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/268817742010035689'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/268817742010035689'/><link rel='alternate' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/corejava-interview-questions3.html' title='COREJAVA INTERVIEW QUESTIONS3'/><author><name>Tiru Reddy</name><uri>http://www.blogger.com/profile/13152630017999545653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8829103433621523357.post-1250397505797408609</id><published>2010-08-02T22:21:00.000-07:00</published><updated>2010-08-02T22:24:18.506-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="COREJAVA INTERVIEW QUESTIONS2"/><title type='text'>COREJAVA INTERVIEW QUESTIONS2</title><content type='html'>&lt;strong&gt;&lt;H4&gt;&lt;FONT COLOR=&quot;BLACK&quot;&gt;51. Can a class be defined inside an Interface?&lt;br /&gt;Yes it&#39;s possible.&lt;br /&gt;52. Can an Interface be defined inside a class?&lt;br /&gt;Yes it&#39;s possible.&lt;br /&gt;53. What is a Marker Interface?&lt;br /&gt;An Interface which doesn&#39;t have any declaration inside but still enforces a mechanism.&lt;br /&gt;54. Which object oriented Concept is achieved by using overloading and overriding?&lt;br /&gt;Polymorphism.&lt;br /&gt;55. Why does Java not support operator overloading?&lt;br /&gt;Operator overloading makes the code very difficult to read and maintain. To maintain code simplicity, Java doesn&#39;t support operator overloading.&lt;br /&gt;56. Can we define private and protected modifiers for variables in interfaces?&lt;br /&gt;No.&lt;br /&gt;57. What is Externalizable?&lt;br /&gt;Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in)&lt;br /&gt;58. What modifiers are allowed for methods in an Interface?&lt;br /&gt;Only public and abstract modifiers are allowed for methods in interfaces.&lt;br /&gt;59. What is a local, member and a class variable?&lt;br /&gt;Variables declared within a method are &quot;local&quot; variables.&lt;br /&gt;Variables declared within the class i.e not within any methods are &quot;member&quot; variables (global variables).&lt;br /&gt;Variables declared within the class i.e not within any methods and are defined as &quot;static&quot; are class variables.&lt;br /&gt;60. What is an abstract method?&lt;br /&gt;An abstract method is a method whose implementation is deferred to a subclass.&lt;br /&gt;61. What value does read() return when it has reached the end of a file?&lt;br /&gt;The read() method returns -1 when it has reached the end of a file.&lt;br /&gt;62. Can a Byte object be cast to a double value?&lt;br /&gt;No, an object cannot be cast to a primitive value.&lt;br /&gt;63. What is the difference between a static and a non-static inner class?&lt;br /&gt;A non-static inner class may have object instances that are associated with instances of the class&#39;s outer class. A static inner class does not have any object instances.&lt;br /&gt;64. What is an object&#39;s lock and which object&#39;s have locks?&lt;br /&gt;An object&#39;s lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object&#39;s lock. All objects and classes have locks. A class&#39;s lock is acquired on the class&#39;s Class object.&lt;br /&gt;65. What is the % operator?&lt;br /&gt;It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.&lt;br /&gt;66. When can an object reference be cast to an interface reference?&lt;br /&gt;An object reference be cast to an interface reference when the object implements the referenced interface.&lt;br /&gt;67. Which class is extended by all other classes?&lt;br /&gt;The Object class is extended by all other classes.&lt;br /&gt;68. Which non-Unicode letter characters may be used as the first character of an identifier?&lt;br /&gt;The non-Unicode letter characters $ and _ may appear as the first character of an identifier&lt;br /&gt;69. What restrictions are placed on method overloading?&lt;br /&gt;Two methods may not have the same name and argument list but different return types.&lt;br /&gt;70. What is casting?&lt;br /&gt;There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.&lt;br /&gt;71. What is the return type of a program&#39;s main() method?&lt;br /&gt;void.&lt;br /&gt;72. If a variable is declared as private, where may the variable be accessed?&lt;br /&gt;A private variable may only be accessed within the class in which it is declared.&lt;br /&gt;73. What do you understand by private, protected and public?&lt;br /&gt;These are accessibility modifiers. Private is the most restrictive, while public is the least restrictive. There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.&lt;br /&gt;74. What is Downcasting ?&lt;br /&gt;Downcasting is the casting from a general to a more specific type, i.e. casting down the hierarchy&lt;br /&gt;75. What modifiers may be used with an inner class that is a member of an outer class?&lt;br /&gt;A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.&lt;br /&gt;76. How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?&lt;br /&gt;Unicode requires 16 bits and ASCII require 7 bits Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits.&lt;br /&gt;UTF-8 represents characters using 8, 16, and 18 bit patterns.&lt;br /&gt;UTF-16 uses 16-bit and larger bit patterns.&lt;br /&gt;77. What restrictions are placed on the location of a package statement within a source code file?&lt;br /&gt;A package statement must appear as the first line in a source code file (excluding blank lines and comments).&lt;br /&gt;78. What is a native method?&lt;br /&gt;A native method is a method that is implemented in a language other than Java.&lt;br /&gt;79. What are order of precedence and associativity, and how are they used?&lt;br /&gt;Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left.&lt;br /&gt;80. Can an anonymous class be declared as implementing an interface and extending a class?&lt;br /&gt;An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.&lt;br /&gt;81. What is the range of the char type?&lt;br /&gt;The range of the char type is 0 to 216 - 1 (i.e. 0 to 65535.)&lt;br /&gt;82. What is the range of the short type?&lt;br /&gt;The range of the short type is -(215) to 215 - 1. (i.e. -32,768 to 32,767)&lt;br /&gt;83. Why isn&#39;t there operator overloading?&lt;br /&gt;Because C++ has proven by example that operator overloading makes code almost impossible to maintain.&lt;br /&gt;84. What does it mean that a method or field is &quot;static&quot;?&lt;br /&gt;Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That&#39;s how library methods likeSystem.out.println() work. out is a static field in the java.lang.System class.&lt;br /&gt;85. Is null a keyword?&lt;br /&gt;The null value is not a keyword.&lt;br /&gt;86. Which characters may be used as the second character of an identifier, but not as the first character of an identifier?&lt;br /&gt;The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.&lt;br /&gt;87. Is the ternary operator written x : y ? z or x ? y : z ?&lt;br /&gt;It is written x ? y : z.&lt;br /&gt;88. How is rounding performed under integer division?&lt;br /&gt;The fractional part of the result is truncated. This is known as rounding toward zero.&lt;br /&gt;89. If a class is declared without any access modifiers, where may the class be accessed?&lt;br /&gt;A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.&lt;br /&gt;90. Does a class inherit the constructors of its superclass?&lt;br /&gt;A class does not inherit constructors from any of its superclasses.&lt;br /&gt;91. Name the eight primitive Java types.&lt;br /&gt;The eight primitive types are byte, char, short, int, long, float, double, and boolean.&lt;br /&gt;92. What restrictions are placed on the values of each case of a switch statement?&lt;br /&gt;During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.&lt;br /&gt;93. What is the difference between a while statement and a do while statement?&lt;br /&gt;A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do while statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do whilestatement will always execute the body of a loop at least once.&lt;br /&gt;94. What modifiers can be used with a local inner class?&lt;br /&gt;A local inner class may be final or abstract.&lt;br /&gt;95. When does the compiler supply a default constructor for a class?&lt;br /&gt;The compiler supplies a default constructor for a class if no other constructors are provided.&lt;br /&gt;96. If a method is declared as protected, where may the method be accessed?&lt;br /&gt;A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.&lt;br /&gt;97. What are the legal operands of the instanceof operator?&lt;br /&gt;The left operand is an object reference or null value and the right operand is a class, interface, or array type.&lt;br /&gt;98. Are true and false keywords?&lt;br /&gt;The values true and false are not keywords.&lt;br /&gt;99. What happens when you add a double value to a String?&lt;br /&gt;The result is a String object.&lt;br /&gt;100. What is the diffrence between inner class and nested class?&lt;br /&gt;When a class is defined within a scope od another class, then it becomes inner class. If the access modifier of the inner class is static, then it becomes nested class.&lt;/FONT&gt;&lt;/H4&gt;&lt;/strong&gt;</content><link rel='replies' type='application/atom+xml' href='http://itjobsfaqs.blogspot.com/feeds/1250397505797408609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/corejava-interview-questions2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/1250397505797408609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/1250397505797408609'/><link rel='alternate' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/corejava-interview-questions2.html' title='COREJAVA INTERVIEW QUESTIONS2'/><author><name>Tiru Reddy</name><uri>http://www.blogger.com/profile/13152630017999545653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8829103433621523357.post-8171352423116059004</id><published>2010-08-02T22:14:00.000-07:00</published><updated>2010-08-02T22:24:34.527-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="COREJAVA INTERVIEW QUESTIONS1"/><title type='text'>COREJAVA INTERVIEW QUESTIONS1</title><content type='html'>&lt;strong&gt;&lt;H4&gt;&lt;FONT COLOR=&quot;BLACK&quot;&gt;1. What is the most important feature of Java?&lt;br /&gt;Java is a platform independent language.&lt;br /&gt;2. What do you mean by platform independence?&lt;br /&gt;Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (Linux,Solaris,etc).&lt;br /&gt;3. What is a JVM?&lt;br /&gt;JVM is Java Virtual Machine which is a run time environment for the compiled java class files.&lt;br /&gt;4. Are JVM&#39;s platform independent?&lt;br /&gt;JVM&#39;s are not platform independent. JVM&#39;s are platform specific run time implementation provided by the vendor.&lt;br /&gt;5. What is the difference between a JDK and a JVM?&lt;br /&gt;JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.&lt;br /&gt;6. What is a pointer and does Java support pointers?&lt;br /&gt;Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn&#39;t support the usage of pointers.&lt;br /&gt;7. What is the base class of all classes?&lt;br /&gt;java.lang.Object&lt;br /&gt;8. Does Java support multiple inheritance?&lt;br /&gt;Java doesn&#39;t support multiple inheritance.&lt;br /&gt;9. Is Java a pure object oriented language?&lt;br /&gt;Java uses primitive data types and hence is not a pure object oriented language.&lt;br /&gt;10. Are arrays primitive data types?&lt;br /&gt;In Java, Arrays are objects.&lt;br /&gt;11. What is difference between Path and Classpath?&lt;br /&gt;Path and Classpath are operating system level environment variales. Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .class files.&lt;br /&gt;12. What are local variables?&lt;br /&gt;Local varaiables are those which are declared within a block of code like methods. Local variables should be initialised before accessing them.&lt;br /&gt;13. What are instance variables?&lt;br /&gt;Instance variables are those which are defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.&lt;br /&gt;14. How to define a constant variable in Java?&lt;br /&gt;The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can&#39;t be changed also.&lt;br /&gt;static final int PI = 2.14; is an example for constant.&lt;br /&gt;15. Should a main() method be compulsorily declared in all java classes?&lt;br /&gt;No not required. main() method should be defined only if the source class is a java application.&lt;br /&gt;16. What is the return type of the main() method?&lt;br /&gt;Main() method doesn&#39;t return anything hence declared void.&lt;br /&gt;17. Why is the main() method declared static?&lt;br /&gt;main() method is called by the JVM even before the instantiation of the class hence it is declared as static.&lt;br /&gt;18. What is the arguement of main() method?&lt;br /&gt;main() method accepts an array of String object as arguement.&lt;br /&gt;19. Can a main() method be overloaded?&lt;br /&gt;Yes. You can have any number of main() methods with different method signature and implementation in the class.&lt;br /&gt;20. Can a main() method be declared final?&lt;br /&gt;Yes. Any inheriting class will not be able to have it&#39;s own default main() method.&lt;br /&gt;21. Does the order of public and static declaration matter in main() method?&lt;br /&gt;No. It doesn&#39;t matter but void should always come before main().&lt;br /&gt;22. Can a source file contain more than one class declaration?&lt;br /&gt;Yes a single source file can contain any number of Class declarations but only one of the class can be declared aspublic.&lt;br /&gt;23. What is a package?&lt;br /&gt;Package is a collection of related classes and interfaces. package declaration should be first statement in a java class.&lt;br /&gt;24. Which package is imported by default?&lt;br /&gt;java.lang package is imported by default even without a package declaration.&lt;br /&gt;25. Can a class declared as private be accessed outside it&#39;s package?&lt;br /&gt;Not possible.&lt;br /&gt;26. Can a class be declared as protected?&lt;br /&gt;A class can&#39;t be declared as protected. only methods can be declared as protected.&lt;br /&gt;27. What is the access scope of a protected method?&lt;br /&gt;A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.&lt;br /&gt;28. What is the purpose of declaring a variable as final?&lt;br /&gt;A final variable&#39;s value can&#39;t be changed. final variables should be initialized before using them.&lt;br /&gt;29. What is the impact of declaring a method as final?&lt;br /&gt;A method declared as final can&#39;t be overridden. A sub-class can&#39;t have the same method signature with a different implementation.&lt;br /&gt;30. I don&#39;t want my class to be inherited by any other class. What should i do?&lt;br /&gt;You should declared your class as final. But you can&#39;t define your class as final, if it is an abstract class. A class declared as final can&#39;t be extended by any other class.&lt;br /&gt;31. Can you give few examples of final classes defined in Java API?&lt;br /&gt;java.lang.String, java.lang.Math are final classes.&lt;br /&gt;32. How is final different from finally and finalize()?&lt;br /&gt;final is a modifier which can be applied to a class or a method or a variable. final class can&#39;t be inherited, finalmethod can&#39;t be overridden and final variable can&#39;t be changed. &lt;br /&gt;&lt;br /&gt;finally is an exception handling code section which gets executed whether an exception is raised or not by the try block code segment. &lt;br /&gt;&lt;br /&gt;finalize() is a method of Object class which will be executed by the JVM just before garbage collecting object to give a final chance for resource releasing activity.&lt;br /&gt;33. Can a class be declared as static?&lt;br /&gt;No a class cannot be defined as static. Only a method, a variable or a block of code can be declared as static.&lt;br /&gt;34. When will you define a method as static?&lt;br /&gt;When a method needs to be accessed even before the creation of the object of the class then we should declare the method as static.&lt;br /&gt;35. What are the restriction imposed on a static method or a static block of code?&lt;br /&gt;A static method should not refer to instance variables without creating an instance and cannot use &quot;this&quot; operator to refer the instance.&lt;br /&gt;36. I want to print &quot;Hello&quot; even before main() is executed. How will you acheive that?&lt;br /&gt;Print the statement inside a static block of code. Static blocks get executed when the class gets loaded into the memory and even before the creation of an object. Hence it will be executed before the main() method. And it will be executed only once.&lt;br /&gt;37. What is the importance of static variable?&lt;br /&gt;static variables are class level variables where all objects of the class refer to the same variable. If one object changes the value then the change gets reflected in all the objects.&lt;br /&gt;38. Can we declare a static variable inside a method?&lt;br /&gt;Static varaibles are class level variables and they can&#39;t be declared inside a method. If declared, the class will not compile.&lt;br /&gt;39. What is an Abstract Class and what is it&#39;s purpose?&lt;br /&gt;A Class which doesn&#39;t provide complete implementation is defined as an abstract class. Abstract classes enforce abstraction.&lt;br /&gt;40. Can a abstract class be declared final?&lt;br /&gt;Not possible. An abstract class without being inherited is of no use and hence will result in compile time error.&lt;br /&gt;41. What is use of a abstract variable?&lt;br /&gt;Variables can&#39;t be declared as abstract. only classes and methods can be declared as abstract.&lt;br /&gt;42. Can you create an object of an abstract class?&lt;br /&gt;Not possible. Abstract classes can&#39;t be instantiated.&lt;br /&gt;43. Can a abstract class be defined without any abstract methods?&lt;br /&gt;Yes it&#39;s possible. This is basically to avoid instance creation of the class.&lt;br /&gt;44. Class C implements Interface I containing method m1 and m2 declarations. Class C has provided implementation for method m2. Can i create an object of Class C?&lt;br /&gt;No not possible. Class C should provide implementation for all the methods in the Interface I. Since Class Cdidn&#39;t provide implementation for m1 method, it has to be declared as abstract. Abstract classes can&#39;t be instantiated.&lt;br /&gt;45. Can a method inside a Interface be declared as final?&lt;br /&gt;No not possible. Doing so will result in compilation error. public and abstract are the only applicable modifiers for method declaration in an interface.&lt;br /&gt;46. Can an Interface implement another Interface?&lt;br /&gt;Intefaces doesn&#39;t provide implementation hence a interface cannot implement another interface.&lt;br /&gt;47. Can an Interface extend another Interface?&lt;br /&gt;Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.&lt;br /&gt;48. Can a Class extend more than one Class?&lt;br /&gt;Not possible. A Class can extend only one class but can implement any number of Interfaces.&lt;br /&gt;49. Why is an Interface be able to extend more than one Interface but a Class can&#39;t extend more than one Class?&lt;br /&gt;Basically Java doesn&#39;t allow multiple inheritance, so a Class is restricted to extend only one Class. But an Interface is a pure abstraction model and doesn&#39;t have inheritance hierarchy like classes(do remember that the base class of all classes is Object). So an Interface is allowed to extend more than one Interface.&lt;br /&gt;50. Can an Interface be final?&lt;br /&gt;Not possible. Doing so so will result in compilation error.&lt;/FONT&gt;&lt;/H4&gt;&lt;/strong&gt;</content><link rel='replies' type='application/atom+xml' href='http://itjobsfaqs.blogspot.com/feeds/8171352423116059004/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/corejava-interview-questions1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/8171352423116059004'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8829103433621523357/posts/default/8171352423116059004'/><link rel='alternate' type='text/html' href='http://itjobsfaqs.blogspot.com/2010/08/corejava-interview-questions1.html' title='COREJAVA INTERVIEW QUESTIONS1'/><author><name>Tiru Reddy</name><uri>http://www.blogger.com/profile/13152630017999545653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>