Monday, 4 March 2019

DBMS Handson

DDL HANDSON
create table Department (dept_id number(10),dept_name varchar(20));
Press continue
alter table Department add Location varchar(20);

Press continue
drop table Department;

DQL HANDS ON

Step 1: click on the commands given side
step 2: select DEPT_NAME
              from department
              where DEPT_ID = 100;


DML HANDSON

Step 1: insert into Employee values(1,'AAA',20000,100);
Insert into Employee values(2,'BBB',30000,200);
insert into Employee values(3,'CCC',30000,300);
commit;
STEP 2: update Department set DEPT_NAME='FINANCE' where DEPT_ID=100;
commit;


Constraints hands on

alter table department add constraint dept_id primary key (dept_id);
alter table employee add foreign key (dept_id) references department (dept_id);

*5. Joins hands-on*

Step 1:
Simply enter User name and password

Step 2:
Select SALARY
from Employee, department
where DEPT_NAME = 'IT'
and Employee.DEPT_ID = department.DEPT_ID;

Step 3:
Select DEPT_NAME
from department
where DEPT_ID = (select DEPT_ID from
(Select DEPT_ID, count(DEPT_ID)
from Employee
group by DEPT_ID
order by 2 desc) where rownum = 1);p
----------------
PL/SQL
SET SERVEROUTPUT ON
DECLARE
    i NUMBER(3);
    j NUMBER(3);
   s NUMBER(3);
BEGIN
    s := 0;
    i := 2;
    LOOP
        j := 2;
        LOOP
            EXIT WHEN( ( MOD(i, j) = 0 )
                        OR ( j = i ) );
            j := j + 1;
        END LOOP;
        IF( j = i )THEN
           s := s + I;       
        END IF;
        i := i + 1;
        exit WHEN i = 30;
    END LOOP;
   dbms_output.Put(s||'   ');
 dbms_output.new_line;
END;
/

CURSORS
SET SERVEROUTPUT ON
DECLARE
    s NUMBER(3);
    CURSOR employee_cur IS
      SELECT salary
      FROM   Employee;
BEGIN
    s := 0;
    FOR employee_rec IN employee_cur LOOP
        IF employee_rec.salary < 50000 THEN
          s := s + 1;
        END IF;
    END LOOP;
 dbms_output.Put(s||'   ');
dbms_output.new_line;
END;
/


IamAnarchy:
PL/SQL:
SET SERVEROUTPUT ON
DECLARE
    i NUMBER(3);
    j NUMBER(3);
   s NUMBER(3);
BEGIN
    s := 0;
    i := 2;
    LOOP
        j := 2;
        LOOP
            EXIT WHEN( ( MOD(i, j) = 0 )
                        OR ( j = i ) );
            j := j + 1;
        END LOOP;
        IF( j = i )THEN
           s := s + I;         
        END IF;
        i := i + 1;
        exit WHEN i = 30;
    END LOOP;
   dbms_output.Put(s||'   ');
 dbms_output.new_line;
END;
/

CURSORS:
SET SERVEROUTPUT ON
DECLARE 
s NUMBER(3);
 c_salary Employee.salary%type;
CURSOR c_employee is 
      SELECT salary FROM Employee; 
BEGIN 
s := 0;
   OPEN c_employee; 
   LOOP 
      FETCH c_employee into c_salary; 
      EXIT WHEN c_employee%notfound; 
     IF c_salary < 50000 THEN
          s := s + 1;
        END IF;
   END LOOP; 
 dbms_output.put_line(s || ' '); 
   CLOSE c_employee; 
END; 
/

AVERAGE:
create or replace function findAverage(a number,b number,c number)
return number
as out number;
begin
 out := a+b+c;
 out := out/3;
 return out;
end;
/

DBMS

INTRO TO DBMS QUIZ
1.cardinity
2.many to many
3.eliminating
4.primary key value must be unique and primary key values must not change
5.each table column should contain a unique value and each record needs to be unique
-----------------
Sql type quiz ans
Defferable
Drop,rename,add,modify
All of these
Datatype constraint
Truncate
---------------
Database constraints quiz
Alter table drop constraint
Check(budget>=0)
Not null
All of these
Select constraint_name,constraint_type from user_constraints where table name=“
-------------------
Functions in SQL Quiz

* Group By
* Total
* Count
* Count(*)
* Having
----------------------
SQL Joins
*FALSE
*Super key
*Relational database system (most useful database model)
*Relational database system
Primary key(unique)
-----------------------
DB objects
1). Nextval
2)Sequences
3)Create fulltext index and system stored procedures
4)two
5)none of these
---------------------
Sql cursors
1)true
2)false(cursor declared at beginning)
3)cursor
4)exit when Sql %notfound
5)none of these
-------------------------
 Exception handling
1)true
2)0
3)sqlcode
4)calling environment
5)at the end
 Stored procedures
1)all the above
2)all the above
3)an execution of a specific procedure
4)false
5)return varchar2
---------------------
 Sql blocks
1)all of these
2)return varchar2(function header)
3)return(function body)
4)false(function can return more than one value)
5)true(function can be used)

Sunday, 3 March 2019

UNIX CODES

UNIX - FindDepartmentEmployeeCount

#!/bin/bash
#write your code here
if [ $# -ne 2 ]
then
echo "Pass appropriate number of command line arguments"
elif [ -d $1 ]
then
echo "Input file is not an ordinary file"

elif [ ! -f $1 ]
then
echo "Input file does not exists"
elif [ ! -r $1 ]
then
echo "Input file does not have read permission"
else
grep -i $2 $1 | wc -l
fi

UNIX - CountWords

#!/bin/bash
#write your code here
if [ $# -ne 2 ]
then
echo "Pass appropriate number of command line arguments"
elif [ -d $1 ]
then
echo "Input file is not an ordinary file"
elif [ ! -f $1 ]
then
echo "Input file does not exists"
elif [ ! -r $1 ]
then
echo "Input file does not have read permission"
else
grep -i $2 $1 | wc -l
fi

UNIX - COUNT EMPTY FILES

j=0
k=0
count=0
total=0
for i in $@
do
if [ -s $i ]
then
count=`wc -w $i|cut -d ' ' -f 1`
let total=$count+$total
let k=$k+1
else
let j=$j+1
fi
done
echo $

UNIX - STUDENTS RECORDS


UN IX-AVREAGE SALARY
sum=0
count=0
firstLine=0
found=0

if [ $# -ne 2 ] ; then
echo "Pass appropriate number of command line arguments"
elif [ -d $1 ]; then
echo "Input file is not an ordinary file"
elif [ ! -f $1 ] ; then
echo "Input file does not exist"
elif [ ! -r $1 ]; then
echo "Input file does not have read permission"
else
while read -r line; do
if [ $firstLine -eq 0 ] ; then
firstLine=1
else
while IFS=',' read -r a b c; do
if [ $b = $2 ] ; then
found=1
sum="$(($sum + $c))"
count="$(($count + 1))"
fi
done <<< "$line"
fi
done < "$1"
avg="$(($sum / $count))"
if [ $found -eq 0] ; then
echo "Given designation not found"
else
echo $avg
fi
fi


Saturday, 2 March 2019

UI codes

Vehicle Registration
<html>
    <head>
         <title>Vehicle Registration</title>
        <script type="text/javascript" scr="index.js" ></script>
    </head>
    <body>
        <form id="registerVehicle" >
            <h1>Motor Vehicle Department of Kerala</h1>
   <hr>
            <div id="registerDiv">
                <h2>Vehicle Registration Form</h2>
            
            <table  id="vehicleForm" style="border:; 1px solid black; width: 80%; text-align: center; background-color:#EF45E0;">
                <tr>
                    <td>Full name of Applicant</td>
                    <td>
                        <input type="text" required id="fullName" />
                        <span id="err1"></span>
                    </td>
                </tr>
                <tr>
                    <td>Age</td>
                    <td>
                        <input type="number" required id="age" />
                        <span id="err2"></span>
                    </td>
                </tr>
                <tr>
                    <td>Permanent Address</td>
                    <td>
                        <textarea required id="address"></textarea>
                        <span id="err3"></span>
                    </td>
                </tr>
                <tr>
                    <td>Contact Phone</td>
                    <td>
                        <input required type="text" id="phone" />
                        <span id="err4"></span>
                    </td>
                </tr>
                <tr>
                    <td>Class of vehicle</td>
                    <td>
                        <select id="vehClass">
                            <option value="Motorcycle With out Gear">Motorcycle With out Gear</option>
                            <option value="Motorcycle With Gear">Motorcycle With Gear</option>
                            <option value="Motor Car">Motor Car</option>
                            <option value="Light Motor Vehicle-Transport">Light Motor Vehicle-Transport</option>
                        </select>
                        <span id="err5"></span>
                    </td>
                </tr>
                <tr>
                    <td>Engine No</td>
                    <td>
                        <input type="number" id="engineNo"/>
                        <span id="err6"></span>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <button type="submit" id="register" onclick="validateRegister();">Register</button>
                        <button type="reset" id="cancel">Cancel</button>
                    </td>
                </tr>
            </table>
 </div>
 </form>
  <div id="resultDiv" style="display: none;">   
  <p>An event is created with id = <span id="eid"></span></p>   
  <p>Department :<span id="dep"></span></p>   
  <p>Status :<span id="sta"></span></p>   
  <p>Raised By :<span id="rai"></span></p>   
  <button id="close" onclick="show()">Close</button>   </div>
        
    </body>
</html>

js code:



function validateRegister() {
}

Event Mangement System

<html>
<head>
<title>Event Mangement System</title>
<script type="text/javascript" src="index.js"></script>
<style>
</style>
<head>
<body>
<!-- Design & Develop your code here -->
<center>
<h1>Event Mangement System</h1>
<hr>
<div id="creationDiv">
<form name="createEvent" id="createEvent" method="post" action="index.js" onsubmit="return validateCreation()">
<h2>Event Creation Form</h2>
<table id="eventForm" align="center" width="80%" border="1px solid black" background-color="#FE45E0">
<tbody>
<tr>
<td><label>Event id</label></td>
<td><input type="number" name="eventId" required><span id="err1"></span></td>
</tr>
<tr>
<td><label>Department</label></td>
<td><input type="text" name="department" required><span id="err2"></span></td>
</tr>
<tr>
<td><label>Status</label></td>
<td>
<select name="status" required>
<option value="Open">Open</option>
<option value="In Progress">In Progress</option>
<option value="Rejected">Rejected</option>
<option value="Complete">Complete</option>
</select>
<span id="err3"></span>
</td>
</tr>
<tr>
<td><label>Description</label></td>
<td><input type="textarea" name="description" required><span id="err4"></span></td>
</tr>
<tr>
<td><label>Raised By</label></td>

<td><input type="text" name="raisedBy" required><span id="err5"></span></td>
</tr>
<tr>
<td><label>Contact Phone</label></td>
<td><input type="text" name="contactPhone" required><span id="err6"></span></td>
</tr>
<tr>
<td><button name="create" type="submit" value="create" style="background-color:#2345E4">Create</button></td>
<td><button name="cancel" type="reset" value="cancel" style="background-color:#2345E4">Cancel</button></td>
</tr>
</tbody>
</table>
</form>
<div id="resultDiv"></div>
</div>
</center>
</body>
</html>




index.js:
--------------

function validateCreation(){
var eventId=document.myform.eventId.value;
var department=document.myform.department.value;
var status=document.myform.status.value;
var option = status.options[status.selectedIndex].text;
var description=document.myform.description.value;
var raisedBy=document.myform.raisedBy.value;
var contactPhone=document.myform.contactPhone.value;

  if (eventId===null || eventId===""){
    document.getElementById("err1").innerHTML = "Invalid Entry";
    return false;
  }else if (department===null || department===""){
    document.getElementById("err2").innerHTML = "Invalid Entry";
    return false;
  }else if (status===null || status===""){
    document.getElementById("err3").innerHTML = "Invalid Entry";
    return false;
  }else if (description===null || description===""){
    document.getElementById("err4").innerHTML = "Invalid Entry";
    return false;
  }else if (raisedBy===null || raisedBy===""){
    document.getElementById("err5").innerHTML = "Invalid Entry";
    return false;
  }else if (contactPhone===null || contactPhone===""){
    document.getElementById("err6").innerHTML = "Invalid Entry";
    return false;
  }else {
document.getElementById("resultDiv").innerHTML = "An event is created with event id ="
    + eventId + "<br> Department :"
+ department + "<br> Status :"
+ status + "<br> Raised By :"
+ raisedBy + "<a href="index.html">[Close]</a>";
  }
}



UI - CONTACT MANAGEMENT -

<!DOCTYPE html>
<html>
<head>
    <title>.</title>
    <style>
        table,tr,th,td
        {
            border: 1px solid black;
            border-collapse: collapse;
        }
    </style>
    
    <script>
        function func()
        {
            document.getElementById("message").innerHTML ="Customer Contact Created";
        }
    </script>
</head>

<body>
    <h1 style="text-align: center;">ABC Hotels</h1>
    
    <div id="message" onsubmit="func()">
        <form name="contactCustomer" id="contactCustomer" >
            <table id="contactTable" style="text-align: center;" width="30%" align="center">
            <tr>
            <th>Label</th>
            <th>Control</th>
            <th>Validation</th>
            </tr>
<tr>
<td>Name</td>
<td><input type="text" name="name" placeholder="Customer Name"
maxlength="50" required= ></td>
<td>Mandatory,Max size=50</td>
</tr>
<tr>
<td>Age</td>
<td><input type="text" placeholder="Customer Age" name="age" min="20"
max="65" required></td>
<td>Mandatory,Value range 20-65</td>
</tr>
<tr>
<td>Email</td>
<td><input type="email" name="email" placeholder="Customer Email"></td>
<td>Mandatory,Valid Email</td>
</tr>
<tr>
<td>Address</td>
<td><input type="textarea" name="address" placeholder="Customer Address"></td>
<td>Mandatory</td>
</tr>
<tr>
<td>Phone</td>
<td><input type="text" name="phone" placeholder="Customer Phone"></td>
<td>Mandatory</td>
</tr>
<tr>
<td>Send</td>
<td><input type="submit" name="send" value="send" style="background-color:#fe45e4;" ></td>
<td></td>
</tr>
<tr>
<td>Cancel</td>
<td><input type="reset" name="reset" style="background-color:#fe45e4;"></td>
<td></td>
</tr>
</table>
</form>
</div>
</body>
</html>
UI - GRADE SIMPLE TASK

You have to first write in a .gradle file :-
apply plugin: 'java'
task(runSimple, dependsOn: 'classes', type: JavaExec) {
main = 'prime.java'
classpath = sourceSets.main.runtimeClasspath
}
defaultTasks 'runSimple'

Now in the folder prime.java you need to write the prime number code like that :-
class prime
{
public static void main (String[] args)
{

int i =0;
int num =0;
String prime = "";
for (i = 1; i <= 20; i++)
{
int counter=0;
for(num =i; num>=1; num--)
{
if(i%num==0)
{
counter = counter + 1;
}
}
if (counter ==2)
{
primeNumbers = prime + i + " ";
}
}
System.out.println(prime);
}
}
UI - VEHICLE MANAGEMENT

<html>
<head>
<title>Vehicle Registration</title>
<script type="text/javascript" scr="index.js" > </script>
</head>
<body>
<form id="registerVehicle">
<h1>Motor Vehicle Department of Kerala</h1>
<div id="registerDiv">
<h2>Vehicle Registration Form</h2>
</div>
<table style="border:; 1px solid black; width: 80%; text-align: center;
background-color:#EF45E0;" id="vehicle">
<tr>
<td>Full name of Applicant</td>
<td>
<input type="text" required id="fullName" />
<span id="err1"></span>
</td>
</tr>
<tr>
<td>Age</td>
<td>
<input type="number" required id="age" />
<span id="err2"></span>
</td>
</tr>
<tr>
<td>Permanent Address</td>
<td>
<textarea required id="address"></textarea>
<span id="err3"></span>
</td>
</tr>
<tr>
<td>Contact Phone</td>
<td>
<input required type="text" id="phone" />
<span id="err4"></span>

</td>
</tr>
<tr>
<td>Class of vehicle</td>
<td>
<select id="vehClass">
<option value="Motorcycle With out Gear">Motorcycle With out Gear</option>
<option value="Motorcycle With Gear">Motorcycle With Gear</option>
<option value="Motor Car">Motor Car</option>
<option value="Light Motor Vehicle-Transport">Light Motor Vehicle-Transport</option>
</select>
<span id="err5"></span>
</td>
</tr>
<tr>
<td>Engine No</td>
<td>
<input type="number" id="engineNo"/>
<span id="err6"></span>
</td>
</tr>
<tr>
<td colspan="2">
<button type="submit" id="register">Register</button>
<button type="reset" id="cancel">Cancel</button>
</td>
</tr>
</table>
</form>
<div id="resultDiv">Close</div>
</body>
</html>

Index.js :-

Function validateRegister() {

}

Contact List


<html>
<head>
<script src="index.js"></script>
</head>

<body>
<table id="contactList" border="1px" width="80%:" align="center">
<tr style="background-color:#42aaf4">
<th>Phone No.</th><th>Name</th><th>Gender</th><th>City</th><th>Action</th>
</tr>

<tr>
<td>9874563210</td><td>Akshay Kumar</td><td>Male</td><td>Chennai</td><td><input type="Button" value="delete" onclick="confirmDelete(this)"</td>
</tr>
<tr>
<td>9632587410</td><td>Shyama P</td><td>Female</td><td>Trivandrum</td><td><input type="Button" value="delete" onclick="confirmDelete(this)"</td>
</tr>
<tr>
<td>7896541230</td><td>Nalini Kumari</td><td>Female</td><td>Banglore</td><td><input type="Button" value="delete" onclick="confirmDelete(this)"</td>
</tr>
<tr>
<td>9513571233</td><td>Raj Shyam</td><td>Male</td><td>Chennai</td><td><input type="Button" value="delete" onclick="confirmDelete(this)"</td>
</tr>
<tr>
<td>8745632109</td><td>Sundar G</td><td>Male</td><td>Manglore</td><td><input type="Button" value="delete" onclick="confirmDelete(this)"</td>
</tr>
<tr>
<td>7412580963</td><td>Kishore P</td><td>Male</td><td>Calicut</td><td><input type="Button" value="delete" onclick="confirmDelete(this)"</td>
</tr>
</body>
</html>


Js:
function confirmDelete(o) {
    var retVal = confirm("Do you want to Delete ?");
               if( retVal == true ) {
                  deleteContact(o);
                  return true;
               }
           
 }

function deleteContact(o) {
      var p=o.parentNode.parentNode;
      p.parentNode.removeChild(p);

 }




Hindusthan Liver:
       -----------
<!DOCTYPE html>
<html>
<head>
    <script src="shop.js"></script>
</head>
<body>
    <div id="head"><h1>Hindustan Liver</h1></div>
    <div id="body" name="body">
        <h2>My Cart</h2>
        <table id="myCarts" align="center" width="80%" border="1" name="myCarts">
            <tr>
                <th style="backgroud-color:#45E078">Product Name</th>
                <th style="backgroud-color:#45E078">Description</th>
                <th style="backgroud-color:#45E078">Unit Price</th>
                <th style="backgroud-color:#45E078">Quantity</th>
                <th style="backgroud-color:#45E078">Total</th>
            <tr>
            <tr>
                <td>Surf Excel</td>
                <td>Washing Powder</td>
                <td>85.00</td>
                <td><input type="number" id="item01" name="item01" onchange="calculateTotal('01')" value="1" /></td>
                <td><span id="total01">85.00</span></td>
            </tr>
            <tr>
                <td>Harpic</td>
                <td>Toilet Cleaner</td>
                <td>48.00</td>
                <td><input type="number" id="item02" name="item02" onchange="calculateTotal('02')" value="2" /></td>
                <td><span id="total02">96.00</span></td>
            </tr>
            <tr>
                <td>Lux</td>
                <td>Toilet Soap</td>
                <td>36.00</td>
                <td><input type="number" id="item03" name="item03" onchange="calculateTotal('03')" value="2" /></td>
                <td><span id="total03">72.00</span></td>
            </tr>
        </table>
        <div id="gtotal"></div>
        <button id="continue" style="backgroud-color:#FF0000">Continue Shopping</button>
        <button id="calculate" style="backgroud-color:#FF0000" onclick="calculateGrandTotal()">Calculate Total</button>


        <footer>
            <h4>(c) All rights reserved to Hindustan Liver 2018-2019</h4>
        </footer>
    </div>
</body>
</html>

index.js: (Hindusthan Liver) :
-----------------------------

function calculateTotal(id) {
    var n = "item" + id;
    var t = "total" + id;
    var x = document.getElementById(n).value;
    var total;
    if (n.localeCompare("item01") == 0)
        total = x * 85.00;
    else if (n.localeCompare("item02") == 0)
        total = x * 48.00;
    else
        total = x * 36.00;
    var s = total + ".00";
    document.getElementById(t).innerHTML = s;
}

function calculateGrandTotal() {
    var x1 = parseFloat(document.getElementById("total01").innerHTML);
    var x2 = parseFloat(document.getElementById("total02").innerHTML);
    var x3 = parseFloat(document.getElementById("total03").innerHTML);
    var total = x1 + x2 + x3;
    var s = total + ".00";
    document.getElementById("gtotal").innerHTML = s;
}


Thursday, 28 February 2019

Java hands on programs

These  are  java hands on
Java EXTRA Hands on

TCS XPLORE PROGRAMS 28-2-2019

PRINT LEAST ASCII VALUE CHARACTER
Main.java
public class Main{
public static void main(String []args){
String string="heLlo";
char ascii='z';
char[] strarray=string.toCharArray();
for(int i=0;i<strarray.length;i++)
if(ascii>strarray[i])ascii=strarray[i];
System.out.println(ascii);
}
}
Output: L
FILE HANDLING IN JAVA
Main.java
public class Main
{
public static void main(String[] args) {
Document obj1=new Document(1,"intro","intro_details",10);
Document obj2=new Document(2,"contents","contents_details",3);
Document obj3=new Document(3,"history","history_details",25);
Document obj4=new Document(4,"war","war_details",38);
Document arr[]={obj1,obj2,obj3,obj4};
combineDocument(arr);
}
public static void combineDocument(Document[] arrayobj){
int id=0,pages=0,arrlen=arrayobj.length;
System.out.println("id: "+(arrayobj.length+1));
System.out.println("Titles: "+arrayobj[0].getTitle()+"#"+arrayobj[1].getTitle()+"#"+arrayobj[2].getTitle()+"#"+arrayobj[3].getTitl
e());
System.out.println("Folders: "+arrayobj[0].getFolderName()+"@"+arrayobj[1].getFolderName()+"@"+arrayobj[2].getFolderName()
+"@"+arrayobj[3].getFolderName());
for(int i=0;i<arrayobj.length;i++)pages=pages+arrayobj[i].getPages();
System.out.println("Pages: "+pages);
}
}
Document.java
public class Document{
private int id;
private String title;
private String folderName;
private int pages;
public Document(int id,String title,String folderName,int pages){
super();

this.id=id;
this.title=title;
this.folderName=folderName;
this.pages=pages;
}
public int getId(){
return id;
}
public String getTitle(){
return title;
}
public String getFolderName(){
return folderName;
}
public int getPages(){
return pages;
}
}
Output:
id: 5
Titles: intro#contents#history#war
Folders: intro_details@contents_details@history_details@war_details
Pages: 76

Wednesday, 27 February 2019

Web Development

TCS Tech Web Development With Java 

What is the output of the following code
The value is <%=””%>
Ans: The value is

Which of the following is not an attribute of Page Directive
Ans: name

Select valid expression tag from the following
Ans: <%=new java.util.Date().toString()%>

Comments in Jsp file can be written by
Ans: <%--  ……….. --%> and <!--  ……….. -->

Why RequestDispatcher to forward a request to another resource, instead of using a sendRedirect?
Ans:  The RequestDispatcher does not require a round trip to the client, and thus is more efficient and allows the server to maintain request state.
In JSP, how can you know that HTTP method (GET or POST) is used by client request?
Ans:  request.getMethod()

Select the correct scopes in JSp
Ans: page,request,session,application
What is a benefit of using JavaBeans to separate business logic from presentation markup within the JSP environment?      Ans:
Which of the following are correct. Select the one correct answer.
Ans:  To use the character %> inside a scriptlet, you may use %\> instead.

 What gets printed when the following JSP code is invoked in a browser. Select the one correct answer.
    <%= if(Math.random() < 0.5) %>
      hello
    <%= } else { %>
      hi
    <%= } %>
Ans: The JSP file will not compile.

What gets printed when the following is compiled. Select the one correct answer.
    <% int y = 0; %>
    <% int z = 0; %>

    <% for(int x=0;x<3;x++) { %>
    <% z++;++y;%>
    <% }%>
    <% if(z<y) {%>
    <%= z%>
    <% } else {%>
    <%= z - 1%>
    <% }%>

Ans: 3

Which of the following is not implicit object in JSP?
Ans: pageConfig

Which of the following code is used to set the session timeout in servlets?
Ans: session.setMaxInactiveInterval(interval)

What is the return type of getParameter(String name) in ServletRequest
Ans:  String

Which of the following code is used to set auto refresh of a page after 5 seconds?
Ans: response.setIntHeader(“Refresh”,5)

How to create a cookie in a servlet?
Ans: Use new Operator

Which of the following code retrieves the MIME type of the body of the request?
Ans: request.getContentType()

Which of the following code delete a cookie in servlet?
Ans: cookie.setMaxAge(0);
Select the right options which second.jsp can be included in first.jsp
Ans:  <%@include file=”second.jsp”%> , <jsp:include page=”second.jsp”/>

Which of the below methods returns a string containing information about the servlet, such as its author, version, and copyright.
Ans: getServletInfo()

A JSP page called test.jsp is passed a parameter name in the URL using “http://localhost:8080/projectName/test.jsp?
Ans:
Which of the following code used to get session in servlet?
Ans: request.getSession()
In HTTp request which asks for the loopbacks of the request message, for testing or troubleshooting?
TRACE
What is the return type of getAttribute(String name) in ServletRequest
Ans: Object
Select the right method to include welcome file in a web application
Which of the following code can be used to set the character encoding for the body of the response?
ANS: response.setCharacterEncoding(charset)
Which of the following package contains servlet classes?
ANS: javax.servlet, javax.servlet.http
Select a valid declaration from the following
Ans: <%! String orgName=”TCS”;%>
What is the return type of getAttribute(String name) in ServletRequest
ANS: Object
A JSP needs to generate an XML file. Which attribute of page directive may be used to specify that JSP is generating an XML file?
ANS: contentType
How can you make jsp page as error page
ANS: isErrorPage=”true”
String name = request.getAttribute(“name”); Select the correct option from below for this code statement.
Ans: It gives compilation error as we need to use the casting of (String)
Which of the following code can be used to clear the content of the underlying buffer in the response without clearing headers or status code.
Ans: response.resetBuffer()
Java Declaration tag is used to declare
ANS: both variables and methods
Which of the following is true about javax.servlet.error.exception_type?
Ans: This attribute gives information about exception type which can be stored and analyzed after storing in a java.lang.Class data type
Which of the following is legal JSP syntax to print the value of i.select the one correct answer
ANS: <%int i = 1;%>
<%= i %> (d)

Which method is used to retrieve a form values in a JSP or servlet?
ANS: request.getParameter(String)
Jsp is used for
ANS: Server Side Programming
Which is not a JSP directive ?
ANS: scriptlet
Which of the following code sends a cookie in servlet?
ANS: response.addCookie(cookie);
 Web Development With Java mcqs
1. Error Message displayed when the page is not found at current location?
Ans: 404

2. What is the output of the following code. The value is <%=""%>
Ans: The value is

3. What gets printed when the following JSP code is invoked in a browser. Select the one correct answer. <%=if(Math.random()<0.5%)>hello<%=}else{%>hi<%=}%>
Ans: The JSP file will not compile

4. Select the right option to set session expiry after 1 minute of inactiveness
Ans: <session-config><session-timeout>1</session-timeout></session-config>

5. JSP is used for
Ans: Server Side Programming

6. Which of the following is true about javax.servlet.error.exception_type?
Ans: This attribute gives information about exception type which can be stored and analyzed after storing in a java.lang.Class data type

7. Which is not a JSP directive
Ans: scriptlet

8. Which of the following package contains servlet classes?
Ans: (a) javax.servlet
         (b) javax.servlet.http

9. JSP is
Ans: Java Server Pages

10. Select the correct scopes in JSP
Ans: page, request, session, application

11. Select a valid declaration from the following
Ans: <%! String orgName="TCS";%>

12. How to create a cookie in servlet?
Ans: Use new operator

13. How many implicit objects are there in JSP
Ans: 9

14. In JSP, how can you know what HTTP method (GET or POST) is used by client request?
Ans: request.getMethod()

16. Comments in JSP can be written by
Ans: Both a and b (a. <%--comments--%>, b. <!--comments-->)



19. Which of the following tags can be used to print the value of an expression to the output stream?
Ans: <%=%>

20. Why use RequestDispatcher to forward a request to another resource, instead of using a sendRedirect?
Ans: The RequestDispatcher does not require a round trip to the client, and thus is more efficient and allows the server to maintain request state

21. A JSP needs to generate an XML file. Which attribute of page directive may be used to specify that JSP is generating an XML file?
Ans: contentType

22. Select the right method to include welcome file in a web application
Ans: <welcome-file-list><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file-list>

23. Select a valid expression tag from the following
Ans: <%=new java.util.Dat().toString()%>


25. What is the difference between doing an include or a forward with a RequestDispatcher?
Ans: The forward method transfers control to the designated resource, while the include method invokes the designated resource, substitutes its output dynamically in the display, and returns control to the calling page

26. Which of the following is true about javax.servlet.error.exception_type?
Ans: This attribute gives information about exception type which can be stored and analyzed after storing in a java.lang.Class data type

27. What are Servlets?
Ans: Both of the above (Java Servlets are programs that run on a Web or Application server. Java Servlets act as a middle layer between a request coming from a web browser or other HTTP client and databases or applications on the HTTP server)

28. Which of the following is true about servlets?
Ans: All of the above. ((a) Servlets execute within the address space of a Web server. (b) Servlets are platform-independent because they are written in Java. (c)The full functionality of the Java class libraries is available to a servlet.)

29.  Which of the following is the correct order of servlet life cycle phase methods?
Ans: init, service, destroy

30. When init method of servlet gets called?
Ans: The init method is called when the servlet is first created.

31. Which of the following is true about init method of servlet?
Ans: Both of the above. ((a) The init method simply creates or loads some data that will be used throughout the life of the servlet. (b) The init method is not called again and again for each user request.)

32. When service method of servlet gets called?
Ans:  The service method is called whenever the servlet is invoked.

33. Which of the following is true about service method of servlet?
Ans: All of the above ((a) The servlet container i.e.webserver calls the service method to handle requests coming from the client. (b) Each time the server receives a request for a servlet, the server spawns a new thread and calls service. (c) The service method checks the HTTP request type GET,POST,PUT,DELETE,etc. and calls doGet, doPost, doPut, doDelete, etc. methods as appropriate. )

34. When doGet method of servlet gets called?
Ans: Both of the above. ((a) A GET request results from a normal request for a URL. (b) The service method checks the HTTP request type as GET and calls doGet method.)

35. When doPost method of servlet gets called?
Ans: Both of the above. ((a) A POST request results from an HTML form that specifically lists POST as the METHOD. (b) The service method checks the HTTP request type as POST and calls doPost method.)

37. How can you make jsp page as error page
Ans: isErrorPage="true"

38. In JSP, how can you know what HTTP method (GET or POST) is used by client request?
Ans: request.getMethod()

39. Which of the following code can be used to set the character encoding for the body of the response?
Ans: response.setCharacterEncoding(charset)

40. Which of the following is not an implicit object in JSP?
Ans: pageConfig

41. Java declaration tag is used to declare
Ans: Both variables and methods

42. What is the return type of getParameter(String name) in ServletRequest?
Ans: String

What will be the output of the following code?
<% int x=5;%>; <%! Int x =10; %><%! Int y=50;%><%y*x%>
ANS: 250.0

how to get multiple values of selected checkboxes in a servlet?
ANS: String values[]=request.getParameterValues(“hobbies”);

which of the following code is used to get names of the parameters in servlet
ANS: request.getParameterNames()
JSP is
ANS: Java Server Pages
Which of the following code is used to set content type of a page to be serviced using servlet?

ANS: response.setContentType()

ASP.NET Core: How to implement Azure Active Directory (AAD) Authentication in ASP.NET Core

  In this tutorial, we will implement security for ASP.NET Core Application using Azure Active Directory (AAD).  In this tutorial, I will co...