The document contains 12 code snippets with multiple choice questions about Java concepts like threads, collections, serialization, patterns, and more. For each code snippet, 4 possible outputs are provided to choose from as the answer. The correct answers are also provided with brief explanations.
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Udayan Khattry
Assess your preparation with these Practice Test Questions with Explanation. Questions are Extracted from Highest Rated Course on Udemy which has helped a lot of students to pass the exam with good score.
500+ multiple choice questions with explanation to assess Oracle Certified Associate, Java SE 8 Programmer II preparation.
Highest Rated course on UDEMY
Read the students success stories at:
https://udayankhattry.com/ocp/
Enroll now to receive maximum discount on the course ie. for just $9.99 or ₹640.00, click the link below- https://www.udemy.com/java-ocp/?couponCode=UDAYANKHATTRY.COM
To avail maximum discount on all courses visit: www.udayankhattry.com
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Udayan Khattry
Assess your preparation with these Practice Test Questions with Explanation. Questions are Extracted from Highest Rated Course on Udemy which has helped a lot of students to pass the exam with good score.
500+ multiple choice questions with explanation to assess Oracle Certified Associate, Java SE 8 Programmer II preparation.
Highest Rated course on UDEMY
Read the students success stories at:
https://udayankhattry.com/ocp/
Enroll now to receive maximum discount on the course ie. for just $9.99 or ₹640.00, click the link below- https://www.udemy.com/java-ocp/?couponCode=UDAYANKHATTRY.COM
To avail maximum discount on all courses visit: www.udayankhattry.com
SoCal Code Camp 2015: An introduction to Java 8Chaitanya Ganoo
Java 8 introduced cool new features such as Lambdas and Streams. We'll take a look at what they are how to use them effectively. We'll also walkthrough an example of a lightweight Java 8 service running in AWS cloud, which can read and index tweets into an ElasticSearch cluster
TDD, BDD, ATDD are all methodologies that enable incremental design that is suitable for Agile environments. It seems that every day a new xDD methodology is born with the promise to be better than what came before. Should you use behaviour-driven tests or plain old unit tests? Which methodology is better? And how exactly would it benefit the development life cycle?
In this session, Dror will help to sort out the various methodologies – explaining where they came from, the tools they use, and discussing how and when to use each one. Here we will once and for all answer the question as to whether or not there’s one “DD” to rule them all.
How difficult is to automatically test the HelloWorld.
We fix it and other many difficult scenarios with techniques like:
- lower "s" singleton
- law of demeter
- dependency injection
- and more examples
These slides contain an introduction to Symbolic execution and an introduction to KLEE.
I made this for a small demo/intro for my research group's meeting.
SoCal Code Camp 2015: An introduction to Java 8Chaitanya Ganoo
Java 8 introduced cool new features such as Lambdas and Streams. We'll take a look at what they are how to use them effectively. We'll also walkthrough an example of a lightweight Java 8 service running in AWS cloud, which can read and index tweets into an ElasticSearch cluster
TDD, BDD, ATDD are all methodologies that enable incremental design that is suitable for Agile environments. It seems that every day a new xDD methodology is born with the promise to be better than what came before. Should you use behaviour-driven tests or plain old unit tests? Which methodology is better? And how exactly would it benefit the development life cycle?
In this session, Dror will help to sort out the various methodologies – explaining where they came from, the tools they use, and discussing how and when to use each one. Here we will once and for all answer the question as to whether or not there’s one “DD” to rule them all.
How difficult is to automatically test the HelloWorld.
We fix it and other many difficult scenarios with techniques like:
- lower "s" singleton
- law of demeter
- dependency injection
- and more examples
These slides contain an introduction to Symbolic execution and an introduction to KLEE.
I made this for a small demo/intro for my research group's meeting.
تهدف الوحدة إلى عمل مشروع استرشادي يهدف إلى توثيق تاريخ كلية الآداب منذ نشأتها حتى الآن.عن طريق إعداد قاعدة بيانات تضم جميع ملفات الكلية بعد إخضاعها للعمليات الفنية من فهرسة وتصنيف وحفظها حفظا سليما. وقد انتهت الوحدة بالفعل من إعداد قاعدة البيانات وسيتم إدخال بيانات الملفات لاحقا.
تحت اشرافالدكتورة/ وفاء صادق الأستاذ المساعد بقسم المكتبات والوثائق والمعلومات شعبة الوثائق بإدارة وحدة الذاكرة الإلكترونية بتاريخ 30/10/2011.
E learning university social - content marketing - sam fiorellaSam Fiorella
Sam Fiorella from Sensei Marketing delivered this Webinar for eLearning University; discussing the opportunities in Social Search and Content Marketing for businesses.
Social sales influencemktg_samfiorella_april2014Sam Fiorella
Presentation made to 3M Frontline sales conference in Chicago.
Summary: Reverse engineering influence marketing strategies for improved social selling and measurement; social relationship management practices.
العرض الذى قدمته "وحدة الذاكرة الالكترونية " فى الاحتفال الذي اقامته كلية الآ...NADA SAMER
العرض الذى قدمته "وحدة الذاكرة الالكترونية " فى الاحتفال الذي اقامته كلية الآداب بجامعة القاهرة لشيخ المحققين وعمدة الأدباء واللغويين الأستاذ الدكتور / حسين نصار بمناسبة بلوغ سيادته سن التسعين .. متعه الله بالصحة و العافية
In this session you will learn:
Deep dive into coding OOP with Java… with practical examples.
How to create a class
How to create objects
How to create instance variables
How to create class variables
Constructors
For more information: https://www.mindsmapped.com/courses/software-development/become-a-java-developer-hands-on-training/
1z0 851 exam-java standard edition 6 programmer certified professionalIsabella789
Guaranteed success with updated troytec dumps for 1Z0-851 Exam-Java Standard Edition 6 Programmer Certified Professional visit@ https://www.troytec.com/1Z0-851-exams.html
Q3 GIVEN THE TREND EQUATION NO OF STUDENTS-3000+200 YEAR BASE: 2003-0
1.INTERPRET EQUATION RESULTS 2.FORECAST FOR 2020 3.WHEN WILL THE NO OF
STUDENTS REACH 6000
Solution
x no of years from 2003 y no of students y = 3000+200x 1) The regression
equation has a positive slope of 200 y intercept is 3000 i.e. no of students in the year 2000
Thus for every year 200 students increase 2) For 2020, x = 17, y = 3000+200(17) = 6400
3) When y =6000, 6000 = 3000+200x or x = 15 Hence in year 2018 students reach 6000
B Regression C D. All the above.
This comprehensive program covers essential aspects of performance marketing, growth strategies, and tactics, such as search engine optimization (SEO), pay-per-click (PPC) advertising, content marketing, social media marketing, and more
New Explore Careers and College Majors 2024.pdfDr. Mary Askew
Explore Careers and College Majors is a new online, interactive, self-guided career, major and college planning system.
The career system works on all devices!
For more Information, go to https://bit.ly/3SW5w8W
Want to move your career forward? Looking to build your leadership skills while helping others learn, grow, and improve their skills? Seeking someone who can guide you in achieving these goals?
You can accomplish this through a mentoring partnership. Learn more about the PMISSC Mentoring Program, where you’ll discover the incredible benefits of becoming a mentor or mentee. This program is designed to foster professional growth, enhance skills, and build a strong network within the project management community. Whether you're looking to share your expertise or seeking guidance to advance your career, the PMI Mentoring Program offers valuable opportunities for personal and professional development.
Watch this to learn:
* Overview of the PMISSC Mentoring Program: Mission, vision, and objectives.
* Benefits for Volunteer Mentors: Professional development, networking, personal satisfaction, and recognition.
* Advantages for Mentees: Career advancement, skill development, networking, and confidence building.
* Program Structure and Expectations: Mentor-mentee matching process, program phases, and time commitment.
* Success Stories and Testimonials: Inspiring examples from past participants.
* How to Get Involved: Steps to participate and resources available for support throughout the program.
Learn how you can make a difference in the project management community and take the next step in your professional journey.
About Hector Del Castillo
Hector is VP of Professional Development at the PMI Silver Spring Chapter, and CEO of Bold PM. He's a mid-market growth product executive and changemaker. He works with mid-market product-driven software executives to solve their biggest growth problems. He scales product growth, optimizes ops and builds loyal customers. He has reduced customer churn 33%, and boosted sales 47% for clients. He makes a significant impact by building and launching world-changing AI-powered products. If you're looking for an engaging and inspiring speaker to spark creativity and innovation within your organization, set up an appointment to discuss your specific needs and identify a suitable topic to inspire your audience at your next corporate conference, symposium, executive summit, or planning retreat.
About PMI Silver Spring Chapter
We are a branch of the Project Management Institute. We offer a platform for project management professionals in Silver Spring, MD, and the DC/Baltimore metro area. Monthly meetings facilitate networking, knowledge sharing, and professional development. For event details, visit pmissc.org.
The Impact of Artificial Intelligence on Modern Society.pdfssuser3e63fc
Just a game Assignment 3
1. What has made Louis Vuitton's business model successful in the Japanese luxury market?
2. What are the opportunities and challenges for Louis Vuitton in Japan?
3. What are the specifics of the Japanese fashion luxury market?
4. How did Louis Vuitton enter into the Japanese market originally? What were the other entry strategies it adopted later to strengthen its presence?
5. Will Louis Vuitton have any new challenges arise due to the global financial crisis? How does it overcome the new challenges?Assignment 3
1. What has made Louis Vuitton's business model successful in the Japanese luxury market?
2. What are the opportunities and challenges for Louis Vuitton in Japan?
3. What are the specifics of the Japanese fashion luxury market?
4. How did Louis Vuitton enter into the Japanese market originally? What were the other entry strategies it adopted later to strengthen its presence?
5. Will Louis Vuitton have any new challenges arise due to the global financial crisis? How does it overcome the new challenges?Assignment 3
1. What has made Louis Vuitton's business model successful in the Japanese luxury market?
2. What are the opportunities and challenges for Louis Vuitton in Japan?
3. What are the specifics of the Japanese fashion luxury market?
4. How did Louis Vuitton enter into the Japanese market originally? What were the other entry strategies it adopted later to strengthen its presence?
5. Will Louis Vuitton have any new challenges arise due to the global financial crisis? How does it overcome the new challenges?
1. Questions no -1 <br />What is the output for the below code ?<br />class A implements Runnable{<br />public void run(){<br />System.out.println(Thread.currentThread().getName());<br />} <br />}<br />public class Test {<br />public static void main(String... args) {<br />A a = new A();<br />Thread t = new Thread(a);<br />Thread t1 = new Thread(a);<br />t.setName(quot;
tquot;
);<br />t1.setName(quot;
t1quot;
);<br />t.setPriority(10);<br />t1.setPriority(-3);<br />t.start();<br />t1.start();<br />}<br />}<br />Options are A.t t1B.t1 tC.t tD.Compilation succeed but Runtime ExceptionAnswer :D is the correct answer. <br />Thread priorities are set using a positive integer, usually between 1 and 10. t1.setPriority(-3); throws java.lang.IllegalArgumentException. <br />Questions no -2 <br />What is the output for the below code ?<br />class A implements Runnable{<br />public void run(){<br />System.out.println(Thread.currentThread().getName());<br />} <br />}<br />1. public class Test {<br />2.public static void main(String... args) {<br />3.A a = new A();<br />4.Thread t = new Thread(a);<br />5.t.setName(quot;
goodquot;
);<br />6.t.start();<br />7.}<br />8. }<br />Options are A.goodB.nullC.Compilation fails with an error at line 5D.Compilation succeed but Runtime ExceptionAnswer :A is the correct answer. <br />Thread.currentThread().getName() return name of the current thread. <br />Questions no -3 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String[] args) {<br />Boolean expr = true;<br />if (expr) {<br />System.out.println(quot;
truequot;
);<br />} else {<br />System.out.println(quot;
falsequot;
);<br />}<br />}<br />}<br />options<br />A)true<br />B)Compile Error - can't use Boolean object in if().<br />C)false<br />D)Compile Properly but Runtime Exception.<br />Correct answer is : A<br />Explanations : In the if statement, condition can be Boolean object in jdk1.5 and jdk1.6.<br />In the previous version only boolean is allowed.<br />Questions no -4 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String[] args) {<br />List<Integer> list = new ArrayList<Integer>(); <br />list.add(0, 59);<br />int total = list.get(0);<br />System.out.println(total);<br />}<br />}<br />options<br />A)59<br />B)Compile time error, because you have to do int total = ((Integer)(list.get(0))).intValue();<br />C)Compile time error, because can't add primitive type in List.<br />D)Compile Properly but Runtime Exception.<br />Correct answer is : A<br />Explanations :Manual conversion between primitive types (such as an int) and wrapper classes <br />(such as Integer) is necessary when adding a primitive data type to a collection in jdk1.4 but<br />The new autoboxing/unboxing feature eliminates this manual conversion in jdk 1.5 and jdk 1.6.<br />Questions no -3 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String[] args) {<br />Integer i = null;<br />int j = i;<br />System.out.println(j);<br />}<br />}<br />options<br />A)0<br />B)Compile with error <br />C)null<br />D)NullPointerException<br />Correct answer is : D<br />Explanations :An Integer expression can have a null value. If your program tries to autounbox null, it will throw a NullPointerException.<br />Questions no -4 <br />What is the output for the below code ?<br />public class Outer {<br />private int a = 7;<br /> <br /> class Inner {<br /> public void displayValue() {<br /> System.out.println(quot;
Value of a is quot;
+ a);<br /> }<br /> }<br />}<br />public class Test {<br />public static void main(String... args) throws Exception {<br />Outer mo = new Outer(); <br /> Outer.Inner inner = mo.new Inner();<br /> inner.displayValue();<br />}<br />}<br />options<br />A)Value of a is 7<br />B)Compile Error - not able to access private member.<br />C)Runtime Exception<br />D)Value of a is 8<br />Correct answer is : A<br />Explanations : An inner class instance can never stand alone without a direct relationship to an instance of the outer class.<br />you can access the inner class is through a live instance of the outer class.<br />Inner class can access private member of the outer class.<br />Questions no -5 <br />What is the output for the below code ?<br />public class B {<br />public String getCountryName(){<br />return quot;
USAquot;
;<br />}<br />public StringBuffer getCountryName(){<br />StringBuffer sb = new StringBuffer();<br />sb.append(quot;
UKquot;
);<br />return sb;<br />}<br />public static void main(String[] args){<br />B b = new B();<br />System.out.println(b.getCountryName().toString());<br />}<br />}<br />options<br />A)Compile with error<br />B)USA<br />C)UK<br />D) Runtime Exception<br />Correct answer is : A<br />Explanations : You cannot have two methods in the same class with signatures that only differ by return type.<br />Questions no -6<br />What is the output for the below code ?<br />public class C {<br />}<br />public class D extends C{<br />}<br />public class A {<br />public C getOBJ(){<br />System.out.println(quot;
class A - return Cquot;
);<br />return new C();<br />}<br />}<br />public class B extends A{<br />public D getOBJ(){<br />System.out.println(quot;
class B - return Dquot;
);<br />return new D();<br />}<br />}<br />public class Test {<br />public static void main(String... args) {<br /> A a = new B();<br /> a.getOBJ();<br /> }<br />}<br />options<br />A)Compile with error - Not allowed to override the return type of a method with a subtype of the original type.<br />B)class A - return C<br />C)class B - return D<br />D) Runtime Exception<br />Correct answer is : C<br />Explanations : From J2SE 5.0 onwards. You are now allowed to override the return type of a method with a subtype of the original type.<br />Questions no -7<br />What is the output for the below code ?<br />public class A {<br />public String getName() throws ArrayIndexOutOfBoundsException{<br />return quot;
Name-Aquot;
;<br />}<br />}<br />public class C extends A{<br />public String getName() throws Exception{<br />return quot;
Name-Cquot;
;<br />}<br />}<br />public class Test {<br />public static void main(String... args) {<br />A a = new C();<br />a.getName();<br />}<br />}<br />options<br />A)Compile with error<br />B)Name-A<br />C)Name-C<br />D)Runtime Exception<br />Correct answer is : A<br />Explanations : Exception Exception is not compatible with throws clause in A.getName().<br />Overridden method should throw only same or sub class of the exception thrown by super class method.<br />Questions no -8 <br />What is the output for the below code ?<br />import java.util.regex.Matcher;<br />import java.util.regex.Pattern;<br />public class Test {<br />public static void main(String... args) {<br /> <br />Pattern p = Pattern.compile(quot;
a*bquot;
);<br />Matcher m = p.matcher(quot;
bquot;
);<br />boolean b = m.matches();<br />System.out.println(b);<br />}<br />}<br />options<br />A)true<br />B)Compile Error<br />C)false<br />D)b<br />Correct answer is : A<br />Explanations : a*b means quot;
aquot;
may present zero or more time and quot;
bquot;
should be present once.<br />Questions no -9 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br /> <br />String input = quot;
1 fish 2 fish red fish blue fishquot;
;<br />Scanner s = new Scanner(input).useDelimiter(quot;
s*fishs*quot;
);<br />System.out.println(s.nextInt());<br />System.out.println(s.nextInt());<br />System.out.println(s.next());<br />System.out.println(s.next());<br />s.close(); <br />}<br />}<br />options<br />A)1 2 red blue<br />B)Compile Error - because Scanner is not defind in java.<br />C)1 fish 2 fish red fish blue fish<br />D)1 fish 2 fish red blue fish<br />Correct answer is : A<br />Explanations : java.util.Scanner is a simple text scanner which can parse primitive types and strings using regular expressions.<br />Questions no -10 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br /> <br />Pattern p = Pattern.compile(quot;
a{3}b?c*quot;
);<br />Matcher m = p.matcher(quot;
aaabquot;
);<br />boolean b = m.matches();<br />System.out.println(b);<br />}<br />}<br />options<br />A)true<br />B)Compile Error <br />C)false<br />D)NullPointerException<br />Correct answer is : A<br />Explanations :<br />X? X, once or not at all <br />X* X, zero or more times <br />X+ X, one or more times <br />X{n} X, exactly n times <br />X{n,} X, at least n times <br />X{n,m} X, at least n but not more than m times<br />Questions no -11 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br /> <br />Pattern p = Pattern.compile(quot;
a{1,3}b?c*quot;
);<br />Matcher m = p.matcher(quot;
aaabquot;
);<br />boolean b = m.matches();<br />System.out.println(b);<br />}<br />}<br />options<br />A)true<br />B)Compile Error <br />C)false<br />D)NullPointerException<br />Correct answer is : A<br />Explanations :<br />X? X, once or not at all <br />X* X, zero or more times <br />X+ X, one or more times <br />X{n} X, exactly n times <br />X{n,} X, at least n times <br />X{n,m} X, at least n but not more than m times<br />Questions no -12 <br />What is the output for the below code ?<br />public class A {<br />public A() {<br /> System.out.println(quot;
Aquot;
);<br /> }<br />}<br />public class B extends A implements Serializable {<br />public B() {<br /> System.out.println(quot;
Bquot;
);<br /> }<br />}<br />public class Test {<br />public static void main(String... args) throws Exception {<br />B b = new B();<br /> <br /> ObjectOutputStream save = new ObjectOutputStream(new FileOutputStream(quot;
datafilequot;
));<br /> save.writeObject(b); <br /> save.flush(); <br /> <br /> ObjectInputStream restore = new ObjectInputStream(new FileInputStream(quot;
datafilequot;
));<br /> B z = (B) restore.readObject();<br /> <br />}<br />}<br />options<br />A)A B A<br />B)A B A B<br />C)B B<br />D)A B<br />Correct answer is : A<br />Explanations :On the time of deserialization , the Serializable object not create new object. So constructor of class B does not called. <br />A is not Serializable object so constructor is called.<br />Questions no -13 <br />What is the output for the below code ?<br />public class A {}<br />public class B implements Serializable {<br />A a = new A();<br />public static void main(String... args){<br />B b = new B();<br />try{<br />FileOutputStream fs = new FileOutputStream(quot;
b.serquot;
);<br />ObjectOutputStream os = new ObjectOutputStream(fs);<br />os.writeObject(b);<br />os.close();<br />}catch(Exception e){<br />e.printStackTrace();<br />}<br />}<br />}<br />options<br />A)Compilation Fail<br />B)java.io.NotSerializableException: Because class A is not Serializable.<br />C)Run properly<br />D)Compilation Fail : Because class A is not Serializable.<br />Correct answer is : B<br />Explanations :It throws java.io.NotSerializableException:A Because class A is not Serializable.<br />When JVM tries to serialize object B it will try to serialize A also because (A a = new A()) is instance variable of Class B.<br />So thows NotSerializableException.<br />Questions no -14 <br />What is the output for the below code running in the same JVM?<br />public class A implements Serializable {<br />transient int a = 7;<br /> static int b = 9;<br />}<br />public class B implements Serializable {<br />public static void main(String... args){<br />A a = new A();<br />try {<br /> ObjectOutputStream os = new ObjectOutputStream(<br /> new FileOutputStream(quot;
test.serquot;
));<br /> os.writeObject(a); <br /> os. close();<br /> System.out.print( + + a.b + quot;
quot;
);<br /> ObjectInputStream is = new ObjectInputStream(new FileInputStream(quot;
test.serquot;
));<br /> A s2 = (A)is.readObject();<br /> is.close();<br /> System.out.println(s2.a + quot;
quot;
+ s2.b);<br /> } catch (Exception x) <br /> {<br /> x.printStackTrace();<br /> }<br />}<br />}<br />options<br />A)9 0 9<br />B)9 7 9<br />C)0 0 0<br />D)0 7 0<br />Correct answer is : A<br />Explanations :transient variables are not serialized when an object is serialized.<br />In the case of static variable you can get the values in the same JVM. <br />Questions no -15 <br />What is the output for the below code ?<br />public enum Test {<br />BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19, 45);<br />private int hh;<br />private int mm;<br />Test(int hh, int mm) {<br />assert (hh >= 0 && hh <= 23) : quot;
Illegal hour.quot;
;<br />assert (mm >= 0 && mm <= 59) : quot;
Illegal mins.quot;
;<br />this.hh = hh;<br />this.mm = mm;<br />}<br />public int getHour() {<br />return hh;<br />}<br />public int getMins() {<br />return mm;<br />}<br />public static void main(String args[]){<br />Test t = new BREAKFAST;<br />System.out.println(t.getHour() +quot;
:quot;
+t.getMins());<br />}<br />}<br />options<br />A)7:30<br />B)Compile Error - an enum cannot be instantiated using the new operator.<br />C)12:50<br />D)19:45<br />Correct answer is : B<br />Explanations : As an enum cannot be instantiated using the new operator, the constructors cannot be called explicitly.<br />You have to do like <br />Test t = BREAKFAST;<br />Questions no -16 <br />What is the output for the below code ?<br />public class Test {<br />enum Day {<br />MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY<br />}<br />enum Month {<br />JAN, FEB<br />}<br />public static void main(String[] args) {<br />int[] freqArray = { 12, 34, 56, 23, 5, 13, 78 };<br />// Create a Map of frequencies<br />Map<Day, Integer> ordinaryMap = new HashMap<Day, Integer>();<br />for (Day day : Day.values()) {<br />ordinaryMap.put(day, freqArray[day.ordinal()]);<br />}<br />// Create an EnumMap of frequencies<br />EnumMap<Day, Integer> frequencyEnumMap = new EnumMap<Day, Integer>(ordinaryMap);<br />// Change some frequencies<br />frequencyEnumMap.put(null, 100);<br />System.out.println(quot;
Frequency EnumMap: quot;
+ frequencyEnumMap);<br />}<br />}<br />options<br />A)Frequency EnumMap: {MONDAY=12, TUESDAY=34, WEDNESDAY=56, THURSDAY=23, FRIDAY=5, SATURDAY=13, SUNDAY=78}<br />B)Compile Error <br />C)NullPointerException<br />D)Frequency EnumMap: {MONDAY=100, TUESDAY=34, WEDNESDAY=56, THURSDAY=23, FRIDAY=5, SATURDAY=13, SUNDAY=123}<br />Correct answer is : C<br />Explanations : The null reference as a key is NOT permitted.<br />Questions no -17 <br />public class EnumTypeDeclarations {<br />public void foo() {<br />enum SimpleMeal { <br />BREAKFAST, LUNCH, DINNER <br />}<br />}<br />}<br />Is the above code Compile without error ?<br />options<br />A)Compile without error<br />B)Compile with error<br />C)Compile without error but Runtime Exception<br />D)Compile without error but Enum Exception<br />Correct answer is : B<br />Explanations :<br />An enum declaration is a special kind of class declaration:<br />a) It can be declared at the top-level and as static enum declaration. <br />b) It is implicitly static, i.e. no outer object is associated with an enum constant. <br />c) It is implicitly final unless it contains constant-specific class bodies, but it can implement interfaces. <br />d) It cannot be declared abstract unless each abstract method is overridden in the constant-specific class body of every enum constant. <br />e) Local (inner) enum declaration is NOT OK! <br />Here in<br />public void foo() {<br />enum SimpleMeal { <br />BREAKFAST, LUNCH, DINNER <br />}<br />}<br />enum declaration is local within method so compile time error.<br />Questions no -18 <br />What is the output for the below code ?<br />public enum Test {<br />int t;<br />BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19, 45);<br />private int hh;<br />private int mm;<br />Test(int hh, int mm) {<br />assert (hh >= 0 && hh <= 23) : quot;
Illegal hour.quot;
;<br />assert (mm >= 0 && mm <= 59) : quot;
Illegal mins.quot;
;<br />this.hh = hh;<br />this.mm = mm;<br />}<br />public int getHour() {<br />return hh;<br />}<br />public int getMins() {<br />return mm;<br />}<br />public static void main(String args[]){<br />Test t = BREAKFAST;<br />System.out.println(t.getHour() +quot;
:quot;
+t.getMins());<br />}<br />}<br />options<br />A)7:30<br />B)Compile Error <br />C)12:15<br />D)19:45<br />Correct answer is : B<br />Explanations : The enum constants must be declared before any other declarations in an enum type.<br />In this case compile error because of declaration int t; before enum declaration.<br />Questions no -19 <br />What is the output for the below code ?<br />public class B extends Thread{<br />public static void main(String argv[]){<br />B b = new B();<br />b.run();<br />} <br />public void start(){<br />for (int i = 0; i < 10; i++){<br />System.out.println(quot;
Value of i = quot;
+ i); <br />} <br />}<br />}<br />options<br />A)A compile time error indicating that no run method is defined for the Thread class<br />B)A run time error indicating that no run method is defined for the Thread class<br />C)Clean compile and at run time the values 0 to 9 are printed out<br />D)Clean compile but no output at runtime<br />Correct answer is : D<br />Explanations : This is a bit of a sneaky one as I have swapped around the names of the methods you need to define and call when running a thread. If the for loop were defined in a method called public void run() and the call in the main method had been to b.start() The list of values from 0 to 9 would have been output.<br />Questions no -20 <br />What is the output for the below code ?<br />public class Test extends Thread{<br /> static String sName = quot;
goodquot;
;<br /> public static void main(String argv[]){<br /> Test t = new Test();<br /> t.nameTest(sName);<br /> System.out.println(sName);<br /> <br /> }<br /> public void nameTest(String sName){<br /> sName = sName + quot;
idea quot;
;<br /> start();<br /> }<br /> public void run(){<br /> <br /> for(int i=0;i < 4; i++){<br /> sName = sName + quot;
quot;
+ i;<br /> <br /> }<br /> }<br />}<br />options<br />A)good<br />B)good idea<br />C)good idea good idea<br />D)good 0 good 0 1<br />Correct answer is : A<br />Explanations : Change value in local methods wouldn’t change in global in case of String ( because String object is immutable).<br />Questions no -21 <br />What is the output for the below code ?<br />public class Test{<br />public static void main(String argv[]){<br />Test1 pm1 = new Test1(quot;
Onequot;
);<br />pm1.run();<br />Test1 pm2 = new Test1(quot;
Twoquot;
);<br />pm2.run();<br />}<br />}<br />class Test1 extends Thread{<br />private String sTname=quot;
quot;
;<br />Test1(String s){<br />sTname = s;<br />}<br />public void run(){<br />for(int i =0; i < 2 ; i++){<br />try{<br /> sleep(1000);<br />}catch(InterruptedException e){}<br />yield();<br />System.out.println(sTname);<br />}<br />}<br />}<br />options<br />A)Compile error<br />B)One One Two Two<br />C)One Two One Two<br />D)One Two<br />Correct answer is : B<br />Explanations : If you call the run method directly it just acts as any other method and does not return to the calling code until it has finished. executing<br />Questions no -22 <br />What is the output for the below code ?<br />public class Test extends Thread{<br /> public static void main(String argv[]){<br /> Test b = new Test();<br /> b.start();<br /> }<br /> public void run(){ <br /> System.out.println(quot;
Runningquot;
);<br /> }<br />}<br />options<br />A)Compilation clean and run but no output<br />B)Compilation and run with the output quot;
Runningquot;
<br />C)Compile time error with complaint of no Thread import<br />D)Compile time error with complaint of no access to Thread package<br />Correct answer is : B<br />Explanations :<br />The Thread class is part of the core java.lang package and does not need any explicit import statement.<br />Questions no -23 <br />What is the output for the below code ?<br />public class Tech {<br /> public void tech() {<br /> System.out.println(quot;
Techquot;
);<br /> }<br />}<br />public class Atech {<br />Tech a = new Tech() { <br /> public void tech() {<br /> System.out.println(quot;
anonymous techquot;
);<br /> }<br /> };<br /> <br /> public void dothis() {<br /> a.tech(); <br /> <br /> }<br />public static void main(String... args){<br />Atech atech = new Atech();<br />atech.dothis();<br />}<br />options<br />A)anonymous tech<br />B)Compile Error <br />C)Tech<br />D)anonymous tech Tech<br />Correct answer is : A<br />Explanations : This is anonymous subclass of the specified class type.<br />Anonymous inner class ( anonymous subclass ) overriden the Tech super class of tech() method.<br />Therefore Subclass method will get called.<br />Questions no -24 <br />What is the output for the below code ?<br />public class Outer {<br /> private String x = quot;
Outer variablequot;
;<br /> void doStuff() {<br /> String z = quot;
local variablequot;
;<br /> class Inner {<br /> public void seeOuter() {<br /> System.out.println(quot;
Outer x is quot;
+ x);<br /> System.out.println(quot;
Local variable z is quot;
+ z); <br /> } <br /> } <br /> } <br /> <br /> <br />}<br />options<br />A)Outer x is Outer variable.<br />B)Compile Error <br />C)Local variable z is local variable.<br />D)Outer x is Outer variable Local variable z is local variable<br />Correct answer is : B<br />Explanations : Cannot refer to a non-final variable z inside an inner class defined in a different method.<br />Questions no -25<br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br />for(int i = 2; i < 4; i++)<br /> for(int j = 2; j < 4; j++)<br /> assert i!=j : i; <br />}<br />}<br />options<br />A)The class compiles and runs, but does not print anything.<br />B)The number 2 gets printed with AssertionError<br />C)The number 3 gets printed with AssertionError<br />D)compile error<br />Correct answer is : B<br />Explanations : When i and j are both 2, assert condition is false, and AssertionError gets generated. <br />Questions no -26<br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br />for(int i = 2; i < 4; i++)<br /> for(int j = 2; j < 4; j++)<br />if(i < j)<br /> assert i!=j : i; <br />}<br />}<br />options<br />A)The class compiles and runs, but does not print anything.<br />B)The number 2 gets printed with AssertionError<br />C)The number 3 gets printed with AssertionError<br />D)compile error<br />Correct answer is : A<br />Explanations : When if condition returns true, the assert statement also returns true.<br />Hence AssertionError not generated.<br />Questions no -26 <br />What is the output for the below code ?<br />public class NameBean {<br />private String str;<br />NameBean(String str ){<br />this.str = str;<br />}<br />public String toString() {<br />return str;<br />}<br />}<br />import java.util.HashSet;<br />public class CollClient {<br />public static void main(String ... sss) {<br />HashSet myMap = new HashSet();<br />String s1 = new String(quot;
dasquot;
);<br />String s2 = new String(quot;
dasquot;
);<br />NameBean s3 = new NameBean(quot;
abcdefquot;
);<br />NameBean s4 = new NameBean(quot;
abcdefquot;
);<br />myMap.add(s1);<br />myMap.add(s2);<br />myMap.add(s3);<br />myMap.add(s4);<br />System.out.println(myMap);<br />}<br />}<br />options<br />A)das abcdef abcdef<br />B)das das abcdef abcdef<br />C)das abcdef<br />D)abcdef abcdef<br />Correct answer is : A<br />Explanations : Need to implement 'equals' and 'hashCode' methods to get unique Set for user defind objects(NameBean).<br />String object internally implements 'equals' and 'hashCode' methods therefore Set only stored one value.<br />Questions no -27 <br />Synchronized resizable-array implementation of the List interface is _____________?<br />options<br />A)Vector<br />B)ArrayList<br />C)Hashtable<br />D)HashMap<br />Correct answer is : A<br />Explanations : Vector implements List, RandomAccess - Synchronized resizable-array implementation of the List interface with additional quot;
legacy methods.quot;
<br />Questions no -28 <br />What is the output for the below code ?<br />public class Test {<br /> <br /> public static void main(String argv[]){<br /> <br /> ArrayList list = new ArrayList(); <br /> ArrayList<String> listStr = list; <br /> ArrayList<StringBuffer> listBuf = list; <br /> listStr.add(0, quot;
Helloquot;
); <br /> StringBuffer buff = listBuf.get(0); <br /> System.out.println(buff.toString());<br /> }<br />}<br />options<br />A)Hello<br />B)Compile error<br />C)java.lang.ClassCastException<br />D)null<br />Correct answer is : C<br />Explanations : java.lang.String cannot be cast to java.lang.StringBuffer at the code StringBuffer buff = listBuf.get(0); <br />So thows java.lang.ClassCastException.<br />Questions no -29 <br />What is the output for the below code ?<br />import java.util.LinkedList;<br />import java.util.Queue;<br />public class Test {<br />public static void main(String... args) {<br /> <br />Queue<String> q = new LinkedList<String>();<br /> q.add(quot;
newyorkquot;
);<br /> q.add(quot;
caquot;
);<br /> q.add(quot;
texasquot;
);<br /> show(q);<br /> }<br /> public static void show(Queue q) {<br /> q.add(new Integer(11));<br /> while (!q.isEmpty ( ) )<br /> System.out.print(q.poll() + quot;
quot;
);<br /> }<br />}<br />options<br />A)Compile error : Integer can't add<br />B)newyork ca texas 11<br />C)newyork ca texas<br />D)newyork ca <br />Correct answer is : B<br />Explanations : <br /> q was originally declared as Queue<String>, But in show() method it is passed as an untyped Queue. nothing in the compiler or JVM prevents us from adding an Integer after that.<br /> If the show method signature is public static void show(Queue<String> q) than you can't add Integer, Only String allowed. But public static void show(Queue q) is untyped Queue so you can add Integer.<br /> poll() Retrieves and removes the head of this queue, or returns null if this queue is empty.<br />Questions no -30 <br />What is the output for the below code ?<br />public interface TestInf {<br /> int i =10;<br />}<br />public class Test {<br />public static void main(String... args) {<br />TestInf.i=12;<br />System.out.println(TestInf.i);<br />}<br />}<br />options<br />A)Compile with error<br />B)10<br />C)12<br />D) Runtime Exception<br />Correct answer is : A<br />Explanations : All the variables declared in interface is Implicitly static and final , therefore can't change the value.<br />Questions no -31 <br />What is the output for the below code ?<br />public class Test {<br /> static { int a = 5; }<br /> public static void main(String[] args){<br /> System.out.println(a);<br /> }<br /> }<br />options<br />A)Compile with error<br />B)5<br />C)0<br />D) Runtime Exception<br />Correct answer is : A<br />Explanations : A variable declared in a static initialiser is not accessible outside its enclosing block.<br />Questions no -32 <br />What is the output for the below code ?<br />class A {<br /> { System.out.print(quot;
b1 quot;
); }<br /> public A() { System.out.print(quot;
b2 quot;
); }<br />}<br />class B extends A {<br /> static { System.out.print(quot;
r1 quot;
); }<br /> public B() { System.out.print(quot;
r2 quot;
); }<br /> { System.out.print(quot;
r3 quot;
); }<br /> static { System.out.print(quot;
r4 quot;
); }<br />}<br />class C extends B {<br /> public static void main(String[] args) {<br /> System.out.print(quot;
pre quot;
);<br /> new C();<br /> System.out.println(quot;
post quot;
);<br /> }<br />}<br />options<br />A)r1 r4 pre b1 b2 r3 r2 post<br />B)r1 r4 pre b1 b2 post<br />C)r1 r4 pre b1 b2 post r3 r2<br />D)pre r1 r4 b1 b2 r2 r3 post<br />Correct answer is : A<br />Explanations : All static blocks execute first then blocks and constructor. <br />Blocks and constructor executes (super class block then super class constructor, sub class block then sub class constructor).<br />Sequence for static blocks is super class first then sub class.<br />Sequence for blocks is super class first then sub class.<br />Questions no -33 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) throws Exception {<br />Integer i = 34;<br />int l = 34;<br />if(i.equals(l)){<br />System.out.println(true);<br />}else{<br />System.out.println(false);<br />}<br />}<br />}<br />options<br />A)true<br />B)false<br />C)Compile Error<br />D) Runtime Exception<br />Correct answer is : A<br />Explanations : equals() method for the integer wrappers will only return true if the two primitive types and the two values are equal.<br />Questions no -34 <br />Which statement is true about outer class?<br />options<br />A)outer class can only declare public , abstract and final<br />B)outer class may be private<br />C)outer class can't be abstract<br />D)outer class can be static<br />Correct answer is : A<br />Explanations : outer class can only declare public , abstract and final.<br />Questions no -35 <br />What is the output for the below code ?<br />static public class Test {<br />public static void main(String[] args) {<br /> char c = 'a';<br /> switch(c){<br /> case 65:<br /> System.out.println(quot;
onequot;
);break;<br /> case 'a':<br /> System.out.println(quot;
twoquot;
);break;<br /> case 3:<br /> System.out.println(quot;
threequot;
);<br />}<br />}<br />}<br />options<br />A)one<br />B)two<br />C)Compile error - char can't be permitted in switch statement <br />D)Compile error - Illegal modifier for the class Test; only public, abstract & final are permitted.<br />Correct answer is : D<br />Explanations : outer class can only declare public , abstract and final.<br />Illegal modifier for the class Test; only public, abstract & final are permitted<br />Questions no -36<br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br />ArrayList<Integer> list = new ArrayList<Integer>();<br />list.add(1);<br />list.add(2);<br />list.add(3);<br />for(int i:list)<br />System.out.println(i);<br />}<br />}<br />options<br />A)1 2 3<br />B)Compile error , can't add primitive type in ArrayList<br />C)Compile error on for(int i:list) , Incorrect Syntax<br />D)0 0 0<br />Correct answer is : A<br />Explanations : JDK 1.5, 1.6 allows add primitive type in ArrayList and for(int i:list) syntax is also correct.<br />for(int i:list) is same as <br />for(int i=0; i < list.size();i++){<br />int a = list.get(i);<br />}<br />Questions no -37 <br />What is the output for the below code ?<br />public class SuperClass {<br />public int doIt(String str, Integer... data)throws ArrayIndexOutOfBoundsException{<br />String signature = quot;
(String, Integer[])quot;
;<br />System.out.println(str + quot;
quot;
+ signature);<br />return 1;<br />}<br />}<br />public class SubClass extends SuperClass{<br />public int doIt(String str, Integer... data) throws Exception<br />{<br />String signature = quot;
(String, Integer[])quot;
;<br />System.out.println(quot;
Overridden: quot;
+ str + quot;
quot;
+ signature);<br />return 0;<br />}<br />public static void main(String... args)<br />{<br />SuperClass sb = new SubClass();<br />try{<br />sb.doIt(quot;
helloquot;
, 3);<br />}catch(Exception e){<br />}<br />}<br />}<br />options<br />A)Overridden: hello (String, Integer[])<br />B)hello (String, Integer[])<br />C)This code throws an Exception at Runtime<br />D)Compile with error<br />Correct answer is : D<br />Explanations : Exception Exception is not compatible with throws clause in SuperClass.doIt(String, Integer[]). <br />The same exception or subclass of that exception is allowed.<br />Questions no -38<br />What is the result of executing the following code, using the parameters 0 and 3 ?<br />public void divide(int a, int b) {<br />try {<br />int c = a / b;<br />} catch (Exception e) {<br />System.out.print(quot;
Exception quot;
);<br />} finally {<br />System.out.println(quot;
Finallyquot;
);<br />}<br />options<br />A)Prints out: Exception Finally<br />B)Prints out: Finally<br />C)Prints out: Exception<br />D)Compile with error<br />Correct answer is : B<br />Explanations : finally block always executed whether exception occurs or not. <br />0/3 = 0 Does not throws exception.<br />Questions no -39<br />Which of the below statement is true about Error?<br />options<br />A)An Error is a subclass of Throwable<br />B)An Error is a subclass of Exception<br />C)Error indicates serious problems that a reasonable application should not try to catch.<br />D)An Error is a subclass of IOException<br />Correct answer is : A and C<br />Explanations : An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.<br />Questions no -40<br />Which of the following is type of RuntimeException?<br />options<br />A)IOException<br />B)ArrayIndexOutOfBoundsException<br />C)Exception<br />D)Error<br />Correct answer is : B<br />Explanations : Below is the tree.<br />java.lang.Object<br /> java.lang.Throwable<br /> java.lang.Exception<br /> java.lang.RuntimeException<br /> java.lang.IndexOutOfBoundsException<br /> java.lang.ArrayIndexOutOfBoundsException<br />Questions no -41 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) throws Exception {<br /> File file = new File(quot;
test.txtquot;
); <br /> System.out.println(file.exists());<br /> FileWriter fw = new FileWriter(file); <br /> System.out.println(file.exists());<br />}<br />}<br />options<br />A)true true<br />B)false false<br />C)false true<br />D)true false<br />Correct answer is : C<br />Explanations :Creating a new instance of the class File, you're not yet making an actual file, you're just creating a filename.<br />So file.exists() return false.<br />FileWriter fw = new FileWriter(file) do three things:<br />It created a FileWriter reference variable fw.<br />It created a FileWriter object, and assigned it to fw.<br />It created an actual empty file out on the disk.<br />So file.exists() return true.<br />Questions no -42 <br />When comparing java.io.BufferedWriter and java.io.FileWriter, which capability exist as a method in only one of two ?<br />options<br />A)closing the stream<br />B)flushing the stream<br />C)writting to the stream<br />D)writting a line separator to the stream<br />Correct answer is : D<br />Explanations :A newLine() method is provided in BufferedWriter which is not in FileWriter.<br />Questions no -43 <br />What is the output for the below code ?<br />public class Test{<br />public static void main(String[] args) {<br /> int i1=1;<br /> switch(i1){<br /> case 1:<br /> System.out.println(quot;
onequot;
);<br /> case 2:<br /> System.out.println(quot;
twoquot;
);<br /> case 3:<br /> System.out.println(quot;
threequot;
);<br />}<br />}<br />}<br />options<br />A)one two three<br />B)one<br />C)one two<br />D)Compile error.<br />Correct answer is : A<br />Explanations : There is no break statement in case 1 so it causes the below case statements to execute regardless of their values.<br />Questions no -44 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String[] args) {<br /> char c = 'a';<br /> switch(c){<br /> case 65:<br /> System.out.println(quot;
onequot;
);break;<br /> case 'a':<br /> System.out.println(quot;
twoquot;
);break;<br /> case 3:<br /> System.out.println(quot;
threequot;
);<br />}<br />}<br />}<br />options<br />A)one two three<br />B)one<br />C)two<br />D)Compile error - char can't be in switch statement.<br />Correct answer is : C<br />Explanations : Compile properly and print two.<br />Questions no -45 <br />What is the output for the below code ?<br />import java.util.NavigableMap;<br />import java.util.concurrent.ConcurrentSkipListMap;<br />public class Test {<br />public static void main(String... args) {<br /> <br />NavigableMap <Integer, String>navMap = new <br /> ConcurrentSkipListMap<Integer, String>();<br />navMap.put(4, quot;
Aprilquot;
);<br />navMap.put(5, quot;
Mayquot;
);<br />navMap.put(6, quot;
Junequot;
);<br />navMap.put(1, quot;
Januaryquot;
);<br />navMap.put(2, quot;
Februaryquot;
);<br />navMap.put(3, quot;
Marchquot;
);<br /> navMap.pollFirstEntry();<br /> navMap.pollLastEntry();<br /> navMap.pollFirstEntry();<br /> System.out.println(navMap.size());<br /> <br />}<br />}<br />options<br />A)Compile error : No method name like pollFirstEntry() or pollLastEntry()<br />B)3<br />C)6<br />D)4<br />Correct answer is : B<br />Explanations : <br /> pollFirstEntry() Removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty.<br /> pollLastEntry() Removes and returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.<br />Questions no -46<br />What is the output for the below code ?<br />import java.util.NavigableMap;<br />import java.util.concurrent.ConcurrentSkipListMap;<br />public class Test {<br />public static void main(String... args) {<br /> <br />NavigableMap <Integer, String>navMap = new <br /> ConcurrentSkipListMap<Integer, String>();<br /> System.out.print(navMap.lastEntry());<br /> <br />}<br />}<br />options<br />A)Compile error : No method name like lastEntry()<br />B)null<br />C)NullPointerException<br />D)0<br />Correct answer is : B<br />Explanations : lastEntry() Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.<br />Questions no -47<br />What is the output for the below code ?<br />import java.util.NavigableMap;<br />import java.util.concurrent.ConcurrentSkipListMap;<br />public class Test {<br />public static void main(String... args) {<br /> <br />NavigableMap<Integer, String>navMap = new <br /> ConcurrentSkipListMap<Integer, String>();<br />navMap.put(4, quot;
Aprilquot;
);<br />navMap.put(5, quot;
Mayquot;
);<br />navMap.put(6, quot;
Junequot;
);<br />navMap.put(1, quot;
Januaryquot;
);<br />navMap.put(2, quot;
Februaryquot;
);<br /> System.out.print(navMap.ceilingKey(3));<br /> <br /> <br />}<br />}<br />options<br />A)Compile error : No method name like ceilingKey()<br />B)null<br />C)NullPointerException<br />D)4<br />Correct answer is : D<br />Explanations : Returns the least key greater than or equal to the given key, or null if there is no such key. <br />In the above case : 3 is not a key so return 4 (least key greater than or equal to the given key).<br />Questions no -48<br />What is the output for the below code ?<br />import java.util.NavigableMap;<br />import java.util.concurrent.ConcurrentSkipListMap;<br />public class Test {<br />public static void main(String... args) {<br /> <br />NavigableMap<Integer, String>navMap = new <br /> ConcurrentSkipListMap<Integer, String>();<br />navMap.put(4, quot;
Aprilquot;
);<br />navMap.put(5, quot;
Mayquot;
);<br />navMap.put(6, quot;
Junequot;
);<br />navMap.put(1, quot;
Januaryquot;
);<br />navMap.put(2, quot;
Februaryquot;
);<br /> System.out.print(navMap.floorKey(3));<br /> <br /> <br />}<br />}<br />options<br />A)Compile error : No method name like floorKey()<br />B)null<br />C)NullPointerException<br />D)2<br />Correct answer is : D<br />Explanations : Returns the greatest key less than or equal to the given key, or null if there is no such key. <br />In the above case : 3 is not a key so return 2 (greatest key less than or equal to the given key).<br />Questions no -49 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br /> <br /> List<Integer> lst = new ArrayList<Integer>();<br /> lst.add(34);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(5);<br /> <br /> NavigableSet<Integer> nvset = new TreeSet(lst);<br /> System.out.println(nvset.tailSet(6));<br /> <br />}<br />}<br />options<br />A)Compile error : No method name like tailSet()<br />B)6 34<br />C)5<br />D)5 6 34<br />Correct answer is : B<br />Explanations : tailSet(6) Returns elements are greater than or equal to 6.<br />Questions no -50 <br />What is the output for the below code ?<br />import java.util.ArrayList;<br />import java.util.List;<br />import java.util.NavigableSet;<br />import java.util.TreeSet;<br />public class Test {<br />public static void main(String... args) {<br /> <br />List<Integer> lst = new ArrayList<Integer>();<br /> lst.add(34);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(6);<br /> <br /> NavigableSet<Integer> nvset = new TreeSet(lst);<br /> nvset.pollFirst(); <br /> nvset.pollLast();<br /> System.out.println(nvset.size());<br /> <br />}<br />}<br />options<br />A)Compile error : No method name like pollFirst() or pollLast()<br />B)0<br />C)3<br />D)5<br />Correct answer is : B<br />Explanations : <br /> pollFirst() Retrieves and removes the first (lowest) element, or returns null if this set is empty.<br /> pollLast() Retrieves and removes the last (highest) element, or returns null if this set is empty.<br />Questions no -51<br />What is the output for the below code ?<br />import java.util.ArrayList;<br />import java.util.List;<br />import java.util.NavigableSet;<br />import java.util.TreeSet;<br />public class Test {<br />public static void main(String... args) {<br /> <br /> List<Integer> lst = new ArrayList<Integer>();<br /> lst.add(34);<br /> lst.add(6);<br /> lst.add(2);<br /> lst.add(8);<br /> lst.add(7);<br /> lst.add(10);<br /> <br /> NavigableSet<Integer> nvset = new TreeSet(lst);<br /> System.out.println(nvset.lower(6)+quot;
quot;
+nvset.higher(6)+ quot;
quot;
+ nvset.lower(2));<br /> <br />}<br />}<br />options<br />A)1 2 7 10 34 null<br />B)2 7 null<br />C)2 7 34<br />D)1 2 7 10 34<br />Correct answer is : B<br />Explanations : <br /> lower() Returns the greatest element in this set strictly less than the given element, or null if there is no such element.<br /> higher() Returns the least element in this set strictly greater than the given element, or null if there is no such element.<br />Questions no -52<br />What is the output for the below code ?<br />import java.util.ArrayList;<br />import java.util.Iterator;<br />import java.util.List;<br />import java.util.NavigableSet;<br />import java.util.TreeSet;<br />public class Test {<br />public static void main(String... args) {<br /> <br /> List<Integer> lst = new ArrayList<Integer>();<br /> lst.add(34);<br /> lst.add(6);<br /> lst.add(2);<br /> lst.add(8);<br /> lst.add(7);<br /> lst.add(10);<br /> <br /> NavigableSet<Integer> nvset = new TreeSet(lst);<br /> System.out.println(nvset.headSet(10));<br /> <br />}<br />}<br />options<br />A)Compile error : No method name like headSet()<br />B)2, 6, 7, 8, 10<br />C)2, 6, 7, 8<br />D)34<br />Correct answer is : C<br />Explanations : <br /> headSet(10) Returns the elements elements are strictly less than 10.<br /> headSet(10,false) Returns the elements elements are strictly less than 10.<br /> headSet(10,true) Returns the elements elements are strictly less than or equal to 10.<br />Questions no -53 <br />What is the output for the below code ?<br />import java.io.Console;<br />public class Test {<br />public static void main(String... args) {<br /> <br />Console con = System.console();<br /> boolean auth = false;<br /> <br /> if (con != null)<br /> {<br /> int count = 0;<br /> do<br /> {<br /> String uname = con.readLine(null);<br /> char[] pwd = con.readPassword(quot;
Enter %s's password: quot;
, uname);<br /> <br /> con.writer().write(quot;
quot;
); <br /> } while (!auth && ++count < 3);<br /> }<br /> <br />}<br />}<br />options<br />A)NullPointerException<br />B)It works properly<br />C)Compile Error : No readPassword() method in Console class.<br />D)null<br />Correct answer is : A<br />Explanations : passing a null argument to any method in Console class will cause a NullPointerException to be thrown.<br />