java - Programming Ability - JAVA (Event-III)
java - Programming Ability - JAVA (Event-III)
National Crime Records Bureau, East Block-7, R.K. Puram, Delhi 110066
Negative
SlNo Question Option A Option B Option C Option D Answer Max Marks Marks
<pre>if (a<0){ <pre>if (a < 0){
System.out.print("("+(a-(2*a))+")"); <pre>if (a < 0){ System.out.print(a.toString().replace("-
You are required to print the negative number into brackets instead of } System.out.print("("+Math.abs(a)+")"); ","(")+")");
1 minus sign (e.g., -3998 is (3998) ). Let a=-3998 </pre> }</pre> }</pre> All of the above D 2 0.5
Consider the following table created in MSSQL server 2008:<br/> SELECT * FROM [TblTrn_DMT] where SELECT * FROM [TblTrn_DMT] where SELECT * FROM [TblTrn_DMT] where SELECT * FROM [TblTrn_DMT] where D 4
TblTrn_DMT(Name, Desgnation, DateOfJoining, Remarks), all columns DateOfJoining<'04/12/2016' order by CONVERT((DateTime, DateOfJoining <='03/12/2016' order by CONVERT(DateTime, DateOfJoining,103)
having nvarchar(100) datatype. <br/>You are required to fetch records DateOfJoining DESC; DateOfJoining,108)<='03/12/2016' order CONVERT(Date, DateOfJoining,108) DESC; <= CONVERT (DateTime,
having DateOfJonining less than and equal to '03/12/2016'. <br/>Record by CONVERT(DateTime, '03/12/2016',103) ORDER BY
Should be in descending order by DateOfJonining. DateOfJoining,108) DESC; CONVERT(DateTime, DateOfJoining,103)
2 Which one is correct: DESC; 1
Page 1 of 8 60th All India Police Durty Meet 2016, Mysuru, Karnataka
Programming Ability (Event-III) - JAVA
National Crime Records Bureau, East Block-7, R.K. Puram, Delhi 110066
Negative
SlNo Question Option A Option B Option C Option D Answer Max Marks Marks
What will be the output of the code given below? <br/> 56 65 66 77
<pre>
public static void main (String[] args) throws java.lang.Exception
{
int num = 1, z = 5;
if (!(num <= 0))
System.out.println( ++num + z++ + " " + ++z ); else
System.out.println( --num + z-- + " " + --z );
}
9 </pre> D 2 0.5
What will be the output of the code given below? <br/> 8 4 16 12 20 4 8 12 16 20 4 8 16 32 64 2 4 6 8 10
<pre>int i, j = 1, k;
for (i = 0; i < 5; i++)
{
k = j++ + ++j;
System.out.println(k + " ");
}
10 </pre> B 2 0.5
returns a list containing elements
returns object stored at the specified returns object at the specified memory between specified index and end in the returns a list containing elements
11 What does get(int index) method define by List interface do ? index cell collection between first and end in the collection A 2 0.5
Identify the type of sorting code below?<br/>
<pre>func sort( var a as array )
for i from 1 to N
for j from 0 to N - 1
if a[j] > a[j + 1]
swap( a[j], a[j + 1] )
12 end func</pre> Insertion Sort Merge Sort Radix Sort Bubble Sort D 2 0.5
What is the output of the following code ? <br/> HI HI HI HI Stack overflow exception Compile time error
<pre>import java.io.IOException;
class Main{
public static void main(String[] args)throws IOException
{
m();
System.in.read();
}
private static void m()
{
System.out.println("HI");
m();
}
}
13 </pre> C 2 0.5
Which two among the following are Java Exception classes?
<br/>1.SecurityException
<br/>2.DuplicatePathException
<br/>3.IllegalArgumentException
14 <br/>4.TooManyArgumentsException 1 and 2 1 and 3 2 and 3 3 and 4 B 2 0.5
Page 2 of 8 60th All India Police Durty Meet 2016, Mysuru, Karnataka
Programming Ability (Event-III) - JAVA
National Crime Records Bureau, East Block-7, R.K. Puram, Delhi 110066
Negative
SlNo Question Option A Option B Option C Option D Answer Max Marks Marks
Given the code fragment:
<br/>
<pre>
public static void main(string args){
String[][] arr={{"A","B","C"},{"D","E"}};
for(int i=0;i<=arr.length-1;i++){
for(int j=0;j<=arr[i].length-1;j++){
System.out.print(arr[i],[j]+" ");
if(arr[i][j].equals("B")){
break;
}
}
continue;
}
}
</pre>
<br/>
15 What is the result ? ABC ABCDE ABDE Compilation Fails C 2 0.5
Given below code fragment, which of the following would be the result of
the execution?
<br/><pre>
public class FieldInit
{
char c;
boolean b;
float f;
void printAll() {
System.out.println("c = " + c);
System.out.println("b = " + b);
System.out.println("f = " + f);
}
switch(color){
case "Red":
System.out.println("Found Red");
case "Blue":
System.out.println("Found Blue");
break;
case "Teal":
System.out.println("Found Teal");
break;
default: Found Red
System.out.println("Found Default"); Found Red Found Blue
} Found Red Found Blue Found Teal
17 </pre> Found Blue Found Red Found Teal Found Default A 2 0.5
Page 3 of 8 60th All India Police Durty Meet 2016, Mysuru, Karnataka
Programming Ability (Event-III) - JAVA
National Crime Records Bureau, East Block-7, R.K. Puram, Delhi 110066
Negative
SlNo Question Option A Option B Option C Option D Answer Max Marks Marks
Given the below mentioned lines of code <br/>
<pre>
1 public class NcrbLabs{
2 public static void main(String args[]){
3 List<Integer> list= new ArrayList<>();
4 list.add(21); list.add(13);
5 list.add(30); list.add(11);
6 list.add(2);
7 List<Integer> filteredList = list.stream().filter( // Insert code here
).collect(Collectors.toList());
8 System.out.println(filteredList);
9 }
10 }
</pre>
Which of the following code inserted in line 7 to get the following output?
18 <br/> 21,13,11 i -> i%2!=0 i -> i%2==0 Compilation fail i -> i/2==0 A 4 1
Given below code fragment.<br/>
<pre>
1. public class App {
2. // Insert code here
3. System.out.print("Welcome to the world of Java");
4. }
</pre><br/>
Which of the following code inserted in Line 2 to enable the program to
execute and print the welcome message on the screen? <pre>static void main (String [] args) <pre>public static void Main (String [] <pre>public static void main (String [] <pre>public void main (String [] args) {
19 {</pre> args) {</pre> args) {</pre> </pre> C 2 0.5
Which usage represents a valid way of compiling java source file with the
20 name "Main"? javac Main.java java Main.class java Main.java javac Main A 2 0.5
You have a large flat file having product name and price. which is updated you will open the file and store the you will open the file and convert into you will save the file as object in NoSql None of the above
once in a day. you need to display the proudct name and price on your product list and price in static array array and assign to catelogue view database and access from there
webpage catalogue. you have two point of consideration Quick Access of
product list and second is consume least memory to implememnt it. what
21 method you will follow to achive this goal D 2 0.5
Assume that you are distributing a java based web application, which uses Encrypting the data in the application Using a code obfuscator Using LDAP Circle of Trust based Querying the user for his or her
connection information stored in a properties file, which among the configuration file authentication for database credentials at run time
following would be your preferred choice for ensuring that the connection
22 information remains confidential C 2 0.5
Identify the flow chart <br/> <a href="../images/flowchar1.png" D
target="_blank"><img src="../images/flowchar1.png" alt="Flow Chart"
23 height="550" width="500"></a> Binomial Armstrong Palindrome Number Factorial 2 0.5
A
Choose Correct option <br/> <a href="../images/FourFlowChart.png"
target="_blank"><img src="../images/FourFlowChart.png" alt="Flow Chart"
height="600" width="800"></a><br/>
NOTE:<br/> 1. An Armstrong number of three digits is an integer such that
the sum of the cubes of its digits is equal to the number itself. For example,
371 is an Armstrong number since 3^3 + 7^3 + 1^3 = 371.<br/>
2. Fibonacci is a series of numbers in which each number ( Fibonacci
number ) is the sum of the two preceding numbers. The simplest is the
series 1, 1, 2, 3, 5, 8, etc <br/>
3. A palindromic number or numeral palindrome is a number that remains FC1=Armstrong, FC2=Binary Search, FC1=Palindrome, FC2=Binary Search, FC1=Armstrong, FC2=Binary Search, FC1=Fibonacci, FC2=Binary Search,
24 the same when its digits are reversed. Like 16461 FC3=Fibonacci, FC4=Palindrome FC3=Fibonacci, FC4=Armstrong FC3=Palindrome, FC4=Fibonacci FC3=Armstrong,FC4=Palindrome 4 1
<pre>Find the output of the following code if x=10.
int sum(int x)
{
if (x >= 1) return x+sum(x-1); else return 0;
}
25 </pre> 55 56 Compiler Error Stack over flow A 2 0.5
Which among the following is a server side framework written in Java
26 Script Angular JS Express JS ReactJS EmberJS B 2 0.5
27 JWT or the JSON Web Tokens is a methodology to implement Authentication Authorization Both Authentication an d Authorization None of the above C 2 0.5
Page 4 of 8 60th All India Police Durty Meet 2016, Mysuru, Karnataka
Programming Ability (Event-III) - JAVA
National Crime Records Bureau, East Block-7, R.K. Puram, Delhi 110066
Negative
SlNo Question Option A Option B Option C Option D Answer Max Marks Marks
Given the following Code :
<pre>
public class Animal {
private String species;
private boolean canHop;
private boolean canSwim;
public Animal(String speciesName, boolean hopper, boolean swimmer) {
species = speciesName;
canHop = hopper;
canSwim = swimmer;
}
public boolean canHop() { return canHop; }
public boolean canSwim() { return canSwim; }
public String toString() { return species; }
}
National Crime Records Bureau, East Block-7, R.K. Puram, Delhi 110066
Negative
SlNo Question Option A Option B Option C Option D Answer Max Marks Marks
Consider the Database Function:<br/> <br/>i) Return type missing <br/>i)Dept_name is mismatched <br/>i) Reference relation is not <br/>i) No Error A
<pre> <br/>ii) Select dept name, budget <br/>ii) Select dept name, budget mentioned <br/>ii) Select dept name, budget
Create function dept count(dept_name varchar(20)) from instructor from instructor <br/>ii) Select dept name, budget from instructor
begin where dept count(dept name) > 12; where dept count() > 12; where dept count(dept name) > 12; where dept count(budget) > 12;
declare d count integer;
select count(*) into d count
from instructor
where instructor.dept_name= dept_name
return d count;
end
</pre><br/>
i) Find the error in the above statement. <br/>
ii) For the function created,which of the following is a proper select
31 statement ? 4 1
Consider the following database for IO's to maintain a checklist against a C
particular FIR.<br/>
The database maintains tasks which have been completed(checked) and
which are incomplete(unchecked).<br/> <pre> <pre>
It is having two masters and two transactional tables.<br/> select a.checkName, b.offence_id, <pre> select a.checkName, b.offence_id, <pre>
Find <q>checkName</q>, <q>offenc_id</q> and <q>firno_id</q> of b.firNo_id from m_offence a select a.checkName, b.offence_id, b.firNo_id from m_offence a select a.checkName, b.offence_id,
checked and unchecked <q>checkNames</q> of body right outer join b.firNo_id from m_offence a left outer join b.firNo_id from m_offence a
offence(<q>offenceType_id</q>=601) regarding fir#123/16 as shown in (select * from t_checkedOffence right outer join (select * from t_checkedOffence join
output table <br/><a href="../images/database.jpg" target="_blank"> where firNo_id= (select id from t_fir (select * from t_checkedOffence where firNo_id= (select id from t_fir (select * from t_checkedOffence
<img src="../images/database.jpg" alt="database" height="500" where firNo='123/16') where firNo_id= (select id from t_fir where firNo='123/16') where id= (select id from t_fir where
width="700"></a><br/> OR firNo_id IS NULL ) b where firNo='123/16')) b OR firNo_id IS NULL ) b firNo='123/16')) b
Which of following SQL Statement produces output as shown in Desired on a.id=b.offence_id on a.id=b.offence_id on a.id=b.offence_id on a.id=b.offence_id
output. where offenceType_id=601 where offenceType_id=601 where offenceType_id=601 where offenceType_id=601
32 </pre> </pre> </pre> </pre> 4 1
Consider the following database for IO's to maintain a checklist against a C
particular FIR.<br/>
The database maintains tasks which have been completed(checked) and
which are incomplete(unchecked).<br/> <pre>
It is having two masters and two transactional tables.<br/> <pre> select a.checkName, b.firNo select a.checkName, b.firNo
from m_offence a left outer join from m_offence a
<a href="../images/database1.png" target="_blank"> t_checkedOffence c on a.id=c.offence_id left outer join t_fir b on <pre>select a.checkName, b.firNo
<img src="../images/database1.png" alt="database1" height="317" inner join t_fir b on c.firNo_id=b.id a.id=b.offenceType_id from m_offence a,t_fir
width="742"></a><br/> inner join m_offencetype d on join t_checkedOffence c on c.firNo_id=b.id b,t_checkedOffence c
A officer wants to check whether <q>Spot verification</q> of Fir #123/16 d.id=c.offence_id where a.checkName='Spot verification' where a.checkName='Spot verification'
has been done or not. Find out which of the following SQL query correctly where a.checkName='Spot verification' and b.firNo='123/16'; and a.id=c.offence_id and c.firNo_id=b.id
33 evaluates this. and b.firNo='123/16'; </pre> </pre> and b.firNo='123/16'; </pre> None of the above 4 1
Consider the following database for IO's to maintain a checklist against a D
particular FIR.<br/>
The database maintains tasks which have been completed(checked) and
which are incomplete(unchecked).<br/>
It is having two masters and two transactional tables.<br/> <pre>select count(a.offence_id), b.firNo <pre>select count(a.offence_id), b.firNo <pre>
<a href="../images/database1.png" target="_blank"> <pre>select count(a.offence_id), b.firNo from t_checkedOffence a right outer join from t_checkedOffence a,t_fir select count(a.offence_id), b.firNo
<img src="../images/database1.png" alt="database1" height="317" from t_checkedOffence a,t_fir t_fir b on a.firNo_id=b.id right outer join b,m_offenceType c where a.firNo_id=b.id from t_checkedOffence a,t_fir
width="742"></a> <br/> b,m_offenceType c where a.firNo_id=b.id m_offenceType c on and c.id=b.offenceType_id and b,m_offenceType c where a.firNo_id=b.id
<p>Find no. of checks that have been done in each fir with offence type is and c.id=b.offenceType_id c.id=b.offenceType_id c.name='Body Offence' group by and c.id=b.offenceType_id and
<q>Body Offence</q> in ascending order by <q>firNo</q>. Which of the group by b.firNo having c.id='Body group by b.firNo having c.id='Body b.firNo,a.offence_id order by b.firNo c.name='Body Offence'group by b.firNo
34 following query will produce the desired result. </p> Offence' order by b.firNo asc</pre> Offence' order by b.firNo asc </pre> asc</pre> order by b.firNo</pre> 4 1
What is the priority of the thread in output of this program? </br>
<pre>
class multithreaded_programing {
public static void main(String args[]) {
Thread t = Thread.currentThread();
System.out.println(t);
}
}
35 </pre> 4 5 1 0 B 2 0.5
Page 6 of 8 60th All India Police Durty Meet 2016, Mysuru, Karnataka
Programming Ability (Event-III) - JAVA
National Crime Records Bureau, East Block-7, R.K. Puram, Delhi 110066
Negative
SlNo Question Option A Option B Option C Option D Answer Max Marks Marks
<pre>class X implements Runnable
{
public static void main ( String args[])
{
/* Missing Code/ */
}
public void run ()
{
}</pre><br/> <pre>Thread t = new <pre>X run = new X();Thread t= new <pre>Thread t = new Thread(); <pre>Thread t= new
36 Identify the missing code. Thread(X);t.start();</pre> Thread(run);t.start();</pre> x.run();t.start();</pre> Thread(X);t.start();</pre> B 2 0.5
Choose correct option <br/>
<pre>
import java.net.*;
class networking {
public static void main(String[] args) throws
UnknownHostException {
InetAddress obj1 = InetAddress.getByName("cisco.com");
System.out.print(obj1.getHostName());
}
}
37 </pre> 127.0.0.0//cisco.com cisco.com www.cisco.com http://www.cisco.com B 2 0.5
Wakes up all threads that are waiting on Wakes up all threads that are not waiting Wakes up all threads that are in runnable Wakes up main threads that are not
38 What notifyAll() method do? this object's monitor on this object's monitor state on this object's monitor runnable on this object's monitor A 2 0.5
Which collection class grows or shrinks its size and provides indexed access
39 to its elements, but methods are not synchronized? java.util.ArrayList java.util.List java.util.HashSet java.util.Vector A 2 0.5
What is the output for the below code ? <br/>
<pre>
1. public class Test {
2. public static void main(String[] args){
3. byte i = 128;
4. System.out.println(i);
5. }
6. }
</pre>
40 0 128 Compilation fails with an error at line 4 Compilation fails with an error at line 3 D 2 0.5
FourFlowChart.png
database.jpg
Page 7 of 8 60th All India Police Durty Meet 2016, Mysuru, Karnataka
Programming Ability (Event-III) - JAVA
National Crime Records Bureau, East Block-7, R.K. Puram, Delhi 110066
Negative
SlNo Question Option A Option B Option C Option D Answer Max Marks Marks
flowchart1.png
database1.png
Page 8 of 8 60th All India Police Durty Meet 2016, Mysuru, Karnataka