Wednesday, 22 August 2012

net beans revision


UNIT 2 Programming
Key Points:-

    IDE- Integrated development Environment:
o     A programming environment, where all the tools required for programming are available under one roof is called IDE.

    RAD- Rapid Application Development:
o     A programming style which aims at building programs fastly through the use of tools and wizards is called RAD.

    Token:
o    The smallest individual unit in a program is known as Token. Java has the following types of tokens: keyword, Identifier, literal, punctuators and operators.

    Keywords:
o     Keywords are words that have a specific predefined meaning in Java. They cannot be used as variable names. They are also known as reserve words. Eg. void, private, if, while etc.

    Literals:
o     items having fixed data values are referred to as Literals. They are also known as Constants. Various types of literals available in Java are :
•    integer literals
•    Floating literals
•    Boolean literals
•    Character literals
•    String literals
•    Null literals
    Variable:
o    Variable is a named storage location in computer memory whose contents can change during a program run.
    Data Type:
o    Data type helps us identify the type and the range of value that can be stored in a variable. For example a short data type variable in java can store only non-decimal values in the range -32768 to 32767. Various primitive data types available in java are byte, short, int, long, float, double, char and Boolean.

variable Types

Variable IS used to temporarily hold value in the memory.
All variables in the Java language must have a data type. A variable's type determines the values that the variable can have and the operations that can be performed on it. For example, the declaration int count declares that count is an integer (int). Integers can have only whole number values (both positive and negative) and you can use the standard arithmetic operators (+, -, and so on) on integers to perform the standard arithmetic operations (addition, subtraction, and so on). There are two major categories of data types in the Java language: primitive types and reference types.
Primitive types contain a single value and include types such as integer, floating point, character, and boolean. The following table lists, by keyword, all of the primitive data types supported by Java, their size and format, and a brief description of each.
Type    Size/Format              Description
(whole numbers)
byte    8-bit two's complement          Byte-length integer
short   16-bit two's complement          Short integer
int     32-bit two's complement          Integer
long    64-bit two's complement          Long integer

(real numbers)
float   32-bit IEEE 754           Single-precision floating point
double  64-bit IEEE 754           Double-precision floating point

(other types)
char    16-bit Unicode character  A single character
boolean true or false             A boolean value (true or false)


    Operators:
o     Operators are symbols or group of symbols, which represent a operation in java. Operators in java can be classified as Unary operator- operators that require only one operand like ++, -- etc; Binary operator – operator that require two operands like +, - *, > <, == etc.; ternary operator – which require three operands like?:.

Relational Operators in Java
Greater than: >
Less than:    <
Equal to:     ==
Not equal to: !=
Greater than or equal to: >=
Less than or equal to:    <=

Logical Operators in Java
     
Logical AND: &&
Logical OR: ||
Logical NOT: !
 
   Scope of a Variable:
o    The part of program where a variable is usable is called scope of a variable.
    Block:  there are two scopes : global , local scope.
o    A group of statement enclosed in pair of parenthesis {} is called block or a compound statement.

Postfix, prefix OPERATORS
Both the increment operator (++) and the decrement operator(--) come in two varieties: prefix and postfix. The prefix variety is written before the variable name (++myAge); the postfix variety is written after (myAge++).
In a simple statement, it doesn't much matter which you use, but in a complex statement, when you are incrementing (or decrementing) a variable and then assigning the result to another variable, it matters very much. The prefix operator is evaluated before the assignment, the postfix is evaluated after.
The semantics of prefix is this: Increment the value and then fetch it. The semantics of postfix is different: Fetch the value and then increment the original.
This can be confusing at first, but if x is an integer whose value is 5 and you write
int a = ++x;
you have told the compiler to increment x (making it 6) and then fetch that value and assign it to a. Thus, a is now 6 and x is now 6.
If, after doing this, you write
int b = x++;
you have now told the compiler to fetch the value in x (6) and assign it to b, and then go back and increment x. Thus, b is now 6, but x is now 7. Listing below shows the use and implications of both types.

int Total=50,Number=10;
Total=Total + Number++;
Total will be 60 and Number will be 11
int Total=50,Number=10;
Total=Total + ++Number;
Total will be 61 and Number will be 11

Selection statements:

    If Statement:
o     If statement helps to execute a block of statement based on the result of a condition. If the condition set evaluates to true on block of statement is executed otherwise another block is executed.
if (Condition)
Statement;
[else
    Statement;]

‘else’ part of ‘if statement’ is optional, if the user doesn’t provide an else part and the condition evaluates to false, then nothing would happen. Complier will not produce an error in this case.
    Switch Statement:
o     A Switch statement is used execute a statement from a group of statement based on the result of a expression. The expression must result in either of byte, short, integer or character.
Switch(Expression)
{
    case value 1:
        statement(s);
        break;
    case value 2:
        statement(s);
        break;
case value 3:
        statement(s);
        break;
    ----
    ----
    ----
    [default:
        statement(s);
}
Note:
The default statement is executed when none of the above mention case matches with the result of the switch expression. Default is optional.

    Loop/Iteration:
o    loop or iterations helps to repeat a group of statements number of times under a condition. Java supports three kinds of loop: while loop, for loop, do while loop

    Entry control loop / Pre-Tested loop/ Top-Tested loop:
o     An entry control loop first test the terminating condition and then executes the loop body. If the condition is found true the loop body is execute other wise the loop terminates. In case if the condition is false in first time only then the loop will not get execute even once.
    Exit control loop / Post-Tested loop/ Bottom-Tested loop:
o     An exit control loop first executes the loop body and then test the terminating condition. If the condition is found true the loop body executed again other wise the loop terminates. In case if the condition is false in first time only then the loop will still get execute at-least once.
    While loop:
o    It is an entry control loop
while (condition)
{
    statement(s);
}


    for loop:
o    is a compact entry control loop, which all the tree parts of the loop (i.e. initialization, terminating condition, and increment/decrement of the counter variable) exists in a single line.
for(initialization ; terminating condition ; increment/decrement)
It is to be noted that all the parts of the loop in the above statement are optional. In case if a programmer wants to specify more than one initialization or increment/decrement then it has to be separated by (,).
for(int i=1; i<= 10; i++)
for(i=1, j = 10; i<j; i++, j++) // more than one initialization or increment/decrement
for(i = 10, j= 20; i>= 1 && j<= 30 ; i-- , j++) // more than one condition joined using &&
for(; i<= 10; i++) //initialization missing still using ;
for(; i<= 10;) //initialization, inc./dec. missing still using ;
    do while loop:
o    it is a exit control loop
do
{
    statement(s);
}
while (condition);

NOTE:
    Break:
o     break is used to terminate the current switch statement or the loop.
    Continue:
o     Continue statement skips the remaining part of the current loop and begins the next iteration of the loop.
    Object:
o    An Object is an identifiable entity, which has certain properties (attributes) and methods (functions) associated with it.

    Class:
o     A Class is a group of similar objects. It is a generalization of an object. To make a class we encapsulate (join to from bundles) all the properties and method associated with the class.
    Package:
o    A Package is a group of logically related classes.
    Method:
o    Methods are functions associated to a class or an object.
    Function:
o    Function is a group of statement under a name, which are executed in an order to achieve a particular task.
    Parameter:
o    The set of values passed as in input to a function are known as parameters to that function. For example jTextFiled1.setText(“Apple”); Here JTextField1 is an object of the class jTextFiled, setText() is a function/method of the class jTextFiled, “Apple” is the parameter passed to the function setText(). Parameters are also known as Arguments.

    Content Pane:
o     The area on the frame where all the GUI controls are placed is called Content pane.
Commonly available Swing Controls in Java
    jFrame: A Frame is a container control, in which all the controls can be place.
    jLabel: JLable allows placing un-editable text on the Frame/Panel
    jTextField: JTextFiled allows placing editable text on the Frame/Pane. User can enter text in a textFiled during runtime.
    jbutton: is used to initiate an action when it is clicked.
    jList: is a group of values or items from which one or more selections can be made.
    jComboBox: jComboBox is similar to jList but also allow to enter editable text during run time. It is a combination of jTextFiled and jList.
    jPanel: Act like a frame, to group one or more controls.
    jRadioButton: Allow us to choose a single item from a group of jRadioButton options.
Remember that out of several radio buttons belonging to a group, only one can be selected. Therefore, the next step is toassociate the two radio buttons to each other. This is achieved by linking both the radiobuttons with a ButtonGroup. For each group of radio buttons, we need to create a ButtonGroup instance and add each radio button to it. It is necessary to associate all theradio buttons in a group to one ButtonGroup. The ButtonGroup takes care of unselectingthe previously selected button when the user selects another button in the group. So draga Button Group component from the Swing Controls tab and drop it anywhere on theform. This is an invisible component which is just used to associate several radio buttons.Now to associate them to same button group, select the first radio button and edit thebuttonGroup property of this radio button using the Properties Window

    jCheckBox: Allow us to choose one or more items from a group of jCheckBox options.
    jPasswordField: Allow us to enter a text during the run time but shows an encrypted text instead of the original text
    jTextArea: JTextArea is a multi-line text component to enter or edit text.
    Focus: The control under execution is said to have the focus. The control having the focus obtains input form the user.
    getText(): getText() method is used to obtain the text from a jTextFiled during the run time.
    setText(): setText() method is used to set or change the text of a jTextFiled during run time.

->Few MORE methods:
1.The setVisible() method - to set the visibility of a component at run time. setVisible(true) implies that the component is visible and setVisible(false) implies that the component is hidden.

2. The setEditable() method - to set the editing property of a component at run time.The setEditable(true) implies that the contents of this component can be changed at run time and setEditable(false) implies that the contents of this component cannot be changed at run time.

3. The setEnabled() method - to set the enabled property of a component at run time.The setEnabled(true) implies that this component can trigger a reaction at run timeand setEnabled (false) implies that this component cannot trigger a reaction at run time.


 

 Commonly available functions in String class in Java are:
o    equal( ):Compares two string – the string that calls the function and the argument string . If both the strings are equal it return otherwise false.
o    length( ) :
o    capacity( ):
o    toLowerCase( ):
o    toUpperCase( ):
o    toString( ):
o    trim( ):
o    concat( ):
o    substring( ):
    Commonly available functions in Math class in Java are:
o    pow( ):
o    round( ):
o    sqrt( ):


Shorthand way:
The expression [Amount = Amount + 3500;] can also be written as [Amount+=3500;]. In the same way -=, *= and /= can also be used to simplify the expressions. While deciding between using an if statement and a switch statement always remember that although switch is easier to read but it can only be used to test for equality. The if statement on the other hand can test for equality as well as inequality.
--------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
The tooltip text is the text that appears when the user moves the cursor over a component, without clicking it. The tooltip generally appears in a small "hover box" within formation about the component being hovered over.

Tuesday, 21 August 2012

special note


A column level constraint supports all type of constraints,Whereas table level does not support not null constraint... we cannot declare not null at table level.

Composite primary key must be declared using table level constraints

sql - part 2 of sample paper

Answer the following questions:
(a)
Compare DDL and DML statements of SQL.
(b)
Swati needs to remove all the rows from SALES table to release the storage space. But she does not want to remove the table structure. Which statement should she use?
(c)
Meena uses a EMP table with following columns:
NAME ,SAL,ID,DNAME
She needs to display names of employees who have not been assigned any department or have been assigned “pathology” department. Pathology course’s names end with “Pathology”. She wrote the following query:
SELECT NAME,SAL
FROM EMP,COURSE
WHERE DNAME = NULL OR DNAME = “%pathology”;
But the query is not producing result. Identify the problem.
(d)
What is the importance of primary key in a table? Explain with example.
(e)
The Title and Price columns of table “Library” are given below:
TITLE
PRICE
Mastering C++
495
Guide Network
500
Mastering SQL
650
Dos GUIDE
400
Basic for beginners
399
Mastering Window
Null

Based on this information ,find the output of the following queries:
(a)    SELECT MIN(Price)from library;
(b)   SELECT COUNT(Title) from library WHERE Price < 150;
(c)    Select  AVG(price) from library WHERE title like ‘%e%’;
(d)   Select title from library where price = (select max(price) from library);
(f)
A table ACCOUNT in a database has 6 columns and 60 rows. The DBA has added 3 more columns and 50 more rows to the table. But the table has about 15 records where balance is null. What is the degree and cardinality of this table now ?  
(a)
Name the constraints(4) which can be added at both the levels.(table and column).
(b)
What are different types of SQL functions? Explain and give examples.
(c)
Consider the table Hospital given below.          Hospital
No
Name
Age
DEPARTMENT
DateOfAdm
Charges
Sex
1
Sandeep
64
Surgery
23/02/97
400
F
2
Ravina
24
Orthopedic
20/01/98
200
F
3
Karan
45
Orthopedic
10/02/97
200
M
4
Tarun
12
Surgery
01/01/98
300
F
5
Zubin
36
ENT
12/01/98
250
M
6
Ketaki
16
ENT
12/02/98
300
F
7
Ankita
29
Cardiology
20/02/98
800
F
8
Zareen
45
Gynecology
22/02/98
500
F
9
Kush
19
Cardiology
13/01/97
800
M
10
Shailya
31
Medicine
19/02/97
400
F

Write commands in SQL for (i) to (xii)

(i)    To show all information about the MALE patients of cardiology department.
(ii)    To list the names of male patients who are in orthopaedic department.
(iii)   To display Patient’s name, charges, Age for  male and female patients.
(iv)  To count the number of patients with Age < 30.
(v)    Increase the charges of male patient in ENT department by 4%.
  (vi) Add another column email_id with suitable data type.
  (vii) Delete the records of all female patients in Surgery department.
  (viii)Display a report listing name, age, charges and amount of charges including VAT as 2%  on charges name the column as total charges and keep the data in ascending order of name.
  (ix)To display the difference of highest and lowest charges of each department having maximum charges more than 300.
 
 (x) Find out the details of patients whose age  is same or more than that of patient whose hospital charges are maximum.
 (xi)Display the details of all the patients who are hospitalised in 1998.
 (xii)Display the charges of various departments .A charge amount should appear only once.   
Find out the  output for SQL commands (xiii) to (xvi).
  (xiii)SELECT COUNT(DISTINCT  Department) FROM HOSPITAL ;
  (xiv)SELECT MAX(Age) FROM HOSPITAL  WHERE SEX=’M’;
  (xv)SELECT AVG(Charges) FROM HOSPITAL  WHERE SEX=’F’;
  (xvi)SELECT SUM(Charges) FROM HOSPITAL  WHERE DATEOFadm < ’12/08/98’ ;
(a)
Write an SQL command for creating a table Teacher whose structure is given below:
FIELD NAME
DATATYPE
SIZE
CONSTRAINT
Tno
Number
3
Part of Primary Key
Class
Varchar
5
Part of Primary Key
age
Number
5,2
>22 and <=40
Projno
Number
6
FK –Project(pno)
Address
Varchar
30
Default Mumbai
               
(b)
In a database there are two tables ‘LOAN’ and ‘BORROWER’ as shown below:                                                       LOAN
Loan_number
Branch_name
Amount
K-70
Downtown
5000
K-230
Redwood
6000
K-260
Perryridge
3700
                     BORROWER
Customer_Name
Loan_no
Jones
K-170
Smith
K-230
Hayes
K-155

(i)                  Identify the foregin key column in the table BORROWER.
(ii)                How many rows and columns will be there in the crossl join of these two tables?
(c)
Consider  the tables PEOPLE and PROPERTIES given below:
                PEOPLE
Name
Phone
PID
Aisha
9411223344
1
Karan
9422114455
2
Rosy
9433112244
3

                    PROPERTIES
PID
SPID
Farm_Name
1              
1
Old house farm
3
2
Nanada’s farm
3
3
Will’s farm
3
4
Tall farm
4
5
The florist







With reference to these tables, write command in SQL for (i) and (iii) and output for (iii)
(i)                  Display the name and phone number of each person who has a farm.
(ii)                Display the farm name of farm(s) owned by Karan.