Google Analytics

Wednesday 16 April 2014

SAMPLE PL/SQL ASSIGNMENTS Answers

Anonymous Block
1.
declare
v_maxdep varchar2(10);
begin
select max(deptno) into v_maxdep from dept;
dbms_output.put_line('The max dept number is: '||v_maxdep);
end;
/

2.
declare
v_max dept.deptno%type;
begin
select Max(deptno)+1 into v_max from dept;
insert into dept values(v_max,'FINANCE',null);
end;
/

3.
ACCEPT v_loc varchar2(10) prompt 'Enter Location: '
declare
v_location varchar2(10):= ('&v_loc');
begin
update dept set loc=v_location where deptno=5;
dbms_output.put_line('Location has been updated with '||v_location||' succesfully');
commit;
end;
/

4.
begin
delete from dept where deptno=(select max(deptno) from DEPT);
dbms_output.put_line('The Finance dept has been deleted successfully.');
end;
/

5.
accept v_name varchar(20) prompt 'Enter name: '
DECLARE
v_ename emp.ename%type:=('&v_name');
v_basic dept.basic%type;
PF emp.sal%type;
HRA emp.sal%type;
DA emp.sal%type;
NetSal emp.sal%type;
begin
select basic into v_basic from dept where DEPTNO in (select deptno from emp where ename =upper(v_ename));
HRA:= v_basic * 0.31;
DA :=v_basic * 0.15;
if v_basic < 3000 then
pf:= v_basic * 0.05;
elsif v_basic between 3000 and 5000 then
pf:=v_basic * 0.07;
elsif v_basic between 5000 and 8000 then
pf := v_basic * 0.08;
end if;
netsal := v_basic+da+hra+pf;
dbms_output.put_line('The pf and net salary for '||v_ename||' is '||pf||' and '||netsal);
exception
when no_data_found then
dbms_output.put_line('There is no employee found with this name.!!');
end;
/

6.
declare
v_grade salgrade.grade%type;
cursor gradecur is select * from salgrade;
cursor empsal is select ename,sal from emp;
cur_grd gradecur%rowtype;
v_sal emp.sal%type;
v_name emp.ename%type;
begin
open empsal;
loop
fetch empsal into v_name,v_sal;
exit when empsal%notfound;
open gradecur;
loop fetch gradecur into cur_grd;
exit when gradecur%notfound;
if v_sal between cur_grd.lowsal and cur_grd.highsal then
v_grade:=cur_grd.grade;
if v_grade='A' then
dbms_output.put_line('The employee is Project manager');
elsif v_grade = 'B' then
dbms_output.put_line('The employee is Team lead');
else
dbms_output.put_line('The employee is engineer');
end if;
end if;
end loop;
close gradecur;
end loop;
close empsal;
end;
/

7.
accept v_empno emp.empno%type prompt 'Enter emplyee no: '
declare
v_empno emp.empno%type:= ('&v_empno');
v_sal emp.sal%type;
v_comm emp.comm%type;
v_bonus emp.sal%type;
begin
select comm into v_comm from emp where empno=v_empno;
if v_comm is null then
dbms_output.put_line('Employee doesn''t earn any commision.');
else
v_bonus:= v_comm *0.15;
v_sal := v_sal + v_bonus;
dbms_output.put_line(v_bonus||' bonus has been added to the salary and the current salary is: '||v_sal);
end if;
end;
/

8.
declare
v_empcnt number(3);
v_depname DEPT.DNAME%type;
v_avgsal emp.sal%type;
cursor c1 is select d.dname,count(e.empno) EmpCount,avg(e.sal) AvgSal from emp e join dept d on e.deptno=d.deptno group by d.dname;
begin
open c1;
loop
fetch c1 into v_depname,v_empcnt,v_avgsal;
exit when c1%notfound;
if v_empcnt is null then
dbms_output.put_line('No employees are working in this department.');
else
dbms_output.put_line(v_depname||' has '||v_empcnt||' employee(s) and the average salary is '||v_avgsal);
end if;
end loop;
end;
/

9.
accept v_empno emp.empno%tye prompt 'Enter employee No: '
declare
v_empno emp.empno%type :=('&v_empno');
v_empsal emp.sal%type;
v_avgsal emp.sal%type;
begin
select sal into v_empsal from emp where empno=v_empno;
select avg(sal) into v_avgsal from emp where deptno in (select deptno from emp where empno=v_empno);
if v_empsal > v_avgsal then
dbms_output.put_line('employee salary is more than the average salary');
else
dbms_output.put_line('employee salary is less than the average salary');
end if;
end;
/

Procedures and functions:
1.
create or replace procedure delempbyjob(p_deptno number) is
cnt number;
begin
delete from emp where deptno =p_deptno;
cnt:=sql%rowcount;
dbms_output.put_line(cnt||' employees have been deleted.');
end;
/
Execution:
exec delempbyjob(4);

2.
create or replace procedure delempbyjob(p_deptno number,empcnt out number) is
begin
delete from emp where deptno =p_deptno;
empcnt:=sql%rowcount;
end;
/
Execution:
declare
empcnt number;
begin
delempbyjob(4,empcnt);
dbms_output.put_line(empcnt||' employees have been deleted.');
end;
/

3.
create or replace function delempbydep(p_deptno number) return number is
cnt number;
PRAGMA AUTONOMOUS_TRANSACTION;
begin
delete from emp where deptno =p_deptno;
commit;
cnt:=sql%rowcount;
dbms_output.put_line(cnt||' employees have been deleted.');
return cnt;
end;
/

declare
cnt number;
begin
cnt:=delempbydep(4);
dbms_output.put_line(cnt);
end;
/

4.A.
create or replace procedure Withdraw(p_accno number,p_amt number) is
v_bal customers.balance%type;
begin
select balance into v_bal from customers where accno=p_accno;
if v_bal < p_amt then
raise_application_error(-20002,'There is not sufficient funds in your account.');
else
v_bal :=v_bal - p_amt;
update customers set balance = v_bal where accno=p_accno;
commit;
dbms_output.put_line(p_amt||' has been debited from your account.');
end if;
exception
when no_data_found then
raise_application_error(-20001,'Invalid account number.');
end;
end;
/

4.B.
create or replace procedure Deposit(p_accno number,p_amt number) is
v_bal customers.balance%type;
begin
select balance into v_bal from customers where accno=p_accno;
v_bal :=v_bal + p_amt;
update customers set balance = v_bal where accno=p_accno;
commit;
dbms_output.put_line(p_amt||' has been credited to your account.');
exception
when no_data_found then
raise_application_error(-20001,'Invalid account number.');
end;
/

4.C.
create or replace procedure Transfer(p_acc1 number,p_acc2 number,p_amt number) is
v_bal1 number;
v_bal2 number;
begin
select balance into v_bal1 from customers where accno=p_acc1;
select balance into v_bal2 from customers where accno=p_acc2;
if v_bal1 < p_amt then
raise_application_error(-20001,'There is not sufficient funds in your account.');
else
v_bal1 := v_bal1- p_amt;
v_bal2 := v_bal2 + p_amt;
update customers set balance = v_bal1 where accno = p_acc1;
update customers set balance = v_bal2 where accno = p_acc2;
commit;
dbms_output.put_line(p_amt||' has been transfered from '||p_acc1||' to '||p_acc2);
end if;
exception
when no_data_found then
raise_application_error(-20003,'Invalid account entered.');
end;
/

Cursors and Data Types as in 3GL:
1.
accept v_empno emp.empno%type prompt 'Enter employee no: '
declare
v_empno emp.empno%type:= ('&v_empno');
cursor c1 is select ename,hiredate,sal,mgr,deptno from emp where empno=v_empno;
emp_rec c1%rowtype;
begin
open c1;
fetch c1 into emp_rec;
insert into ret_emp values(v_empno,emp_rec.ename,emp_rec.hiredate,sysdate,emp_rec.sal,emp_rec.mgr,emp_rec.deptno);
close c1;
exception
when no_data_found then
raise_application_error(-20001,'Employee does not exist with this number.');
end;
/

2.
declare
cursor empsal is select sal from emp;
cursor empgrd is select * from empgrade;
v_sal emp.sal%type;
v_grade number(1);
v_grade1 number(1):=0;
v_grade2 number(1):=0;
v_grade3 number(1):=0;
cur_grd empgrd%rowtype;
begin
open empsal;
loop fetch empsal into v_sal;
exit when empsal%notfound;
open empgrd;
loop fetch empgrd into cur_grd;
exit when empgrd%notfound;
if v_sal between cur_grd.lowsal and cur_grd.highsal then
v_grade := cur_grd.grade;
if v_grade = 1 then
v_grade1 := v_grade1 + 1;
elsif v_grade = 2 then
v_grade2 := v_grade2 +1;
else
v_grade3 := v_grade3+1;
end if;
end if;
end loop;
close empgrd;
end loop;
close empsal;
dbms_output.put_line('No of employees with the grade 1 are '||v_grade1);
dbms_output.put_line('No of employees with the grade 2 are '||v_grade2);
dbms_output.put_line('No of employees with the grade 3 are '||v_grade3);
end;
/

Cursors:
1.
create or replace procedure PayIncrement is
cnt number(1);
begin
update emp set sal = sal + sal * 0.15 where deptno = 1;
cnt := sql%rowcount;
dbms_output.put_line(cnt||' employees have been awarded with 15% increment in thier salary.');
end;
/

2.
declare
cursor empcur is select ename,deptno,sal from emp;
cursor grdcur is select * from empgrade;
grd_rec grdcur%rowtype;
emp_rec empcur%rowtype;
v_grade number(1);
begin
open empcur;
loop fetch empcur into emp_rec;
exit when empcur%notfound;
open grdcur;
loop fetch grdcur into grd_rec;
exit when grdcur%notfound;
if emp_rec.sal between grd_rec.lowsal and grd_rec.highsal then
v_grade := grd_rec.grade;
if v_grade = 5 then
dbms_output.put_line(emp_rec.ename||' grade is '||grd_rec.grade||'  minsal is '||grd_rec.lowsal||' maxsal is '||grd_rec.highsal);
end if;
end if;
end loop;
close grdcur;
end loop;
close empcur;
end;
/

3.
declare
suri varchar2(1000);
begin
suri:='create table old_dept as select * from dept';
execute immediate suri;
dbms_output.put_line(sql%rowcount||' rows were copied to the new table.');
end;
/

4.
declare
v_name emp.ename%type;
cursor c1 is select ename from emp where deptno = 3;
begin
open c1;
loop
fetch c1 into v_name;
exit when c1%notfound;
dbms_output.put_line(v_name||' is working for dept no 3.');
end loop;
end;
/

5.
declare
cursor c1 is select * from dept;
dept_cur c1%rowtype;
begin
for dept_cur in c1 loop
dbms_output.put_line(dept_cur.dname||' '||dept_cur.loc);
end loop;
end;
/

6.
declare
cursor c1 is select ename,sal,deptno from emp where rownum <=6 order by sal desc;
emp_rec c1%rowtype;
begin
for emp_rec in c1 loop
dbms_output.put_line(emp_rec.ename||' '||emp_rec.sal||' '||emp_rec.deptno);
end loop;
end;
/

7.
declare
cursor c1 is select deptno,dname from dept;
v_deptno dept.deptno%type;
v_dname dept.dname%type;
begin
open c1;
loop
fetch c1 into v_deptno,v_dname ;
exit when c1%notfound;
dbms_output.put_line('The list of employees in department '||v_deptno||' is as follows:');
declare
emp_rec emp%rowtype;
cursor c2(v_deptno number) is select * from emp where deptno = v_deptno;
begin
open c2(v_deptno);
loop
fetch c2 into emp_rec;
exit when c2%notfound;
dbms_output.Put_line(emp_rec.ename||' '||emp_rec.job||' '||emp_rec.hiredate||' '||emp_rec.sal);
end loop;
close c2;
end;
end loop;
close c1;
end;
/

8.
create or replace procedure Raise_Sal(p_depno number,increment_pct number) is
cursor c1 is select * from emp where deptno=p_depno for update of sal;
emp_rec c1%rowtype;
begin
open c1;
loop
fetch c1 into emp_rec;
exit when c1%notfound;
update emp set sal = sal + sal*increment_pct where current of c1;
end loop;
close c1;
end;
/

Exception Handling:
1.
declare
v_sal emp.sal%type := &v_sal;
v_cnt number(1):=0;
no_emp exception;
more_emp exception;
begin
select count(*) into v_cnt from emp where sal = v_sal;
if v_cnt = 0 then
raise no_emp;
elsif v_cnt = 1 then
insert into sal_msg values(null,v_sal,'there is an employee does exist');
else raise more_emp;
end if;
exception
when no_emp then
insert into sal_msg values(null,v_sal,'There are no employees found with this salary.');
when more_emp then
insert into sal_msg values(null,v_sal,'More than one employee found.');
when others then
insert into sal_msg values(null,v_sal,'Unknown error occured.');
commit;
end;
/

2.
declare
cnt number:=0;
employee_exist exception;
v_depno emp.deptno%type:= &deptno;
pragma exception_init (employee_exist,-20001);
begin
select count(*) into cnt from emp where deptno = v_depno;
if cnt = 0 then
delete from dept where deptno=v_depno;
dbms_output.put_line(v_depno||' department has been removed from the departments table.');
else
raise employee_exist;
end if;
exception
when employee_exist then
dbms_output.put_line('Empliyee(s) exist in this department that you are trying to delete.');
end;
/

3.
accept v_sal emp.sal%type prompt 'Enter Salary: '
accept v_depno emp.deptno%type prompt 'Enter deptno: '
declare
v_sal emp.sal%type :=('&v_sal');
v_deptno emp.deptno%type:=('&v_depno');
v_minsal emp.sal%type := 800;
v_maxsal emp.sal%type :=  5000;
unknown_dept exception;
salrange_exceed exception;
pragma exception_init(unknown_dept,-22091);
cnt number(1);
begin
select count(*) into cnt from emp e join dept d on e.deptno=d.deptno where d.deptno = v_deptno;
if cnt = 0 then
raise unknown_dept;
else
if v_sal between v_minsal and v_maxsal then
update emp set sal = v_sal where deptno = v_deptno;
commit;
else raise salrange_exceed;
end if;
end if;
exception
when salrange_exceed then
dbms_output.put_line('The specified salary is not in the given range.');
when unknown_dept then
dbms_output.put_line('The given dept doesn''t exist in the dept table.');
when others then
dbms_output.put_line('Unknown error occured.');
end;
/

Packages:
1.
create or replace
package Dep_Store as
procedure CreateNewItem(p_item_no varchar2,p_desc varchar2);
procedure PromoteItem(p_item number,p_cost number);
procedure RemoveItem(p_item number);
procedure ChangeItemCost(p_item number,p_cost number);
end;
create or replace
package body Dep_Store as
procedure CreateNewItem(p_item_no varchar2,p_desc varchar2) is
begin
insert into Items(Item_id,Item_number,Description,Status,Cost) values(ITEMS_ITEM_ID_S.nextval,p_item_no,p_desc,'t',0);
commit;
end;
procedure PromoteItem(p_item number,p_cost number) is
v_cost items.cost%type;
v_status items.status%type;
begin
select cost,status into v_cost,v_status from items where item_id = p_item;
if v_status = 't' then
if p_cost <= 0 or p_cost is null then
raise_application_error(-20003,'Cost cannot be Zero or null');
else
update items set cost = p_cost,status = 'l' where item_id=p_item;
end if;
end if;
commit;
end;
procedure RemoveItem(p_item number) is
v_status items.status%type;
v_cost items.cost%type;
begin
select status,cost into v_status,v_cost from items where item_id = p_item;
if v_status = 't' and v_cost = 0 then
delete from items where item_id=p_item;
else
raise_application_error(-20003,'Item cannot be deleted because either it''s status is live or cost is non-zero.');
end if;
end;
procedure ChangeItemCost(p_item number,p_cost number) is
v_status items.status%type;
begin
select status into v_status from items where item_id = p_item;
if v_status = 't' then
raise_application_error(-20001,'Cost cannot be assigned to a test item.');
else
update items set cost = p_cost where item_id= p_item;
end if;
commit;
end;
end;

Triggers:
1.
create or replace trigger after_delete_item
after delete on items
for each row
begin
insert into items_archive values(:old.item_id,:old.item_number,:old.description,:old.status,:old.cost);
end;
/
create or replace trigger after_update_cost
after update on items
for each row
begin
insert into auditing_cost values(:old.item_id,:old.cost,:new.cost);
end;
/

2.
create or replace trigger after_delete_manager
after delete on emp
for each row
begin
update emp set mgr=null where mgr not in (select empno from emp);
end;
/

3.
create or replace trigger biu_newemployee
before insert or update on emp
for each row
declare
v_minsal job_salary.minsal%type;
v_maxsal job_salary.maxsal%type;
v_Newsal emp.sal%type;
v_oldSal emp.sal%type;
v_hike number(5,2) := 10;
cursor c1 is select minsal,maxsal from job_salary where job= :new.job;
begin
open c1;
loop
fetch c1 into v_minsal,v_maxsal;
exit when c1%notfound;
if inserting then
if :new.sal < v_minsal or :new.sal > v_maxsal then
raise_application_error(-20001,'The given salary is not in the salary range of this job.');
end if;
end if;
v_oldsal := :old.sal;
v_newsal := :new.sal;
v_hike := (v_newsal-v_oldsal)/v_oldsal * 100;
if updating then
if v_hike >10 then
raise_application_error(-20005,'Salary hike of more than 10 % is not allowed!');
elsif :new.sal < v_minsal or :new.sal > v_maxsal then
raise_application_error(-20002,'The change in the salary is not lies between the specified range for this job.');
end if;
end if;
end loop;
close c1;
end;
/

4.
create or replace
trigger bdu_job_salary
before delete or update on job_salary
for each row
declare
v_cnt number;
begin
select count(*) into v_cnt from emp where job = :old.job;
if v_cnt >= 1 then
raise_application_error(-20013,v_cnt||' '||'Employees exist in this job category hence cannot be deleted.');
end if;
end;

Happy Coding...!!!!!






Thursday 3 October 2013

Share What U Can

Hi Everyone,

          I saw that lot of our friends are using this site for the dumps. So, Please mail me the training documents and dumps. I'll post that in this blog, which is helpful for all of us. Tell this to your friends also. Please share...

Mail the dumps to wipro.fresherstraining@gmail.com


Thanks,
Administrator,
http://wipro-training.blogspot.in/

Monday 5 March 2012

Java Important Topics

1.The Java  interpreter is used for the execution of the source code.
True
False
Ans: b.
2) On successful compilation a file with the class extension is created.
a) True
b) False
Ans: a.
3) The Java source code can be created in a Notepad editor.
a) True
b) False
Ans: a.
4) The Java Program is enclosed in a class definition.
a) True
b) False
Ans: a.
5) What declarations are required for every Java application?
Ans: A class and the main( ) method declarations.
6) What are the two parts in executing a Java program and their purposes?
Ans: Two parts in executing a Java program are:
Java Compiler and Java Interpreter.
The Java Compiler is used for compilation and the Java Interpreter is used for execution of the application.
7) What are the three OOPs principles and define them?
Ans : Encapsulation, Inheritance and Polymorphism are the three OOPs
Principles.
Encapsulation:
Is the Mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse.
Inheritance:
Is the process by which one object acquires the properties of another object.
Polymorphism:
Is a feature that allows one interface to be used for a general class of actions.
 8) What is a compilation unit?
Ans : Java source code file.
9) What output is displayed as the result of executing the following statement?
System.out.println("// Looks like a comment.");
// Looks like a comment
The statement results in a compilation error
Looks like a comment
No output is displayed
Ans : a.
10) In order for a source code file, containing the public class Test, to successfully compile, which of the following must be true?
It must have a package statement
It must be named Test.java
It must import java.lang
It must declare a public class named Test
Ans : b
11) What are identifiers and what is naming convention?
Ans : Identifiers are used for class names, method names and variable names. An identifier may be any descriptive sequence of upper case & lower case letters,numbers or underscore or dollar sign and must not begin with numbers.
12) What is the return type of program’s main( ) method?
Ans : void
13) What is the argument type of program’s main( ) method?
Ans : string array.
14) Which characters are as first characters of an identifier?
Ans : A – Z, a – z, _ ,$
15) What are different comments?
Ans : 1) // -- single line comment
2) /* --
*/ multiple line comment
3) /** --
*/ documentation
16) What is the difference between constructor method and method?
Ans : Constructor will be automatically invoked when an object is created. Whereas method has to be call explicitly.
17) What is the use of bin and lib in JDK?
Ans : Bin contains all tools such as javac, applet viewer, awt tool etc., whereas Lib
contains all packages and variables.


Data types,variables and Arrays

1) What is meant by variable?
Ans: Variables are locations in memory that can hold values. Before assigning any value to a variable, it must be declared.
2) What are the kinds of variables in Java? What are their uses?
Ans: Java has three kinds of variables namely, the instance variable, the local variable and the class variable.
Local variables are used inside blocks as counters or in methods as temporary variables and are used to store information needed by a single method.
Instance variables are used to define attributes or the state of a particular object and are used to store information needed by multiple methods in the objects.
Class variables are global to a class and to all the instances of the class and are useful for communicating between different objects of all the same class or keeping track of global states.
3 How are the variables declared?
Ans: Variables can be declared anywhere in the method definition and can be initialized during their declaration.They are commonly declared before usage at the beginning of the definition.
Variables with the same data type can be declared together. Local variables must be given a value before usage.
4) What are variable types?
Ans: Variable types can be any data type that java supports, which includes the eight primitive data types, the name of a class or interface and an array.
5) How do you assign values to variables?
Ans: Values are assigned to variables using the assignment operator =.
6) What is a literal? How many types of literals are there?
Ans: A literal represents a value of a certain type where the type describes how that value behaves.
There are different types of literals namely number literals, character literals,
boolean literals, string literals,etc.
7) What is an array?
Ans: An array is an object that stores a list of items.
8) How do you declare an array?
Ans: Array variable indicates the type of object that the array holds.
Ex: int arr[];
9) Java supports multidimensional arrays.
a)True
b)False
Ans: a.
10) An array of arrays can be created.
a)True
b)False
Ans: a.
11) What is a string?
Ans: A combination of characters is called as string.In java string is an object
12) Strings are instances of the class String.
a)True
b)False
Ans: a.
13) When a string literal is used in the program, Java automatically creates instances of the string class.
a)True
b)False
Ans: a.
14) Which operator is to create and concatenate string?
Ans: Addition operator(+).
15) Which of the following declare an array of string objects?
String[ ] s;
String [ ]s:
String[ s]:
String s[ ]:
Ans : a, b and d


16) What is the value of a[3] as the result of the following array declaration?
1
2
3
4
Ans : d
17) Which of the following are primitive types?
byte
String
integer
Float
Ans : a.
18) What is the range of the char type?
0 to 216
0 to 215
0 to 216-1
0 to 215-1
Ans. d
19) What are primitive data types?
Ans : byte, short, int, long
float, double
boolean
char
20) What are default values of different primitive types?
Ans : int - 0
short - 0
byte - 0
long - 0 l
float - 0.0 f
double - 0.0 d
boolean - false
char - null
21) Converting of primitive types to objects can be explicitly.
a)True
b)False
Ans: b.
22) How do we change the values of the elements of the array?
Ans : The array subscript expression can be used to change the values of the elements of the array.
23) What is final varaible?
Ans : If a variable is declared as final variable, then you can not change its value. It becomes constant.
24) What is static variable?
Ans : Static variables are shared by all instances of a class.


                                                                                        
Operators

1) What are operators and what are the various types of operators available in Java?
Ans: Operators are special symbols used in expressions.
The following are the types of operators:
Arithmetic operators,
Assignment operators,
Increment & Decrement operators,
Logical operators,
Biwise operators,
Comparison/Relational operators and
Conditional operators
2) The ++ operator is used for incrementing and the -- operator is used for
decrementing.
a)True
b)False
Ans: a.
3) Comparison/Logical operators are used for testing and magnitude.
a)True
b)False
Ans: a.
4) Character literals are stored as unicode characters.
a)True
b)False
Ans: a.
5) What are the Logical operators?
Ans: OR(|), AND(&), XOR(^) AND NOT(~).
6) What is the % operator?
Ans : % operator is the modulo operator or reminder operator. It returns the reminder of dividing the first operand by second operand.
7) What is the value of 111 % 13?
3
5
7
9
Ans : c.
8) Is &&= a valid operator?
Ans : No.
9) Can a double value be cast to a byte?
Ans : Yes
10) Can a byte object be cast to a double value ?
Ans : No. An object cannot be cast to a primitive value.
11) What are order of precedence and associativity?
Ans : Order of precedence the order in which operators are evaluated in expressions.
Associativity determines whether an expression is evaluated left-right or right-left.
12) Which Java operator is right associativity?
Ans : = operator.
13) What is the difference between prefix and postfix of -- and ++ operators?
Ans : The prefix form returns the increment or decrement operation and returns the value of the increment or decrement operation.
The postfix form returns the current value of all of the expression and then
performs the increment or decrement operation on that value.
14) What is the result of expression 5.45 + "3,2"?
The double value 8.6
The string ""8.6"
The long value 8.
The String "5.453.2"
Ans : d
15) What are the values of x and y ?
x = 5; y = ++x;
Ans : x = 6; y = 6
16) What are the values of x and z?
x = 5; z = x++;
Ans : x = 6; z = 5


Control Statements

1) What are the programming constructs?
Ans: a) Sequential
b) Selection -- if and switch statements
c) Iteration -- for loop, while loop and do-while loop
2) class conditional {
public static void main(String args[]) {
int i = 20;
int j = 55;
int z = 0;
z = i < j ? i : j; // ternary operator
System.out.println("The value assigned is " + z);
}
}
What is output of the above program?
Ans: The value assigned is 20
3) The switch statement does not require a break.
a)True
b)False
Ans: b.
4) The conditional operator is otherwise known as the ternary operator.
a)True
b)False
Ans: a.
5) The while loop repeats a set of code while the condition is false.
a)True
b)False
Ans: b.
6) The do-while loop repeats a set of code atleast once before the condition is tested.
a)True
b)False
Ans: a.
7) What are difference between break and continue?
Ans: The break keyword halts the execution of the current loop and forces control out of the loop.
The continue is similar to break, except that instead of halting the execution of the loop, it starts the next iteration.

8) The for loop repeats a set of statements a certain number of times until a condition is matched.
a)True
b)False
Ans: a.
9) Can a for statement loop indefintely?
Ans : Yes.
10) What is the difference between while statement and a do statement/
Ans : A while statement checks at the beginning of a loop to see whether the next loop iteration should occur.
A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.