SECTION-1 Q.1.Which two code fragments are most likely to cause a StackOverflowError? (Choose two.)
|
|
- Barnard Davis
- 6 years ago
- Views:
Transcription
1 SECTION-1 Q.1.Which two code fragments are most likely to cause a StackOverflowError? (Choose two.) A. int []x = 1,2,3,4,5; for(int y = 0; y < 6; y++) System.out.println(x[y]); B. staticint[] x = 7,6,5,4; static x[1] = 8; x[4] = 3; C. for(int y = 10; y < 10; y++) dostuff(y); D. voiddoone(int x) dotwo(x); voiddotwo(int y) dothree(y); voiddothree(int z) dotwo(z); E. for(int x = 0; x < ; x++) dostuff(x); F. void counter(inti) counter(++i); Page 1
2 Q class A public void process() System.out.print("A,"); class B extends A public void process() throwsioexception super.process(); 13. System.out.print("B,"); 14. thrownewioexception(); public static void main(string[] args) try new B().process(); catch (IOException e) System.out.println("Exception"); What is the result? A. Exception B. A,B,Exception C. Compilation fails because of an error in line 14. D. Compilation fails because of an error in line 10. E. A NullPointerException is thrown at runtime. Q public void go(int x) 12. assert (x > 0); Page 2
3 13. switch(x) 14. case 2: ; 15. default: assert false; private void go2(int x) assert (x < 0); Which statement is true? A. All of the assert statements are used appropriately. B. Only the assert statement on line 12 is used appropriately. C. Only the assert statement on line 15 is used appropriately. D. Only the assert statement on line 18 is used appropriately. E. Only the assert statements on lines 12 and 15 are used appropriately. F. Only the assert statements on lines 12 and 18 are used appropriately. G. Only the assert statements on lines 15 and 18 are used appropriately. Q.4 Given: public class Breaker2 static String o = ""; public static void main(string[] args) z: for(int x = 2; x < 7; x++) if(x==3) continue; if(x==5) break z; o = o + x; System.out.println(o); Page 3
4 A. 2 B. 24 C. 234 D. 246 E F. Compilation fails. Q.5. public static void main(string[] args) String str = "null"; if (str == null) System.out.println("null"); else (str.length() == 0) System.out.println("zero"); else System.out.println("some"); A. null B. zero C. some D. Compilation fails. E. An exception is thrown at runtime. Q.6. public class Test public static void main(string [] args) int x = 5; boolean b1 = true; boolean b2 = false; Page 4
5 if ((x == 4) &&!b2 ) System.out.print("1 "); System.out.print("2 "); if ((b2 = true) && b1 ) System.out.print("3 "); A. 2 B. 3 C. 1 2 D. 2 3 E F. Compilation fails. G. An exception is thrown at runtime. Q.7. static void test() throws Error if (true) thrownewassertionerror(); System.out.print("test "); public static void main(string[] args) try test(); catch (Exception ex) System.out.print("exception "); System.out.print("end "); A. end Page 5
6 B. Compilation fails. C. exception end D. exception test end E. A Throwable is thrown by main. F. An Exception is thrown by main. Q.8. public class Foo static int[] a; static a[0]=2; public static void main( String[] args ) Which exception or error will be thrown when a programmer attempts to run this code? A. java.lang.stackoverflowerror B. java.lang.illegalstateexception C. java.lang.exceptionininitializererror D. java.lang.arrayindexoutofboundsexception Q.9. public static void main(string[] args) for (int i = 0; i<= 10; i++) if (i> 6) break; System.out.println(i); Page 6
7 A. 6 B. 7 C. 10 D. 11 E. Compilation fails. F. An exception is thrown at runtime. Q static class A 12. void process() throws Exception throw new Exception(); static class B extends A 15. void process() System.out.println("B"); public static void main(string[] args) 18. new B().process(); 19. A. B B. The code runs with no output. C. Compilation fails because of an error in line 12. D. Compilation fails because of an error in line 15. E. Compilation fails because of an error in line 18. Q.11. public class Donkey public static void main(string[] args) boolean assertson = false; assert (assertson) : assertson = true; if(assertson) System.out.println("assert is on"); Page 7
8 If class Donkey is invoked twice, the first time without assertions enabled, and the second time with assertions enabled, what are the results? A. no output B. no output assert is on C. assert is on D. no output AnAssertionError is thrown. E. assert is on AnAssertionError is thrown. Q.12. Float pi = new Float(3.14f); if (pi > 3) System.out.print("pi is bigger than 3. "); else System.out.print("pi is not bigger than 3. "); finally System.out.println("Have a nice day."); A. Compilation fails. B. pi is bigger than 3. C. An exception occurs at runtime. D. pi is bigger than 3. Have a nice day. E. pi is not bigger than 3. Have a nice day. Q.13. public static void main(string[] args) try args = null; args[0] = "test"; System.out.println(args[0]); Page 8
9 catch (Exception ex) System.out.println("Exception"); catch (NullPointerException npe) System.out.println("NullPointerException"); A. test B. Exception C. Compilation fails. D. NullPointerException Q.14. public void go() String o = ""; z: for(int x = 0; x < 3; x++) for(int y = 0; y < 2; y++) if(x==1) break; if(x==2 && y==1) break z; o = o + x + y; System.out.println(o); What is the result when the go() method is invoked? A. 00 B C D Page 9
10 E. Compilation fails. F. An exception is thrown at runtime. Q.15. public class Test public enum Dogs collie, harrier ; public static void main(string [] args) Dogs mydog = Dogs.collie; switch (mydog) casecollie: System.out.print("collie "); caseharrier: System.out.print("harrier "); A. collie B. harrier C. Compilation fails. D. collie harrier E. An exception is thrown at runtime. Q public class Boxer1 2. Integer i; 3. int x; 4. public Boxer1(int y) 5. x = i+y; 6. System.out.println(x); 7. Page 10
11 8. public static void main(string[] args) 9. new Boxer1(new Integer(4)); 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. AnIllegalStateException occurs at runtime. Q static class A void process() throws Exception thrownew Exception(); static class B extends A void process() System.out.println("B"); public static void main(string[] args) new B().process(); 18. A. B B. The code runs with no output. C. Compilation fails because of an error in line 12. D. Compilation fails because of an error in line 15. E. Compilation fails because of an error in line Page 11
12 Q.18. public class Venus public static void main(string[] args) int [] x = 1,2,3; int y[] = 4,5,6; new Venus().go(x,y); void go(int[]... z) for(int[] a : z) System.out.print(a[0]); A. 1 B. 12 C. 14 D. 123 E. Compilation fails. F. An exception is thrown at runtime. Q.19. public class Foo staticint[] a; static a[0]=2; public static void main( String[] args ) Page 12
13 Which exception or error will be thrown when a programmer attempts to run this code? A. java.lang.stackoverflowerror B. java.lang.illegalstateexception C. java.lang.exceptionininitializererror D. java.lang.arrayindexoutofboundsexception Q class X public void foo() System.out.print("X "); public class SubBextends X publicvoid foo() throws RuntimeException super.foo(); 13. if (true) throw newruntimeexception(); 14. System.out.print("B "); public static void main(string[] args) new SubB().foo(); A. X, followed by an Exception. B. No output, and an Exception is thrown. C. Compilation fails due to an error on line 13. D. Compilation fails due to an error on line 18. E. Compilation fails due to an error on line Page 13
14 F. X, followed by an Exception, followed by B. SECTION-2 Q: public static void parse(string str) 12. try 13. float f = Float.parseFloat(str); 14. catch (NumberFormatExceptionnfe) 15. f = 0; 16. finally 17. System.out.println(f); public static void main(string[] args) 21. parse("invalid"); 22. A. 0.0 B. Compilation fails. C. A ParseException is thrown by the parse method at runtime. D. A NumberFormatException is thrown by the parse method at runtime. Q: try Page 14
15 85. ResourceConnection con = resourcefactory.getconnection(); 86. Results r = con.query("get INFO FROM CUSTOMER"); 87. info = r.getdata(); 88. con.close(); 89. catch (ResourceException re) 90. errorlog.write(re.getmessage()); return info; Which statement is true if a ResourceException is thrown on line 86? A. Line 92 will not execute. B. The connection will not be retrieved in line 85. C. The resource connection will not be closed on line 88. D. The enclosing method will throw an exception to its caller. Q: // some code here 32. try 33. // some code here 34. catch (SomeException se) 35. // some code here 36. finally 37. // some code here Page 15
16 Under which three circumstances will the code on line 37 be executed? (Choose three.) A. The instance gets garbage collected. B. The code on line 33 throws an exception. C. The code on line 35 throws an exception. D. The code on line 31 throws an exception. E. The code on line 33 executes successfully. Q: class A 12. public void process() System.out.print("A,"); 13. class B extends A 14. public void process() throws IOException 15. super.process(); 16. System.out.print("B,"); 17. throw new IOException(); public static void main(string[] args) 20. try new B().process(); 21. catch (IOException e) System.out.println("Exception"); A. Exception B. A,B,Exception C. Compilation fails because of an error in line Page 16
17 D. Compilation fails because of an error in line 14. E. A NullPointerException is thrown at runtime. Q: static void test() throws Error 12. if (true) throw new AssertionError(); 13. System.out.print("test "); public static void main(string[] args) 16. try test(); 17. catch (Exception ex) System.out.print("exception "); 18. System.out.print("end "); 19. A. end B. Compilation fails. C. exception end D. exception test end E. A Throwable is thrown by main. F. An Exception is thrown by main. Q: Float pi = new Float(3.14f); 12. if (pi > 3) Page 17
18 13. System.out.print("pi is bigger than 3. "); else 16. System.out.print("pi is not bigger than 3. "); finally 19. System.out.println("Have a nice day."); 20. A. Compilation fails. B. pi is bigger than 3. C. An exception occurs at runtime. D. pi is bigger than 3. Have a nice day. E. pi is not bigger than 3. Have a nice day. Q: public static void main(string[] args) 12. try 13. args = null; 14. args[0] = "test"; 15. System.out.println(args[0]); 16. catch (Exception ex) 17. System.out.println("Exception"); Page 18
19 18. catch (NullPointerExceptionnpe) 19. System.out.println("NullPointerException"); A. test B. Exception C. Compilation fails. D. NullPointerException Q:08. Given: 25. try 26. A a = new A(); 27. a.method1(); 28. catch (Exception e) 29. System.out.print("an error occurred"); 30. Which two statements are true if a NullPointerException is thrown on line 3 of class C? (Choose two.) Page 19
20 A. The application will crash. B. The code on line 29 will be executed. C. The code on line 5 of class A will execute. D. The code on line 5 of class B will execute. E. The exception will be propagated back to line 27. Q: static void test() throws RuntimeException 12. try 13. System.out.print("test "); 14. throw new RuntimeException(); catch (Exception ex) System.out.print("exception "); public static void main(string[] args) Page 20
21 19. try test(); 20. catch (RuntimeException ex) System.out.print("runtime "); 21. System.out.print("end "); 22. A. test end B. Compilation fails. C. test runtime end D. test exception end E. A Throwable is thrown by main at runtime. Q: try 34. // some code here 35. catch (NullPointerException e1) 36. System.out.print("a"); 37. catch (RuntimeException e2) 38. System.out.print("b"); 39. finally 40. System.out.print("c"); 41. What is the result if a NullPointerException occurs on line 34? A. c Page 21
22 B. a C. ab D. ac E. bc F. abc Q: public class Foo 11. staticint[] a; 12. static a[0]=2; 13. public static void main( String[] args ) 14. Which exception or error will be thrown when a programmer attempts to run this code? A. java.lang.stackoverflowerror B. java.lang.illegalstateexception C. java.lang.exceptionininitializererror D. java.lang.arrayindexoutofboundsexception Q: static void test() 12. try 13. String x = null; 14. System.out.print(x.toString() + " "); Page 22
23 16. finally System.out.print("finally "); public static void main(string[] args) 19. try test(); 20. catch (Exception ex) System.out.print("exception "); 21. A. null B. finally C. null finally D. Compilation fails. E. finally exception Q: public void method() 32. A a = new A(); 33. a.method1(); 34. Which statement is true if a TestException is thrown on line 3 of class B? Page 23
24 A. Line 33 must be called within a try block. B. The exception thrown by method1 in class A is not required to be caught. C. The method declared on line 31 must be declared to throw a RuntimeException. D. On line 5 of class A, the call to method2 of class B does not need to be placed in a try/catch block. Q: 14 Which statement is true about the two classes? Page 24
25 A. Compilation of both classes will fail. B. Compilation of both classes will succeed. C. Compilation of class A will fail. Compilation of class B will succeed. D. Compilation of class B will fail. Compilation of class A will succeed. Question: 15 class TestException 1. public class TestException extends Exception 2. class A: 1. public class A public String sayhello(string name) throws TestException if(name == null) 6. throw new TestException(); Page 25
26 return Hello + name; A programmer wants to use this code in an application: 45. A a=new A(); 46. System.out.println(a.sayHello( John )); Which two are true? (Choose two.) A. Class A will not compile. B. Line 46 can throw the unchecked exception TestException. C. Line 45 can throw the unchecked exception TestException. D. Line 46 will compile if the enclosing method throws a TestException. E. Line 46 will compile if enclosed in a try block, where TestException is caught. Question:16 11.classA 12. public void process() System.out.print( A ); 13. class B extends A 14. public void process() throws RuntimeException 15. super.process(); Page 26
27 16. if (true) throw new RuntimeException(); 17. System.out.print( B ); 18. public static void main(string[] args) 19. try ((A)new B()).process(); 20. catch (Exception e) System.out.print( Exception ); 21. A. Exception B. A Exception C. A Exception B D. A B Exception E. Compilation fails because of an error in line 14. F. Compilation fails because of an error in line 19. Q.17. import java.io.*; class Master String dofilestuff() throws FileNotFoundException return "a"; class Slave extends Master public static void main(string[] args) String s = null; try s = new Slave().doFileStuff(); Page 27
28 catch ( Exception x) s = "b"; System.out.println(s); // insert code here Which, inserted independently at // insert code here, will compile, and produce the output b? (Choose all that apply.) A. String dofilestuff() return "b"; B. String dofilestuff() throws IOException return "b"; C. String dofilestuff(int x) throws IOException return "b"; D. String dofilestuff() throws FileNotFoundException return "b"; E. String dofilestuff() throws NumberFormatException return "b"; F. String dofilestuff() throws NumberFormatException, FileNotFoundException return "b"; This method doesn t override, so the output is a. Q.18. class Input public static void main(string[] args) String s = "-"; try domath(args[0]); Page 28
29 s += "t "; // line 6 finally System.out.println(s += "f "); public static void domath(string a) int y = 7 / Integer.parseInt(a); And the command-line invocations: java Input java Input 0 Which are true? (Choose all that apply.) A. Line 6 is executed exactly 0 times. B. Line 6 is executed exactly 1 time. C. Line 6 is executed exactly 2 times. D. The finally block is executed exactly 0 times. E. The finally block is executed exactly 1 time. F. The finally block is executed exactly 2 times. G. Both invocations produce the same exceptions. H. Each invocation produces a different exception. Q.19. class Plane Page 29
30 static String s = "-"; public static void main(string[] args) new Plane().s1(); System.out.println(s); void s1() try s2(); catch (Exception e) s += "c"; void s2() throws Exception s3(); s += "2"; s3(); s += "2b"; void s3() throws Exception throw new Exception(); A. - B. -c C. -c2 D. -2c E. -c22b Page 30
31 F. -2c2b G. -2c2bc H. Compilation fails. Q.20. try int x = Integer.parseInt("two"); Which could be used to create an appropriate catch block? (Choose all that apply.) A. ClassCastException B. IllegalStateException C. NumberFormatException D. IllegalArgumentException E. ExceptionInInitializerError F. ArrayIndexOutOfBoundsException Q class Ping extends Utils 2. public static void main(string [] args) 3. Utils u = new Ping(); 4. System.out.print(u.getInt(args[0])); intgetint(string arg) 7. returninteger.parseint(arg); 8. Page 31
32 classutils 11. intgetint(string x) throws Exception return 7; 12. And the following three possible changes: C1. Declare that main() throws an Exception. C2. Declare that Ping.getInt() throws an Exception. C3. Wrap the invocation of getint() in a try / catch block. Which change(s) allow the code to compile? (Choose all that apply.) A. Just C1 is sufficient. B. Just C2 is sufficient. C. Just C3 is sufficient. D. Both C1 and C2 are required. E. Both C1 and C3 are required. F. Both C2 and C3 are required. G. All three changes are required. Q.22. class Emu static String s = "-"; public static void main(string[] args) try throw new Exception(); Page 32
33 catch (Exception e) try try throw new Exception(); catch (Exception ex) s += "ic "; throw new Exception(); catch (Exception x) s += "mc "; finally s += "mf "; finally s += "of "; System.out.println(s); A. -ic of B. -mf of C. -mc mf D. -ic mf of E. -ic mc mf of F. -ic mc of mf G. Compilation fails. Q.23. class Mineral class Gem extends Mineral Page 33
34 class Miner staticint x = 7; static String s = null; public static void getweight(mineral m) int y = 0 / x; System.out.print(s + " "); public static void main(string[] args) Mineral[] ma = new Mineral(), new Gem(); for(object o : ma) getweight((mineral) o); And the command-line invocation: java Miner.java A. null B. null null C. A ClassCastException is thrown. D. A NullPointerException is thrown. E. A NoClassDefFoundError is thrown. F. AnArithmeticException is thrown. Page 34
35 G. AnIllegalArgumentException is thrown. H. AnArrayIndexOutOfBoundsException is thrown. Q.24. Which are most typically thrown by an API developer or an application developer as opposed to being thrown by the JVM? (Choose all that apply.) A. ClassCastException B. IllegalStateException C. NumberFormatException D. IllegalArgumentException E. ExceptionInInitializerError Q: public class test SECTION-3 9. public static void main(string [] a) 10. asserta.length == 1; Which two will produce an AssertionError? (Choose two.) A. java test B. java -ea test C. java test file1 D. java -ea test file1 Page 35
36 E. java -ea test file1 file2 F. java -ea:test test file1 Q: 02 Given a method that must ensure that its parameter is not null: 11. public void somemethod(object value) 12. // check for null value System.out.println(value.getClass()); 21. What, inserted at line 12, is the appropriate way to handle a null value? A. assert value == null; B. assert value!= null, "value is null"; C. if (value == null) throw new AssertionException("value is null"); D. if (value == null) throw new IllegalArgumentException("value is null"); Q: int z = 5; public void stuff1(int x) Page 36
37 26. assert (x > 0); 27. switch(x) 28. case 2: x = 3; 29. default: assert false; private void stuff2(int y) assert (y < 0); private void stuff3() assert (stuff4()); privateboolean stuff4() z = 6; return false; Which statement is true? A. All of the assert statements are used appropriately. B. Only the assert statement on line 31 is used appropriately. C. The assert statements on lines 29 and 31 are used appropriately. D. The assert statements on lines 26 and 29 are used appropriately. E. The assert statements on lines 29 and 33 are used appropriately. F. The assert statements on lines 29, 31, and 33 are used appropriately. G. The assert statements on lines 26, 29, and 31 are used appropriately. Question: 04 Click the Exhibit button. 1. public class Test 2. Page 37
38 3. public static void main(string [] args) 4. boolean assert = true; 5. if(assert) 6. System.out.println( assert is true ); Given: javac -source 1.3 Test.java A. Compilation fails. B. Compilation succeeds with errors. C. Compilation succeeds with warnings. D. Compilation succeeds without warnings or errors. 05. Given two files: 1. class One 2. public static void main(string[] args) 3. int assert = 0; 4. Page 38
39 5. 1. class Two 2. public static void main(string[] args) 3. assert(false); And the four command-line invocations: javac -source 1.3 One.java javac -source 1.4 One.java javac -source 1.3 Two.java javac -source 1.4 Two.java (Choose all that apply.) A. Only one compilation will succeed. B. Exactly two compilations will succeed. C. Exactly three compilations will succeed. D. All four compilations will succeed. E. No compiler warnings will be produced. F. At least one compiler warning will be produced. Q.06. Which are true? (Choose all that apply.) A. It is appropriate to use assertions to validate arguments to methods marked public. Page 39
40 B. It is appropriate to catch and handle assertion errors. C. It is NOT appropriate to use assertions to validate command-line arguments. D. It is appropriate to use assertions to generate alerts when you reach code that should notbe reachable. E. It is NOT appropriate for assertions to change a program s state. Page 40
For more details on SUN Certifications, visit
Exception Handling For more details on SUN Certifications, visit http://sunjavasnips.blogspot.com/ Q: 01 Given: 11. public static void parse(string str) { 12. try { 13. float f = Float.parseFloat(str);
More informationModule 4 - 异常和断言 一 选择题 :
一 选择题 : Question 1 Click the Exhibit button. 10. public class ClassA { 11. public void methoda() { 12. ClassB classb = new ClassB(); 13. classb.getvalue(); 14. } 15. } And: 20. class ClassB { 21. public
More informationRZQ 12/19/2008 Page 1 of 11
Q: 121 Given: 10. class Nav{ 11. public enum Direction { NORTH, SOUTH, EAST, WEST } 12. } 13. public class Sprite{ 14. // insert code here Which code, inserted at line 14, allows the Sprite class to compile?
More informationLara Technologies Special-Six Test
Flow control Part-1 Q: 01 Given: 10. public class Bar 11. static void foo( int... x ) 12. // insert code here 13. 14. Which two code fragments, inserted independently at line 12, will allow the class to
More informationPASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year
PASS4TEST IT Certification Guaranteed, The Easy Way! \ We offer free update service for one year Exam : 310-055 Title : Sun Certified Programmer for the Java 2 Platform.SE 5.0 Vendors : SUN Version : DEMO
More informationExam Questions 1z0-853
Exam Questions 1z0-853 Java Standard Edition 5 Programmer Certified Professional Exam https://www.2passeasy.com/dumps/1z0-853/ 1.Given: 10. class One { 11. void foo() { } 12. } 13. class Two extends One
More informationAnswer: QUESTION: Answer:
}; B. new Thread() { public void start() { dostuff(); } }; C. new Thread() { public void start() { dostuff(); } }.run(); D. new Thread() { public void run() { dostuff(); } }.start(); E. new Thread(new
More informationAnswer: ABD 2. Answer: BD 3
1. Given 11. public interface Status { 12. /* insert code here */ int MY_VALUE = 10; 13. } Which three are valid on line 12? (Choose three.) A. final B. static C. native D. public E. private F. abstract
More information1.Which four options describe the correct default values for array elements of the types indicated?
1.Which four options describe the correct default values for array elements of the types indicated? 1. int -> 0 2. String -> "null" 3. Dog -> null 4. char -> '\u0000' 5. float -> 0.0f 6. boolean -> true
More informationMore on Exception Handling
Chapter 18 More on Exception Handling Lecture slides for: Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2
More informationExam : Title : Sun Certified Programmer for the Java 2 Platform.SE 5.0. Version : Demo
Exam : 310-055 Title : Sun Certified Programmer for the Java 2 Platform.SE 5.0 Version : Demo 1.Given: 10. class One { 11. void foo() {} 12. } 13. class Two extends One { 14. //insert method here 15. }
More informationMore on Exception Handling
Chapter 18 More on Exception Handling Lecture slides for: Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2
More informationSoal Code A Q: 1 Given: D. The set variable contains only three elements from the coll collection, but the order is NOT guaranteed to be. preserved.
Q: 1 Given: 11. public class Person 12. private String name, comment; 13. private int age; 14. public Person(String n, int a, String c) 15. name = n; age = a; comment = c; 16. 17. public boolean equals(object
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Version of February 23, 2013 Abstract Handling errors Declaring, creating and handling exceptions
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Version of February 23, 2013 Abstract Handling errors Declaring, creating and handling exceptions
More informationExceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws
Lecture 14 Summary Exceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws 1 By the end of this lecture, you will be able to differentiate between errors, exceptions,
More informationCOE318 Lecture Notes Week 10 (Nov 7, 2011)
COE318 Software Systems Lecture Notes: Week 10 1 of 5 COE318 Lecture Notes Week 10 (Nov 7, 2011) Topics More about exceptions References Head First Java: Chapter 11 (Risky Behavior) The Java Tutorial:
More informationIf you like our services please help us in 2 ways.
This Download is from www.downloadmela.com. The main motto of this website is to provide free download links of ebooks,video tutorials,magazines,previous papers,interview related content. To download more
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions and
More informationLecture 14 Summary 3/9/2009. By the end of this lecture, you will be able to differentiate between errors, exceptions, and runtime exceptions.
Lecture 14 Summary Exceptions vs. Errors Exceptions vs. RuntimeExceptions...catch...finally throw and throws By the end of this lecture, you will be able to differentiate between errors, exceptions, and
More informationChapter 9. Exception Handling. Copyright 2016 Pearson Inc. All rights reserved.
Chapter 9 Exception Handling Copyright 2016 Pearson Inc. All rights reserved. Last modified 2015-10-02 by C Hoang 9-2 Introduction to Exception Handling Sometimes the best outcome can be when nothing unusual
More informationFull file at Chapter 2 - Inheritance and Exception Handling
Chapter 2 - Inheritance and Exception Handling TRUE/FALSE 1. The superclass inherits all its properties from the subclass. ANS: F PTS: 1 REF: 76 2. Private members of a superclass can be accessed by a
More informationOracle 1z Java Standard Edition 5 Programmer Certified Professional Upgrade Exam. Practice Test. Version: https://certkill.
Oracle 1z0-854 Java Standard Edition 5 Programmer Certified Professional Upgrade Exam Practice Test Version: 14.20 QUESTION NO: 1 Oracle 1z0-854: Practice Exam 20. public class CreditCard { 21. 22. private
More informationA Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1
A Third Look At Java Chapter Seventeen Modern Programming Languages, 2nd ed. 1 A Little Demo public class Test { public static void main(string[] args) { int i = Integer.parseInt(args[0]); int j = Integer.parseInt(args[1]);
More informationC16b: Exception Handling
CISC 3120 C16b: Exception Handling Hui Chen Department of Computer & Information Science CUNY Brooklyn College 3/28/2018 CUNY Brooklyn College 1 Outline Exceptions Catch and handle exceptions (try/catch)
More informationVendor: Oracle. Exam Code: 1Z Exam Name: Java SE 8 Programmer. Version: Demo
Vendor: Oracle Exam Code: 1Z0-808 Exam Name: Java SE 8 Programmer Version: Demo DEMO QUESTION 1 Which of the following data types will allow the following code snippet to compile? A. long B. double C.
More informationWhat are Exceptions?
Exception Handling What are Exceptions? The traditional approach Exception handing in Java Standard exceptions in Java Multiple catch handlers Catching multiple exceptions finally block Checked vs unchecked
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions
More informationChanakya The King of IT Certifications Sun Certified Programmer for the Java 2 Platform.SE 6.0
Chanakya The King of IT Certifications 310-065 Sun Certified Programmer for the Java 2 Platform.SE 6.0 Ver 4.2 Q&A 281 itchanakya@hotmail.com itcertification39@gmail.com Chanakya was founded in 2008. The
More informationpublic class Test { static int age; public static void main (String args []) { age = age + 1; System.out.println("The age is " + age); }
Question No :1 What is the correct ordering for the import, class and package declarations when found in a Java class? 1. package, import, class 2. class, import, package 3. import, package, class 4. package,
More informationEXCEPTION-HANDLING INTRIVIEW QUESTIONS
EXCEPTION-HANDLING INTRIVIEW QUESTIONS Q1.What is an Exception? Ans.An unwanted, unexpected event that disturbs normal flow of the program is called Exception.Example: FileNotFondException. Q2.What is
More informationTutorial 8 Date: 15/04/2014
Tutorial 8 Date: 15/04/2014 1. What is wrong with the following interface? public interface SomethingIsWrong void amethod(int avalue) System.out.println("Hi Mom"); 2. Fix the interface in Question 2. 3.
More informationCS 3 Introduction to Software Engineering. 3: Exceptions
CS 3 Introduction to Software Engineering 3: Exceptions Questions? 2 Objectives Last Time: Procedural Abstraction This Time: Procedural Abstraction II Focus on Exceptions. Starting Next Time: Data Abstraction
More informationProgramming - 2. Common Errors
Common Errors There are certain common errors and exceptions which beginners come across and find them very annoying. Here we will discuss these and give a little explanation of what s going wrong and
More informationd. If a is false and b is false then the output is "ELSE" Answer?
Intermediate Level 1) Predict the output for the below code: public void foo( boolean a, boolean b) if( a ) System.out.println("A"); if(a && b) System.out.println( "A && B"); if (!b ) System.out.println(
More informationException-Handling Overview
م.عبد الغني أبوجبل Exception Handling No matter how good a programmer you are, you cannot control everything. Things can go wrong. Very wrong. When you write a risky method, you need code to handle the
More informationFundamentals of Object Oriented Programming
INDIAN INSTITUTE OF TECHNOLOGY ROORKEE Fundamentals of Object Oriented Programming CSN- 103 Dr. R. Balasubramanian Associate Professor Department of Computer Science and Engineering Indian Institute of
More informationInheritance. SOTE notebook. November 06, n Unidirectional association. Inheritance ("extends") Use relationship
Inheritance 1..n Unidirectional association Inheritance ("extends") Use relationship Implementation ("implements") What is inherited public, protected methods public, proteced attributes What is not inherited
More informationCS115. Chapter 17 Exception Handling. Prof. Joe X. Zhou Department of Computer Science. To know what is exception and what is exception handling
CS115 Pi Principles i of fcomputer Science Chapter 17 Exception Handling Prof. Joe X. Zhou Department of Computer Science CS115 ExceptionHandling.1 Objectives in Exception Handling To know what is exception
More informationCorrectness and Robustness
Correctness and Robustness 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University 1 Agenda Introduction
More informationException Handling. Sometimes when the computer tries to execute a statement something goes wrong:
Exception Handling Run-time errors The exception concept Throwing exceptions Handling exceptions Declaring exceptions Creating your own exception Ariel Shamir 1 Run-time Errors Sometimes when the computer
More informationException Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong:
Exception Handling Run-time errors The exception concept Throwing exceptions Handling exceptions Declaring exceptions Creating your own exception 22 November 2007 Ariel Shamir 1 Run-time Errors Sometimes
More informationHere is a hierarchy of classes to deal with Input and Output streams.
PART 15 15. Files and I/O 15.1 Reading and Writing Files A stream can be defined as a sequence of data. The InputStream is used to read data from a source and the OutputStream is used for writing data
More informationIntroduction. Exceptions: An OO Way for Handling Errors. Common Runtime Errors. Error Handling. Without Error Handling Example 1
Exceptions: An OO Way for Handling Errors Introduction Rarely does a program runs successfully at its very first attempt. It is common to make mistakes while developing as well as typing a program. Such
More informationJava Errors and Exceptions. Because Murphy s Law never fails
Java Errors and Exceptions Because Murphy s Law never fails 1 Java is the most distressing thing to hit computing since MS-DOS. Alan Kay 2 Corresponding Book Sections Pearson Custom Computer Science: Chapter
More informationCOMP-202 Unit 9: Exceptions
COMP-202 Unit 9: Exceptions Course Evaluations Please do these. -Fast to do -Used to improve course for future. (Winter 2011 had 6 assignments reduced to 4 based on feedback!) 2 Avoiding errors So far,
More informationWhat is the purpose of exceptions and exception handling? Vocabulary: throw/raise and catch/handle Exception propagation Java checked and unchecked
What is the purpose of exceptions and exception handling? Vocabulary: throw/raise and catch/handle Exception propagation Java checked and unchecked exceptions Java try statement Final wishes Java try-resource
More informationLe L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling
Course Name: Advanced Java Lecture 5 Topics to be covered Exception Handling Exception HandlingHandlingIntroduction An exception is an abnormal condition that arises in a code sequence at run time A Java
More informationBBM 102 Introduction to Programming II Spring Exceptions
BBM 102 Introduction to Programming II Spring 2018 Exceptions 1 Today What is an exception? What is exception handling? Keywords of exception handling try catch finally Throwing exceptions throw Custom
More informationExceptions Questions https://www.journaldev.com/2167/java-exception-interview-questionsand-answers https://www.baeldung.com/java-exceptions-interview-questions https://javaconceptoftheday.com/java-exception-handling-interviewquestions-and-answers/
More informationTraining topic: OCPJP (Oracle certified professional Java programmer) or SCJP (Sun certified Java programmer) Content and Objectives
Training topic: OCPJP (Oracle certified professional Java programmer) or SCJP (Sun certified Java programmer) Content and Objectives 1 Table of content TABLE OF CONTENT... 2 1. ABOUT OCPJP SCJP... 4 2.
More informationCS159. Nathan Sprague
CS159 Nathan Sprague What s wrong with the following code? 1 /* ************************************************** 2 * Return the mean, or -1 if the array has length 0. 3 ***************************************************
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationChapter 12 Exception Handling
Chapter 12 Exception Handling 1 Motivations Goal: Robust code. When a program runs into a runtime error, the program terminates abnormally. How can you handle the runtime error so that the program can
More informationExceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages
References Exceptions "Handling Errors with Exceptions", Java tutorial http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html CSE 413, Autumn 2005 Programming Languages http://www.cs.washington.edu/education/courses/413/05au/
More information1Z0-854
1Z0-854 Passing Score: 800 Time Limit: 4 min Exam A QUESTION 1 20. public class CreditCard { 21. 22. private String cardid; 23. private Integer limit; 24. public String ownername; 25. 26. public void setcardinformation(string
More informationExceptions Handling Errors using Exceptions
Java Programming in Java Exceptions Handling Errors using Exceptions Exceptions Exception = Exceptional Event Exceptions are: objects, derived from java.lang.throwable. Throwable Objects: Errors (Java
More informationCHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA
1. JIT meaning a. java in time b. just in time c. join in time d. none of above CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA 2. After the compilation of the java source code, which file is created
More informationCOMP-202 Unit 9: Exceptions
COMP-202 Unit 9: Exceptions Announcements - Assignment 4: due Monday April 16th - Assignment 4: tutorial - Final exam tutorial next week 2 Exceptions An exception is an object that describes an unusual
More informationEXCEPTION HANDLING. // code that may throw an exception } catch (ExceptionType parametername) {
EXCEPTION HANDLING We do our best to ensure program correctness through a rigorous testing and debugging process, but that is not enough. To ensure reliability, we must anticipate conditions that could
More informationLARA TECHNOLOGIES EXAM_SPECIALSIX SECTION-1
Q: 01. SECTION-1 Q: 02 Given: 12. import java.io.*; 13. public class Forest implements Serializable { 14. private Tree tree = new Tree(); 15. public static void main(string [] args) { 16. Forest f = new
More informationException Handling. Exception Handling
References: Jacquie Barker, Beginning Java Objects ; Rick Mercer, Computing Fundamentals With Java; Wirfs - Brock et. al., Martin Fowler, OOPSLA 99 Tutorial ; internet notes; notes:h. Conrad Cunningham
More informationChapter 2 Flow Control
Chapter 2 Flow Control 2.1 Develop code that implements if or switch statement; and identify legal argument types for these statements The syntax of the switch statement is extended ever-so-slightly. The
More informationRecitation 3. 2D Arrays, Exceptions
Recitation 3 2D Arrays, Exceptions 2D arrays 2D Arrays Many applications have multidimensional structures: Matrix operations Collection of lists Board games (Chess, Checkers) Images (rows and columns of
More informationthis keyword (1). this with constructor (2). cisc3120 design and implementation of software applications I spring 2015 lecture # I.
topics: introduction to java, part 4 this references exception handling comparing objects vectors utility classes cisc3120 design and implementation of software applications I spring 2015 lecture # I.4
More informationI pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.
Name: Covers Chapters 1-3 50 mins CSCI 1301 Introduction to Programming Armstrong Atlantic State University Instructor: Dr. Y. Daniel Liang I pledge by honor that I will not discuss this exam with anyone
More informationBirkbeck (University of London) Software and Programming 1 In-class Test Mar 2018
Birkbeck (University of London) Software and Programming 1 In-class Test 2.1 22 Mar 2018 Student Name Student Number Answer ALL Questions 1. What output is produced when the following Java program fragment
More informationMidterm Exam CS 251, Intermediate Programming March 6, 2015
Midterm Exam CS 251, Intermediate Programming March 6, 2015 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible
More informationExceptions, try - catch - finally, throws keyword. JAVA Standard Edition
Exceptions, try - catch - finally, throws keyword JAVA Standard Edition Java - Exceptions An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception
More information3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal
APCS A Midterm Review You will have a copy of the one page Java Quick Reference sheet. This is the same reference that will be available to you when you take the AP Computer Science exam. 1. n bits can
More informationExceptions and I/O: sections Introductory Programming. Errors in programs. Exceptions
Introductory Programming Exceptions and I/O: sections 80 83 Anne Haxthausen a IMM, DTU 1 Exceptions (section 80) 2 Input and output (I/O) (sections 81-83) a Parts of this material are inspired by/originate
More informationIntroductory Programming Exceptions and I/O: sections
Introductory Programming Exceptions and I/O: sections 80 83 Anne Haxthausen a IMM, DTU 1 Exceptions (section 80) 2 Input and output (I/O) (sections 81-83) a Parts of this material are inspired by/originate
More informationCS 200 Command-Line Arguments & Exceptions Jim Williams, PhD
CS 200 Command-Line Arguments & Exceptions Jim Williams, PhD This Week 1. Battleship: Milestone 3 a. First impressions matter! b. Comment and style 2. Team Lab: ArrayLists 3. BP2, Milestone 1 next Wednesday
More informationInput-Output and Exception Handling
Software and Programming I Input-Output and Exception Handling Roman Kontchakov / Carsten Fuhs Birkbeck, University of London Outline Reading and writing text files Exceptions The try block catch and finally
More informationWOSO Source Code (Java)
WOSO 2017 - Source Code (Java) Q 1 - Which of the following is false about String? A. String is immutable. B. String can be created using new operator. C. String is a primary data type. D. None of the
More informationAssoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Marenglen Biba Exception handling Exception an indication of a problem that occurs during a program s execution. The name exception implies that the problem occurs infrequently. With exception
More informationCSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige
CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors
More informationChapter 14. Exception Handling and Event Handling ISBN
Chapter 14 Exception Handling and Event Handling ISBN 0-321-49362-1 Chapter 14 Topics Introduction to Exception Handling Exception Handling in Ada Exception Handling in C++ Exception Handling in Java Introduction
More informationCSCI 261 Computer Science II
CSCI 261 Computer Science II Department of Mathematics and Computer Science Lecture 2 Exception Handling New Topic: Exceptions in Java You should now be familiar with: Advanced object-oriented design -
More informationExceptions. CSE 142, Summer 2002 Computer Programming 1.
Exceptions CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ 12-Aug-2002 cse142-19-exceptions 2002 University of Washington 1 Reading Readings and References»
More informationExceptions. Readings and References. Exceptions. Exceptional Conditions. Reading. CSE 142, Summer 2002 Computer Programming 1.
Readings and References Exceptions CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ Reading» Chapter 18, An Introduction to Programming and Object Oriented
More informationMidterm Exam CS 251, Intermediate Programming March 12, 2014
Midterm Exam CS 251, Intermediate Programming March 12, 2014 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible
More informationAbout This Lecture. Outline. Handling Unusual Situations. Reacting to errors. Exceptions
Exceptions Revised 24-Jan-05 CMPUT 115 - Lecture 4 Department of Computing Science University of Alberta About This Lecture In this lecture we will learn how to use Java Exceptions to handle unusual program
More informationTo Think About. MyClass.mogrify(new int[] { 1, 2, 4, 6 }));
A student adds a JUnit test: To Think About @Test public void mogrifytest() { assertequals("mogrify fails", new int[] { 2, 4, 8, 12 }, MyClass.mogrify(new int[] { 1, 2, 4, 6 })); } The test always seems
More informationTypes, Values and Variables (Chapter 4, JLS)
Lecture Notes CS 141 Winter 2005 Craig A. Rich Types, Values and Variables (Chapter 4, JLS) Primitive Types Values Representation boolean {false, true} 1-bit (possibly padded to 1 byte) Numeric Types Integral
More informationLecture 19 Programming Exceptions CSE11 Fall 2013
Lecture 19 Programming Exceptions CSE11 Fall 2013 When Things go Wrong We've seen a number of run time errors Array Index out of Bounds e.g., Exception in thread "main" java.lang.arrayindexoutofboundsexception:
More informationObject-Oriented Programming in the Java language
Object-Oriented Programming in the Java language Part 5. Exceptions. I/O in Java Yevhen Berkunskyi, NUoS eugeny.berkunsky@gmail.com http://www.berkut.mk.ua Exceptions Exceptions in Java are objects. All
More informationASSERTIONS AND LOGGING
SUMMARY Exception handling, ASSERTIONS AND LOGGING PROGRAMMAZIONE CONCORRENTE E DISTR. Università degli Studi di Padova Dipartimento di Matematica Corso di Laurea in Informatica, A.A. 2015 2016 rcardin@math.unipd.it
More informationException Handling CSCI 201 Principles of Software Development
Exception Handling CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D. jeffrey.miller@usc.edu Outline Program USC CSCI 201L 2/19 Exception Handling An exception is an indication of a problem
More informationTopic 6: Exceptions. Exceptions are a Java mechanism for dealing with errors & unusual situations
Topic 6: Exceptions Exceptions are a Java mechanism for dealing with errors & unusual situations Goals: learn how to... think about different responses to errors write code that catches exceptions write
More informationWhy Exceptions? (1.1) Exceptions. Why Exceptions? (1.2) Caller vs. Callee. EECS2030 B: Advanced Object Oriented Programming Fall 2018
Why Exceptions? (1.1) Exceptions EECS2030 B: Advanced Object Oriented Programming Fall 2018 CHEN-WEI WANG 1 class Circle { 2 double radius; 3 Circle() { /* radius defaults to 0 */ 4 void setradius(double
More informationCOMP 213. Advanced Object-oriented Programming. Lecture 17. Exceptions
COMP 213 Advanced Object-oriented Programming Lecture 17 Exceptions Errors Writing programs is not trivial. Most (large) programs that are written contain errors: in some way, the program doesn t do what
More informationExceptions. EECS2030 B: Advanced Object Oriented Programming Fall 2018 CHEN-WEI WANG
Exceptions EECS2030 B: Advanced Object Oriented Programming Fall 2018 CHEN-WEI WANG Caller vs. Callee Within the body implementation of a method, we may call other methods. 1 class C1 { 2 void m1() { 3
More informationGlobalLogic Technical Question Paper
GlobalLogic Technical Question Paper What is the output of the following code when compiled and run? Select two correct answers. public class Question01 { public static void main(string[] args){ int y=0;
More informationOracle 1Z Java SE 8 Programmer I. Download Full Version :
Oracle 1Z0-808 Java SE 8 Programmer I Download Full Version : https://killexams.com/pass4sure/exam-detail/1z0-808 QUESTION: 121 And the commands: Javac Jump.java Java Jump crazy elephant is always What
More informationBBM 102 Introduction to Programming II Spring 2017
BBM 102 Introduction to Programming II Spring 2017 Exceptions Instructors: Ayça Tarhan, Fuat Akal, Gönenç Ercan, Vahid Garousi Today What is an exception? What is exception handling? Keywords of exception
More informationAssertions and Exceptions Lecture 11 Fall 2005
Assertions and Exceptions 6.170 Lecture 11 Fall 2005 10.1. Introduction In this lecture, we ll look at Java s exception mechanism. As always, we ll focus more on design issues than the details of the language,
More informationChapter 13 Exception Handling
Chapter 13 Exception Handling 1 Motivations When a program runs into a runtime error, the program terminates abnormally. How can you handle the runtime error so that the program can continue to run or
More informationitexamdump 최고이자최신인 IT 인증시험덤프 일년무료업데이트서비스제공
itexamdump 최고이자최신인 IT 인증시험덤프 http://www.itexamdump.com 일년무료업데이트서비스제공 Exam : 1Z0-854 Title : Java Standard Edition 5 Programmer Certified Professional Upgrade Exam Vendors : Oracle Version : DEMO Get Latest
More informationGetting started with Java
Getting started with Java by Vlad Costel Ungureanu for Learn Stuff Programming Languages A programming language is a formal constructed language designed to communicate instructions to a machine, particularly
More information