0% found this document useful (0 votes)
5 views

Copy of E3Java

Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Copy of E3Java

Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 16

What is the one defining characteristic of Fluent API Builder Pattern Method Chaining

Starting from Which version Java has added support Java 7u45 Java7u80
for Lambda Expressions

What is the output of the below code ? 128328192 1280128


<pre>
public class Main {

public static void main(String[] args)


{
int i=2048;
int j=0;
int k=0;
k = i << 2;
j = k >> 8;
i = j << 2;
System.out.print(i);
System.out.print(j);
System.out.print(k);

}
}
</pre>
What is the output of the following code snippet? 00 09
<pre>
class class1{

int value=0;
public int getValue()
{
return value;
}
}
class class2 extends class1{
public int getValue()
{
return 9;
}
}

public class Main {

public static void main(String[] args)


{
class1 obj1;
class2 obj2;
obj1 = new class2();
obj2=new class2();
System.out.print(obj1.getValue());
System.out.print(obj2.getValue());
}
}
</pre>

what is the best explanation with regards to the Compilation Error Runtime Error
below code snippet ?
<pre>
List<Integer> container= new ArrayList<>();
/*..
..Other code Fragments
..*/
container=container.stream().filter(item-
>item<12).collect(Collectors.toList());
</pre>

Whether the below is a valid statement in Java ? Statement is Valid Statement is Invalid
<pre>
/**
* variable container is of type List
**/
container.forEach(System.out::println);
</pre>
A programmer must create a generic class MinMax <pre> <pre>
and the type parameter of MinMax must implement classB.MinMax<E
class MinMax<E implements Comparable<E>> {
Comparable. Which implementation of MinMax will extends E min = null;
compile? Comparable<E>> { E max = null;
E min = null; public MinMax() {}
E max
public
= null;
void put(E value) { /* store min or max */ }
public MinMax() {} </pre>
public void put(E
value) { /* store
min or max */ }
</pre>

<pre> Deleting a Person


Thekey
time
from
to find
a HashMap
the will delete all map entries for all keys of type
class Person { value from
private String name; HashMap with a
Person key depends
public Person(String name) { on the size of the
this.name = name; map.
}

public int hashCode() {


return 420;
}
}
</pre>
With reference to the code Snippet above , Which
statement is true?
<pre> Mr. John Doe
An exception is thrown at runtime.
public enum Title {
MR("Mr."), MRS("Mrs."), MS("Ms.");
private final String title;

private Title(String t) {
title = t;
}

public String format(String last, String first) {


return title + " " + first + " " + last;
}
}

public static void main(String[] args)


{
System.out.println(Title.MR.format("Doe",
"John"));
}
</pre>
What is the output of the Above Expression

The statement widely used while making a JDBC


This lineThis
is mandatory,
line registers
and without this the connections could not be made
connection the JDBC driver
<pre>
class.forName("com.mysql.jdbc.Driver");
</pre>
choose which of the following is incorrect.
<pre> restore 400 restore 403
import java.io.*;

class Food implements Serializable {


int good = 3;
}

class Fruit extends Food {


int juice = 5;
}

public class Banana extends Fruit {


int yellow = 4;

public static void main(String[] args) {


Banana b = new Banana();
Banana b2 = new Banana();
b.serializeBanana(b); // assume correct
serialization
b2 = b.deserializeBanana(); // assume correct
System.out.println("restore " + b2.yellow + b2.juice
+ b2.good);
}
// more Banana methods go here

}
</pre>
What is the result?

<pre> CompilationAn
fails.
exception is thrown at runtime.
public class Threads4 {
public static void main (String[] args) {
new Threads4().go();
}
public void go() {
Runnable r = new Runnable() {
public void run() {
System.out.print("foo");
}
};
Thread t = new Thread(r);
t.start();
t.start();
}
}
</pre>
What is the result?
Given: CompilationAn
fails.
exception is thrown at runtime.
<pre>
public class Threads5 {
public static void main (String[] args) {
new Thread(new Runnable() {
public void run() {
System.out.print("bar");
}}).start();
}
}
</pre>
What is the result?

A class games.cards.Poker is correctly defined


put Poker.jar
in the input
directory
Poker.jar
/stuff/java,
in and set the CLASSPATH to include /stuff/java
jar file Poker.jar. A directory
user wants to execute the main method of Poker on /stuff/java, and set
a UNIX system using the command: the CLASSPATH to
java games.cards.Poker include /stuff/java
What allows the user to do this?

Given the command line java Pass2 and: CompilationAn


fails.
exception is thrown at runtime.
<pre>
public class Pass2 {
public void main(String [] args) {
int x = 6;
Pass2 p = new Pass2();
p.doStuff(x);
System.out.print(" main x = " + x);
}

void doStuff(int x) {
System.out.print(" doStuff x = " + x++);
}
}
</pre>
What is the result?

Which Man class properly represents the <pre>class


<pre>class
ManMan { private Dog bestFriend; }</pre>
relationship "Man has a best { private BestFriend
friend who is a Dog"? dog; }</pre>
Given code in separate source files: Value: 3 Value: 8
<pre>
public class Foo {
public int a;
public Foo() { a = 3; }
public void addFive() { a += 5;}
} and: 20. public class Bar extends Foo {
public int a;
public Bar() { a = 8; }
public void addFive() { this.a += 5; }
}
</pre>
invoked with:
<pre>
Foo foo = new Bar();
foo.addFive();
System.out.println("Value: " + foo.a);
</pre>
What is the result?

Given: 0, 0, 0 150, 60, 0


<pre>
abstract class Vehicle { public int speed() { return 0; }
class Car extends Vehicle { public int speed() { return
60; }
class RaceCar extends Car { public int speed()
{ return 150; }
...
RaceCar racer = new RaceCar();
Car car = new RaceCar();
Vehicle vehicle = new RaceCar();
System.out.println(racer.speed() + ", " + car.speed()
+ ", " + vehicle.speed());
</pre>
What is the result?
Given: B The code runs with no output.
<pre>
static class A {
void process() throws Exception { throw new
Exception(); }
}
static class B extends A {
void process() { System.out.println("B"); }
}
public static void main(String[] args) {
new B().process();
}
</pre>
What is the result?

Given: ten times zero times


<pre>
int x = 10;
do { 37. x--;
} while (x < 10);
</pre>
How many times will line 37 be executed?

SQL statement to list all the MALE SUSPECTS who’s <pre> <pre>
HEIGHT is between
SELECT 175 to
FIRNo
185, AS
ageExpr1,
between
SQL statement to list all cases registered IN YEAR FIRDate
30 to
AS Expr2,
SELECT SuspectName
FIRNo
<pre> AS AS Expr3, SuspectSex AS Expr4, SuspectAddress A
<pre>
40,
2018and suspect
in LUCKNOW name contains
district. SELECTword
Output BHAI.
should Output
Location.Description
contain Expr1, FIRDate
ASSELECT
Expr1, AS SuspectHeight AS Expr7
SQL statement
should contain to list
FIRNO, allFIRDATE,
the casesSUSPECT
assigned to IO
NAME, <pre> MajorHead.Description
Expr2, FROM <pre> FIRAS Expr2, FIR.FIRNo AS Expr3, F
POLICE
KRISHNA STATION
SELECT
BHINDE NAME,
for MAJORHEAD
IO.IOCode
year 2018.ASOutput
Expr1, DESCRIPTION,
IO.IOName
should Location.Descriptio
FROMFIR.FIRNo
ASSELECT
Expr2, FIR,Location,
IO.IOCode MajorHead, Location Location_1
SQLNO.
FIR statement
and WHERE
FIRto list
DATE (SuspectSex
Police
sortedStation = 'male')
on MAJOR wiseHEADANDin(SuspectHeight
SuspectName
nAS<pre>
AS Expr1, ASAS175
BETWEEN Expr3,
AND FIR.FIRDate
<pre>
WHERE
AS Expr4,
185) AND (SuspectAge FIR.Actcode
BETWEENAS 30Exor
contain IO CODE,
Arrested/Surrendered IO NAME,
person FIRNO,
detailsFIRDATE, Expr1, FROM FIR,IO,
</pre> MajorHead
SQL statement
ACTCODE, to list the
and MAJOR HEADMURDER ORinRAPE
DESCRIPTION
LUCKNOW SELECT
cases
sorted
SELECT
FIR.FIRNo
FIR.FIRNo
<pre>
IO.IOName
AS Expr1, Location.Description
in MajorHead.Descript
FIR.MajorHeadKey
AS = MajorHead.MajorHeadKey
<pre>
WHERE
AS Expr2,AND
ArrestDetail.*
ON FIR.PSCode
district.
= Location.LocationKey
Output should
registered in LUCKNOW SELECTcontain
INNER FIRNO,
district. JOIN
FIR.FIRNo Location
POLICE
OutputAS should Location_1
Expr1, FIR.FIRDate AS
ON Expr1,
FIR.DistrictCode
FIR.StateCode
SELECTFIR.FIRNo
ASFIR.FIRNo
Expr2,FIR.IOCode== Location_1.LocationKey
Location_1.LocationKey
FIRVictim.VictimName INNER JOIN Arre
AS Expr3, FIRVictim.Age AS
STATION NAME, and all the ARREST details. Expr2,
Location.Descriptio AS = IO.IOCode AND
</pre>
contain FIRNO, FIRDATE, VICTIM NAME, VICTIM AND (YEAR(FIR.FIRDate)
Expr1, =FROM2018) AND
ASFIR.MajorHeadKey = (Location_1.Description
FIR INNER JOIN
MajorHead.MajorHeadKey = ' LUCKNOW'
AGE, and IO NAME MajorHead nON
ASFIR.MajorHeadKey
Expr2,
FIR.FIRDate ORDER
AS =BY2008)MajorHead.Description
=AND
MajorHead.MajorHeadKey
AND (YEAR(FIR.FIRDate) (IO.IOName = 'BHINDE INNER JOIN
KRISHNA')
FIRVictim
Expr2, ON FIR.FIRNo
ORDER BY </pre>
= FIRVictim.FIRNo
FIR.FIRDate INNER JOIN
IO ON FIR.IOCode </pre>
= IO.IOCode INNER JOIN
Location ON FIR.DistrictCode = Location.LocationKey
WHERE (MajorHead.Description LIKE 'RAPE' AND
MajorHead.Description LIKE 'MURDER') AND (Location.Description LIKE ' LUCKNO
</pre>
None of the Above Both of the above D

Java8u1 Java8u20 C

1282048256 204808192 A
90 99 D

iltering the ArrayListFiltering


with values
the array
less than
list with
12 values less Dthat 12

Insufficient InformationNone of the above A


<pre> <pre> A
. class MinMax<E D.
extends
class MinMax<E
Comparable<E>>
implements
{ Comparable<E>> {
<E> E min = null; <E> E min = null;
<E> E max = null; <E> E max = null;
public MinMax() {} public MinMax() {}
c <E> void put(Epublic
value)<E>
{ /*void
storeput(E
min value)
or max{ */
/* }store min or max */ }
</pre> </pre>

nto
whether
a HashSet
a Person
will object
cause the
is contained
first Person
in aobject
HashSet
to be
is constant
removed
A andas adoes
duplicate.
NOT depend on the size of the map.
Compilation fails None of the Above A

optional, connections
This line iscan
used
stillforproceed
validating
without
the classpath
this line of Bthe application
restore 453 Compilation fails. C

The code executesThe


normally
code executes
and prints
normally,
"foo". but nothingBis printed.
The code executes normally
The codeand
executes
printsnormally,
"bar". but nothing
C prints.

yoker.jar
/stuff/java,
in directory
and set/stuff/java/games/cards,
the CLASSPATH to includeand
/stuff/java/Poker.jar
set the CLASSPATH
C to include /stuff/java

doStuff x = 6 main x =doStuff


6 x = 6 main x = 7 B

e>class Man { private


<pre>class
Dog<bestFriend>;
Man { private
}</pre>
BestFriend<dog>;
B }</pre>
Value: 13 Compilation fails. A

Compilation fails. 150, 150, 150 D


ompilation fails because
Compilation
of an error
failsinbecause
line 12.of an error inAline 15.

one to nine times more than ten times D

<pre> <pre> C
FIRDate
spectName AS Expr2,
AS Expr3,SuspectName
SuspectSex
<pre> AS
AS Expr3,
Expr4, SuspectSex
SuspectAddress
<pre> AS Expr4,
D AS Expr5,
SuspectAddress
SuspectAgeASASExpr5,
Expr6,SuspectAge AS Expr6,
tion.Description SuspectHeight
pr1, MajorHead.Description
AS Expr1, AS Expr7SuspectHeight AS Expr7
FROM <pre> MajorHead.Description
AS Expr2, FIR.FIRNo
FIR JOIN FROM <pre> FIRAS ASExpr3,
Expr2,CFIR.FIRDate
FIR.FIRNo ASASExpr3,
Expr4FIR.FIRDate AS Expr4
O.IOName
ctcode FROM
AS Expr5,
AS FROM
Expr2, FIR OUTER
FIR,Location,
MajorHead.Description
FIR.FIRNo AS Expr3, MajorHead,
FIR.FIRDate
AS Expr6 Location
AS Location_1
e')
BETWEEN
or (SuspectHeight
ocation ON 175 AND
FIR.PSCode 185)
BETWEEN
<pre> AND (SuspectAge
=INNER 175 ANDWHERE
Location.LocationKey 185)
BETWEEN
<pre> AND
INNER 30Expr4,
(SuspectAge
JOINAND
B 40) FIR.Actcode
BETWEEN ASAND
Expr5,
AND (SuspectName
30 40)MajorHead.Description
like
or (SuspectName
'BHAI') AS Expr6
like 'BHIA')
RNo FROM FIR
</pre> FROM
JOIN FIR,IO,
</pre> MajorHead
d ONASSELECT
Expr1, Location.Description
FIR.FIRNo
FIR.MajorHeadKey
IO ON <pre>
FIR.IOCode ==AS Expr1,=Location.Description
FIR.PSCode AS Expr2,
MajorHead.MajorHeadKey
IO.IOCode
ArrestDetail.*
Location.LocationKey
<pre>JOIN
INNER
WHERE
ASAAND
OUTER Expr2,
JOIN ArrestDetail.*
tion
AS Expr1,
Expr2,ON FROM
Location_1 ON
FIR.FIRDate FIR
FIRVictim.VictimName LEFTJOIN
FIR.MajorHeadKey
FIR.DistrictCode
ASFIR.IOCode FROM == FIR INNER JOIN
MajorHead.MajorHeadKey
Location_1.LocationKey
Expr2, =FIR.SuspectName
AS AND
orHead FIR.MajorHeadKey
ON FIR.DistCodeLocation
= AND
Location.LocationKey =Expr3, FIRVictim.Age
MajorHead.MajorHeadKey
IORank.IORankCode
ON(Location_1.Description
FIR.PSCode ==FIR
AS Expr3,
Location.LocationKey
INNER JOIN
AS
ANDFIRVictim.Age
Expr4, IO.IOName
INNER JOIN
AS Expr4,
AS Expr5
IO.IOName AS Expr5
R.FIRDate)
OM
(FIR.FIRDate)=
FIR, 2018)
MajorHead,
= 2018) FIR.DistrictCode
FIRVictim,
FIR.MajorHeadKey
AND FROM
(IO.IOName IO, = Location_1.LocationKey
Location
= INNER = 'LUCKNOW')
JOIN
MajorHead.MajorHeadKey
'KRISHNA BHINDE')
_1 ON
Location
ANDFIR.DistrictCode
ORDER Location_1 =ON Location_1.LocationKey
FIR.DistrictCode = Location_1.LocationKey
INNER JOIN INNERJOIN
JOIN
AND(YEAR(FIR.FIRDate)
MajorHead
rrestDetail ON
BY
ORDER MajorHead.Description
ON
WHERE
BY
FIR.FIRNoFIR.FIRDate
ArrestDetail
=
= 2018)
FIR.MajorHeadKey
(YEAR(FIR.FIRDate) AND
= 2018)
ArrestDetail.FIRNo
ON FIR.FIRNo
(Location_1.Description
=AND
MajorHead.MajorHeadKey
=(IO.IOName = ' INNER
= 'KRISHNA
ArrestDetail.FIRNo
LUCKNOW')
BHINDE')
MajorHeadKey =FIRVictim </pre>
</pre> ORDER
MajorHead.MajorHeadKey BY
ON FIR.FIRNo
ORDER MajorHead.Description
= FIRVictim.FIRNo
BY AND
FIR.FIRDate INNER JOIN
HERE FIR.FIRNo
(Location_1.Description
WHEREON FIR.DistrictCode
=Location
FIRVictim.FIRNo (Location.Description
= 'AND
LUCKNOW')
</pre> = ' LUCKNOW')
= Location.LocationKey
</pre> </pre>
FIR.IOCodeWHERE = IO.IOCode AND </pre>
(MajorHead.Description LIKE 'RAPE' OR
MajorHead.Description
FIR.DistrictCode = Location.LocationKey
LIKE 'MURDER') AND (Location.Description LIKE ' LUCKNOW')
AND (MajorHead.Description LIKE 'RAPE' </pre>
OR
tion LIKE 'MURDER') OR (Location.Description LIKE ' LUCKNOW')
</pre>

You might also like