Saturday, December 28, 2013

How To Use javadoc Utility in Java

To create the document API of your java program use javadoc utility.Open your any java program for which you want to create api and then use document comment /** .... */ to post information about the class, its data method,data members ,constrcutor,blocks etc.

Let's see the simple class that contains documentation comment.

package com.java-interview-preparations;
/** This class is a user-defined class that contains one methods areaRectangle.*/
public class MyFile{

/** The method method prints area of the rectangle based on length and width */
public static void  areaRectangle(int l,int w){
    System.out.println("Area = " + (l*w));
}
}  // end of class
To create the document API, you need to use the javadoc utility followed by your java file name. For this there is no need to compile the javafile.

On the command prompt, you need to write:

javadoc MyFile.java    
to generate the document api. Now, there will be created a lot of html files. Open the index.html file to get the information about the classes.

Thursday, December 26, 2013

Use of Select Keyword in Query

1. Finding how many rows in tables.

2. Finding all records from tables; we are using wildcard start * for getting all columns.

3. Selecting few records based on some condition from tables in SQL.

4. Select few columns instead of all columns of a table.

5. Select distinct (unique) records from Columns.

6. Selecting value with condition based on less than, greater than (>, <, >=, <=) etc.

7. Combining condition using logical operator AND & OR.

8. How to find records which is not null using keyword NULL and IS NULL.

9. SELECT Statement using BETWEEN and NOT BETWEEN.

10. Pattern matching in SQL queries using LIKE and NOT LIKE.

11. IN and NOT IN Statement in Query

12. Sorting ResultSet in SQL using ORDER BY, ASC, DESC.

14. Selecting data from multiple tables by using JOIN in SQL.

15. Calling function on SELECT clause e.g. displaying current date.

16. Doing calculation using SELECT CLAUSE.

17. SELECT data from one row till another row like Paging.

18. Selecting data from result of another query by using derived table.

Difference Between Primary Key and Unique Key in SQL


Primary and unique key uniquely identifies each row in table but there are some subtle difference between them. here are some of them :

1) Unique key in a table can be null, at-least one but primary key can not be null in any table in relation database like MySQL , Oracle etc.

2) Primary key can be combination of more than one unique keys in same table.

3) There can be only one primary key per table in relation database e.g. MySQL, Oracle or Sybase but there can be more than one unique key per table.

4) Unique key is represented using unique constraint while primary key is created using primary key constraint in any table and it's automatically gets unique constraint.

5) Many database engine automatically puts clustered index on primary key and since you can only have one clustered index per table, its not available to any other unique key at same time.

Difference Between Truncate and Delete Command in SQL

This is an important point to understand before using truncate or delete on production environment, or writing any script which purges data from tables.

1. Truncate is fast delete is slow.
2. Truncate doesn't do logging delete logs on per row basis.
3. Rollback is possible with delete not with truncate until specifically supported by vendor.
4. Truncate doesn't fire trigger, delete does.
5. Don't delete, truncate it when it comes to purge tables.
6. Truncate reset identity column in table if any, delete doesn't.
7. Truncate is DDL while delete is DML (use this when you are writing exam)
8. Truncate doesn't support where clause, delete does.

So finally If you have table with huge data and want to empty it don’t Delete, truncate it

1) If you have table which contains large amount of data which command will you use for removing data, truncate or delete?
2) What are differences between truncate and delete?
3) Which one is fast truncate or delete?
4) What is disadvantage of using truncate in sql?
5) How will you delete data if truncate is not supported and log segment is also not big enough to support complete delete?
6) Is there any way to remove data other than truncate and delete in SQL?

Difference between Candidate Key vs Primary Key in MYSQL

Some Differences are given below.
 1) Both Primary and Candidate keys can uniquely identify records in a table on database.
 2) Both Primary and Candidate keys are has constraints UNIQUE and NOT NULL.
 3) Primary key or Candidate keys can be either single column or combination of multiple columns in a table.


Now from interview point of view here is difference between Candidate key and primary key in SQL table on point format for easy to remember :

1) There can be multiple Candidate keys in a table in relation database e.g. Oracle, MySQL, Sybase or MSSQL but only one primary key is permitted.
2) An example of Primary key and Candidate key can be ID and SSN number in a Employee table, Since both can identify each employee uniquely .They are candidate key and any one can become primary key. Now if you have to choose between them as primary key, I will go ID as primary key because SSN is sensitive information and may not be allow/not safe to use as String in queries as frequently as ID. Second reason of choosing ID over SSN as primary key can be use of ID as primary tracking ID within organization and its frequent use all over the place. Once you choose a primary key,
3) All candidate key  are like unique keys.

JSP Interview Questions Answers

What is JSP?
Java Server Page (JSP) is a technology for creating dynamically generated web pages through the use of servlets.
----------------------------------------------------------------------------------------------------
Syntax of JSP declarative tag ?
<%!
%>
----------------------------------------------------------------------------------------------------
Syntax of JSP expression tag?
<%= Expression Tag %>
----------------------------------------------------------------------------------------------------
What is the difference b/w variable declared inside a declaration  and variable declared in scriplet ?
Variable declared inside a declaration tag treated as instance variable and will be placed at class level in the generated servlet.
<%!
int a =10;
%>
Variable declared inside a scriplet tag will be placed inside _jspService() method of generated servlet.
It act as local variable.
<%
int b = 20;
%>