For more details on SUN Certifications, visit

Similar documents
Oracle 1Z Java Standard Edition 5 Programmer Certified Professional.

SUN. Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0

itexamdump 최고이자최신인 IT 인증시험덤프 일년무료업데이트서비스제공

Selected Questions from by Nageshwara Rao

Oracle 1z Java Standard Edition 5 Programmer Certified Professional Upgrade Exam. Practice Test. Version:

Exam : 1Z Title : Java Standard Edition 5 Programmer Certified Professional Upgrade Exam. Version : Demo

Chapter 11: Collections and Maps

ITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!

Training topic: OCPJP (Oracle certified professional Java programmer) or SCJP (Sun certified Java programmer) Content and Objectives

Module 4 - 异常和断言 一 选择题 :

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

Inheritance (Part 5) Odds and ends

The class Object. Lecture CS1122 Summer 2008

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

Introduction to Object-Oriented Programming

Polymorphism. return a.doublevalue() + b.doublevalue();

Domain-Driven Design Activity

WES-CS GROUP MEETING #9

Java Fundamentals (II)

PASS4TEST IT 인증시험덤프전문사이트

Ans: Store s as an expandable array of chars. (Double its size whenever we run out of space.) Cast the final array to a String.

SECTION-1 Q.1.Which two code fragments are most likely to cause a StackOverflowError? (Choose two.)

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline

Java Classes. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar

String temp [] = {"a", "b", "c"}; where temp[] is String array.

CLASS DESIGN. Objectives MODULE 4

CMSC 132: Object-Oriented Programming II. Effective Java. Department of Computer Science University of Maryland, College Park

Index COPYRIGHTED MATERIAL

C12a: The Object Superclass and Selected Methods

JAVA MOCK TEST JAVA MOCK TEST III

Lab5. Wooseok Kim

Points To Remember for SCJP

Java Collections. Wrapper classes. Wrapper classes

Java Collections. Engi Hafez Seliem

Operators and Expressions

Mutable and Immutable Objects

Exam Questions 1z0-853

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Exam : Title : Sun Certified Programmer for the Java 2 Platform.SE 5.0. Version : Demo

Testing Driven Development. Advanced Programming

Another IS-A Relationship

The Object Class. java.lang.object. Important Methods In Object. Mark Allen Weiss Copyright 2000

15CS45 : OBJECT ORIENTED CONCEPTS

Interfaces (1/2) An interface forms a contract between the object and the outside world.

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

LARA TECHNOLOGIES EXAM_SPECIALSIX SECTION-1

Goals for Today. CSE1030 Introduction to Computer Science II. CSE1030 Lecture #9. Review is-a versus has-a. Lecture #9 Inheritance I

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

CS 302 Week 9. Jim Williams

MIT AITI Lecture 18 Collections - Part 1

Answer: QUESTION: Answer:

Language Features. 1. The primitive types int, double, and boolean are part of the AP

Abstract Classes and Interfaces

Name Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

Class, Variable, Constructor, Object, Method Questions

CS 113 PRACTICE FINAL

Goals for Today. CSE1030 Introduction to Computer Science II. CSE1030 Lecture #4. Review: Methods / Code

Java and C# in Depth Carlo A. Furia, Marco Piccioni, Bertrand Meyer

Chapter 7 User-Defined Methods. Chapter Objectives

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

Subtype Polymorphism

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Final Exam Practice Questions

Vendor: Oracle. Exam Code: 1Z Exam Name: Java SE 8 Programmer. Version: Demo

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages

University of Palestine. Mid Exam Total Grade: 100

For more details on SUN Certifications, visit

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

A final method is a method which cannot be overridden by subclasses. A class that is declared final cannot be inherited.

Java Programming Training for Experienced Programmers (5 Days)

Operators. 3 Two-Minute Drill CERTIFICATION OBJECTIVES Q&A. Using Operators. Self Test

For this section, we will implement a class with only non-static features, that represents a rectangle

Super-Classes and sub-classes

Exam Part 3. Q.1) What is the output of the following code?

Interfaces. An interface forms a contract between the object and the outside world.

itexamdump 최고이자최신인 IT 인증시험덤프 일년무료업데이트서비스제공

Brief Summary of Java

JAVA WRAPPER CLASSES

20 Most Important Java Programming Interview Questions. Powered by

String is one of mostly used Object in Java. And this is the reason why String has unique handling in Java(String Pool). The String class represents

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

More about inheritance

CSC Java Programming, Fall Java Data Types and Control Constructs

Programming in the Large II: Objects and Classes (Part 1)

Inheritance. Notes Chapter 6 and AJ Chapters 7 and 8

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

interface MyAnno interface str( ) val( )

Canonical Form. No argument constructor Object Equality String representation Cloning Serialization Hashing. Software Engineering

Questions Answer Key Questions Answer Key Questions Answer Key

Oracle 1Z Java SE 8 Programmer I. Download Full Version :

Java Magistère BFA

Java Strings Java, winter semester

Operators. 3 Two-Minute Drill CERTIFICATION OBJECTIVES Q&A. Using Operators. Self Test

Full file at Chapter 2 - Inheritance and Exception Handling

Rules and syntax for inheritance. The boring stuff

Equality for Abstract Data Types

Transcription:

Java.lang Package For more details on SUN Certifications, visit http://sunjavasnips.blogspot.com/ Q:01 Given: public class Person { private String name, comment; private int age; public Person(String n, int a, String c) { name = n; age = a; comment = c; public boolean equals(object o) { if (! (o instanceof Person)) return false; Person p = (Person)o; return age == p.age && name.equals(p.name); What is the appropriate definition of the hashcode method in class Person? A. return super.hashcode(); B. return name.hashcode() + age * 7; C. return name.hashcode() + comment.hashcode() / 2; D. return name.hashcode() + comment.hashcode() / 2 - age * 3; B Q: 02 Given this method in a class: 21. public String tostring() { 22. StringBuffer buffer = new StringBuffer(); 23. buffer.append('<'); 24. buffer.append(this.name); 25. buffer.append('>'); 26. return buffer.tostring(); 27. Which statement is true? A. This code is NOT thread-safe. B. The programmer can replace StringBuffer with StringBuilder with no other changes. C. This code will perform poorly. For better performance, the code should be rewritten: return "<" + this.name + ">"; D. This code will perform well and converting the code to use StringBuilder will not enhance the performance. B Q: 03 Given: 11. public void testifa() { 12. if (testifb("true")) { 13. System.out.println("True"); 14. else { 15. System.out.println("Not true"); 16. 18. public Boolean testifb(string str) { 19. return Boolean.valueOf(str); 20. What is the result when method testifa is invoked? A. True B. Not true C. An exception is thrown at runtime.

D. Compilation fails because of an error at line 12. E. Compilation fails because of an error at line 19. A Q: 04 Given: 1. public class Boxer1{ 2. Integer i; 3. int x; 4. public Boxer1(int y) { 5. x = i+y; 6. System.out.println(x); 7. 8. public static void main(string[] args) { 9. new Boxer1(new Integer(4)); 10. 11. What is the result? A. The value "4" is printed at the command line. B. Compilation fails because of an error in line 5. C. Compilation fails because of an error in line 9. D. A NullPointerException occurs at runtime. E. A NumberFormatException occurs at runtime. F. An IllegalStateException occurs at runtime. D Q: 05 Given: 1. public class TestString3 { 2. public static void main(string[] args) { 3. // insert code here 5. System.out.println(s); 6. 7. Which two code fragments, inserted independently at line 3, generate the output 4247? (Choose two.) A. String s = "123456789"; s = (s-"123").replace(1,3,"24") - "89"; B. StringBuffer s = new StringBuffer("123456789"); s.delete(0,3).replace(1,3,"24").delete(4,6); C. StringBuffer s = new StringBuffer("123456789"); s.substring(3,6).delete(1,3).insert(1, "24"); D. StringBuilder s = new StringBuilder("123456789"); s.substring(3,6).delete(1,2).insert(1, "24"); E. StringBuilder s = new StringBuilder("123456789"); s.delete(0,3).delete(1,3).delete(2,5).insert(1, "24"); B, E Q: 06 Given: 11. public static void test(string str) { 12. int check = 4; 13. if (check = str.length()) { 14. System.out.print(str.charAt(check -= 1) +", "); 15. else { 16. System.out.print(str.charAt(0) + ", "); 18. and the invocation: 21. test("four"); 22. test("tee");

23. test("to"); What is the result? A. r, t, t, B. r, e, o, C. Compilation fails. D. An exception is thrown at runtime. C Q: 07 Given: 11. public class Person { 12. private String name; 13. public Person(String name) { 14. this.name = name; 15. 16. public boolean equals(object o) { 17. if (! o instanceof Person ) return false; 18. Person p = (Person) o; 19. return p.name.equals(this.name); 20. 21. Which statement is true? A. Compilation fails because the hashcode method is not overridden. B. A HashSet could contain multiple Person objects with the same name. C. All Person objects will have the same hash code because the hashcode method is not overridden. D. If a HashSet contains more than one Person object with name="fred", then removing another Person, also with name="fred", will remove them all. B Q: 08 Which two statements are true about the hashcode method? (Choose two.) A. The hashcode method for a given class can be used to test for object equality and object inequality for that class. B. The hashcode method is used by the java.util.sortedset collection class to order the elements within that set. C. The hashcode method for a given class can be used to test for object inequality, but NOT object equality, for that class. D. The only important characteristic of the values returned by a hashcode method is that the distribution of values must follow a Gaussian distribution. E. The hashcode method is used by the java.util.hashset collection class to group the elements within that set into hash buckets for swift retrieval. C, E Q: 09 Click the Task button.

1.<T extends Pet> 2. T 3.T 4.T Q: 10 Given: 10. public class MyClass { 11. 12. public Integer startingi; 13. public void methoda() { 14. Integer i = new Integer(25); 15. startingi = i; 16. methodb(i); 18. private void methodb(integer i2) { 19. i2 = i2.intvalue(); 20. 21. 22. If methoda is invoked, which two are true at line 20? (Choose two.) A. i2 == startingi returns true. B. i2 == startingi returns false. C. i2.equals(startingi) returns true. D. i2.equals(startingi) returns false. B, C Question: 11 Given: 11. public String makinstrings() { 12. String s = Fred ; 13. s = s + 47 ;

14. s = s.substring(2, 5); 15. s = s.touppercase(); 16. return s.tostring(); How many String objects will be created when this method is invoked? A. 1 B. 2 C. 3 D. 4 E. 5 F. 6 E 12. Which statements are true about comparing two instances of the same class, given that the equals() and hashcode() methods have been properly overridden? (Choose all that apply.) A. If the equals() method returns true, the hashcode() comparison == might return false. B. If the equals() method returns false, the hashcode() comparison == might return true. C. If the hashcode() comparison == returns true, the equals() method must return true. D. If the hashcode() comparison == returns true, the equals() method might return true. E. If the hashcode() comparison!= returns true, the equals() method might return true. - > B and D. B is true because often two dissimilar objects can return the same hashcode value. D is true because if the hashcode() comparison returns ==, the two objects might or might not be equal. -> A, C, and E are incorrect. C is incorrect because the hashcode() method is very flexible in its return values, and often two dissimilar objects can return the same hash code value. A and E are a negation of the hashcode() and equals() contract. 13. Given: 1. class Convert { 2. public static void main(string[] args) { 3. Long xl = new Long(456L); 4. long x1 = Long.valueOf("123"); 5. Long x2 = Long.valueOf("123"); 6. long x3 = xl.longvalue(); 7. Long x4 = xl.longvalue(); 8. Long x5 = Long.parseLong("456"); 9. long x6 = Long.parseLong("123"); 10. 11. Which will compile using Java 5, but will NOT compile using Java 1.4? (Choose all that apply.) A. Line 4. B. Line 5. C. Line 6. D. Line 7. E. Line 8. F. Line 9. -> A, D, and E are correct. Because of the methods return types, these method calls required autoboxing to compile. -> B, C, and F are incorrect based on the above.

14. Given: class TKO { public static void main(string[] args) { String s = "-"; Integer x = 343; long L343 = 343L; if(x.equals(l343)) s += ".e1 "; if(x.equals(343)) s += ".e2 "; Short s1 = (short)((new Short((short)343)) / (new Short((short)49))); if(s1 == 7) s += "=s "; if(s1 < new Integer(7+1)) s += "fly "; System.out.println(s); Which of the following will be included in the output String s? (Choose all that apply.) A..e1 B..e2 C. =s D. fly E. None of the above. F. Compilation fails. G. An exception is thrown at runtime. - > B, C, and D are correct. Remember, that the equals() method for the integer wrappers will only return true if the two primitive types and the two values are equal. With C, it's okay to unbox and use ==. For D, it's okay to create a wrapper object with an expression, and unbox it for comparison with a primitive. -> A, E, F, and G are incorrect based on the above. (Remember that A is using the equals() method to try to compare two different types.) 15. Which about the three java.lang classes String, StringBuilder, and StringBuffer are true? (Choose all that apply.) A. All three classes have a length() method. B. Objects of type StringBuffer are thread-safe. C. All three classes have overloaded append() methods. D. The "+" is an overloaded operator for all three classes. E. According to the API, StringBuffer will be faster than StringBuilder under most implementations. F. The value of an instance of any of these three types can be modified through various methods in the API. -> A and B are correct. -> C is incorrect because String does not have an "append" method. D is incorrect because only String objects can be operated on using the overloaded "+" operator. E is backwards, StringBuilder is typically faster because it's not thread-safe. F is incorrect because String objects are immutable. A String reference can be altered to refer to a different String object, but the objects themselves are immutable. 16. Given: class Polish { public static void main(string[] args) { int x = 4; StringBuffer sb = new StringBuffer("..fedcba"); sb.delete(3,6); sb.insert(3, "az"); if(sb.length() > 6) x = sb.indexof("b"); sb.delete((x-3), (x-2)); System.out.println(sb);

What is the result? A..faza B..fzba C...azba D..fazba E...fezba F. Compilation fails. G. An exception is thrown at runtime. -> C is correct. Remember that StringBuffer methods use zero-based indexes, and that ending indexes are typically exclusive. -> A, B, D, E, F, and G are incorrect based on the above. (Objective 3.1)