0% found this document useful (0 votes)
567 views

C, C, Java, Python

This document contains the questions and answers for a closed book examination on programming languages C++ and Java. It discusses: 1. Major advantages of C++ over Java include more consistency between built-in types and user-defined classes, operator overloading for cleaner syntax, and usually more efficient execution. Major advantages of Java over C++ include garbage collection, interfaces that support multiple inheritance paths, byte-code allowing programs to run on any platform, and built-in support for GUI objects. 2. Programmers should avoid built-in arrays in C due to lack of bounds checking leading to bugs, but can feel free to use them in Java which performs bounds checking. 3. When choosing an internal data

Uploaded by

sures_89
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
567 views

C, C, Java, Python

This document contains the questions and answers for a closed book examination on programming languages C++ and Java. It discusses: 1. Major advantages of C++ over Java include more consistency between built-in types and user-defined classes, operator overloading for cleaner syntax, and usually more efficient execution. Major advantages of Java over C++ include garbage collection, interfaces that support multiple inheritance paths, byte-code allowing programs to run on any platform, and built-in support for GUI objects. 2. Programmers should avoid built-in arrays in C due to lack of bounds checking leading to bugs, but can feel free to use them in Java which performs bounds checking. 3. When choosing an internal data

Uploaded by

sures_89
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

This is a closed book examination. Do not consult any sources.

Use additional sheets if needed, and be sure your name is


on every page. When you finish, turn in these pages. If you like, you may then take a short break before beginning part B,
which must be finished by the time written on the board in front.

Throughout this part of the examination I gave partial credit for an answer that was not directly
responsive to the question, but true and even slightly relevant to the topic.

1. Comparing C++ and Java, describe the major ways in which one is better (easier to use,
easier to learn, more powerful, more flexible, or more suitable) than the other:

(a). Major C++ advantages over Java (or Java disadvantages): (10 points)

 More consistency between built-in types and user-defined classes.


 In particular operator overloading supports cleaner syntax in application programs.
 Usually more efficient execution.
 Supports multiple inheritance (but only one path for polymorphic function invocation and
possible problems with duplicate member names).

(Full credit for any two)

(b). Major Java advantages over C++ (or C++ disadvantages): (10 points)

 Garbage collection relieves programmer of having to manage memory.


 Interfaces support polymorphism along multiple inheritance paths.
 Byte-code allows compiled programs to run on any platform that has a java interpreter.
 Standard library support for GUI objects at several levels.
 Supports safe applets to run under a user’s browser.
 New enum feature provides excellent support for discrete types having small no. of values.

(Full credit for any two. Also see question #2.)


2. Explain why programmers should avoid using the built-in (language-provided) arrays in C
programs, but should feel free to use them in Java programs. (8 points)

 The main issue (full credit for this one):


Java generates code to verify that all references to array elements are within the allocated bounds.
C++ doesn’t, so code can refer to any cell in memory, a source of catastrophic bugs as well as
possible entry for malicious virus programs.
 Also Java supplies the LENGTH attribute, so a function can reliably determine the size of an array
passed as an argument. In C++ you have to pass a second size argument, which could be
erroneous.
Several students asserted that Java arrays are dynamic (can grow and shrink) while C++’s are not.
Wrong! Both are fixed at allocation time. But Vector or other container (collection) classes in
either language can be dynamic.

3. For any type of data item explain the criteria a programmer (or database designer) should
apply:
(a). For choosing its internal representation (11 points)

Essential criteria:
 Simple
 Efficient
Desirable criteria:
 Flexible
 Standard, interchangeable with other applications or other organizations.

(b). For choosing its external representation(s) (11 points)

 Familiar (to end users)


 Not error prone, esp. with regard to data entry

You might also like