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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Built-in Concurrency Primitives in Java Programming Language. by Yourii Martiak and Mahir Atmis

Built-in Concurrency Primitives in Java Programming Language. by Yourii Martiak and Mahir Atmis Built-in Concurrency Primitives in Java Programming Language by Yourii Martiak and Mahir Atmis Overview One of the many strengths of Java is the built into the programming language support for concurrency

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

History OOP languages Year Language 1967 Simula-67 1983 Smalltalk

History OOP languages Year Language 1967 Simula-67 1983 Smalltalk History OOP languages Intro 1 Year Language reported dates vary for some languages... design Vs delievered 1957 Fortran High level programming language 1958 Lisp 1959 Cobol 1960 Algol Structured Programming

More information

Licensed for viewing only. Printing is prohibited. For hard copies, please purchase from www.agileskills.org

Licensed for viewing only. Printing is prohibited. For hard copies, please purchase from www.agileskills.org Unit Test 301 CHAPTER 12Unit Test Unit test Suppose that you are writing a CourseCatalog class to record the information of some courses: class CourseCatalog { CourseCatalog() { void add(course course)

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

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

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input

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

Advanced OOP Concepts in Java

Advanced OOP Concepts in Java Advanced OOP Concepts in Java Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh spring@imap.pitt.edu http://www.sis.pitt.edu/~spring 09/28/2001 1 Overview

More information

Collections in Java. Arrays. Iterators. Collections (also called containers) Has special language support. Iterator (i) Collection (i) Set (i),

Collections in Java. Arrays. Iterators. Collections (also called containers) Has special language support. Iterator (i) Collection (i) Set (i), Arrays Has special language support Iterators Collections in Java Iterator (i) Collections (also called containers) Collection (i) Set (i), HashSet (c), TreeSet (c) List (i), ArrayList (c), LinkedList

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything

More information

PLV Goldstein 315, Tuesdays and Thursdays, 6:00PM-7:50PM. Tuesdays and Thursdays, 4:00PM-5:30PM and 7:50PM 9:30PM at PLV G320

PLV Goldstein 315, Tuesdays and Thursdays, 6:00PM-7:50PM. Tuesdays and Thursdays, 4:00PM-5:30PM and 7:50PM 9:30PM at PLV G320 CRN:22430/21519 Pace University Spring 2006 CS122/504 Computer Programming II Instructor Lectures Office Hours Dr. Lixin Tao, ltao@pace.edu, http://csis.pace.edu/~lixin Pleasantville Office: G320, (914)773-3449

More information

Class 32: The Java Collections Framework

Class 32: The Java Collections Framework Introduction to Computation and Problem Solving Class 32: The Java Collections Framework Prof. Steven R. Lerman and Dr. V. Judson Harward Goals To introduce you to the data structure classes that come

More information

CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris

CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris 1 Collections - Set What is a Set? A Set is an unordered sequence of data with no duplicates Not like a List where you

More information

Glossary of Object Oriented Terms

Glossary of Object Oriented Terms Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction

More information

Outline of this lecture G52CON: Concepts of Concurrency

Outline of this lecture G52CON: Concepts of Concurrency Outline of this lecture G52CON: Concepts of Concurrency Lecture 10 Synchronisation in Java Natasha Alechina School of Computer Science nza@cs.nott.ac.uk mutual exclusion in Java condition synchronisation

More information

J a v a Quiz (Unit 3, Test 0 Practice)

J a v a Quiz (Unit 3, Test 0 Practice) Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

More information

STORM. Simulation TOol for Real-time Multiprocessor scheduling. Designer Guide V3.3.1 September 2009

STORM. Simulation TOol for Real-time Multiprocessor scheduling. Designer Guide V3.3.1 September 2009 STORM Simulation TOol for Real-time Multiprocessor scheduling Designer Guide V3.3.1 September 2009 Richard Urunuela, Anne-Marie Déplanche, Yvon Trinquet This work is part of the project PHERMA supported

More information

Threads & Tasks: Executor Framework

Threads & Tasks: Executor Framework Threads & Tasks: Executor Framework Introduction & Motivation WebServer Executor Framework Callable and Future 12 April 2012 1 Threads & Tasks Motivations for using threads Actor-based Goal: Create an

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) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

Java Memory Model: Content

Java Memory Model: Content Java Memory Model: Content Memory Models Double Checked Locking Problem Java Memory Model: Happens Before Relation Volatile: in depth 16 March 2012 1 Java Memory Model JMM specifies guarantees given by

More information

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 SOLUTIONS.

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 SOLUTIONS. Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 Name: SOLUTIONS Athena* User Name: Instructions This quiz is 50 minutes long. It contains

More information

Designing with Exceptions. CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219

Designing with Exceptions. CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219 Designing with Exceptions CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219 Testing vs. Debugging Testing Coding Does the code work properly YES NO 2 Debugging Testing

More information

The Java Collections Framework

The Java Collections Framework The Java Collections Framework Definition Set of interfaces, abstract and concrete classes that define common abstract data types in Java e.g. list, stack, queue, set, map Part of the java.util package

More information

Datastrukturer och standardalgoritmer i Java

Datastrukturer och standardalgoritmer i Java 1 (8) Datastrukturer och standardalgoritmer i Java Dokumentet listar ett urval av konstruktorer och metoder för några vanliga Javaklasser. Class ArrayList ArrayList() Constructs an empty list. void

More information

Crash Course in Java

Crash Course in Java Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is

More information

Java Coding Practices for Improved Application Performance

Java Coding Practices for Improved Application Performance 1 Java Coding Practices for Improved Application Performance Lloyd Hagemo Senior Director Application Infrastructure Management Group Candle Corporation In the beginning, Java became the language of the

More information

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT BSc (Hons) in Computer Applications, BSc (Hons) Computer Science with Network Security, BSc (Hons) Business Information Systems & BSc (Hons) Software Engineering Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT

More information

JAVA - MULTITHREADING

JAVA - MULTITHREADING JAVA - MULTITHREADING http://www.tutorialspoint.com/java/java_multithreading.htm Copyright tutorialspoint.com Java is amulti threaded programming language which means we can develop multi threaded program

More information

Exception Handling. Overloaded methods Interfaces Inheritance hierarchies Constructors. OOP: Exception Handling 1

Exception Handling. Overloaded methods Interfaces Inheritance hierarchies Constructors. OOP: Exception Handling 1 Exception Handling Error handling in general Java's exception handling mechanism The catch-or-specify priciple Checked and unchecked exceptions Exceptions impact/usage Overloaded methods Interfaces Inheritance

More information

09336863931 : provid.ir

09336863931 : provid.ir provid.ir 09336863931 : NET Architecture Core CSharp o Variable o Variable Scope o Type Inference o Namespaces o Preprocessor Directives Statements and Flow of Execution o If Statement o Switch Statement

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75 Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship

More information

Monitors, Java, Threads and Processes

Monitors, Java, Threads and Processes Monitors, Java, Threads and Processes 185 An object-oriented view of shared memory A semaphore can be seen as a shared object accessible through two methods: wait and signal. The idea behind the concept

More information

http://algs4.cs.princeton.edu dictionary find definition word definition book index find relevant pages term list of page numbers

http://algs4.cs.princeton.edu dictionary find definition word definition book index find relevant pages term list of page numbers ROBERT SEDGEWICK KEVI WAYE F O U R T H E D I T I O ROBERT SEDGEWICK KEVI WAYE ROBERT SEDGEWICK KEVI WAYE Symbol tables Symbol table applications Key-value pair abstraction. Insert a value with specified.

More information

public static void main(string[] args) { System.out.println("hello, world"); } }

public static void main(string[] args) { System.out.println(hello, world); } } Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

Getting Started with the Internet Communications Engine

Getting Started with the Internet Communications Engine Getting Started with the Internet Communications Engine David Vriezen April 7, 2014 Contents 1 Introduction 2 2 About Ice 2 2.1 Proxies................................. 2 3 Setting Up ICE 2 4 Slices 2

More information

Génie Logiciel et Gestion de Projets. Object-Oriented Programming An introduction to Java

Génie Logiciel et Gestion de Projets. Object-Oriented Programming An introduction to Java Génie Logiciel et Gestion de Projets Object-Oriented Programming An introduction to Java 1 Roadmap History of Abstraction Mechanisms Learning an OOPL Classes, Methods and Messages Inheritance Polymorphism

More information

Author: Sascha Wolski Sebastian Hennebrueder http://www.laliluna.de/tutorials.html Tutorials for Struts, EJB, xdoclet and eclipse.

Author: Sascha Wolski Sebastian Hennebrueder http://www.laliluna.de/tutorials.html Tutorials for Struts, EJB, xdoclet and eclipse. JUnit Testing JUnit is a simple Java testing framework to write tests for you Java application. This tutorial gives you an overview of the features of JUnit and shows a little example how you can write

More information

Generic Types in Java. Example. Another Example. Type Casting. An Aside: Autoboxing 4/16/2013 GENERIC TYPES AND THE JAVA COLLECTIONS FRAMEWORK.

Generic Types in Java. Example. Another Example. Type Casting. An Aside: Autoboxing 4/16/2013 GENERIC TYPES AND THE JAVA COLLECTIONS FRAMEWORK. Generic Types in Java 2 GENERIC TYPES AND THE JAVA COLLECTIONS FRAMEWORK Lecture 15 CS2110 Spring 2013 When using a collection (e.g., LinkedList, HashSet, HashMap), we generally have a single type T of

More information

University of Twente. A simulation of the Java Virtual Machine using graph grammars

University of Twente. A simulation of the Java Virtual Machine using graph grammars University of Twente Department of Computer Science A simulation of the Java Virtual Machine using graph grammars Master of Science thesis M. R. Arends, November 2003 A simulation of the Java Virtual Machine

More information

cs2010: algorithms and data structures

cs2010: algorithms and data structures cs2010: algorithms and data structures Lecture 11: Symbol Table ADT. Vasileios Koutavas 28 Oct 2015 School of Computer Science and Statistics Trinity College Dublin Algorithms ROBERT SEDGEWICK KEVIN WAYNE

More information

Threads 1. When writing games you need to do more than one thing at once.

Threads 1. When writing games you need to do more than one thing at once. Threads 1 Threads Slide 1 When writing games you need to do more than one thing at once. Threads offer a way of automatically allowing more than one thing to happen at the same time. Java has threads as

More information

Construction of classes with classes

Construction of classes with classes (November 13, 2014 Class hierarchies 1 ) Construction of classes with classes Classes can be built on existing classes through attributes of object types. Example: I A class PairOfDice can be constructed

More information

API for java.util.iterator. ! hasnext() Are there more items in the list? ! next() Return the next item in the list.

API for java.util.iterator. ! hasnext() Are there more items in the list? ! next() Return the next item in the list. Sequences and Urns 2.7 Lists and Iterators Sequence. Ordered collection of items. Key operations. Insert an item, iterate over the items. Design challenge. Support iteration by client, without revealing

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Inner classes, RTTI, Tree implementation Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 29, 2010 G. Lipari (Scuola Superiore Sant

More information

Chapter 2 Introduction to Java programming

Chapter 2 Introduction to Java programming Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break

More information

Copyright. Restricted Rights Legend. Trademarks or Service Marks. Copyright 2003 BEA Systems, Inc. All Rights Reserved.

Copyright. Restricted Rights Legend. Trademarks or Service Marks. Copyright 2003 BEA Systems, Inc. All Rights Reserved. Version 8.1 SP4 December 2004 Copyright Copyright 2003 BEA Systems, Inc. All Rights Reserved. Restricted Rights Legend This software and documentation is subject to and made available only pursuant to

More information

Description of Class Mutation Mutation Operators for Java

Description of Class Mutation Mutation Operators for Java Description of Class Mutation Mutation Operators for Java Yu-Seung Ma Electronics and Telecommunications Research Institute, Korea ysma@etri.re.kr Jeff Offutt Software Engineering George Mason University

More information

TABLE OF CONTENTS...2 INTRODUCTION...3 APPLETS AND APPLICATIONS...3 JAVABEANS...4 EXCEPTION HANDLING...5 JAVA DATABASE CONNECTIVITY (JDBC)...

TABLE OF CONTENTS...2 INTRODUCTION...3 APPLETS AND APPLICATIONS...3 JAVABEANS...4 EXCEPTION HANDLING...5 JAVA DATABASE CONNECTIVITY (JDBC)... Advanced Features Trenton Computer Festival May 1 sstt & 2 n d,, 2004 Michael P.. Redlich Senior Research Technician ExxonMobil Research & Engineering michael..p..redlich@exxonmobil..com Table of Contents

More information

CompSci-61B, Data Structures Final Exam

CompSci-61B, Data Structures Final Exam Your Name: CompSci-61B, Data Structures Final Exam Your 8-digit Student ID: Your CS61B Class Account Login: This is a final test for mastery of the material covered in our labs, lectures, and readings.

More information

Java from a C perspective. Plan

Java from a C perspective. Plan Java from a C perspective Cristian Bogdan 2D2052/ingint04 Plan Objectives and Book Packages and Classes Types and memory allocation Syntax and C-like Statements Object Orientation (minimal intro) Exceptions,

More information

Pemrograman Dasar. Basic Elements Of Java

Pemrograman Dasar. Basic Elements Of Java Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle

More information

What is Java? Applications and Applets: Result of Sun s efforts to remedy bad software engineering practices

What is Java? Applications and Applets: Result of Sun s efforts to remedy bad software engineering practices What is Java? Result of Sun s efforts to remedy bad software engineering practices It is commonly thought of as a way to make Web pages cool. It has evolved into much more. It is fast becoming a computing

More information

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program. Software Testing Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program. Testing can only reveal the presence of errors and not the

More information

Inheritance, overloading and overriding

Inheritance, overloading and overriding Inheritance, overloading and overriding Recall with inheritance the behavior and data associated with the child classes are always an extension of the behavior and data associated with the parent class

More information

Java CPD (I) Frans Coenen Department of Computer Science

Java CPD (I) Frans Coenen Department of Computer Science Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials

More information

The Interface Concept

The Interface Concept Multiple inheritance Interfaces Four often used Java interfaces Iterator Cloneable Serializable Comparable The Interface Concept OOP: The Interface Concept 1 Multiple Inheritance, Example Person name()

More information

Software Engineering Techniques

Software Engineering Techniques Software Engineering Techniques Low level design issues for programming-in-the-large. Software Quality Design by contract Pre- and post conditions Class invariants Ten do Ten do nots Another type of summary

More information

Génie Logiciel et Gestion de Projets. Object-Oriented Programming An introduction to Java

Génie Logiciel et Gestion de Projets. Object-Oriented Programming An introduction to Java Génie Logiciel et Gestion de Projets Object-Oriented Programming An introduction to Java 1 Roadmap History of Abstraction Mechanisms Learning an OOPL Classes, Methods and Messages Inheritance Polymorphism

More information

Java Cheatsheet. http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix

Java Cheatsheet. http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix Java Cheatsheet http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix Hello World bestand genaamd HelloWorld.java naam klasse main methode public class HelloWorld

More information

Agenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism

Agenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism Polymorphism 1 Agenda What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism 2 What is & Why Polymorphism? 3 What is Polymorphism? Generally, polymorphism refers

More information

Yosemite National Park, California. CSE 114 Computer Science I Inheritance

Yosemite National Park, California. CSE 114 Computer Science I Inheritance Yosemite National Park, California CSE 114 Computer Science I Inheritance Containment A class contains another class if it instantiates an object of that class HAS-A also called aggregation PairOfDice

More information

Abstract Class & Java Interface

Abstract Class & Java Interface Abstract Class & Java Interface 1 Agenda What is an Abstract method and an Abstract class? What is Interface? Why Interface? Interface as a Type Interface vs. Class Defining an Interface Implementing an

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

Grundlæggende Programmering IT-C, Forår 2001. Written exam in Introductory Programming

Grundlæggende Programmering IT-C, Forår 2001. Written exam in Introductory Programming Written exam in Introductory Programming IT University of Copenhagen, June 11, 2001 English version All materials are permitted during the exam, except computers. The exam questions must be answered in

More information

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be: Lecture 7 Picking Balls From an Urn The problem: An urn has n (n = 10) balls numbered from 0 to 9 A ball is selected at random, its' is number noted, it is set aside, and another ball is selected from

More information

Lecture J - Exceptions

Lecture J - Exceptions Lecture J - Exceptions Slide 1 of 107. Exceptions in Java Java uses the notion of exception for 3 related (but different) purposes: Errors: an internal Java implementation error was discovered E.g: out

More information

Smallest Java Package? Java.applet.* having 1 class and 3 interfaces. Applet Class and AppletContext, AppletStub, Audioclip interfaces.

Smallest Java Package? Java.applet.* having 1 class and 3 interfaces. Applet Class and AppletContext, AppletStub, Audioclip interfaces. OBJECTIVES OF JAVA Objects in java cannot contain other objects; they can only have references to other objects. Deletion of objects will be managed by Run time system. An Object can pass a message to

More information

Chapter 1 Fundamentals of Java Programming

Chapter 1 Fundamentals of Java Programming Chapter 1 Fundamentals of Java Programming Computers and Computer Programming Writing and Executing a Java Program Elements of a Java Program Features of Java Accessing the Classes and Class Members The

More information