SlideShare a Scribd company logo
1 of 7
Java 7 NIIT
Page 1 of 7
JAVA7 Questions
1) Whichisan invalidstatement.
a. longa=123_456_ _789L;
b. longb=0XCAFE_BABE;
c. longc=123_456_789L;
d. longd=567.89L;
2) Switchstatementinjavawill notaccept_______ datatype.
a. String
b. Long
c. Enum
d. Char
3) Sam iss/w developerwhoisworkingforXYZtechnosolutions.Forvariousreasonshe needtoextend
a class fromanotherclasswhere he needall the initial valuesof the variablesinthe existingclass.How
can he getit.
a. Do nothingextrajustextendnew classfromexistingclass
b. Write hisownconstructor
c. Thisis notsupportedbyJava
d. Use Collectionsandgenerics
4) Abilitytorefertoan objectusingeitherit’sactual formor parentformiscalled
a. Inheritance
b. Polymorphism
c. Instantiation
d. Generalization
5) A. Defaultmemberscanbe accessedinsame andsub classesinsame as well asdifferentpackages.
B. Publicvariablescanbe accessedinsame and subclassesinsame but notdifferentpackages.
a. A istrue B istrue
b. A istrue B isfalse
c. A isfalse B is true
d. A isfalse B isfalse
6) Nonprivate fieldsof superclasscanbe declaredinsubclassandthe fieldscanbe hiddeninsubclass
a. True-Itsdue tothe inheritance feature supportedbyjava
b. True-Itscalledasfieldshadowing
c. True- Its calledasdata hiding(AbstractionandEncapsulation)
d. False-Notsupportedbyjava
7) A. Abstractclass cannotbe instantiated
B. A classextendinganabstractclassmay or may not override the methodsof the abstractclass.
Java 7 NIIT
Page 2 of 7
a. A istrue B istrue
b. A istrue B isfalse
c. A isfalse B istrue
d. A isfalse B isfalse
8) What is the outputof the followingcode snippet.
class static_out {
static int x;
static int y;
void add(int a , int b){
x = a + b;
y = x + b;
}
}
class static_use {
public static void main(String args[])
{
static_out obj1 = new static_out();
static_out obj2 = new static_out();
int a = 2;
obj1.add(a, a + 1);
obj2.add(5, a);
System.out.println(obj1.x + " " + obj2.y);
}
}
a) 7 7
b) 6 6
c) 7 9
d) 9 7
9) Find the output
1. class PersonalLoan{
2. public final String getName(){
3. return "personal loan";
4. }
5. }
6. class CheapPersonalLoan extends PersonalLoan{
7. @Override
8. public final String getName(){
9. return "cheap personal loan";
10. }
11. }
12.
a) Error at line2
b) Error at line6
c) Error at line8
d) Cheap personal loan
Java 7 NIIT
Page 3 of 7
10)
13. enum Color{
14. black,white,green,yellow;
15. }
16. public class EnumTest {
17. public static void main(String[] args){
i. for(Color bar: Color.values())
ii. System.out.println(bar.ordinal());
18. }
19. }
What will output when you compile and run the above java code?
(a)1 2 3 4
(b)0 1 2 3
(c)a b c d
(d)97 98 99 100
11)
1. import java.io.*;
2. class serialization {
3. public static void main(String[] args) {
4. try {
5. Myclass object1 = new Myclass("Hello", -7, 2.1e10);
6. FileOutputStream fos = new FileOutputStream("serial");
7. ObjectOutputStream oos = new ObjectOutputStream(fos);
8. oos.writeObject(object1);
9. oos.flush();
10. oos.close();
11. }
12. catch(Exception e) {
13. System.out.println("Serialization" + e);
14. System.exit(0);
15. }
16. try {
17. Myclass object2;
18. FileInputStream fis = new FileInputStream("serial");
19. ObjectInputStream ois = new ObjectInputStream(fis);
20. object2 = (Myclass)ois.readObject();
21. ois.close();
22. System.out.println(object2);
23. }
24. catch (Exception e) {
25. System.out.print("deserialization" + e);
26. System.exit(0);
27. }
28. }
29. }
30. class Myclass implements Serializable {
31. String s;
32. int i;
33. double d;
34. Myclass (String s, int i, double d){
Java 7 NIIT
Page 4 of 7
35. this.d = d;
36. this.i = i;
37. this.s = s;
38. }
39. }
40. @Override
41. public String toString() {
42. return "String tt" + gets() + "n"
43. + "int tt" + geti() + "n"
44. + "double " + getd();
45. }
a) String=Hello;int=-7;double=2.1E10
b) Hello;-7; 2.1E10
c) s; i; 2.1E10
d) Serialization
12)
1. public class MaximumTest
2. {
3. public static <T extends Comparable<T>> T maximum(T x, T y, T z)
4. {
5. T max = x
6. if ( y.compareTo( max ) > 0 ){
7. max = y; }
8. if ( z.compareTo( max ) > 0 ){
9. max = z;
10. }
11. return max
12. }
13. public static void main( String args[] )
14. {
15. System.out.printf( "Max of %d, %d and %d is %dnn",
16. 3, 4, 5, maximum( 3, 4, 5 ) );
17. System.out.printf( "Maxm of %.1f,%.1f and %.1f is %.1fnn",
18. 6.6, 8.8, 7.7, maximum( 6.6, 8.8, 7.7 ) );
19. System.out.printf( "Max of %s, %s and %s is %sn","pear",
20. "apple", "orange", maximum( "pear", "apple", "orange" ) );
21. }
22. }
a) Maximum of 3, 4 and 5 is 5
Maximum of 6.6, 8.8 and 7.7 is 8.8
Maximum of pear, apple and orange is pear
b) Error at line3
c) Error at line 6,8
d) Compiles successfullybutnooutput
13) A.StringBuildersare usedinsteadof Stringincase of frequentmodificationsrequiredandcanbe
usedinsynchronizedblocks/codes.
Java 7 NIIT
Page 5 of 7
B. StringBuffersare similartoStringBuildersexcepttheycannotbe usedinsynchronized
blocks/codes.
a. A istrue B istrue
b. A istrue B isfalse
c. A isfalse B istrue
d. A isfalse B isfalse
14) A.split() canparse stringusingmultiple delimiters.
B. StringTokenizercanparse Stringusingmultiple delimiters.
a. A istrue B istrue
b. A istrue B isfalse
c. A isfalse B istrue
d. A isfalse B isfalse
15) Findoutput.
1. public class Rex
2. {
3. public static void main( String args[] ){
4. String line = "This order was placed for QT3000! OK?";
5. String pattern = "(.*)(QT)(d+)(.*)";
6. Pattern r = Pattern.compile(pattern);
7. Matcher m = r.matcher(line);
8. if (m.find( )) {
9. System.out.println("Found value: " + m.group(0) );
10. System.out.println("Found value: " + m.group(1) );
11. System.out.println("Found value: " + m.group(2) );
12. System.out.println("Found value: " + m.group(3) );
13. System.out.println("Found value: " + m.group(4) );
14. } else {
15. System.out.println("NO MATCH");} }}
a) Will notcompile,erroratline 4,5
b) Foundvalue:Thisorderwas placedforQT3000! OK?
Foundvalue:Thisorderwas placedfor
Foundvalue:QT
Foundvalue:3000
Foundvalue:! OK?
c) Compilessuccessfullybutnooutput
d) Foundvalue:Thisorderwas placedfor
Foundvalue:QT
Foundvalue:3000
Foundvalue:! OK?
Foundvalue:
16) Findthe wrongchoice
Java 7 NIIT
Page 6 of 7
a) While usingatry withresource AutoCloseble interface neednotbe implemented,itsincluded
by defaut.
b) In a try withresource statementmultiple resourcescanbe opened.
c) Resourcesare closedinopposite orderof theirusage intrywithresource
d) Try withresourcesare mainlytoavoidlengthyfinallystatements.
17) Findthe rightchoice
a) In a try withresource statementif anexceptionoccursatthe time of resource creationthe
exceptionhandlerisexecuted.
b) In a try withresource statementif anexceptionoccursatthe time of closingthe resource the
program stopsabruptly.
c) In a try withresource statementif anexceptionoccursat the time of resource creationthe try
blockisexecuted.
d) In a try withresource statementif anexceptionoccursatthe time of closingthe resource the
exceptionisexecuted.
18) Findthe outputof the code snippetandassume there ismyf.txtfile inthe pathpppandfile myff.txt
isnot presentinthe path specifiedinpz.
1. Path ppp=Paths.get("D:Tempfoobarexamplecarmyf.txt");
2. Path pp = ppp.subpath (1, 5);
3. pz=Paths.get("D:Tempfoobarexamplecarmyff.txt");
4. System.out.format("Path %s exists: %b%n", p5,Files.exists(p5,
LinkOption.NOFOLLOW_LINKS));
5. Files.copy(ppp,pz,StandardCopyOption.REPLACE_EXISTING);
6. System.out.println("copied");
a)Error at line1
b)error at line4
c)error at line5
d)will copy the contents of myf.txt to myff.txt and will display the
output copied.
19) While programmingwiththreadsyourthreadneedtoreturnsome value.Forthatyouwill
a) ExtendThreadandoverride run()
b) ImplementRunnable andoverriderun()
c) ImplementCallable andoverriderun()
d) Not supportedbyjava
20) To submita workby a threadone shouldmake use of
a) ThreadClass
b) Runnable Inteface
c) ExecutorServiceClass
d) ResultSetclass
21) Robertiscreatinga java applicationIwhichcustomerdetailsneedtobe displayedfromthe
customerdatabase inSQL.Whichinterface shouldhe use toestablishconnectionbetweenthe SQL
database and the Javaapplication.
a) StatementInterface
b) ConnectionInterface
c) ResultsetInterface
Java 7 NIIT
Page 7 of 7
d) DriverInteface
22) What doesa DriverInterface in a JDBC programindicates
a) Loadsdriverfor a DB
b) RepresentsaDB server
c) ExecutesSQLStatement
d) RepresentsinformationretrievedfromaDB

More Related Content

What's hot

20190907 Julia the language for future
20190907 Julia the language for future20190907 Julia the language for future
20190907 Julia the language for future岳華 杜
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Baruch Sadogursky
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesGanesh Samarthyam
 
Metaprogramming in julia
Metaprogramming in juliaMetaprogramming in julia
Metaprogramming in julia岳華 杜
 
Jakarta Commons - Don't re-invent the wheel
Jakarta Commons - Don't re-invent the wheelJakarta Commons - Don't re-invent the wheel
Jakarta Commons - Don't re-invent the wheeltcurdt
 
The Ring programming language version 1.5.2 book - Part 76 of 181
The Ring programming language version 1.5.2 book - Part 76 of 181The Ring programming language version 1.5.2 book - Part 76 of 181
The Ring programming language version 1.5.2 book - Part 76 of 181Mahmoud Samir Fayed
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101Ankur Gupta
 
Concurrency Concepts in Java
Concurrency Concepts in JavaConcurrency Concepts in Java
Concurrency Concepts in JavaDoug Hawkins
 
The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212Mahmoud Samir Fayed
 
No dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldNo dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldtcurdt
 
Python Programming: Data Structure
Python Programming: Data StructurePython Programming: Data Structure
Python Programming: Data StructureChan Shik Lim
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Chih-Hsuan Kuo
 
Predictably
PredictablyPredictably
Predictablyztellman
 
Python opcodes
Python opcodesPython opcodes
Python opcodesalexgolec
 
Java 8 Puzzlers [as presented at OSCON 2016]
Java 8 Puzzlers [as presented at  OSCON 2016]Java 8 Puzzlers [as presented at  OSCON 2016]
Java 8 Puzzlers [as presented at OSCON 2016]Baruch Sadogursky
 
PyconKR 2018 Deep dive into Coroutine
PyconKR 2018 Deep dive into CoroutinePyconKR 2018 Deep dive into Coroutine
PyconKR 2018 Deep dive into CoroutineDaehee Kim
 
TCO in Python via bytecode manipulation.
TCO in Python via bytecode manipulation.TCO in Python via bytecode manipulation.
TCO in Python via bytecode manipulation.lnikolaeva
 
PVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesAndrey Karpov
 

What's hot (20)

20190907 Julia the language for future
20190907 Julia the language for future20190907 Julia the language for future
20190907 Julia the language for future
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java Bytecodes
 
Metaprogramming in julia
Metaprogramming in juliaMetaprogramming in julia
Metaprogramming in julia
 
Jakarta Commons - Don't re-invent the wheel
Jakarta Commons - Don't re-invent the wheelJakarta Commons - Don't re-invent the wheel
Jakarta Commons - Don't re-invent the wheel
 
The Ring programming language version 1.5.2 book - Part 76 of 181
The Ring programming language version 1.5.2 book - Part 76 of 181The Ring programming language version 1.5.2 book - Part 76 of 181
The Ring programming language version 1.5.2 book - Part 76 of 181
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101
 
Concurrency Concepts in Java
Concurrency Concepts in JavaConcurrency Concepts in Java
Concurrency Concepts in Java
 
The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212
 
Clang tidy
Clang tidyClang tidy
Clang tidy
 
No dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldNo dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real world
 
Python Programming: Data Structure
Python Programming: Data StructurePython Programming: Data Structure
Python Programming: Data Structure
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36
 
Predictably
PredictablyPredictably
Predictably
 
Python opcodes
Python opcodesPython opcodes
Python opcodes
 
Java 8 Puzzlers [as presented at OSCON 2016]
Java 8 Puzzlers [as presented at  OSCON 2016]Java 8 Puzzlers [as presented at  OSCON 2016]
Java 8 Puzzlers [as presented at OSCON 2016]
 
PyconKR 2018 Deep dive into Coroutine
PyconKR 2018 Deep dive into CoroutinePyconKR 2018 Deep dive into Coroutine
PyconKR 2018 Deep dive into Coroutine
 
TCO in Python via bytecode manipulation.
TCO in Python via bytecode manipulation.TCO in Python via bytecode manipulation.
TCO in Python via bytecode manipulation.
 
PVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error Examples
 

Similar to Java Questions

Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guidekrtioplal
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy PluginsPaul King
 
Java常见疑惑和陷阱
Java常见疑惑和陷阱Java常见疑惑和陷阱
Java常见疑惑和陷阱Ady Liu
 
Do we need Unsafe in Java?
Do we need Unsafe in Java?Do we need Unsafe in Java?
Do we need Unsafe in Java?Andrei Pangin
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Ayes Chinmay
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistAnton Arhipov
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paperfntsofttech
 
Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentalsKapish Joshi
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operatorsHarleen Sodhi
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfmayorothenguyenhob69
 
1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professionalIsabella789
 

Similar to Java Questions (20)

Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
 
Core java
Core javaCore java
Core java
 
Java常见疑惑和陷阱
Java常见疑惑和陷阱Java常见疑惑和陷阱
Java常见疑惑和陷阱
 
Java Language fundamental
Java Language fundamentalJava Language fundamental
Java Language fundamental
 
Do we need Unsafe in Java?
Do we need Unsafe in Java?Do we need Unsafe in Java?
Do we need Unsafe in Java?
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with Javassist
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
 
Revisão OCPJP7 - Class Design (parte 03)
Revisão OCPJP7 - Class Design (parte 03)Revisão OCPJP7 - Class Design (parte 03)
Revisão OCPJP7 - Class Design (parte 03)
 
Java
JavaJava
Java
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
 
Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentals
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Java file
Java fileJava file
Java file
 
Groovy Basics
Groovy BasicsGroovy Basics
Groovy Basics
 
1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional
 
Java puzzles
Java puzzlesJava puzzles
Java puzzles
 

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

Java Questions

  • 1. Java 7 NIIT Page 1 of 7 JAVA7 Questions 1) Whichisan invalidstatement. a. longa=123_456_ _789L; b. longb=0XCAFE_BABE; c. longc=123_456_789L; d. longd=567.89L; 2) Switchstatementinjavawill notaccept_______ datatype. a. String b. Long c. Enum d. Char 3) Sam iss/w developerwhoisworkingforXYZtechnosolutions.Forvariousreasonshe needtoextend a class fromanotherclasswhere he needall the initial valuesof the variablesinthe existingclass.How can he getit. a. Do nothingextrajustextendnew classfromexistingclass b. Write hisownconstructor c. Thisis notsupportedbyJava d. Use Collectionsandgenerics 4) Abilitytorefertoan objectusingeitherit’sactual formor parentformiscalled a. Inheritance b. Polymorphism c. Instantiation d. Generalization 5) A. Defaultmemberscanbe accessedinsame andsub classesinsame as well asdifferentpackages. B. Publicvariablescanbe accessedinsame and subclassesinsame but notdifferentpackages. a. A istrue B istrue b. A istrue B isfalse c. A isfalse B is true d. A isfalse B isfalse 6) Nonprivate fieldsof superclasscanbe declaredinsubclassandthe fieldscanbe hiddeninsubclass a. True-Itsdue tothe inheritance feature supportedbyjava b. True-Itscalledasfieldshadowing c. True- Its calledasdata hiding(AbstractionandEncapsulation) d. False-Notsupportedbyjava 7) A. Abstractclass cannotbe instantiated B. A classextendinganabstractclassmay or may not override the methodsof the abstractclass.
  • 2. Java 7 NIIT Page 2 of 7 a. A istrue B istrue b. A istrue B isfalse c. A isfalse B istrue d. A isfalse B isfalse 8) What is the outputof the followingcode snippet. class static_out { static int x; static int y; void add(int a , int b){ x = a + b; y = x + b; } } class static_use { public static void main(String args[]) { static_out obj1 = new static_out(); static_out obj2 = new static_out(); int a = 2; obj1.add(a, a + 1); obj2.add(5, a); System.out.println(obj1.x + " " + obj2.y); } } a) 7 7 b) 6 6 c) 7 9 d) 9 7 9) Find the output 1. class PersonalLoan{ 2. public final String getName(){ 3. return "personal loan"; 4. } 5. } 6. class CheapPersonalLoan extends PersonalLoan{ 7. @Override 8. public final String getName(){ 9. return "cheap personal loan"; 10. } 11. } 12. a) Error at line2 b) Error at line6 c) Error at line8 d) Cheap personal loan
  • 3. Java 7 NIIT Page 3 of 7 10) 13. enum Color{ 14. black,white,green,yellow; 15. } 16. public class EnumTest { 17. public static void main(String[] args){ i. for(Color bar: Color.values()) ii. System.out.println(bar.ordinal()); 18. } 19. } What will output when you compile and run the above java code? (a)1 2 3 4 (b)0 1 2 3 (c)a b c d (d)97 98 99 100 11) 1. import java.io.*; 2. class serialization { 3. public static void main(String[] args) { 4. try { 5. Myclass object1 = new Myclass("Hello", -7, 2.1e10); 6. FileOutputStream fos = new FileOutputStream("serial"); 7. ObjectOutputStream oos = new ObjectOutputStream(fos); 8. oos.writeObject(object1); 9. oos.flush(); 10. oos.close(); 11. } 12. catch(Exception e) { 13. System.out.println("Serialization" + e); 14. System.exit(0); 15. } 16. try { 17. Myclass object2; 18. FileInputStream fis = new FileInputStream("serial"); 19. ObjectInputStream ois = new ObjectInputStream(fis); 20. object2 = (Myclass)ois.readObject(); 21. ois.close(); 22. System.out.println(object2); 23. } 24. catch (Exception e) { 25. System.out.print("deserialization" + e); 26. System.exit(0); 27. } 28. } 29. } 30. class Myclass implements Serializable { 31. String s; 32. int i; 33. double d; 34. Myclass (String s, int i, double d){
  • 4. Java 7 NIIT Page 4 of 7 35. this.d = d; 36. this.i = i; 37. this.s = s; 38. } 39. } 40. @Override 41. public String toString() { 42. return "String tt" + gets() + "n" 43. + "int tt" + geti() + "n" 44. + "double " + getd(); 45. } a) String=Hello;int=-7;double=2.1E10 b) Hello;-7; 2.1E10 c) s; i; 2.1E10 d) Serialization 12) 1. public class MaximumTest 2. { 3. public static <T extends Comparable<T>> T maximum(T x, T y, T z) 4. { 5. T max = x 6. if ( y.compareTo( max ) > 0 ){ 7. max = y; } 8. if ( z.compareTo( max ) > 0 ){ 9. max = z; 10. } 11. return max 12. } 13. public static void main( String args[] ) 14. { 15. System.out.printf( "Max of %d, %d and %d is %dnn", 16. 3, 4, 5, maximum( 3, 4, 5 ) ); 17. System.out.printf( "Maxm of %.1f,%.1f and %.1f is %.1fnn", 18. 6.6, 8.8, 7.7, maximum( 6.6, 8.8, 7.7 ) ); 19. System.out.printf( "Max of %s, %s and %s is %sn","pear", 20. "apple", "orange", maximum( "pear", "apple", "orange" ) ); 21. } 22. } a) Maximum of 3, 4 and 5 is 5 Maximum of 6.6, 8.8 and 7.7 is 8.8 Maximum of pear, apple and orange is pear b) Error at line3 c) Error at line 6,8 d) Compiles successfullybutnooutput 13) A.StringBuildersare usedinsteadof Stringincase of frequentmodificationsrequiredandcanbe usedinsynchronizedblocks/codes.
  • 5. Java 7 NIIT Page 5 of 7 B. StringBuffersare similartoStringBuildersexcepttheycannotbe usedinsynchronized blocks/codes. a. A istrue B istrue b. A istrue B isfalse c. A isfalse B istrue d. A isfalse B isfalse 14) A.split() canparse stringusingmultiple delimiters. B. StringTokenizercanparse Stringusingmultiple delimiters. a. A istrue B istrue b. A istrue B isfalse c. A isfalse B istrue d. A isfalse B isfalse 15) Findoutput. 1. public class Rex 2. { 3. public static void main( String args[] ){ 4. String line = "This order was placed for QT3000! OK?"; 5. String pattern = "(.*)(QT)(d+)(.*)"; 6. Pattern r = Pattern.compile(pattern); 7. Matcher m = r.matcher(line); 8. if (m.find( )) { 9. System.out.println("Found value: " + m.group(0) ); 10. System.out.println("Found value: " + m.group(1) ); 11. System.out.println("Found value: " + m.group(2) ); 12. System.out.println("Found value: " + m.group(3) ); 13. System.out.println("Found value: " + m.group(4) ); 14. } else { 15. System.out.println("NO MATCH");} }} a) Will notcompile,erroratline 4,5 b) Foundvalue:Thisorderwas placedforQT3000! OK? Foundvalue:Thisorderwas placedfor Foundvalue:QT Foundvalue:3000 Foundvalue:! OK? c) Compilessuccessfullybutnooutput d) Foundvalue:Thisorderwas placedfor Foundvalue:QT Foundvalue:3000 Foundvalue:! OK? Foundvalue: 16) Findthe wrongchoice
  • 6. Java 7 NIIT Page 6 of 7 a) While usingatry withresource AutoCloseble interface neednotbe implemented,itsincluded by defaut. b) In a try withresource statementmultiple resourcescanbe opened. c) Resourcesare closedinopposite orderof theirusage intrywithresource d) Try withresourcesare mainlytoavoidlengthyfinallystatements. 17) Findthe rightchoice a) In a try withresource statementif anexceptionoccursatthe time of resource creationthe exceptionhandlerisexecuted. b) In a try withresource statementif anexceptionoccursatthe time of closingthe resource the program stopsabruptly. c) In a try withresource statementif anexceptionoccursat the time of resource creationthe try blockisexecuted. d) In a try withresource statementif anexceptionoccursatthe time of closingthe resource the exceptionisexecuted. 18) Findthe outputof the code snippetandassume there ismyf.txtfile inthe pathpppandfile myff.txt isnot presentinthe path specifiedinpz. 1. Path ppp=Paths.get("D:Tempfoobarexamplecarmyf.txt"); 2. Path pp = ppp.subpath (1, 5); 3. pz=Paths.get("D:Tempfoobarexamplecarmyff.txt"); 4. System.out.format("Path %s exists: %b%n", p5,Files.exists(p5, LinkOption.NOFOLLOW_LINKS)); 5. Files.copy(ppp,pz,StandardCopyOption.REPLACE_EXISTING); 6. System.out.println("copied"); a)Error at line1 b)error at line4 c)error at line5 d)will copy the contents of myf.txt to myff.txt and will display the output copied. 19) While programmingwiththreadsyourthreadneedtoreturnsome value.Forthatyouwill a) ExtendThreadandoverride run() b) ImplementRunnable andoverriderun() c) ImplementCallable andoverriderun() d) Not supportedbyjava 20) To submita workby a threadone shouldmake use of a) ThreadClass b) Runnable Inteface c) ExecutorServiceClass d) ResultSetclass 21) Robertiscreatinga java applicationIwhichcustomerdetailsneedtobe displayedfromthe customerdatabase inSQL.Whichinterface shouldhe use toestablishconnectionbetweenthe SQL database and the Javaapplication. a) StatementInterface b) ConnectionInterface c) ResultsetInterface
  • 7. Java 7 NIIT Page 7 of 7 d) DriverInteface 22) What doesa DriverInterface in a JDBC programindicates a) Loadsdriverfor a DB b) RepresentsaDB server c) ExecutesSQLStatement d) RepresentsinformationretrievedfromaDB