Fall Problem Set 1

Similar documents
Assigned Date: August 27, 2014 Due Date: September 7, 2015, 11:59 PM

15CS45 : OBJECT ORIENTED CONCEPTS

Framework Fundamentals

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

Introduction to Programming Using Java (98-388)

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Multiple Inheritance, Abstract Classes, Interfaces

SRM INSTITUTE OF SCIENCE & TECHNOLOGY Faculty of Science and Humanities Department of Computer Science UNIT I - INTRODUCTION TO JAVA

Object Oriented Programming with Java. Unit-1

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Objective Questions. BCA Part III Paper XIX (Java Programming) page 1 of 5

Fundamentals of Object Oriented Programming

VALLIAMMAI ENGINEERING COLLEGE

Multithreading in Java Part 2 Thread - States JAVA9S.com

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

Object Oriented Programming: Based on slides from Skrien Chapter 2

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

Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multit

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

PESIT Bangalore South Campus

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

CS180 Review. Recitation Week 15

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

More on Objects in JAVA TM

Java Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources.

Midterm Exam CS 251, Intermediate Programming March 6, 2015

Midterm Exam CS 251, Intermediate Programming March 12, 2014

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

Tutorial 8 Date: 15/04/2014

5/23/2015. Core Java Syllabus. VikRam ShaRma

CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Compaq Interview Questions And Answers

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

CS 162, Lecture 25: Exam II Review. 30 May 2018

Midterm Exam CS 251, Intermediate Programming October 8, 2014

Exceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws

Java Programming. Price $ (inc GST)

FINALTERM EXAMINATION Spring 2009 CS506- Web Design and Development Solved by Tahseen Anwar

Programming II (CS300)

This page intentionally left blank

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Inheritance. SOTE notebook. November 06, n Unidirectional association. Inheritance ("extends") Use relationship

Object-oriented programming in Java (2)

What can go wrong in a Java program while running?

Modern Programming Languages. Lecture Java Programming Language. An Introduction

JAVA MOCK TEST JAVA MOCK TEST III

What does it mean by information hiding? What are the advantages of it? {5 Marks}

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2015

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA

CS 11 java track: lecture 3

Why use inheritance? The most important slide of the lecture. Programming in C++ Reasons for Inheritance (revision) Inheritance in C++

Core Java Contents. Duration: 25 Hours (1 Month)

[CHAPTER] 1 INTRODUCTION 1

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

Inheritance, Polymorphism, and Interfaces

Chapter 5 Object-Oriented Programming

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?

UMBC CMSC 331 Final Exam

20 Most Important Java Programming Interview Questions. Powered by

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

Exercise 8 Parametric polymorphism November 18, 2016

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

COMP 401 Spring 2013 Midterm 2

Lecture 14 Summary 3/9/2009. By the end of this lecture, you will be able to differentiate between errors, exceptions, and runtime exceptions.

Object-Oriented Programming (OOP) Fundamental Principles of OOP

(Not Quite) Minijava

Govt. of Karnataka, Department of Technical Education Diploma in Information Science & Engineering. Fifth Semester

The design of an ADT should evolve naturally during the problem-solving process Questions to ask when designing an ADT

Generics method and class definitions which involve type parameters.

CMSC 331 Second Midterm Exam

DHANALAKSHMI SRINIVASAN COLLEGE OF ENGINEERING AND TECHNOLOGY ACADEMIC YEAR (ODD SEM)

(2½ hours) Total Marks: 75

C++ Important Questions with Answers

[Course Overview] After completing this module you are ready to: Develop Desktop applications, Networking & Multi-threaded programs in java.

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

CS 251 Intermediate Programming Exceptions

Constructors for classes

VALLIAMMAI ENGINEERING COLLEGE

Rules and syntax for inheritance. The boring stuff

COMP 401 Spring 2013 Midterm 2

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004

CS Programming Language Java. Fall 2004 Sept. 29

LTBP INDUSTRIAL TRAINING INSTITUTE

Table of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7...

Core Java Syllabus DAY -1 :

Java 1.8 Programming

Tutorial 7. If it compiles, what does it print? Inheritance 1. Inheritance 2

Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling

F1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept

Declarations and Access Control SCJP tips

Full file at Chapter 2 - Inheritance and Exception Handling

CS 251 Intermediate Programming Inheritance

"Charting the Course... Java Programming Language. Course Summary

Quiz on Tuesday April 13. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 4. Java facts and questions. Things to try in Java

Objects and Iterators

UMBC CMSC 331 Final Exam

Transcription:

15440 - Fall 2017 Problem Set 1 Out: August 24, 2017 Due: September 11, 2017 1 Warm Up [40 Points] Warm up with some critical concepts in Java Object Oriented and Multithreading Programming: Choose the correct answer(s). Explain and justify. (a) Which of the following statements is correct for a method that overrides the following method: (2 Points) The overriding method must return void The overriding method must return int The overriding method can return any type (b) Which of the following statements is correct for a method that overloads the following method: (2 Points) The overloading method must return void The overloading method can return any type The overloading method must take int a as a parameter The overloading method can take any parameters 1

(c) Given the following classes dened in separate les, what is the eect of compiling and running class Test? (2 Points) Generates compile error at v = c Generates runtime error at v = c Prints: Vehicle : drive Car: drive Car: drive Prints: Vehicle : drive Car: drive Vehicle: drive 2

(d) What is wrong with the following code? (2 Points) Since the method foo() does not catch the exception generated by the method baz(), it must declare the RuntimeException in a throws clause A try block cannot be followed by both a catch and a nally block An empty catch block is not allowed A catch block cannot follow a nally block A nally block must always follow one or more catch blocks (e) What is the result of compiling and running the following code: (2 Points) Prints a sequence of ve zeros Generates runtime error since array arr has not been initialized Generates other error(s) 3

(f) Which statement, when inserted at (1), will raise a runtime exception? (2 Points) x = y; z = x; y = (B) x; z = (C) y; y = (A) y; (g) Which statement(s) are true about the following code? (2 Points) The code will fail to compile The constructor in A that takes an int as an argument will never be called as a result of constructing an object of class B or C Class C denes three constructors Objects of class B cannot be constructed At most one of the constructors of each class is called as a result of constructing an object of class C 4

(h) What is the output of the given function? (2 Points) Finally Exception Exception Finally No Output (i) Which type constraints, when inserted at (1), will allow the class to compile? (3 Points) N extends Object N extends Comparable<N> N extends Object & Comparable<N> N extends Number N extends Number & Comparable<N> N extends Comparable<N> & Number N extends Integer N extends Integer & Comparable<N> 5

(j) Given the following interface declaration, which declaration is valid? (2 Points) 6

(k) Which parameter declarations can be inserted at (1) so that the program compiles without warning? (3 Points) List<? extends Pet> List<? super Pet> List<? extends Wagger> List<? super Wagger> List<?> All of the above 7

(l) Given the following code, which statements are true about the program? (3 Points) Fails to compile Compiles, but throws a runtime exception Prints (Aesop, 100, 1)(NoName, 0, 1) Prints (Aesop, 100, 1)(Aesop, 100, 1) Prints (Aesop, 100, 1)(null, 0, 1) 8

(m) Which statements are true about the classes SupA, SubB, and SubC? (3 Points) Class SubB will not compile Class SubC will not compile Class SubB will compile Class SubC will compile Class SubB overloads the methods in class SupA Class SubC overloads the methods in class SupA Class SubB overrides the methods in class SupA Class SubC overrides the methods in class SupA (n) Which interface is used to dene a class that can execute within its own thread? (2 Points) Run Runnable Thread Threadable Executable (o) Which method is used to schedule a thread for execution? (2 Points) Init() Start() Run() 9

(p) Which method(s) may cause a thread to stop execution? (3 Points) Sleep() Stop() Yield() Wait() Notify() (q) Given the following code, which of the following statements are true? (3 Points) Fails to compile Prints "waiting" Prints "waiting" "nished" Compiles, but throws a runtime exception 10

2 Practice with Inheritance and Polymorphism [15 Points] Let's use polymorphism to implement a very famous story line from our childhood - the Tortoise and Hare race. In this race, the Tortoise moves slowly and steadily with the motto of "slowly and steady wins the race." On the other hand, the Hare spurts to the nish line with the philosophy of "jump, let the muscles pump." Hence our two racers dier in the way they move. To represent a contender, we dene a base class Racer and two derived class Tortoise and Hare. The Racer class has three instance variables: String ID that identies the type of racer ('Tortoise' and 'Hare'), int x which denotes the x-axis position, and int y which denote the y-axis position. Inspect and study the activity's archive, HareTortoise.zip, and perform the following: (a) Create a collection of racers: before a race begins, the user enters, via a pre-programmed dialog box, the desired number of racers of each type. Your job is to create, instantiate, and add Tortoise and/or Hare objects to an ArrayList leveraging the concept of polymorphism. Complete the appropriate method to do so. (5 Points) (b) Run the race: run the race by moving and re-drawing all the racers towards the nish line. Complete the appropriate method to do so. (5 Points) (c) Rank the racers: at the end of the race, display the nal positions of all the racers sorted by their proximity to the nish line (from the farthest to the closest). For this purpose, use the sort method of the Arrays class. Complete the appropriate method to do so. (5 Points) 3 Practice with Socket Programming [45 Points] In this exercise, you will code a group chat room. In this chat room, clients connect to a remote server with a designated IP and port number. The server accepts connections from an arbitrary number of clients. Any message sent from one client is broadcast to all other clients. You must leverage the concepts of socket programming and multi-threading to achieve this task. You may or may not create a GUI for your chat room. 11