Sie sind auf Seite 1von 63

QID QN Skill

08081620CJ0406181 1 Core Java

08081620CJ0406182 2 Core Java

08081620CJ0406183 3 Core Java

08081620CJ0406184 4 Core Java


08081620CJ0406185 5 Core Java

08081620CJ0406186 6 Core Java

08081620CJ0406187 7 Core Java

08081620CJ0406188 8 Core Java


08081620CJ0406189 9 Core Java

08081620CJ04061810 10 Core Java

08081620CJ04061811 11 Core Java

08081620CJ04061812 12 Core Java


08081620CJ04061813 13 Core Java

08081620CJ04061814 14 Core Java

08081620CJ04061815 15 Core Java

08081620CJ04061816 16 Core Java


08081620CJ04061817 17 Core Java

08081620CJ04061818 18 Core Java

08081620CJ04061819 19 Core Java

08081620CJ04061820 20 Core Java


08081620CJ04061821 21 Core Java

08081620CJ04061822 22 Core Java

08081620CJ04061823 23 Core Java

08081620CJ04061824 24 Core Java


08081620CJ04061825 25 Core Java

08081620CJ04061826 26 Core Java

08081620CJ04061827 27 Core Java

08081620CJ04061828 28 Core Java


08081620CJ04061829 29 Core Java

08081620CJ04061830 30 Core Java

08081620CJ04061831 31 Core Java

08081620CJ04061832 32 Core Java


08081620CJ04061833 33 Core Java

08081620CJ04061834 34 Core Java

08081620CJ04061835 35 Core Java


Sub-skill Difficulty Level Creator

Easy WeCP

Easy WeCP

Easy WeCP

Easy WeCP
Easy WeCP

Easy WeCP

Easy WeCP

Easy WeCP
Easy WeCP

Easy WeCP

Easy WeCP

Medium WeCP
Medium WeCP

Medium WeCP

Medium WeCP

Medium WeCP
Medium WeCP

Medium WeCP

Medium WeCP

Medium WeCP
Medium WeCP

Medium WeCP

Medium WeCP

Medium WeCP
Medium WeCP

Medium WeCP

Medium WeCP

Difficult WeCP
Difficult WeCP

Difficult WeCP

Difficult WeCP

Difficult WeCP
Difficult WeCP

Difficult WeCP

Difficult WeCP
QAM(E.g,: To assess basic Quality Check Good to go?(Enter: "1 or
understanding of Design Yes" if approved
principles in OOP through code otherwise, leave it
snippets) BLANK, if question does
NA not
1 qualify to get billed

NA 1

NA 1

NA 1
NA 1

NA 1

NA 1

NA 1
NA 1

NA 1

NA 1

NA 1
NA 1

NA 1

NA 1

NA 1
NA 1

NA 1

NA 1

NA 1
NA 1

NA 1

NA 1

NA 1
NA 1

NA 1

NA 1

NA 1
NA 1

NA 1

NA 1

NA 1
NA 1

NA 1

NA 1
Final Question

A class named "MyClass" contains multiple methods like Sample1(), Sample2(), Sample3() ,..Sampled().
Consider a predefined integer variable X that is to be used to call the method i.e. if value of integer x is 2,
call Sample2().

Which of these code snippets can be used to do so?

(Assume that X<d)

A string variable needs to print the next letter in the alphabet in place of the first character in the defined
string.

Which of the following code snippets will implement the same?

You have already defined two interfaces as shown alongside. If you need to implement a third interface that
can accept the instances of these two interfaces.

Which of these code snippets can be used to do so?

A string array "sampleArray" containing some null elements is given. Which of these code snippets can be
used to remove these null values from the array?

(Assume if the input array is {"sample1","","sample3"} the output should be {"sample1","sample3"})


Consider the program given alongside. If the user wants to start a thread which of the code snippets will be
suitable for this purpose?

You are given the code snippet shown alongside. If you want to print all Client names along with their
clientids, which of these choices would you need to append to the code.

Also, identify the type of functional interface being implemented in the given scenario?

Which of the following class declarations can be used to represent aggregation in java?

You are assigned a number of tasks while working with threads in java. Two of the tasks assigned are high
priority while the rest of the tasks have normal priority.

Which of the following scheduling methods would be used by the Java thread scheduler in this situation?
You are given the Java class shown alongside. What would happen if you run the Java statement given
below?

final A aa = new A();

You want to create a method that would be used to convert an 'optional' object to a stream. Which of the
following statements would most likely form a part of this function?
(Assume that myopt is the optional object that has been sent as argument.)

Which of the following classes are not instantiable in java if reflections cannot be used?

An object in a swing application extends an AccessibleContext class. If a property bound to the object is
modified which of the following behaviour can be expected?
You are collecting a list of employee names from an employee database using the StringBuilder class.
If you pass a null argument to a method in this class while doing the above operation, which of these
exceptions are you likely to encounter?

You are writing a class that inherits itself in java, when it results in a overflow crash. If the code alongside is
given to you which of the following code snippets can be used to achieve this?

You declare an arraylist of class sample as shown alongside.


Class sample is defined to have two string attributes named first and second. If you wish to add objects of
class sample into the list and prevent adding duplicates while doing so.

Which of these code snippets can be used to do so by overriding the equal method in java?

You have a string defined and you wish to modify this string by adding a special character(#) before and
after every character in the string. Which of the following code snippets can be used to do so?

(Assume that if the input is sample ,the corresponding output will be #s#a#m#p#l#e#)
You are provided the code shown alongsside. Which of the following code snippets can be used to make
sampleList immutable?

You need to obtain the string shown alongside using string formatter. Which of the following commands can
be used to produce the required output using string.format()?

You have a class named Sample which is extended by Sample1 and Sample2.

Which of these code snippets can be used to determine if a given object of class Sample is of type
Sample1 or Sample2?

You wish to read a file using java. However, before reading the file you need to check whether the file is
present. Which of the following code snippets can be used to do so?
A Set interface with only one operation, and one simple implementation class is given alongside. The class
Universe is unable to correctly implement the Set interface. Identify the correct reason for this behavior.

Predict the output of the program given alongside and choose the appropriate option.

Consider the code snippet given alongside.If a function "printArray()" is called to print the values. Which of
the following can be considered as the valid function definition?

Which of these choices represent an immutable class in java?


Given is a code snippet. This code snippet is expected to give a concurrency problem. Given are two
statements that may ideally be the Reason(R) and Solution(S) to this issue. Read the statements and mark
the appropriate option.

R : Strings are interned in Java. Hence, the literal string "LOCK" turns out to be the same instance of
java.lang.String even though they are declared completely disparately from each other.

S : private static final Object LOCK = new Object();

Consider the code snippet given alongside. Which of these are likely to be the value of sl when the snippet
is run?

What would be the output of the code snippet shown alongside?

Which of the following options can be used to define monitors for various objects for thread synchronization
in a multithreaded process in Java?
You have been asked to create a Java class that has two initialization blocks and one constructor. Which of
the following options would you follow to define the class correctly?

An Intrinsic lock is utilised to establish which of the following relationships between resources in order to
maintain visibility in a Java 8 Environment ?

You are provided with the code given alongside to implement a Reentrant Lock in a Multithreaded
environment designed for Java 8.

Which of the following alternatives can be utilized while requesting access to the lock to check for access
without affecting the current thread execution?

You want to find the length of the longest line within a file using the code snipppet given alongside.

Which of these code snippets can be utilized to perform the same operations using streams in a more
optimal manner?
While troubleshooting an error, you need to read all the files from a particular folder.

Which of the following code snippets can be used to do this task?

While running the code snippet shown alongside, you find a typemismatch error.

Which of these values need to be assigned in place of X in order to prevent this error?

What would be the output of the code snippet when executed using the main function.

Main Function:

class TestThread {
public static void main(String args[]) {
threadDemo T1 = new threadDemo( ""T 1"");
T1.start();
threadDemo T2 = new threadDemo( ""T 2"");
T2.start();
}
}

Code Snippet:

class threadDemo implements Runnable {


private Thread t; private String tName;
threadDemo( String name) {
tName = name; }
public void run() { try {
for(int i = 2; i > 0; i--) {
System.out.println(tName + ", " + i);
Thread.sleep(100);
}
}catch (InterruptedException e) {
System.out.println("Thread " + tName + " interrupted.");
}}
public void start () {
t = new Thread (this, tName);
t.start ();
}}
Visuals/Additional Information Answer Choice 1 Answer Choice 2

Method method = Method method =


MyClass.class.getDeclared MyClass.class.callDeclared
Method("Sample") + x; Method("Sample" + x);
method.invoke(); method.invoke();

I/P: abcd String next = int charValue = x.charAt(0);


O/P: bbcd String.valueOf(x + 1); String next =
System.out.println(next); String.valueOf( charValue +
1);
System.out.println(next);

public interface SampleA { public <T instance of public <T extends SampleA
void First(); SampleA & SampleB> void & SampleB> void
} FirstAndSecond(T x) { FirstAndSecond(T x) {
x.First(); x.First();
public inteface SampleB { x.Second(); x.Second();
void Second(); } }
}

sampleArray = sampleArray
sampleArray = .filter(s => (s !=
Arrays.stream(sampleArray) null && s.length() > 0))
.filter(s -> (s !=
null && s.length() > 0)) .toArray(String[]::new);

.toArray(String[]::new);
class Child implements Parent Thread c = new Thread(); Child run = new Child();
{ p.run(); Thread c = new
public static void main(String args[ ]) Thread(run);
{ c.start();
}
public void run() { }
}

Map<String, Integer> clientid = new HashMap<>(); A:clientid.forEach((name, A:clientid.forAny((name,


clientid.put("John", 2); clientid) -> clientid) ).
clientid.put("Don", 4); System.out.println(name + " System.out.println(name + "
clientid.put("Ron", 30); is " + clientid + " id")); is " + clientid + " id"));
B: BiConsumer B: Consumer

class A{ class A{
} }
class B{ class B extends A{
A obj; }
}

Preemptive Scheduling Time Slicing


Class A{ A new instance "aa" of A new instance "aa" of
private int x = 5; class A will be defined with class A will be defined
public static fun(int x){ x = 5. without any value assigned
return this.x + x; to x.
}
}

myoptj.isPresent() ? myopt.isPresent() ?
Stream.of(myopt.get()) : Stream.of(myopt.get()) :
Stream.close(); Stream.empty();

public class A{ public class A{


private int x; private int x;
private A() { public A() {
this.x = 2; this.x = 2;
} }
} }

A UpdateEvent is fired A PropertyChangeEvent is


fired
IllegalArgumentException IllegalReferenceException

class SampleA { public class Test { public class Test {


SampleB b = new SampleB(); public static void public static void
} main(String[] args) { main(String[] args) {
new SampleB() new SampleA()
class SampleB extends SampleA { instanceOf SampleA; instanceOf SampleB();
} } }
} }

List<sample> sampleList = new ArrayList<sample>(); public boolean public boolean


equals(Object sample) { equals(Object sample) {
Sample that = Sample that =
(Sample)sample; (Sample)sample;
return return
this.second.equals(that.get this.first.equals(that.getFirst
First()) && ()) &&
this.first.equals(that.getSec this.second.equals(that.get
ond()); Second());
} }

String inp = "sample"; String inp = "sample";


inp = "#" + inp.replaceAll("(.)","$1#");
inp = "#" +
System.out.println(inp); inp.replaceAll("(.)","$1%");
System.out.println(inp);
public class Sample public List<String> getList() public List<String> getList()
{ { {
private List<String> sampleList = new return return sampleList.Copy();
List<String>{"1","2"}; sampleList.Unmodified(); }
}
public List<String> getList()
{
return sampleList;
}
}

“My Name Is Name” String.format("My %1$s is String.format("My %s is


%1$s", "Name") %s", "Name")

Sample returnObject = getSample();


Sample returnObject = getSample();

if (returnObject instanceof Sample1)


if (returnObject
{ .. } extends Sample1) { .. }
else if (returnObject instanceof
elseSample2)
if (returnObject
{ .. } extends Sample2) { .. }

File f = new File(filePathString);


File f = new File(filePathString);
if(!f.exists() && !f.isDirectory())
if(f.exists()
{ && f.isDirectory()) {
// implementation // implementation
} }
interface Set<E> { Universe.contains doesn't Universe is mutable
public boolean contains(E e); satisfy the spec of
} Set.contains
class Universe<E> {
public Universe() { }
public boolean contains(E e) {
return true;
}
}

class Class1 { In Class1::show() In Class2::show()


public static void show() {
System.out.println("In Class1::show()");
}
}

class Class2 extends Base {


public static void show() {
System.out.println("In Class2::show()");
}
}

class Main {
public
public static
static void
void main(String[]
main(String args)
args[]) { { static void printArray( E[] arr static < E > void
Class1 b = new Class2();;
Integer[] a = { 1, 2, 3, 4, 5 }; ){ printArray( E[] arr ) {
b.show();
Double[] b = { 1.1, 2.2, 3.3, 4.4 }; for(int i=0; i<arr.length; i++){ for(E element : arr) {
} Character[] c = { 'H', 'E', 'L', 'L', 'O' }; System.out.print(arr[i]+" "); System.out.printf("%s ",
} printArray(a); } element);
printArray(b); } }
printArray(c); }
}

public static class C{ public final class C{

private final String s1 private final String s1


private final String s2 private final String s2

public X(String s1, String public X(String s1, String


s2){ s2){

this.s1 = s1 this.s1 = s1
this.s2 = s2 this.s2 = s2
} }

public String f1(){ return public String f1(){ return


s1; } s1; }
public String f2(){ return public String f2(){ return
s2; } s2; }

} }
private static final String LOCK = "LOCK"; R is the correct reason and R is the correct reason but
public dummy_module() { S is a correct Workaround S is not a correct
synchronized(LOCK) { Workaround
this.work();
}
}

List<String> names = Arrays.asList("Ashley", "Angelo", Ashley weds Angelo AshleywedsAliceAngelo


"Makay", "Steve", "Marsh");
List<String> mylist = names.stream()
.filter(name -> name.startsWith("A"))
.collect(Collectors.toList());
Stream<String> sl = mylist.stream();
mylist.add("Alice");
String s = sl.collect(joining(" weds "));

static String f(Supplier x, Supplier y) { false. executing...


return x.get() && y.get() ? "true" : "false"; executing...
} false

public static void main(String [] args) {


System.out.println(f(() -> compute("one"), () ->
compute("two")));
}

synchronized(ObjectID){ monitor(sync = True,


//processing the resources ObjectID){
} //processing the resources
}
public class A{ public class A{

{ //initialization block 1 public A(int x) {


} this.x = x;
}
public A(int x) {
this.x = x; { //initialization block 1
} }

{ //initialization block 2 { //initialization block 2


} }

} }
happens-with happens-before

ExecutorService excalibur = SyncLock() TryLock()


Executors.newFixedThreadPool(2);
Reentrant lock= new ReentrantLock();
excalibur.submit(() ->{ lock.lock();
try{ sleep(2);}finally{lock.unlock(); }
});
excalibur.submit(()->{ lock.lock()});
stop.excalibur(excalibur);

String findMaxStringLine(String longest, List<String> reader.getlines() reader.lines()


l, int i) .sort(comparingInt(String::le .max(comparingInt(String::l
{ ngth)) .(c); ength)) .get();
if (l.get(i).length() > longest.length())

long= l.get(i);
if (i < l.length() - 1)
long = findMaxStringLine(longest,
l,i +1);
if (longest.length() > l.get(i).length())

return long;
return l.get(i);
}
try (Stream<Paths> paths = try (Stream<Path> paths =
Files.walk(Paths.get("/samp Files.walk(Paths.get("/samp
le/SampleFolder"))) { le/SampleFolder"))) {
paths paths

.filter(Files::isRegularFile) .filter(Files::isRegularFile)

.forEach(System.out::println .forEach(System.out::println
); );
} }

String List<Future<String>>
X futures =
executorService.invokeAll(callableTasks);

0 T 2, 2
T 1, 2
T 2, 1
T 1, 1
Answer Choice 3 Answer Choice 4 Answer Choice 5 Correct answer
(optional)

Method method = None of these Choice 3


MyClass.class.getDeclared
Method("Sample" + x);
method.invoke();

String next = int charValue = x.charAt(0); Choice 4


String.valueOf( (char) (x + String next =
1)); String.valueOf( (char)
System.out.println(next); (charValue + 1));
System.out.println(next);

public <T extends SampleA None of these Choice 2


> void FirstAndSecond(T
x)<extends SampleB> {
x.First();
x.Second();
}

sampleArray = sampleArray None of these Choice 1


.filter(s -> (s !=
null && s.length() > 0));
Thread c = new Thread c = new Choice 2
Thread(Child); Thread(Child);
c.start();

A:clientid.forAll((name, A:clientid.forEach(name, Choice 1


clientid) ). clientid) ->
System.out.println(name + System.out.println(name + "
"" is "" + clientid + "" id"")); is " + clientid + " id");
B: Predicate B: Supplier

class A{ class A{ All the above Choice 1


} }
class B extends A{ class B extends A{
} }
class C extends A{ class C extends B{
} }

Priority Based Scheduling Token Ring Scheduling Choice 1


A new instance "aa" of No class instance will be Choice 1
class A will be defined with created. The statement will
x = 5 and the function fun() throw an error as no
will be called automatically. constructor has been
defined inside class A.

myopt.isPresent() ? myopt.isPresent() ? Choice 2


Stream.of(new Stream.of(new
Value(myopt.get())) : Value(myopt.get())) :
Stream.close(); Stream.empty();

public class A{ Both Choice 1 and Choice 2 Both Choice 1 and choice 3 Choice 5
public int x;
private A() {
this.x = 2;
}
}

A FrameLoadEvent is fired A ContextRefreshEvent is Choice 2


fired
NullPointerException IndexOutOfBounds Choice 3
Exception

public class Test { public class Test { Choice 4


public static void public static void
main(String[] args) { main(String[] args) {
new SampleB(); new SampleA();
} }
} }

public boolean public boolean Choice 2


equals(Object sample) { equals(Object sample) {
return Sample that =
this.first.equals(that.getFirst (Sample)sample;
()) && return
this.second.equals(that.get this.first.equals(that.getSec
Second()); ond()) &&
} this.second.equals(that.get
First());
}

String inp = "sample"; String inp = "sample"; Choice 2


inp = "#" + inp = "%" +
inp.replaceAll("(.)","$1%") + inp.replaceAll("(.)","$1%");
“#”; System.out.println(inp);
System.out.println(inp);
public List<String> getList() public List<String> getList() Choice 4
{ {
return return
Collections.modifiableList(s Collections.unmodifiableList
ampleList); (sampleList);
} }

String.format("My %1$s is String.format("My %1s is Choice 1


%2$s", "Name") %1s", "Name")

Sample returnObject = getSample();


Both choice 1 and choice 2 Choice 1

if (returnObject extends Sample1 && !instanceOf Sample2) { .. }


else if (returnObject extends Sample2 && !instanceOf Sample1) { .. }

File f = new File(filePathString);FilePath f = new FilePath(filePathString); Choice 3


if(f.exists() && !f.isDirectory())if(f.exists()
{ && !f.isDirectory()) {
// implementation // implementation
} }
Universe doesn't declare Creating a Universe is likely Choice 3
that it implements Set<E> to cause an
OutOfMemoryError
because it will have to point
to all objects of type E

Runtime error Compile error Choice 1

static < E > void static < class E > void Choice 2
printArray( E[] arr ) { printArray( E[] arr ) {
for(element : arr) { for(E element : arr) {
System.out.printf("%s ", System.out.printf("%s ",
element); element);
} }
} }

public final class C{ public static class C{ Choice 2

private static String s1 private static String s1


private static String s2 private static String s2

public X(String s1, String public X(String s1, String


s2){ s2){

this.s1 = s1 this.s1 = s1
this.s2 = s2 this.s2 = s2
} }

public String f1(){ return public String f1(){ return


s1; } s1; }
public String f2(){ return public String f2(){ return
s2; } s2; }

} }
R is the incorrect reason but R is the incorrect Reason Choice 1
S is the correct Workaround and S is the incorrect
Workaround

Ashley Angelo Alice None of these Choice 4

executing... Choice 4
executing... executing...
executing... false

synchronized(monitor = Object.Monitor(mode = Choice 1


True, ObjectID){ Synchronized){
//processing resources //processing resources
} }
public class A{ public class A{ All of them Choice 3

{ //initialization block 1 public A(int x) {


}
{ //initialization block 1
{ //initialization block 2 }
}
{ //initialization block 2
public A(int x) { }
this.x = x;
} this.x = x;
} }

has-to }alongwith Choice 2

RequestLock() CheckLock() Choice 2

reader.max(comparingInt(St reader- Choice 2


ring::length)) .get(); >max(string::length(c));
try (Stream<Paths> paths = try (Stream<Path> paths = Choice 2
Files.walk(Path.get("/sampl Files.walk(Path.get("/sampl
e/SampleFolder"))) { e/SampleFolder"))) {
paths paths

.filter(Files::isRegularFile) .filter(Files::isRegularFile)

.forEach(System.out::println .forEach(System.out::println
); );
} }

Future<String> Array<Future<String>> Choice 2

T 1, 2 Both 1 & 2 Both 2 & 3 Choice 5


T 2, 2
T 1, 1
T 2, 1
Answer Description Reference link (if referred)

usage of getDeclared

casting charvalue after


increasing by 1

NA

checking array elements


from the stream and
converting back to string
array
NA

This is the usage of a http://www.baeldung.com/java-8-functional-interfaces


BiConsumer interface to
iterate through map values
as shown in Choice 1

NA https://docs.google.com/spreadsheets/d/1XcJYJeVU-gL4g3R_jaRLcqhxjs84PgR_Pp-foSBANTI/ed

NA
Java implicitly creates a
constructor when no
constructor is defined in a
class.

By design https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0a

Private constructors are not


instantiable

pg 1184 https://www.csie.ntu.edu.tw/~r93020/eBook/OReilly.Java.Swing.2nd.2002.pdf
NA https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html

new SampleA() creates an


object of SampleA which
creates an object of
SampleB which extends
SampleA

seperate conditions on
instances of both classes.
Checks for first instance
equals to first object and
likewise

NA
Na

NA

NA

NA
Choice 1: https://docs.oracle.com/javase/tutorial/java/IandI/usinginterface.html
Universe.contains does
satisfy the spec of
Set.contains
Choice 2: Universe is not
mutable. It has no mutator
Choice 3: Universe does
not declare that it
implements Set<E>, so
that would indeed keep it
from implementing the
interface correctly.
Choice 4: Universe
doesn't need to
when methods point
are to
static
every possible object.
runtime polymorphism does It
already
not work does what its
spec promises, without
knowing about any of the
actual objects in E.

NA

NA
NA

output would be like Ashley


weds Angelo weds Alice
since alice is added before
terminal collect to mylist

Due to lazy evaluation


compute is evaluated when
the function method gets
invoked

the synchronized code


block is often termed as a
monitor for resources.
Initialization blocks must be
defined before a
constructor.

NA https://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html

NA http://winterbe.com/posts/2015/04/30/java8-concurrency-tutorial-synchronized-locks-examples/

The code in choice 2 https://www.jfokus.se/jfokus16/preso/Lambdas-Streams--Beyond-the-Basics.pdf


accurately takes
comparingInt comparator
which is a specialized part
of the max function to
accurately find the longest
line length within a file
NA

By design http://www.baeldung.com/java-executor-service-tutorial

NA

Das könnte Ihnen auch gefallen