Java Programming: Final Examination 6/ 姓名 : 學號 : 分數 :

Size: px
Start display at page:

Download "Java Programming: Final Examination 6/ 姓名 : 學號 : 分數 :"

Transcription

1 Java Programming: Final Examination 6/ 姓名 : 學號 : 分數 : I (105 pts) 選擇題 [Questions marked with * (ex: Question 9) mean they have more than one answer ] 1. Fill in the blank in: Comparable c = new Date(); so that c.compareto( new Date()) executes normally. a) <?> b) <E> c) <String> d) <Date> 2. If you want to store non-duplicated objects in the order in which they are inserted, you should use. a) LinkedHashSet b) ArrayList c) HashSet d) LinkedList e) TreeSet 3. Which method do you use to test if an element e is in a set or list named x? a) x.include(e) b) (e instanceof List) (e instanceof Set) c) x.in(e) d) x.contain(e) e) x.contains(e) 4. Which of the following is correct to perform the set intersection of two sets s1 and s2? a) s1.intersect(s2) b) s1.intersection(s2) c) s1.join(s2) d) s1.retainall(s2) 5. The printout of the following code is. LinkedHashSet<String> set1 = new LinkedHashSet<String>(); set1.add("new York"); LinkedHashSet<String> set2 = (LinkedHashSet<String>)(set1.clone()); set1.add("atlanta"); set2.add("dallas"); System.out.println(set2); a) [New York, Atlanta, Dallas] b) [New York, Dallas] c) [New York] d) [New York, Atlanta] 6. Suppose set s1 is [1, 2, 5] and list L2 is [2, 3, 6]. After s1.addall(l2), s1 is. a) [1, 2, 2, 3, 5, 6] b) [2] c) [1, 5] d) [1, 2, 3, 5, 6] e) runtime exception 7. Suppose set s1 is [1, 2, 5] and set s2 is [2, 3, 6]. After s1.removeall(s2), s1 is. a) [1, 5] b) [1, 2, 2, 3, 5, 6] c) [1, 2, 3, 5, 6] d) [2] 8. The method in the Queue interface retrieves and removes the head of this queue, or null if this queue is empty. a) remove() b) poll() c) element() d) peek() 9. * To create a set that consists of string elements "red", "green", and "blue", use a) new HashSet(new String[ ]{"red", "green", "blue"}) b) new LinkedHashSet(Arrays.asList(new String[ ]{"red", "green", "blue"})) c) new Set(Arrays.asList(new String[ ]{"red", "green", "blue"})) d) new HashSet(Arrays.asList(new String[ ]{"red", "green", "blue"})) e) new HashSet({"red", "green", "blue"}) 10. Which of the following is correct to create a list from an array? a) new ArrayList(new String[ ]{"red", "green", "blue"}) b) new List({"red", "green", "blue"}) c) new LinkedList(new String[ ]{"red", "green", "blue"}) 1

2 d) Arrays.asList(new String[ ]{"red", "green", "blue"}) e) new List(new String[ ]{"red", "green", "blue"}) 11. Which of the following is correct to sort the elements in a list lst? a) lst.sort() b) Collections.sort(lst) c) new LinkedList(new String[ ]{"red", "green", "blue"}) d) Arrays.sort(lst) 12. To get an iterator from a set, you may use the method. a) iterators b) finditerator c) getiterator d) iterator 13. Which of the data types below could be used to store elements in their natural order based on the compareto method. a) Collection b) HashSet c) Set d) TreeSet e) LinkedHashSet 14. Which of the following data types does not implement the Collection interface? a) HashSet b) ArrayList c) Map d) TreeSet e) LinkedList 15. Which of the data types below does not allow duplicates? a) List b) LinkedList c) Stack d) Vector e) Set 16. Which of the following statements is not defined in the Object class? a) sleep(long milliseconds) b) tostring() c) notifyall() d) wait() e) notify() 17. * You can use the method to temporarily release time for other threads. a) suspend() b) stop() c) yield() d) sleep(long milliseconds) 18. Which of the following expressions must be true if you create a thread using Thread = new Thread(object)? a) object instanceof Runnable b) object instanceof Thread c) object instanceof String d) object instanceof Number 19. Analyze the following code: public abstract class Test implements Runnable { public void dosomething() { }; } a) The program will not compile because it does not contain abstract methods. b) The program will not compile because it does not implement the run() method. c) The program compiles fine. d) None of the above. 20. *Which of the following methods are in the Collection interface? a) isempty() b) clear() c) size() d) getsize() 21. *The Collection interface is the base interface for. a) Map b) List c) Set d) LinkedList e) ArrayList 22. When you run the following program, what will happen? public class Test extends Thread { public static void main(string[ ] args) { Test t = new Test(); t.start(); t.start(); } public void run() { System.out.println("test"); } a) The program displays test twice. b) Nothing is displayed. 2

3 c) The program displays test once. d) An illegal java.lang.illegalthreadstateexception may be thrown because you just started thread t and thread might have not yet finished before you start it again. t cannot be restarted! 23. You can use the method to force one thread to wait for another thread to finish. a) sleep(long milliseconds) b) yield() c) suspend() d) join() e) stop() 24. Which of the following declarations use raw type? a) ArrayList<String> list = new ArrayList<String>(); b) ArrayList<Object> list = new ArrayList<Object>(); c) ArrayList list = new ArrayList(); d) ArrayList<Integer> list = new ArrayList<Integer>(); 25. To create a list to store integers, use a) ArrayList<Object> list = new ArrayList<Integer>(); b) ArrayList<Number> list = new ArrayList<Integer>(); c) ArrayList<Integer> list = new ArrayList<Integer>(); d) ArrayList<int> list = new ArrayList<int>(); 26. To declare a class named A with a generic type, use a) public class A(E) {... } b) public class A(E, F) {... } c) public class A<E, F> {... } d) public class A<E> {... } 27. Which of the following methods in Thread throws InterruptedException? a) setpriority(int) b) sleep(long) c) yield() d) run() e) start() 28. Suppose there are three Runnable tasks, task1, task2, task3. How do you run them in a thread pool with 2 fixed threads? a) ExecutorService executor = Executors.newFixedThreadPool(2); executor.execute(task1); executor.execute(task2); executor.execute(task3); b) new Thread(task1).start(); new Thread(task2).start(); new Thread(task3).start(); c) ExecutorService executor = Executors.newFixedThreadPool(1); executor.execute(task1); executor.execute(task2); executor.execute(task3); d) ExecutorService executor = Executors.newFixedThreadPool(3); executor.execute(task1); executor.execute(task2); executor.execute(task3); 29. Which of the following method is a static in java.lang.thread? a) join() b) setpriority(int) c) sleep(long) d) run() ) start() 30. The equals method is defined in the Object class. Which of the following is correct to override it in the String class? a) public boolean equals(string other) b) public static boolean equals(object other) c) public static boolean equals(string other) d) public boolean equals(object other) 31. Which of the statements regarding the super keyword is incorrect? a) You can use super to invoke a super class constructor. b) You cannot invoke a method in superclass's parent class which is overridden by a superclass method. c) You can use super.super.p to invoke a method in superclass's parent class. d) You can use super to invoke a super class method. 32. You can assign to a variable of Object[ ] type. 3

4 a) new String[100] b) new int[100] c) new double[100] d) new char[100] 33. Suppose A is an inner class in Test. A is compiled into a file named. a) A.class b) A$Test.class c) Test$A.class d) Test&A.class 34. Which statement is true about a non-static inner class? a) It must be final if it is declared in a method scope. b) It can access private instance variables in the enclosing object. c) It can only be instantiated in the enclosing class. d) It is accessible from any other class. e) It must implement an interface. 35. *Which of the following statements is correct? a) Comparable<String> c = new Date(); b) Comparable<Object> c = new Date(); c) Comparable<String> c = new String("abc"); d) Comparable<String> c = "abc"; 36. A variable defined inside a method is referred to as. a) a method variable b) a local variable c) a block variable d) a global variable 37. All Java applications must have a method. a) public static main(string[ ] args) b) public static Main(String args[ ]) c) public static void main(string[ ] args) d) public void main(string[ ] args) 38. Suppose your method does not return any value, which of the following keywords can be used as a return type? a) void b) double c) public d) int e) None of the above 39. Which of the following statements are correct? a) char[ ][ ][ ] chararray = new char[2][2][ ]; b) char[ ][ ][ ] chararray = new char[][2][2]; c) char[ ][ ][ ] chararray = {{'a', 'b'}, {'c', 'd'}, {'e', 'f'}}; d) char[2][2][ ] chararray = {'a', 'b'}; 40. Which of the following statements are correct? a) char[2][2] chararray = {{'a', 'b'}, {'c', 'd'}}; b) char[ ][ ] chararray = {'a', 'b'}; c) char[ ][ ] chararray = {{'a', 'b'}, {'c', 'd'}}; d) char[2][ ] chararray = {{'a', 'b'}, {'c', 'd'}}; 41. Which of the following declarations are correct? a) public static void print(string... strings, double... numbers) b) public static void print(double... numbers, String name) c) public static void print(int n, double... numbers) d) public static double... print(double d1, double d2) 42. Which of the following kind of nested classes can be instantiated without the need of a containing object? a) Anonymous inner class. b) Local class. c) Member inner class d) Static nested class. 43. The method copies the sourcearray to the targetarray. a) System.arrayCopy(sourceArray, 0, targetarray, 0, sourcearray.length); b) System.copyArrays(sourceArray, 0, targetarray, 0, sourcearray.length); c) System.arraycopy(sourceArray, 0, targetarray, 0, sourcearray.length); d) System.copyarrays(sourceArray, 0, targetarray, 0, sourcearray.length); 44. Assume int[ ] t = {1, 2, 3, 4}. What is t.length? 4

5 a) 5 b) 0 c) 4 d) *Which of the following statements is valid? a) int i = new int(30); b) char[ ] c = new char(); c) double d[ ] = new double[30]; d) int[ ] i = {3, 4, 3, 2}; e) char[ ] c = new char[4]{'a', 'b', 'c', 'd'}; 46. If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is. a) 3 b) 4 c) 0 d) 1 e) What is the representation of the third element in an array called a? a) a[3] b) a(3) c) a(2) d) a[2] 48. You can declare two variables with the same name in. a) two nested blocks in a method (two nested blocks means one being inside the other) b) a block c) different methods in a class d) a method one as a formal parameter and the other as a local variable 49. To prevent a class from being instantiated, a) use the static modifier on the constructor. b) don't use any modifiers on the constructor. c) use the private modifier on the constructor. d) use the public modifier on the constructor. 50. A method that is associated with an individual object is called. a) a static method b) an instance method c) a class method d) an object method 51. Variables that are shared by every instances of a class are. a) class variables b) public variables c) instance variables d) private variables 52. The default value for data field of a boolean type, numeric type, object type is, respectively. a) false, 0, null b) true, 1, Null c) true, 1, null d) true, 0, null e) false, 1, null 53. Given the declaration Circle x = new Circle(), which of the following statement is most accurate? a) x contains a reference to a Circle object. b) You can assign an int value to x. c) x contains an int value. d) x contains an object of the Circle type. 54. is invoked to create an object. a) The main method b) A method with the void return type c) A method with a return type d) A constructor 55. Which of the following statements are correct? (Choose all that apply.) a) Number i = 4.5; b) Double i = 4.5; c) Integer i = 4.5; d) Object i = 4.5; 56. *Which of the following classes are immutable? a) Integer b) String c) Double d) BigInteger e) BigDecimal 57. *Suppose A is an interface, B is a concrete class with a default constructor that implements A. Which of the following is correct? a) B b = new B(); b) A a = new A(); c) A a = new B(); d) B b = new A(); 58. *Suppose A is an abstract class, B is a concrete subclass of A, and both A and B have a default constructor. Which of the following is correct? a) B b = new B(); b) A a = new A(); c) B b = new A(); d) A a = new B(); 59. Given the class definition : class A { class A1 { } },which of the following is the correct way to create an instance of class A1 a) new A.A1() b) (new A()). new A.A1() c) new A(new A.A1() ) d) new A.A1(new A() ) 5

6 60. Which of the following class definitions defines a legal abstract class? a) public class abstract A { abstract void unfinished(); } b) class A { abstract void unfinished(); } c) class A { abstract void unfinished() { } } d) abstract class A { abstract void unfinished(); } 61. Inheritance means. a) that data fields should be declared private b) that a variable of supertype can refer to a subtype object c) that a class can extend another class d) that a class can contain another class 62. Encapsulation means that. a) a class can extend another class b) a class can contain another class c) data fields should be declared private d) a variable of supertype can refer to a subtype object 63. Polymorphism means that. a)a class can contain another class b) a variable of supertype can refer to a subtype object c) data fields should be declared private d) a class can extend another class 64. Which of the following classes cannot be extended? a) class A { private A();} b) class A { } c) class A { protected A();} d) final class A { } 65. The visibility of Java modifiers increases in which of the following order: a) private, package, protected, and public. b) private, protected, package, and public. c) package, private, protected, and public. d) package, protected, private, and public. 66. What modifier should you use on a class so that a class in the same package can access it but a class in a different package cannot access it? a) protected b) private c) public d) package (default). 67. Object-oriented programming allows you to derive new classes from existing classes. This is called. a) inheritance b) abstraction c) encapsulation d) generalization 68. If the statement S2 cause an exception (and all other Sk( k = 1..7) do not) in the following statement: try { S1; S2; S3; } catch(exception1 e1) { S4; } catch(exception3 e3) { throw new Exception3(); } } catch(exception2 e2) { S5; } finally { S6; } S7; Then which of the following statement sequences is the correct sequence of statements executed after S2, if the exception is of the type Exception3? Suppose that Exception2 is a superclass of Exception3 while Exception1 is not. a) S6 b) S7 c) S6,S7 d) S4,S6,S7 e) S4,S5,S6,S7 69. Which of the following method would cause compile error if we put the code : "L.add(e) ;" into their bodies? a) public <E> void m0(list<e> L, E e) { } b) public <E> void m1(list<? extends E> L, E e) { } c) public <E> void m2(list<? super E> L, E e) { } d) public void m2(list L, Object e) { } 6

7 70. *Which of the following methods can be called by "m(new ArrayList<String>(), new Object() ) " without causing compile error? a) public <E> void m(list<e> L, E e) { } b) public <E> void m(list<? extends E> L, E e) { } c) public <E> void m(list<? super E> L, E e) { } d) public void m2(list L, Object e) { } II 程式設計 (30 pts) 1. Given the following class : public class Sum implements Runnable { public int rlt, from, to; Sum(int f, int t) { from = f; to = t} public void run() { for(int k = from; k<= to; k++) rlt += k; } Suppose we want to compute ( ) using multithreads. Therefore we partition this task into two subtasks: task1 perform ( ) and task2 performs ( ). Now, with the Sum class given, try to design a method which would create and start two threads to perform each subtask, and finally, after they complete, combine their results to get the final one. public static void man() { Sum task1 = _new Sum(1,1000), task2 = new Sum(1001,2000) ; Thread t1 = new Thread(task1), t2 = _new Thread(task2) ; // start both threads t1.start(); t2.start(); //wait them to complete t1.join(); t2.join() int rlt = _task1.rlt + task2.rlt ; out.println( The sum from 1 to 2000 is + rlt); } 2. Design a method duplicate(list L), which, when given a list of objects, can return the set of all objects which occur more than one time in L. import java.uitl.*; static <E> Set<E> duplicate(list<? extends E> L){ Set<E> s1 = new HashSet<E>() ; Set<E> rlt = new HashSet<E>(); for(e e : L) { if( s1.contains(e) ) } rlt.add(e) ; else s1.add(e) ; } return rlt; 7

Mock exam 1 for SCJP 6

Mock exam 1 for SCJP 6 Mock exam 1 for SCJP 6 The sample test is modeled on the Sun Certification for Java TM 6 Programmer exam. The test has 50 questions and needs to be executed in 2 hours. The real exam may be a little tougher

More information

Introduction to Java A First Look

Introduction to Java A First Look Introduction to Java A First Look Java is a second or third generation object language Integrates many of best features Smalltalk C++ Like Smalltalk Everything is an object Interpreted or just in time

More information

(e) none of the above.

(e) none of the above. 1 The default value of a static integer variable of a class in Java is, (a) 0 (b) 1 (c) Garbage value (d) Null (e) -1 2 What will be printed as the output of the following program? public class testincr

More information

Lecture 2 Introduction to Concurrency

Lecture 2 Introduction to Concurrency CMSC 433 Fall 2016 Section 0101 Rance Cleaveland Lecture 2 Introduction to Concurrency 9/1/2016 2012-16 University of Maryland Running a Sequential Program Executable Machine instructions to be performed

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

Lecture 2 Introduction to Concurrency

Lecture 2 Introduction to Concurrency CMSC 433 Spring 2014 Section 0101 Rance Cleaveland Lecture 2 Introduction to Concurrency 1/29/2014 2012-14 University of Maryland Running a Sequential Program Executable Machine instructions to be performed

More information

CS 111 Classes I 1. Software Organization View to this point:

CS 111 Classes I 1. Software Organization View to this point: CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects

More information

Threads. Multithreaded program. Examples of threads. Threads and Processes. Problems of multitasking. Multitask in Java

Threads. Multithreaded program. Examples of threads. Threads and Processes. Problems of multitasking. Multitask in Java Multithreaded program Threads A multithreaded program can start and execute several parts of its code in the same time A thread is a single sequential flow of control within a program R. Grin Java : threads

More information

Exam JP2011(Java Programming) MidTerm Test 5/ Name RegNo % 1 is. a) 1 b) 2 c) 3 d) 4 e) 0

Exam JP2011(Java Programming) MidTerm Test 5/ Name RegNo % 1 is. a) 1 b) 2 c) 3 d) 4 e) 0 Exam JP2011(Java Programming) MidTerm Test 5/6 2011 Name RegNo 1. 25 % 1 is. a) 1 b) 2 c) 3 d) 4 e) 0 2. -24 % -5 is. a) 3 b) -3 c) 4 d) -4 e) 0 3. Which of these data types requires the most amount of

More information

Self-test Java Programming

Self-test Java Programming Self-test Java Programming Document: e0883test.fm 22/01/2013 ABIS Training & Consulting P.O. Box 220 B-3000 Leuven Belgium TRAINING & CONSULTING INTRODUCTION TO THE SELF-TEST JAVA PROGRAMMING This test

More information

Introduction to Java Threads

Introduction to Java Threads Object-Oriented Programming Introduction to Java Threads 4003-243 1 What is a Process? Here s what happens when you run this Java program and launch 3 instances while monitoring with top On a single CPU

More information

CMPU102: Exam 1 Solutions Spring 2005

CMPU102: Exam 1 Solutions Spring 2005 CMPU102: Exam 1 Solutions Spring 2005 1. Consider the following statements: int a = 4; int b = 7; b *= a; What are the resulting values of a and b? a = 4 b = 28 2. Consider the following statements: int

More information

Java Class Library. Java the platform contains around 4,000 classes/interfaces

Java Class Library. Java the platform contains around 4,000 classes/interfaces Java Class Library Java the platform contains around 4,000 classes/interfaces Data Structures Networking, Files Graphical User Interfaces Security and Encryption Image Processing Multimedia authoring/playback

More information

Array-Based Lists. Lists

Array-Based Lists. Lists Array-Based Lists Collections and ArrayIntList Reading: RS Ch. 15 slides created by Marty Stepp http://www.cs.washington.edu/143/ Modified by Sarah Heckman Lists list: a collection storing an ordered sequence

More information

Java Collections Framework

Java Collections Framework Java Collections Framework This article is part of Marcus Biel s free Java course focusing on clean code principles. In this piece, you will be given a high-level introduction of the Java Collections Framework

More information

Java SE 8 Programming

Java SE 8 Programming Oracle University Contact Us: 1.800.529.0165 Java SE 8 Programming Duration: 5 Days What you will learn This Java SE 8 Programming training covers the core language features and Application Programming

More information

The Collections API 9/5/00 1. Lecture Objectives

The Collections API 9/5/00 1. Lecture Objectives The Collections API Mark Allen Weiss Copyright 2000 9/5/00 1 Lecture Objectives To see some bad design (Java 1.1) To see a better design (Java 1.2) To learn how to use the Collections package in Java 1.2.

More information

c) Comments are areas of text ignored by the Java compiler.

c) Comments are areas of text ignored by the Java compiler. 1) Java applications a) A java application has a special method, called the main method, which is where the program will start. i) Each class can only have one main method. ii) You can tell eclipse which

More information

Outline. Inheritance. Abstract Classes Interfaces. Class Extension Overriding Methods Inheritance and Constructors Polymorphism.

Outline. Inheritance. Abstract Classes Interfaces. Class Extension Overriding Methods Inheritance and Constructors Polymorphism. Outline Inheritance Class Extension Overriding Methods Inheritance and Constructors Polymorphism Abstract Classes Interfaces 1 OOP Principles Encapsulation Methods and data are combined in classes Not

More information

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2015 The third

More information

There are two distinct types of Multitasking i.e. Processor-Based and Thread-Based multitasking.

There are two distinct types of Multitasking i.e. Processor-Based and Thread-Based multitasking. Multithreading Multithreading is a conceptual programming concept where a program (process) is divided into two or more subprograms (process), which can be implemented at the same time in parallel. A multithreaded

More information

COMP1008 Inheritance. Outline. Subclass and Superclass. Inheritance. Multiple Subclasses. Inheritance Hierarchy

COMP1008 Inheritance. Outline. Subclass and Superclass. Inheritance. Multiple Subclasses. Inheritance Hierarchy Outline COMP1008 Inheritance Introduction to inheritance. How Java supports inheritance. Inheritance is a key feature of object-oriented programming. 2 Inheritance Subclass and Superclass Models the kind-of

More information

Collections & Iterators

Collections & Iterators Collections & Iterators 9-23-2013 Collections & Iterators Collection interfaces & classes, in java.util Generic Types HW#2 due today HW#3 due Monday, October 7 th Reading Assignment: EJ2, Chapter 5, Items

More information

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,

More information

Fundamentals of Java Programming

Fundamentals of Java Programming Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

TRUE / FALSE MULTIPLE CHOICE

TRUE / FALSE MULTIPLE CHOICE CS 111 Exam 3 FORM A TRUE / FALSE 1. If you write a tostring method for a class, it can be invoked automatically to output the string generated by that method. T 2. You can change the contents of a String

More information

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman

More information

Multithreading in Java

Multithreading in Java Multithreading in Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park Problem Multiple tasks for computer Draw & display images on screen Check keyboard

More information

Using and Programming Generics in J2SE 5.0

Using and Programming Generics in J2SE 5.0 Page 1 of 6 http://java.sun.com/developer/technicalarticles/j2se/generics/ Feb 07, 2005 Article Using and Programming Generics in J2SE 5.0 By Qusay H. Mahmoud, October 2004 A Java collection is a flexible

More information

Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types

Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types Interfaces & Java Types Lecture 10 CS211 Fall 2005 Java Interfaces So far, we have mostly talked about interfaces informally, in the English sense of the word An interface describes how a client interacts

More information

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0 The following applies to all exams: Once exam vouchers are purchased you have up to one year from the date of purchase to use it. Each voucher is valid for one exam and may only be used at an Authorized

More information

Basic Programming and PC Skills: Basic Programming and PC Skills:

Basic Programming and PC Skills: Basic Programming and PC Skills: Texas University Interscholastic League Contest Event: Computer Science The contest challenges high school students to gain an understanding of the significance of computation as well as the details of

More information

Concrete collections in Java library. Java Collection framework: On concrete collections and their implementation. LinkedList: doubly-linked list

Concrete collections in Java library. Java Collection framework: On concrete collections and their implementation. LinkedList: doubly-linked list Concrete collections in Java library Java Collection framework: On concrete collections and their implementation 1 ArrayList: indexed sequence that grows/shrinks dynamically LinkedList: ordered sequence

More information

Java's Collection Framework Another use of polymorphism and interfaces

Java's Collection Framework Another use of polymorphism and interfaces Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer 3-1 Outline Java's Collection Framework Unified architecture for representing and manipulating collections Collection

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

CMSC 433 Section 0101 Fall 2012 Midterm Exam #2

CMSC 433 Section 0101 Fall 2012 Midterm Exam #2 Name: CMSC 433 Section 0101 Fall 2012 Midterm Exam #2 Directions: Test is closed book, closed notes, no electronics. Answer every question; write solutions in spaces provided. Use backs of pages for scratch

More information

CS193j, Stanford Handout #10 OOP 3

CS193j, Stanford Handout #10 OOP 3 CS193j, Stanford Handout #10 Summer, 2003 Manu Kumar OOP 3 Abstract Superclass Factor Common Code Up Several related classes with overlapping code Factor common code up into a common superclass Examples

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Analyze the following code: 1) int[ ] x = {1, 2, 3, 4; int[ ] y = x; x = new int[2];

More information

Answer Key. / append i at the tail of this queue and return i / public int enqueue ( int i ) ;

Answer Key. / append i at the tail of this queue and return i / public int enqueue ( int i ) ; Answer Key 1. General Understanding (10 points) (a) What is the relationship between a method s throws clause and that checked exceptions the can be thrown during the execution of the method? (b) If a

More information

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013 Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper

More information

Java Programming Language

Java Programming Language Lecture 1 Part II Java Programming Language Additional Features and Constructs Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Subclasses and

More information

Lecture 4. The Java Collections Framework

Lecture 4. The Java Collections Framework Lecture 4. The Java s Framework Chapters 6.3-6.4-1 - Outline Introduction to the Java s Framework Iterators Interfaces, Classes and Classes of the Java s Framework - 2 - Outline Introduction to the Java

More information

Java Interview Prep E2 Series Java Interview Prep

Java Interview Prep E2 Series Java Interview Prep Object Oriented Programming 1. What is the difference between object oriented and object based languages? Programming languages that support abstraction, encapsulation, inheritance and polymorphism are

More information

Threads and Synchronization

Threads and Synchronization Threads and Synchronization Mark Allen Weiss Copyright 2000 1 What threads are Outline of Topics The Thread class and starting some threads Synchronization: keeping threads from clobbering each other Deadlock

More information

6) Is the following loop correct?for (; ; ); 6)

6) Is the following loop correct?for (; ; ); 6) Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) You can always convert a while loop to a for loop. 1) 2) Will the following program terminate?int

More information

JAVA COLLECTIONS FRAMEWORK

JAVA COLLECTIONS FRAMEWORK http://www.tutorialspoint.com/java/java_collections.htm JAVA COLLECTIONS FRAMEWORK Copyright tutorialspoint.com Prior to Java 2, Java provided ad hoc classes such as Dictionary, Vector, Stack, and Properties

More information

Name: Pennkey: CIS 120 Midterm II March 30, 2012

Name: Pennkey: CIS 120 Midterm II March 30, 2012 Name: Pennkey: CIS 120 Midterm II March 30, 2012 1 /20 2 /20 3 /16 4 /16 5ab /13 5c /15 Total /100 Do not begin the exam until you are told to do so. You have 50 minutes to complete the exam. There are

More information

using java 1.5 generics

using java 1.5 generics Weiss_3e_04 Page 131 Wednesday, January 12, 2005 3:05 PM 4.7 implementing generic components using java 1.5 generics 131 4.7 implementing generic components using java 1.5 generics We have already seen

More information

Advanced Java Programming. Agenda. Multi-Threaded Programming. Threads. Shmulik London

Advanced Java Programming. Agenda. Multi-Threaded Programming. Threads. Shmulik London Advanced Java Programming Shmulik London Lecture #7 Threads Advanced Java Programming / Shmulik London 2006 Interdisciplinary Center Herzeliza Israel 1 Agenda Threads Scheduling Critical Sections Deadlocks

More information

CS 335 Java Programming Inheritance

CS 335 Java Programming Inheritance CS 335 Java Programming Inheritance Java: Object-Oriented Programming Inheritance: superclasses and subclasses Polymorphism: abstract and concrete classes Dynamic binding Multiple inheritance via Interfaces

More information

CS11 Java. Fall 2014-2015 Lecture 7

CS11 Java. Fall 2014-2015 Lecture 7 CS11 Java Fall 2014-2015 Lecture 7 Today s Topics! All about Java Threads! Some Lab 7 tips Java Threading Recap! A program can use multiple threads to do several things at once " A thread can have local

More information

Part I. Multiple Choice Questions (2 points each):

Part I. Multiple Choice Questions (2 points each): Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******

More information

Generics. IRS W-9 Form

Generics. IRS W-9 Form Generics IRS W-9 Form Generics Generic class and methods. BNF notation Syntax Non-parametrized class: < class declaration > ::= "class" < identifier > ["extends" < type >] ["implements" < type list >]

More information

Android Application Development Course Program

Android Application Development Course Program Android Application Development Course Program Part I Introduction to Programming 1. Introduction to programming. Compilers, interpreters, virtual machines. Primitive data types, variables, basic operators,

More information

Chapter 13 - Inheritance

Chapter 13 - Inheritance Goals Chapter 13 - Inheritance To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package

More information

q Arrays: store multiple values of the same type. q Conveniently refer to items by their index q Need to know the size before declaring them:

q Arrays: store multiple values of the same type. q Conveniently refer to items by their index q Need to know the size before declaring them: Using arrays to store data ArrayLists Chapter 12.1 in Savitch q Arrays: store multiple values of the same type. q Conveniently refer to items by their index q Need to know the size before declaring them:

More information

Part 3: GridWorld Classes and Interfaces

Part 3: GridWorld Classes and Interfaces GridWorld Case Study Part 3: GridWorld Classes and Interfaces In our example programs, a grid contains actors that are instances of classes that extend the Actor class. There are two classes that implement

More information

Comprehensive support for general-purpose concurrent programming; partitioned into three packages:

Comprehensive support for general-purpose concurrent programming; partitioned into three packages: Java 1.5 Concurrency Utilities Comprehensive support for general-purpose concurrent programming; partitioned into three packages: java.util.concurrent support common concurrent programming paradigms, e.g.,

More information

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class This homework is to be done individually. You may, of course, ask your fellow classmates for help if you have trouble editing files,

More information

Introduction to Multithreading in Java. - Alessio Bechini - PCB TCB TCB TCB. Runtime Support Library for Threads (TCB manager)

Introduction to Multithreading in Java. - Alessio Bechini - PCB TCB TCB TCB. Runtime Support Library for Threads (TCB manager) 2 Introduction to Multithreading in Java - Alessio Bechini - Multitasking and Multithreading PCB Single PCB TCB TCB TCB Multiple s Runtime Support Library for s (TCB manager) Operating System (PCB Manager)

More information

JAVA INTERVIEW QUESTIONS

JAVA INTERVIEW QUESTIONS JAVA INTERVIEW QUESTIONS http://www.tutorialspoint.com/java/java_interview_questions.htm Copyright tutorialspoint.com Dear readers, these Java Interview Questions have been designed especially to get you

More information

Course: Introduction to Java Using Eclipse Training

Course: Introduction to Java Using Eclipse Training Course: Introduction to Java Using Eclipse Training Course Length: Duration: 5 days Course Code: WA1278 DESCRIPTION: This course introduces the Java programming language and how to develop Java applications

More information

Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.

Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. JAVA TYPES BASIC DATA TYPES GENERAL Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. Based on the data type

More information

D06 PROGRAMMING with JAVA

D06 PROGRAMMING with JAVA Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch20 Data Structures I PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for

More information

Java EE Web Development Course Program

Java EE Web Development Course Program Java EE Web Development Course Program Part I Introduction to Programming 1. Introduction to programming. Compilers, interpreters, virtual machines. Primitive types, variables, basic operators, expressions,

More information

Java the UML Way: Integrating Object-Oriented Design and Programming

Java the UML Way: Integrating Object-Oriented Design and Programming Java the UML Way: Integrating Object-Oriented Design and Programming by Else Lervik and Vegard B. Havdal ISBN 0-470-84386-1 John Wiley & Sons, Ltd. Table of Contents Preface xi 1 Introduction 1 1.1 Preliminaries

More information

Java Application Developer Certificate Program Competencies

Java Application Developer Certificate Program Competencies Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle

More information

Advanced Placement Computer Science. Main Tenants of OO Programming. Inheritance and Polymorphism. Nomenclature of Inheritance

Advanced Placement Computer Science. Main Tenants of OO Programming. Inheritance and Polymorphism. Nomenclature of Inheritance Advanced Placement Computer Science Inheritance and Polymorphism What s past is prologue. Don t write it twice write it once and reuse it. Bekki George James E. Taylor HS, Katy Main Tenants of OO Programming

More information

C++ How to Program, 8/e by Pearson Education, Inc. All Rights Reserved.

C++ How to Program, 8/e by Pearson Education, Inc. All Rights Reserved. C++ How to Program, 8/e 1992-2012 by Pearson Education, Inc. 1992-2012 by Pearson Education, Inc. 1992-2012 by Pearson Education, Inc. We ve studied fixed-size data structures such as one-dimensional arrays

More information

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system. http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral

More information

Methods and Inheritance: Overriding

Methods and Inheritance: Overriding Methods and Inheritance: Overriding We might want to require that every Person can dance. But the way a Lecturer dances is not likely to be the same as the way a Student dances... Student overrides the

More information

Generic Containers and Iterators in Java

Generic Containers and Iterators in Java Generic Containers and Iterators in Java Motivation containers are objects that store an arbitrary number of other objects these containers are manipulated by iterating over the contents virtually any

More information

An Introduction to Java Threads

An Introduction to Java Threads An Introduction to Java Threads What Are Threads? A Simple Thread Example Thread Attributes Multithreaded Programs What Are Threads? A thread--sometimes known as a lightweight process--is a single sequential

More information

RenderCAD S.r.l. Formazione

RenderCAD S.r.l. Formazione Descrizione This course teaches participants how to develop Java programs. The course focuses on teaching the core Java language (J2SE), including essential object-oriented principles. In addition to Java,

More information

Module 7. Polymorphism, Abstract Classes, and Interfaces. Adapted from Absolute Java, Rose Williams, Binghamton University

Module 7. Polymorphism, Abstract Classes, and Interfaces. Adapted from Absolute Java, Rose Williams, Binghamton University Module 7 Polymorphism, Abstract Classes, and Interfaces Adapted from Absolute Java, Rose Williams, Binghamton University Introduction to Polymorphism There are three main programming mechanisms that constitute

More information

Java Collections Framework. 21 July 2016 OSU CSE 1

Java Collections Framework. 21 July 2016 OSU CSE 1 Java Collections Framework 21 July 2016 OSU CSE 1 Overview The Java Collections Framework (JCF) is a group of interfaces and classes similar to the OSU CSE components The similarities will become clearly

More information

Concurrent Programming (COMP 150-CCP) Spring 2008 Dr. Richard S. Hall April 24 th, 2008

Concurrent Programming (COMP 150-CCP) Spring 2008 Dr. Richard S. Hall April 24 th, 2008 Concurrent Programming (COMP 150-CCP) Spring 2008 Dr. Richard S. Hall April 24 th, 2008 Write your name on each sheet of paper you hand in. Make sure that mobile phones are turned off. This is a closed-book

More information

DM550 Introduction to Programming part 2. Jan Baumbach.

DM550 Introduction to Programming part 2. Jan Baumbach. DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net PROJECT 2 Organizational Details The project has to be passed to pass the course It has to be

More information

Data Structures in the Java API

Data Structures in the Java API Data Structures in the Java API Vector From the java.util package. Vectors can resize themselves dynamically. Inserting elements into a Vector whose current size is less than its capacity is a relatively

More information

G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency G52CON: Concepts of Concurrency Lecture 11 Synchronisation in Java" Brian Logan School of Computer Science bsl@cs.nott.ac.uk Outline of this lecture" mutual exclusion in Java condition synchronisation

More information

Introduction to Collections. 13-Nov-15

Introduction to Collections. 13-Nov-15 Introduction to Collections 13-Nov-15 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections are defined in java.util The Collections framework

More information

The IC Language Specification. Spring 2006 Cornell University

The IC Language Specification. Spring 2006 Cornell University The IC Language Specification Spring 2006 Cornell University The IC language is a simple object-oriented language that we will use in the CS413 project. The goal is to build a complete optimizing compiler

More information

Generics and Collections

Generics and Collections 7 Generics and Collections Certification Objectives l l l Design Using Collections Override equals() and hashcode(), Distinguish == and equals() Use Generic Versions of Collections Including Set, List,

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. For the question(s) below, assume values is an int array that is currently filled to capacity,

More information

Java Programming. Final Examination on August 22, 2015 Summer 2015

Java Programming. Final Examination on August 22, 2015 Summer 2015 Java Programming Final Examination on August 22, 2015 Summer 2015 Department of Computer Science and Information Engineering National Taiwan University Problem 1 (20 points) Multiple choice questions.

More information

D06 PROGRAMMING with JAVA

D06 PROGRAMMING with JAVA Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch13 Inheritance PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for accompanying

More information

Introduction to Java

Introduction to Java Introduction to Java The Java architecture consists of: a high-level object-oriented programming language, a platform-independent representation of a compiled class, a pre-defined set of run-time libraries,

More information

Generic Types and the Java Collections Framework. Lecture 15 CS2110 Fall 2011

Generic Types and the Java Collections Framework. Lecture 15 CS2110 Fall 2011 Generic Types and the Java Collections Framework Lecture 15 CS2110 Fall 2011 Generic Types When using a collection (e.g., LinkedList, HashSet, HashMap), we generally have a single type T of elements that

More information

Lecture 4. The Java Collections Framework

Lecture 4. The Java Collections Framework Lecture 4. The Java s Framework Chapters 6.3-6.4-1 - Outline Introduction to the Java s Framework Iterators Interfaces Classes Classes - 2 - The Java s Framework We will consider the Java s Framework as

More information

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship. CSCI 253 Object Oriented Design: Java Review OOP George Blankenship George Blankenship 1 Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation Abstract Data Type (ADT) Implementation

More information

1 of 1 24/05/2013 10:23 AM

1 of 1 24/05/2013 10:23 AM ?Init=Y 1 of 1 24/05/2013 10:23 AM 1. Which of the following correctly defines a queue? a list of elements with a first in last out order. a list of elements with a first in first out order. (*) something

More information

243 Week 3 Lecture - Interfaces

243 Week 3 Lecture - Interfaces One problem, many solutions 243 Week 3 Lecture - Interfaces Suppose we want to implement a set of classes to represent various shapes such as circles and rectangles. We want to be able to calculate the

More information

CISC 213- Practice Test 2

CISC 213- Practice Test 2 CISC 213- Practice Test 2 Part A- The following questions are multiple choice or short answer: 1. Say we define a class called ABC and we don't define any constructor. Then which of the following is true:

More information

VU Mobile Powered by S NO Group All Rights Reserved S NO Group 2012

VU Mobile Powered by S NO Group All Rights Reserved S NO Group 2012 1 CS304 Final Term Solved MCQs Mega File (Latest All in One) User can make virtual table explicitly. True False In order to define a class template the first line of definition must be: template

More information

Chapter 2. Values, Variables, and Types. 2.1 Java Values in DrJava s Interaction Pane

Chapter 2. Values, Variables, and Types. 2.1 Java Values in DrJava s Interaction Pane 14 Chapter 2 Values, Variables, and Types In this chapter we explore the primitive building blocks that are used to develop Java programs. We experiment with the following concepts within DrJava s interactive

More information

Java Memory Management

Java Memory Management Java Memory Management 1 Tracing program execution Trace: To follow the course or trail of. When you need to find and fix a bug or have to understand a tricky piece of code that your coworker wrote, you

More information

OOP A Deeper Look. Iterators, The Collection Hierarchy

OOP A Deeper Look. Iterators, The Collection Hierarchy OOP A Deeper Look 4B Iterators, The Collection Hierarchy 1 Iterating over a list SinglyLinkedList list = new SinglyLinkedList();... for (int i=0; i

More information

Java's Collection Framework

Java's Collection Framework Java's Collection Framework 1 Java's Collection Framework w w w Collection framework Unified architecture for representing and manipulating collections Java's collection framework contains Interfaces (ADTs):

More information

Topic 4: Inheritance

Topic 4: Inheritance Topic 4: Inheritance Extending, Overriding and Final Jesper Pedersen Notander Department of Computer Science Lund University Faculty of Engineering Learning Scala Seminar 2 Contents Abstract and concrete

More information