Lara Technologies Special-Six Test

Size: px
Start display at page:

Download "Lara Technologies Special-Six Test"

Transcription

1 Flow control Part-1 Q: 01 Given: 10. public class Bar 11. static void foo( int... x ) 12. // insert code here Which two code fragments, inserted independently at line 12, will allow the class to compile? (Choose two.) A. foreach( x ) System.out.println(z); B. for( int z : x ) System.out.println(z); C. while( x.hasnext() ) System.out.println( x.next() ); D. for( int i=0; i< x.length; i++ ) System.out.println(x[i]); Q: 02 Click the Task button.

2 Q: 03 Given: 25. int x = 12; 26. while (x < 10) 27. x--; System.out.print(x); What is the result? A. 0 B. 10 C. 12 D. Line 29 will never be reached. Q: 04 Given: 11. public static void main(string[] args) 12. Object obj = new int[] 1, 2, 3 ; 13. int[] somearray = (int[])obj; 14. for (int i : somearray) System.out.print(i + " "); 15. What is the result? A B. Compilation fails because of an error in line 12. C. Compilation fails because of an error in line 13. D. Compilation fails because of an error in line 14. E. A ClassCastException is thrown at runtime. Q: 05 Given: 11. public static void main(string[] args) 12. for (int i = 0; i <= 10; i++) 13. if (i > 6) break; System.out.println(i); 16. What is the result? A. 6 B. 7 C. 10 D. 11 E. Compilation fails. F. An exception is thrown at runtime.

3 Q: 06 Given: 11. public static void main(string[] args) 12. Integer i = new Integer(1) + new Integer(2); 13. switch(i) 14. case 3: System.out.println("three"); break; 15. default: System.out.println("other"); break; What is the result? A. three B. other C. An exception is thrown at runtime. D. Compilation fails because of an error on line 12. E. Compilation fails because of an error on line 13. F. Compilation fails because of an error on line 15. Q: 07 Given: 10. public class ClassA 11. public void count(int i) 12. count(++i); And: 20. ClassA a = new ClassA(); 21. a.count(3); Which exception or error should be thrown by the virtual machine? A. StackOverflowError B. NullPointerException C. NumberFormatException D. IllegalArgumentException E. ExceptionInInitializerError Q: 08 Given: 35. int x = 10; 36. do 37. x--; 38. while (x < 10); How many times will line 37 be executed? A. ten times B. zero times

4 C. one to nine times D. more than ten times 9. Given the following code: public class OrtegorumFunction public int computediscontinuous(int x) int r = 1; r += x; if ((x > 4) && (x < 10)) r += 2 * x; else (x <= 4) r += 3 * x; else r += 4 * x; r += 5 * x; return r; public static void main(string [] args) OrtegorumFunction o = new OrtegorumFunction(); System.out.println("OF(11) is: " + o.computediscontinuous(11)); What is the result? A. OF(11) is: 45 B. OF(11) is: 56 C. OF(11) is: 89 D. OF(11) is: 111 E. Compilation fails. F. An exception is thrown at runtime. 10. Given: 1. class Crivitch 2. public static void main(string [] args) 3. int x = 0; 4. // insert code here 5. do while (x++ < y); 6. System.out.println(x); Which, inserted at line 4, produces the output 12?

5 A. int y = x; B. int y = 10; C. int y = 11; D. int y = 12; E. int y = 13; F. None of the above will allow compilation to succeed. 11. Given: class Swill public static void main(string[] args) String s = "-"; switch(timezone.cst) case EST: s += "e"; case CST: s += "c"; case MST: s += "m"; default: s += "X"; case PST: s += "p"; System.out.println(s); enum TimeZone EST, CST, MST, PST What is the result? A. -c B. -X C. -cm D. -cmp E. -cmxp F. Compilation fails. G. An exception is thrown at runtime. 12. Given: class Circus public static void main(string[] args) int x = 9; int y = 6; for(int z = 0; z < 6; z++, y--) if(x > 2) x--; label: if(x > 5)

6 System.out.print(x + " "); --x; continue label; x--; What is the result? A. 8 B. 8 7 C D. Compilation fails. E. An exception is thrown at runtime. 13. Given: 1. class Loopy 2. public static void main(string[] args) 3. int[] x = 7,6,5,4,3,2,1; 4. // insert code here 5. System.out.print(y + " "); Which, inserted independently at line 4, compiles? (Choose all that apply.) A. for(int y : x) B. for(x : int y) C. int y = 0; for(y : x) D. for(int y=0, z=0; z<x.length; z++) y = x[z]; E. for(int y=0, int z=0; z<x.length; z++) y = x[z]; F. int y = 0; for(int z=0; z<x.length; z++) y = x[z]; 14. Given: 1. class Ring 2. final static int x2 = 7; 3. final static Integer x4 = 8; 4. public static void main(string[] args) 5. Integer x1 = 5; 6. String s = "a"; 7. if(x1 < 9) s += "b"; 8. switch(x1)

7 9. case 5: s += "c"; 10. case x2: s += "d"; 11. case x4: s += "e"; System.out.println(s); What is the result? A. abc B. abcde C. Compilation fails due only to an error on line 7. D. Compilation fails due only to an error on line 8. E. Compilation fails due only to an error on line 10. F. Compilation fails due only to an error on line 11. G. Compilation fails due to errors on multiple lines. Part-2 1) public void foo( boolean a, boolean b) if( a ) System.out.println("A"); /* Line 5 */ else if(a && b) /* Line 7 */ System.out.println( "A && B"); else /* Line 11 */ if (!b ) System.out.println( "notb") ; else System.out.println( "ELSE" ) ; A. If a is true and b is true then the output is "A && B" B. If a is true and b is false then the output is "notb" C. If a is false and b is true then the output is "ELSE" D. If a is false and b is false then the output is "ELSE" 2) int i = l, j = -1;

8 switch (i) case 0, 1: j = 1; /* Line 4 */ case 2: j = 2; default: j = 0; System.out.println("j = " + j); A. j = -1 B. j = 0 C. j = 1 D. Compilation fails. 3) public class Switch2 final static short x = 2; public static int y = 0; public static void main(string [] args) for (int z=0; z < 3; z++) switch (z) case x: System.out.print("0 "); case x-1: System.out.print("1 "); case x-2: System.out.print("2 "); A B C D

9 4) public void test(int x) int odd = 1; if(odd) /* Line 4 */ System.out.println("odd"); else System.out.println("even"); Which statement is true? A. Compilation fails. B. "odd" will always be output. C. "even" will always be output. D. "odd" will be output for odd values of x, and "even" for even values. 5) public class While public void loop() int x= 0; while ( 1 ) /* Line 6 */ System.out.print("x plus one is " + (x + 1)); /* Line 8 */ A. There is a syntax error on line 1. B. There are syntax errors on lines 1 and 6 C. There are syntax errors on lines 1, 6, and 8. D. There is a syntax error on line 6.

10 6) int i = 1, j = 10; do if(i > j) break; j--; while (++i < 5); System.out.println("i = " + i + " and j = " + j); A. i = 6 and j = 5 B. i = 5 and j = 5 C. i = 6 and j = 4 D. i = 5 and j = 6 7) boolean bool = true; if(bool = false) /* Line 2 */ System.out.println("a"); else if(bool) /* Line 6 */ System.out.println("b"); else if(!bool) /* Line 10 */ System.out.println("c"); /* Line 12 */ else System.out.println("d");

11 A. a B. b C. c D. d 8) public class If1 static boolean b; public static void main(string [] args) short hand = 42; if ( hand < 50 &!b ) /* Line 7 */ hand++; if ( hand > 50 ); /* Line 9 */ else if ( hand > 40 ) hand += 7; hand++; else --hand; System.out.println(hand); A. 41 B. 42 C. 50 D. 51

12 9) for (int i = 0; i < 4; i += 2) System.out.print(i + " "); System.out.println(i); /* Line 5 */ A B C D. Compilation fails. 10) public class Delta static boolean foo(char c) System.out.print(c); return true; public static void main( String[] argv ) int i = 0; for (foo('a'); foo('b') && (i < 2); foo('c')) i++; foo('d'); A. ABDCBDCB B. ABCDABCD C. Compilation fails D. An exception is thrown at runtime.

13 Part-3 1 ) for(int i = 0; i < 3; i++) switch(i) case 0: break; case 1: System.out.print("one "); case 2: System.out.print("two "); case 3: System.out.print("three "); System.out.println("done"); A. done B. one two done C. one two three done D. one two three two three done 2) public class Switch2 final static short x = 2; public static int y = 0; public static void main(string [] args) for (int z=0; z < 4; z++) switch (z) case x: System.out.print("0 "); default: System.out.print("def "); case x-1: System.out.print("1 "); break; case x-2: System.out.print("2 "); A. 0 def 1 B def 1 C def def

14 D def 1 def 1 3) public class Outer public void someoutermethod() //Line 5 public class Inner public static void main(string[] argv) Outer ot = new Outer(); //Line 10 Which of the following code fragments inserted, will allow to compile? A. new Inner(); //At line 5 B. new Inner(); //At line 10 C. new ot.inner(); //At line 10 D. new Outer.Inner(); //At line 10 4) Float f = new Float("12"); switch (f) case 12: System.out.println("Twelve"); case 0: System.out.println("Zero"); default: System.out.println("Default"); A. Zero B. Twelve

15 C. Default D. Compilation fails 5) public void test(int x) int odd = 1; if(odd) /* Line 4 */ System.out.println("odd"); else System.out.println("even"); Which statement is true? A. Compilation fails. B. "odd" will always be output. C. "even" will always be output. D. "odd" will be output for odd values of x, and "even" for even values. 6) public class Switch2 final static short x = 2; public static int y = 0; public static void main(string [] args) for (int z=0; z < 3; z++) switch (z) case y: System.out.print("0 "); /* Line 11 */

16 case x-1: System.out.print("1 "); /* Line 12 */ case x: System.out.print("2 "); /* Line 13 */ A B C. Compilation fails at line 11. D. Compilation fails at line 12. 7) int x = l, y = 6; while (y--) x++; System.out.println("x = " + x +" y = " + y); A. x = 6 y = 0 B. x = 7 y = 0 C. x = 6 y = -1 D. Compilation fails. 8) public class While public void loop() int x= 0; while ( 1 ) /* Line 6 */ System.out.print("x plus one is " + (x + 1)); /* Line 8 */

17 Which statement is true? A. There is a syntax error on line 1. B. There are syntax errors on lines 1 and 6. C. There are syntax errors on lines 1, 6, and 8. D. There is a syntax error on line 6 9) public class Test public static void main(string [] args) int I = 1; do while ( I < 1 ) System.out.print("I is " + I); while ( I > 1 ) ; A. I is 1 B. I is 1 I is 1 C. No output is produced D. Compilation error 10) int x = 3; int y = 1; if (x = y) /* Line 3 */ System.out.println("x =" + x);

18 A. x=1 B. x=3 C. Compilation fails. D. The code runs with no output. 11) Here is the hierarchy of exceptions related to array index and string index errors: Exception +-- RuntimeException +-- IndexOutOfBoundsException +-- ArrayIndexOutOfBoundsException +-- StringIndexOutOfBoundsException Suppose you had a method X that could throw both array index and string index exceptions. Assuming that X does not have any try-catch statements, which of the following statements are correct? (a) The declaration for X must include throws ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException. (b) If a method calling X catches IndexOutOfBoundsException, both array and string index exceptions will be caught. (c) If the declaration for X includes throws IndexOutOfBoundsException, any calling method must use a try-catch block. (d) The declaration for X does not have to mention exceptions. 12) Which will be the first line to cause an error in the following code? Select one correct answer. 1 class Char 2 3 public static void main(string arg[]) 4 5 while(false) 6 7 System.out.println("Hello"); 8 9 while(false) do; 13 while(false); 14 do ;

19 17 18 while(false); (a) Line no. 5 (b) Line no. 9 (c) Line no. 12 (d) Line no ) What will be the result of compiling and running the given program? Select one correct answer. 1 public class exception 2 3 public static void main(string args[]) 4 5 System.out.println("A"); 6 try catch(java.io.ioexception t) System.out.println("B"); System.out.println("C"); (a) Compile time error. (b) Program compiles correctly and prints "A" when executed. (c) Program compiles correctly and prints "A" and "C" when executed. (d) Run time error. 14. What will be the result of compiling and running the given program? Select one correct answer. 1 public class exception 2 3 public static void main(string args[]) 4 5 System.out.println("A"); 6 try

20 7 8 return; 9 10 catch(exception e) System.out.println("B"); System.out.println("C"); (a) Compile time error in line no. 8 as main() method is declared void. (b) Program compiles correctly and prints "A" when executed. (c) Program compiles correctly and prints "A" and "C" when executed. (d) Compile time error at line no.14 due to statement not reached. 15. What will be the result of compiling and running the given program? Select one correct answer. 1 public class exception 2 3 public static void main(string args[]) 4 5 System.out.println("A"); 6 try 7 8 return; 9 10 catch(exception e) System.out.println("B"); finally System.out.println("C"); (a) Compile time error in line no. 8 as main() method is declared void. (b) Program compiles correctly and prints "A" when executed. (c) Program compiles correctly and prints "A" and "C" when executed. (d) Program compiles correctly and prints "A","B" and "C" when executed.

21 16. What will be the result of compiling and running the given program? Select one correct answer. 1 public class exception 2 3 public static void main(string args[]) 4 5 System.out.println("A"); 6 try 7 8 System.out.println("B"); 9 System.exit(0); 9 10 catch(exception e) System.out.println("C"); finally System.out.println("D"); (a) Program compiles correctly and prints "A" when executed. (b) Program compiles correctly and prints "A" and "B" when executed. (c) Program compiles correctly and prints "A" and "C" when executed. (d) Program compiles correctly and prints "A","B" and "C" when executed.

1.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.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 information

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

SECTION-1 Q.1.Which two code fragments are most likely to cause a StackOverflowError? (Choose two.) 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;

More information

d. If a is false and b is false then the output is "ELSE" Answer?

d. 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 information

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

Module 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 information

Sun Certified Programmer for Java 2 Platform 1.4. Version 3.0

Sun Certified Programmer for Java 2 Platform 1.4. Version 3.0 310-035 Sun Certified Programmer for Java 2 Platform 1.4 Version 3.0 Important Note Please Read Carefully Study Tips This product will provide you questions and answers along with detailed explanations

More information

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

Vendor: 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 information

1. Short circuit AND (&&) = if first condition is false then the second is never evaluated

1. Short circuit AND (&&) = if first condition is false then the second is never evaluated 1. What are the 2 types of short circuit operators. 1. Short circuit AND (&&) = if first condition is false then the second is never evaluated because true and false gives you false only. 2. Short circuit

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

AP COMPUTER SCIENCE A

AP COMPUTER SCIENCE A AP COMPUTER SCIENCE A CONTROL FLOW Aug 28 2017 Week 2 http://apcs.cold.rocks 1 More operators! not!= not equals to % remainder! Goes ahead of boolean!= is used just like == % is used just like / http://apcs.cold.rocks

More information

For more details on SUN Certifications, visit

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 information

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below. C212 Early Evaluation Exam Mon Feb 10 2014 Name: Please provide brief (common sense) justifications with your answers below. 1. What is the type (and value) of this expression: 5 * (7 + 4 / 2) 2. What

More information

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

I 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 information

CMPS 12A - Winter 2002 Midterm 2 March 5, Name: ID:

CMPS 12A - Winter 2002 Midterm 2 March 5, Name: ID: CMPS 12A - Winter 2002 Midterm 2 March 5, 2002 Name: ID: This is a closed note, closed book exam. Any place where you are asked to write code, you must declare all variables that you use. However, I just

More information

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

ITCertMaster.  Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way! ITCertMaster Safe, simple and fast. 100% Pass guarantee! Exam : 1z0-853 Title : Java Standard Edition 5 Programmer Certified Professional Exam Vendor : Oracle Version : DEMO Get Latest & Valid 1Z0-853

More information

Chapter 1: Introduction to Computers, Programs, and Java

Chapter 1: Introduction to Computers, Programs, and Java Chapter 1: Introduction to Computers, Programs, and Java 1. Q: When you compile your program, you receive an error as follows: 2. 3. %javac Welcome.java 4. javac not found 5. 6. What is wrong? 7. A: Two

More information

COE318 Lecture Notes Week 10 (Nov 7, 2011)

COE318 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 information

1. Find the output of following java program. class MainClass { public static void main (String arg[])

1. Find the output of following java program. class MainClass { public static void main (String arg[]) 1. Find the output of following java program. public static void main(string arg[]) int arr[][]=4,3,2,1; int i,j; for(i=1;i>-1;i--) for(j=1;j>-1;j--) System.out.print(arr[i][j]); 1234 The above java program

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Selenium Class 9 - Java Operators

Selenium Class 9 - Java Operators Selenium Class 9 - Java Operators Operators are used to perform Arithmetic, Comparison, and Logical Operations, Operators are used to perform operations on variables and values. public class JavaOperators

More information

King Saud University College of Computer and Information Sciences Computer Science Department

King Saud University College of Computer and Information Sciences Computer Science Department King Saud University College of Computer and Information Sciences Computer Science Department Course Code: CSC 111 Course Title: Introduction to Programming 1 Semester: Fall 2017-18 Exercises Cover Sheet:

More information

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1 Name SOLUTION Page Points Score 2 15 3 8 4 18 5 10 6 7 7 7 8 14 9 11 10 10 Total 100 1 P age 1. Program Traces (41 points, 50 minutes)

More information

Day 2 : Intermediate Concepts 1 Examples

Day 2 : Intermediate Concepts 1 Examples Example1 Day 2 : Intermediate Concepts 1 Examples public class Example1 public static void main(string[] args) int a= 5, b = 10, c = 15, d= 20; Assignment int x = a++; a is assigned to x and then increment

More information

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Birkbeck (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 information

Prof. Navrati Saxena TA: Rochak Sachan

Prof. Navrati Saxena TA: Rochak Sachan JAVA Prof. Navrati Saxena TA: Rochak Sachan Operators Operator Arithmetic Relational Logical Bitwise 1. Arithmetic Operators are used in mathematical expressions. S.N. 0 Operator Result 1. + Addition 6.

More information

WOSO Source Code (Java)

WOSO 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 information

Java Programming for Selenium

Java Programming for Selenium Video 5 - Java Control Flow, String Handling and Arrays Java Programming for Selenium 1) Conditional / Decision Making 2) Loop 3) Branching 4) String Handling in Java 5) Java Arrays 1) Conditional / Decision

More information

Some Practice Midterm Problems

Some Practice Midterm Problems Some Practice Midterm Problems September 29, 2017 1. 1 point word count is a legal identifier in Java A. True B. False 2. 1 point k2 is a legal identifier in Java A. True B. False 3. 1 point Krazy1 is

More information

Operators Questions

Operators Questions Operators Questions https://www.geeksforgeeks.org/java-operators-question-1/ https://www.indiabix.com/java-programming/operators-andassignments/ http://www.instanceofjava.com/2015/07/increment-decrementoperators-interview.html

More information

Spring University of New Mexico CS152 Midterm Exam. Print Your Name

Spring University of New Mexico CS152 Midterm Exam. Print Your Name Print Your Name You may use one page of hand written notes (both sides) and a dictionary. No i-phones, calculators or any other type of non-organic computer. Do not take this exam if you are sick. Once

More information

C16b: Exception Handling

C16b: 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 information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Basic Operators Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Motivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018

Motivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018 Motivating Examples (1.1) Selections EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG 1 import java.util.scanner; 2 public class ComputeArea { 3 public static void main(string[] args)

More information

CSC Java Programming, Fall Java Data Types and Control Constructs

CSC Java Programming, Fall Java Data Types and Control Constructs CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference

More information

Module 1-JAVA 基础 一 选择题 :

Module 1-JAVA 基础 一 选择题 : 一 选择题 : Question 1 35. String #name = "Jane Doe"; 36. int $age=24; 37. Double _height = 123.5; 38. double ~temp = 37.5; Which two are true? (Choose two.) A. Line 35 will not compile. B. Line 36 will not

More information

Fundamentals of Object Oriented Programming

Fundamentals 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 information

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

Oracle 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 information

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

CHETTINAD 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 information

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003 1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 7, 2003 Name: Email Address: TA: Section: You have 90 minutes to complete this exam. For coding questions, you do not need to

More information

Term 1 Unit 1 Week 1 Worksheet: Output Solution

Term 1 Unit 1 Week 1 Worksheet: Output Solution 4 Term 1 Unit 1 Week 1 Worksheet: Output Solution Consider the following what is output? 1. System.out.println("hot"); System.out.println("dog"); Output hot dog 2. System.out.print("hot\n\t\t"); System.out.println("dog");

More information

A 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 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 information

Following is the general form of a typical decision making structure found in most of the programming languages:

Following is the general form of a typical decision making structure found in most of the programming languages: Decision Making Decision making structures have one or more conditions to be evaluated or tested by the program, along with a statement or statements that are to be executed if the condition is determined

More information

More on Exception Handling

More 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 information

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

Section 003 Fall CS 170 Exam 2. Name (print): Instructions: CS 170 Exam 2 Section 003 Fall 2012 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

CIS October 19, 2017

CIS October 19, 2017 CIS 1068 October 19, 2017 Administrative Stuff String methods due tomorrow Boston Accent Reading: up to chapter 5 Midterms Last Time midterm discussion guessing game Legal Identifiers Ch33zyHaX0R cous

More information

Name Section Number. Sections 1-3 *** TURN OFF ALL ELECTRONIC DEVICES*** Bob Wilson

Name Section Number. Sections 1-3 *** TURN OFF ALL ELECTRONIC DEVICES*** Bob Wilson Name Section Number CS110 Exam #4 Practice Sections 1-3 *** TURN OFF ALL ELECTRONIC DEVICES*** Bob Wilson You may use your crib sheet (one 8-1/2 x 11 page both sides) and only your crib sheet. 1. Expression

More information

CSE 8B Final Exam Fall 2015

CSE 8B Final Exam Fall 2015 Name: Tutor: Student ID: Signature: CSE 8B Final Exam Fall 2015 You can rip off the last page and use as scratch paper. Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Page 9 Page 10 Page 11 Page 12 0

More information

CMSC131. Exceptions and Exception Handling. When things go "wrong" in a program, what should happen.

CMSC131. Exceptions and Exception Handling. When things go wrong in a program, what should happen. CMSC131 Exceptions and Exception Handling When things go "wrong" in a program, what should happen. Go forward as if nothing is wrong? Try to handle what's going wrong? Pretend nothing bad happened? Crash

More information

King Saud University College of Computer and Information Sciences Computer Science Department

King Saud University College of Computer and Information Sciences Computer Science Department King Saud University College of Computer and Information Sciences Computer Science Department Course Code: CSC 111 Course Title: Introduction to Programming Semester: Fall 2017-2018 Exercises Cover Sheet:

More information

WES-CS GROUP MEETING #9

WES-CS GROUP MEETING #9 WES-CS GROUP MEETING #9 Exercise 1: Practice Multiple-Choice Questions 1. What is output when the following code executes? String S1 = new String("hello"); String S2 = S1 +! ; S1 = S1 + S1; System.out.println(S1);

More information

CIS265 - Spring Exam 2 First Name Last Name CSU#

CIS265 - Spring Exam 2 First Name Last Name CSU# CIS265 - Spring 2013 - Exam 2 First Name Last Name CSU# MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) An instance of describes system errors.

More information

For that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances.

For that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose, java provides control structures

More information

Programming Basics. Digital Urban Visualization. People as Flows. ia

Programming Basics.  Digital Urban Visualization. People as Flows. ia Programming Basics Digital Urban Visualization. People as Flows. 28.09.2015 ia zuend@arch.ethz.ch treyer@arch.ethz.ch Programming? Programming is the interaction between the programmer and the computer.

More information

EXCEPTION HANDLING. // code that may throw an exception } catch (ExceptionType parametername) {

EXCEPTION 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 information

Java Simple Data Types

Java Simple Data Types Intro to Java Unit 1 Multiple Choice Test Key Java Simple Data Types This Test Is a KEY DO NOT WRITE ON THIS TEST This test includes program segments, which are not complete programs. Answer such questions

More information

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>= Operators in java Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc. There are many types of operators in java which are given below: Unary Operator, Arithmetic

More information

Computer Programming, I. Laboratory Manual. Final Exam Solution

Computer Programming, I. Laboratory Manual. Final Exam Solution Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Final Exam Solution

More information

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG Selections EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG Learning Outcomes The Boolean Data Type if Statement Compound vs. Primitive Statement Common Errors

More information

Topic 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 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 information

Chapter 8. Exception Handling. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Chapter 8. Exception Handling. CS 180 Sunil Prabhakar Department of Computer Science Purdue University Chapter 8 Exception Handling CS 180 Sunil Prabhakar Department of Computer Science Purdue University Clarifications Auto cast from char to String does not happen. Cast between int and char happens automatically.

More information

Tutorial # 4. Q1. Evaluate the logical (Boolean) expression in the following exercise

Tutorial # 4. Q1. Evaluate the logical (Boolean) expression in the following exercise Tutorial # 4 Q1. Evaluate the logical (Boolean) expression in the following exercise 1 int num1 = 3, num2 = 2; (num1 > num2) 2 double hours = 12.8; (hours > 40.2) 3 int funny = 7; (funny!= 1) 4 double

More information

CMPS 12A Winter 2006 Prof. Scott A. Brandt Final Exam, March 21, Name:

CMPS 12A Winter 2006 Prof. Scott A. Brandt Final Exam, March 21, Name: CMPS 12A Winter 2006 Prof. Scott A. Brandt Final Exam, March 21, 2006 Name: Email: This is a closed note, closed book exam. There are II sections worth a total of 200 points. Plan your time accordingly.

More information

University of Palestine. Mid Exam Total Grade: 100

University of Palestine. Mid Exam Total Grade: 100 First Question No. of Branches (5) A) Choose the correct answer: 1. If we type: system.out.println( a ); in the main() method, what will be the result? int a=12; //in the global space... void f() { int

More information

Tutorial 06. Conditional statement: if then, if else, switch

Tutorial 06. Conditional statement: if then, if else, switch College of Computer and Infmation Sciences CSC111 Computer Programming I Exercise 1: Tutial 06 Conditional statement: if then, if, switch What is the output of each of the following code fragments? (given

More information

Exceptions 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 information

More on Exception Handling

More 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 information

Full file at Chapter 2 - Inheritance and Exception Handling

Full 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 information

Java certification success, Part 1: SCJP

Java certification success, Part 1: SCJP Skill Level: Introductory Pradeep Chopra Cofounder WHIZlabs Software 06 Nov 2003 This tutorial is designed to prepare programmers for the Sun Certified Java Programmer (SCJP) 1.4 exam, providing a detailed

More information

public class Test { static int age; public static void main (String args []) { age = age + 1; System.out.println("The age is " + age); }

public 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 information

CS 177 Spring 2010 Exam I

CS 177 Spring 2010 Exam I CS 177 Spring 2010 Exam I There are 25 multiple choice questions. Each one is worth 4 points. The total score for the exam is 100. Answer the multiple choice questions on the bubble sheet given. Fill in

More information

CIS October 16, 2018

CIS October 16, 2018 CIS 1068 October 16, 2018 administrative stuff @@@ ADD ME @@@ Midterm Remember, the material is cumulative You ll see this stuff again Legal Identifiers c00lg33k is a legal identifier Legal Identifiers

More information

Midterm Exam CS 251, Intermediate Programming March 12, 2014

Midterm 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 information

Getting started with Java

Getting 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

CIS 120 Programming Languages and Techniques. Midterm II. November 12, 2010

CIS 120 Programming Languages and Techniques. Midterm II. November 12, 2010 CIS 120 Programming Languages and Techniques Midterm II November 12, 2010 Name: Pennkey: Scores: 1 2 3 4 5 6 Total (50 max) 1. (14 points) Pages 7 to 9 define a simplified version of the Java Collection

More information

CS115. Chapter 17 Exception Handling. Prof. Joe X. Zhou Department of Computer Science. To know what is exception and what is exception handling

CS115. 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 information

PASS4TEST. 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 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 information

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010 CS 102 / CS 107 - Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010 What is your name?: There are two sections: I. True/False..................... 60 points; ( 30 questions, 2 points each)

More information

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Page 0 German University in Cairo April 6, 2017 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Bar Code

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ CALLING & DEFINING FUNCTIONS 2 Functions and

More information

AP Computer Science Midterm Review Part 1

AP Computer Science Midterm Review Part 1 AP Computer Science Midterm Review Part 1 1. Consider the following method public void process(string s) s = s.substring(2, 3) + s.substring(1, 2) + s.substring(0, 1); What is printed as a result of executing

More information

CIS March 1, 2018

CIS March 1, 2018 CIS 1068 March 1, 2018 Administrative Stuff Assignment 6 Today s office hours rescheduled: 12:30-1:50 or appointment, or drop by Last Time more on JUnit and what should be done in Assignment 6 Random sentinel

More information

CS 113 PRACTICE FINAL

CS 113 PRACTICE FINAL CS 113 PRACTICE FINAL There are 13 questions on this test. The value of each question is: 1-10 multiple choice (4 pt) 11-13 coding problems (20 pt) You may get partial credit for questions 11-13. If you

More information

CPSC 219 Extra review and solutions

CPSC 219 Extra review and solutions CPSC 219 Extra review and solutions Multiple choice questions: Unless otherwise specified assume that all necessary variable declarations have been made. For Questions 1 6 determine the output of the print()

More information

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn to define and invoke void and return java methods JAVA

More information

COE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F.

COE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F. 1 COE 212 Engineering Programming Welcome to Exam II Thursday April 21, 2016 Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam is Closed Book.

More information

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

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B 1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these 2. How many primitive data types are there in Java? A. 5 B. 6 C. 7 D. 8 3. In Java byte, short, int and long

More information

Practice Questions for Chapter 9

Practice Questions for Chapter 9 Practice Questions for Chapter 9 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) An object is an instance of a. 1) A) program B) method C) class

More information

Repetition with for loops

Repetition with for loops Repetition with for loops So far, when we wanted to perform a task multiple times, we have written redundant code: System.out.println( Building Java Programs ); // print 5 blank lines System.out.println(

More information

CS 200 Command-Line Arguments & Exceptions Jim Williams, PhD

CS 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 information

Java Control Statements

Java Control Statements Java Control Statements An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/

More information

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

Fall CS 101: Test 2 Name UVA  ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17. Grading Page 1 / 4 Page3 / 20 Page 4 / 13 Page 5 / 10 Page 6 / 26 Page 7 / 17 Page 8 / 10 Total / 100 1. (4 points) What is your course section? CS 101 CS 101E Pledged Page 1 of 8 Pledged The following

More information

CMPS 12A - Winter 2002 Final Exam A March 16, Name: ID:

CMPS 12A - Winter 2002 Final Exam A March 16, Name: ID: CMPS 12A - Winter 2002 Final Exam A March 16, 2002 Name: ID: This is a closed note, closed book exam. Any place where you are asked to write code, you must declare all variables that you use. However,

More information

Exam Questions 1z0-853

Exam 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 information

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks: كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this

More information

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade; Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

More information

Happy Cinco de Mayo!!!!

Happy Cinco de Mayo!!!! CSC 1051 Algorithms and Data Structures I Happy Cinco de Mayo!!!! Final Examination May 5, 2018 Name: Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 20 TOTAL 100 Please answer questions

More information

Date: Dr. Essam Halim

Date: Dr. Essam Halim Assignment (1) Date: 11-2-2013 Dr. Essam Halim Part 1: Chapter 2 Elementary Programming 1 Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use

More information

COMP-202 Unit 9: Exceptions

COMP-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 information

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

3. 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 information

Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination

Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination November 11th, 2013 Examiners: Jonathan Tremblay [Sections

More information

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++ Crash Course in Java Netprog: Java Intro 1 Why Java? Network Programming in Java is very different than in C/C++ much more language support error handling no pointers! (garbage collection) Threads are

More information