SlideShare a Scribd company logo
Quiz
A fun way to learn more!
With	contributions	from:	
• Manjunathan
• Vaibhav
• Ganesh
www.codeops.tech
Question	
What	query	language	does	Elasticsearch use?
A.	SQL	
B.	Query	DSL	
C.	Query	SSL	
D.	ElasticClient
Answer
What	query	language	does	Elasticsearch use?
A.	SQL	
B.	Query	DSL	
C.	Query	SSL	
D.	ElasticClient
Explanation
B.	Query	DSL	- Query	DSL	is	Elasticsearch’s
native	Query	Domain	Specific	Language	(DSL)
Question	
In	Elasticsearch,	which	filter	can	be	used	to	combine	
multiple	filters?	
A.	term	
B.	range	
C.	exists	
D.	bool
Answer
In	Elasticsearch,	which	filter	can	be	used	to	combine	
multiple	filters?	
A.	term	
B.	range	
C.	exists	
D.	bool
Explanation
D.	bool,	which	is	used	to	combine	multiple	
filters	using	must/should
Question	
In	Elasticsearch,	"Synonym"	is	an	example	of:	
A.	tokenizer
B.	analyzer
C.	token	filter	
D.	character	filter
Answer
In	Elasticsearch,	"Synonym"	is	an	example	of:	
A.	tokenizer
B.	analyzer
C.	token	filter	
D.	character	filter
Explanation
C.	Token	filter
Here	is	the	usage	of	“synonym”	to	filter	based	
on	“synonyms”	example:
Question	
What	will	be	the	behavior of	running:
java	-server	-client	HelloWorld
A. Error.	
B. It	will	run	in	the	server	mode
C. It	will	run	in	the	client	mode
D. Can't	guess!
Answer
What	will	be	the	behavior of	running:
java	-server	-client	HelloWorld
A. Error.	
B. It	will	run	in	the	server	mode
C. It	will	run	in	the	client	mode
D. Can't	guess!
Question	
How	are	lambda	expressions	translated	by	the	Java	
compiler	and	executed	by	the	JVM?	
A.	Lambda	expressions	are	translated	to	
anonymous	classes
B.	Compiler	translates	to	“invokedynamic”	method	
instruction
C.	Compiler	translates	to	“invokevirtual”	method	
instruction
D.	Compiler	translates	to	“invokestatic”	method	
instruction
Answer
How	are	lambda	expressions	translated	by	the	Java	
compiler	and	executed	by	the	JVM?	
A.	Lambda	expressions	are	translated	to	
anonymous	classes
B.	Compiler	translates	to	“invokedynamic”	method	
instruction
C.	Compiler	translates	to	“invokevirtual”	method	
instruction
D.	Compiler	translates	to	“invokestatic”	method	
instruction
Question	
Which	of	the	following	was	NOT	introduced	in	Java	
version	8?
A. Lambda	functions
B. Streams	API
C. invokedynamic method	instruction	
D. Joda library	as	date/time	API
Answer
Which	of	the	following	was	NOT	introduced	in	Java	
version	8?
A. Lambda	functions
B. Streams	API
C. invokedynamic method	instruction	
D. Joda library	as	date/time	API
Explanation
C.	invokedynamic method	instruction	
Lambda	functions,	streams	API,	and	Joda library	as	
date/time	API	were	introduced	in	Java	version	8.	
The	invokedynamic method	instruction	was	introduced	in	
Java	7.	
[When	functional	programming	support	was	added	in	the	
form	of	lambda	functions	was	added	in	Java	8,	the	
compiler	and	JVM	were	enhanced	to	use	invokedynamic
instruction.]
Question	
class Base	{}
class DeriOne extends Base	{}
class DeriTwo extends Base	{}
class ArrayStore {
public	static	void	main(String	[]args)	{
Base	[]	baseArr =	new DeriOne[3];
baseArr[0]	=	new DeriOne();
baseArr[2]	=	new DeriTwo();
System.out.println(baseArr.length);
}
}
A.	This	program	prints	the	following:	3
B.	This	program	prints	the	following:	2
C.	This	program	throws	an	ArrayStoreException
D.	This	program	throws	an	ArrayIndexOutOfBoundsException
Answer
class Base	{}
class DeriOne extends Base	{}
class DeriTwo extends Base	{}
class ArrayStore {
public	static	void	main(String	[]args)	{
Base	[]	baseArr =	new DeriOne[3];
baseArr[0]	=	new DeriOne();
baseArr[2]	=	new DeriTwo();
System.out.println(baseArr.length);
}
}
A.	This	program	prints	the	following:	3
B.	This	program	prints	the	following:	2
C.	This	program	throws	an	ArrayStoreException
D.	This	program	throws	an	ArrayIndexOutOfBoundsException
Explanation
C.	This	program	throws	an	ArrayStoreException
The	variable	baseArr	is	of	type	Base[]	,	and	it	points	to	
an	array	of	type	DeriOne.	
However,	in	the	statement	baseArr[2]	=	new	
DeriTwo(),	an	object	of	type	DeriTwo	is	assigned	to	
the	type	DeriOne,	which	does	not	share	a	parent-child	
inheritance	relationship-they	only	have	a	common	
parent,	which	is	Base.	Hence,	this	assignment	results	
in	an	ArrayStoreException.
Discussion:	What	is	the	best	practice	here?
Question	
import	java.util.*;	
class UtilitiesTest {
public static void main(String	[]args)	{
List<Integer>	intList =	new LinkedList<>();
List<Double>	dblList =	new LinkedList<>();
System.out.println(intList.getClass()	==	dblList.getClass());
}
}
A.	It	prints:	true
B.	It	prints:	false	
C.	It	results	in	a	compiler	error
D.	It	results	in	a	runtime	exception
Answer
import	java.util.*;	
class UtilitiesTest {
public static void main(String	[]args)	{
List<Integer>	intList =	new LinkedList<>();
List<Double>	dblList =	new LinkedList<>();
System.out.println(intList.getClass()	==	dblList.getClass());
}
}
A.	It	prints:	true
B.	It	prints:	false	
C.	It	results	in	a	compiler	error
D.	It	results	in	a	runtime	exception
Explanation
A.	It	prints:	true
Due	to	type	erasure,	after	compilation	both	types	are	
treated	as	same	LinkedList	type.
First	type:	class	java.util.LinkedList
Second	type:	class	java.util.LinkedList
Discussion:	What	is	the	best	practice	here?
Question	
Consider	the	following	program:
class AutoCloseableTest {
public static void main(String	[]args)	{
try (Scanner	consoleScanner =	new Scanner(System.in))	{
consoleScanner.close();	//	CLOSE
consoleScanner.close();
}
}
}
Which	one	of	the	following	statements	is	correct?
A.	This	program	terminates	normally	without	throwing	any	exceptions
B.	This	program	throws	an	IllegalStateException
C.	This	program	throws	an	IOException
D.	This	program	throws	an	AlreadyClosedException
E.	This	program	results	in	a	compiler	error	in	the	line	marked	with	the
comment	CLOSE
Answer
Consider	the	following	program:
class AutoCloseableTest {
public static void main(String	[]args)	{
try (Scanner	consoleScanner =	new Scanner(System.in))	{
consoleScanner.close();	//	CLOSE
consoleScanner.close();
}
}
}
Which	one	of	the	following	statements	is	correct?
A.	This	program	terminates	normally	without	throwing	any	exceptions
B.	This	program	throws	an	IllegalStateException
C.	This	program	throws	an	IOException
D.	This	program	throws	an	AlreadyClosedException
E.	This	program	results	in	a	compiler	error	in	the	line	marked	with	the
comment	CLOSE
Explanation
A	.	This	program	terminates	normally	without	throwing	any	
exceptions.	
The	try-with-resources	statement	internally	expands	to	call	the	
close()	method	in	the	finally	block.	If	the	resource	is	explicitly	
closed	in	the	try	block,	then	calling	close()
again	does	not	have	any	effect.	From	the	description	of	the	
close()	method	in	the	AutoCloseable interface:	“Closes	this	
stream	and	releases	any	system	resources	associated	with	it.	If	
the	stream	is	already	closed,	then	invoking	this	method	has	no	
effect.”
Discussion:	What	is	the	best	practice	here?
Question	
There	are	two	kinds	of	streams	in	the	java.io	package:	character	streams
(i.e.,	those	deriving	from	Reader	and	Writer	interfaces)	and	byte	streams	(i.e.,	
those	deriving	from	InputStream and	OutputStream).	Which	of	the	following	
statements	is	true	regarding	the	differences	between	these	two	kinds	of	
streams?
A.	In	character	streams,	data	is	handled	in	terms	of	bytes;	in	byte	streams,	data
is	handled	in	terms	of	Unicode	characters.
B.	Character	streams	are	suitable	for	reading	or	writing	to	files	such	as
executable	files,	image	files,	and	files	in	low-level	file	formats	such	as	.zip,
.class
C.	Byte	streams	are	suitable	for	reading	or	writing	to	text-based	I/O	such	as
documents	and	text,	XML,	and	HTML	files.
D.	Byte	streams	are	meant	for	handling	binary	data	that	is	not	human-readable;
character	streams	are	meant	for	human-readable	characters.
Answer
There	are	two	kinds	of	streams	in	the	java.io	package:	character	streams
(i.e.,	those	deriving	from	Reader	and	Writer	interfaces)	and	byte	streams	(i.e.,	
those	deriving	from	InputStream and	OutputStream).	Which	of	the	following	
statements	is	true	regarding	the	differences	between	these	two	kinds	of	streams?
A.	In	character	streams,	data	is	handled	in	terms	of	bytes;	in	byte	streams,	data
is	handled	in	terms	of	Unicode	characters.
B.	Character	streams	are	suitable	for	reading	or	writing	to	files	such	as
executable	files,	image	files,	and	files	in	low-level	file	formats	such	as	.zip,
.class
C.	Byte	streams	are	suitable	for	reading	or	writing	to	text-based	I/O	such	as
documents	and	text,	XML,	and	HTML	files.
D.	Byte	streams	are	meant	for	handling	binary	data	that	is	not	human-readable;
character	streams	are	meant	for	human-readable	characters.
Explanation
D	.	Byte	streams	are	meant	for	handling	binary	data	that	is	not	
human	readable;	character	streams	are	for	human-readable	
characters.
In	character	streams,	data	is	handled	in	terms	of	Unicode	
characters,	whereas	in	byte	streams,	data	is	handled	in	terms	of	
bytes.	Byte	streams	are	suitable	for	reading	or	writing	to	files	such	
as	executable	files,	image	files,	and	files	in	low-level	file	formats
such	as	.zip,	.class,	and	.jar.	Character	streams	are	suitable	for	
reading	or	writing	to	text-based	I/O	such	as	documents	and	text,	
XML,	and	HTML	files.
Discussion:	What	is	the	best	practice	here?
Question	
Which	one	of	the	following	options	is	best	suited	for	generating	random
numbers	in	a	multi-threaded	application?
A.	Using	java.lang.Math.random()
B.	Using	java.util.concurrent.ThreadLocalRandom
C.	Using	java.util.RandomAccess
D.	Using	java.lang.ThreadLocal<T>
Answer
Which	one	of	the	following	options	is	best	suited	for	generating	random
numbers	in	a	multi-threaded	application?
A.	Using	java.lang.Math.random()
B.	Using	java.util.concurrent.ThreadLocalRandom
C.	Using	java.util.RandomAccess
D.	Using	java.lang.ThreadLocal<T>
Explanation
b)	Using	java.util.concurrent.ThreadLocalRandom
java.lang.Math.random()	is	not	efficient	for	
concurrent	programs.	Using	ThreadLocalRandom
results	in	less	overhead	and	contention	when	
compared	to	using	Random	objects	in	concurrent	
programs	(and	hence	using	this	class	type	is
the	best	option	in	this	case).
java.util.RandomAccess is	unrelated	to	random	
number	generation.
ThreadLocal<T>	class	provides	support	for	creating	
thread-local	variables.
Discussion:	What	is	the	best	practice	here?
Question	
Consider	the	following	code	segment:
while(	(ch =	inputFile.read())	!=	VALUE)	{
outputFile.write(	(char)ch );
}
Assume	that	inputFile is	of	type	FileReader ,	and	outputFile is	of	type
FileWriter ,	and	ch is	of	type	int .	The	method	read()	returns	the	character
if	successful,	or	VALUE	if	the	end	of	the	stream	has	been	reached.	What	is	
the	correct	value	of	this	VALUE	checked	in	the	while	loop	for	end-of-stream?
A.		-1
B.	0
C.	255
D.	Integer.MAX_VALUE
E.	Integer.MIN_VALUE
Answer
Consider	the	following	code	segment:
while(	(ch =	inputFile.read())	!=	VALUE)	{
outputFile.write(	(char)ch );
}
Assume	that	inputFile is	of	type	FileReader ,	and	outputFile is	of	type
FileWriter ,	and	ch is	of	type	int .	The	method	read()	returns	the	character
if	successful,	or	VALUE	if	the	end	of	the	stream	has	been	reached.	What	is	
the	correct	value	of	this	VALUE	checked	in	the	while	loop	for	end-of-stream?
A.		-1
B.	0
C.	255
D.	Integer.MAX_VALUE
E.	Integer.MIN_VALUE
Explanation
A.		-1
The	read()	method	returns	the	value	-1	if	end-of-
stream	(EOS)	is	reached,	which	is	checked	in	this	while	
loop.
Discussion:	What	is	the	best	practice	here?
Question	
Consider	the	following	program	and	determine	the	output:
class Test	{
public void print(Integer i)	{
System.out.println("Integer");
}
public void print(int i)	{
System.out.println("int");
}
public void print(long i)	{
System.out.println("long");
}
public static void main(String	args[])	{
Test	test =	new Test();
test.print(10);
}
}
A.	The	program	results	in	a	compiler	error	(“ambiguous	overload”)
B.	long
C.	Integer
D.	int
Answer
Consider	the	following	program	and	determine	the	output:
class Test	{
public void print(Integer i)	{
System.out.println("Integer");
}
public void print(int i)	{
System.out.println("int");
}
public void print(long i)	{
System.out.println("long");
}
public static void main(String	args[])	{
Test	test =	new Test();
test.print(10);
}
}
A.	The	program	results	in	a	compiler	error	(“ambiguous	overload”)
B.	long
C.	Integer
D.	int
Explanation
D.	int
If	Integer	and	long	types	are	specified,	a	literal	will	
match	to	int.	So,	the	program	prints	int	.
Discussion:	What	is	the	best	practice	here?
Meetups
• JavaScript-Meetup-Bangalore
• Core-Java-Meetup-Bangalore
• Software	Architects	Bangalore
• Container-Developers-Meetup
• CloudOps-Meetup-Bangalore
• Software-Craftsmanship-Bangalore
• Mobile-App-Developers-Bangalore
• Bangalore-SDN-IoT-NetworkVirtualization-Enthusiasts
Upcoming	Bootcamps
• Docker	Hands-on	Bootcamp - Oct	15th
• AngularJS Bootcamp – Oct	22nd
• Modern	Software	Architecture – Nov	5th
• SOLID	Principles	&	Design	Patterns – Nov	19th
Please	visit	CodeOps.tech	 Upcomings section	for	
more	details	such	as	agenda/cost/trainer	and	
registration.
Use	FLAT750	
coupon	code	to	
get	Rs 750	
discount
www.codeops.tech

More Related Content

PDF
Natural Language Processing using Java
PDF
OCAJP 7 and OCPJP 7 certifications
PDF
Ocpjp book
PDF
Cracking OCPJP 7 exam
PDF
Coding Guidelines - Crafting Clean Code
PDF
OCP Java SE 8 Exam - Sample Questions - Exceptions and Assertions
PPTX
ElasticSearch Basics
ODP
Elasticsearch presentation 1
Natural Language Processing using Java
OCAJP 7 and OCPJP 7 certifications
Ocpjp book
Cracking OCPJP 7 exam
Coding Guidelines - Crafting Clean Code
OCP Java SE 8 Exam - Sample Questions - Exceptions and Assertions
ElasticSearch Basics
Elasticsearch presentation 1

More from Ganesh Samarthyam (20)

PDF
Wonders of the Sea
PDF
Animals - for kids
PDF
Applying Refactoring Tools in Practice
PDF
CFP - 1st Workshop on “AI Meets Blockchain”
PDF
Great Coding Skills Aren't Enough
PDF
College Project - Java Disassembler - Description
PDF
Design Patterns - Compiler Case Study - Hands-on Examples
PDF
Bangalore Container Conference 2017 - Brief Presentation
PDF
Bangalore Container Conference 2017 - Poster
PDF
Software Design in Practice (with Java examples)
PDF
OO Design and Design Patterns in C++
PDF
Bangalore Container Conference 2017 - Sponsorship Deck
PDF
Let's Go: Introduction to Google's Go Programming Language
PPT
Google's Go Programming Language - Introduction
PDF
Java Generics - Quiz Questions
PDF
Java Generics - by Example
PDF
Software Architecture - Quiz Questions
PDF
Docker by Example - Quiz
PDF
Advanced Debugging Using Java Bytecodes
PDF
Java Class Design
Wonders of the Sea
Animals - for kids
Applying Refactoring Tools in Practice
CFP - 1st Workshop on “AI Meets Blockchain”
Great Coding Skills Aren't Enough
College Project - Java Disassembler - Description
Design Patterns - Compiler Case Study - Hands-on Examples
Bangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Poster
Software Design in Practice (with Java examples)
OO Design and Design Patterns in C++
Bangalore Container Conference 2017 - Sponsorship Deck
Let's Go: Introduction to Google's Go Programming Language
Google's Go Programming Language - Introduction
Java Generics - Quiz Questions
Java Generics - by Example
Software Architecture - Quiz Questions
Docker by Example - Quiz
Advanced Debugging Using Java Bytecodes
Java Class Design
Ad

Recently uploaded (20)

PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPT
Introduction Database Management System for Course Database
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Introduction to Artificial Intelligence
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Introduction Database Management System for Course Database
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Reimagine Home Health with the Power of Agentic AI​
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Internet Downloader Manager (IDM) Crack 6.42 Build 41
How to Migrate SBCGlobal Email to Yahoo Easily
wealthsignaloriginal-com-DS-text-... (1).pdf
Digital Systems & Binary Numbers (comprehensive )
Introduction to Artificial Intelligence
Upgrade and Innovation Strategies for SAP ERP Customers
PTS Company Brochure 2025 (1).pdf.......
VVF-Customer-Presentation2025-Ver1.9.pptx
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Understanding Forklifts - TECH EHS Solution
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Ad

Core Java: Best practices and bytecodes quiz