CSCI 305 – Final Exam 1) What are the 3 primary language categories? For each category: a. Give a brief explanation (2-4 sentences). In other words, what are the main characteristics that describe languages in that category? b. Give two examples of languages from that category. 2) What is the difference between compiled and interpreted programming languages? 3) Two primary functions of a compiler or interpreter are lexical and syntax analysis. Define lexical and syntax analysis. 4) Parsing is done through a top-down or bottom-up method. Also commonly known as LL or LR parsing respectively. a. LL parsing is commonly implemented through a recursive decent parser. Describe briefly how a recursive decent parser is constructed? b. How is LR parsing typically done? 5) Provide the trace of a parse using the input id*(id+id)*id$ using the LR parsing algorithm and the grammar and parsing table shown below. The first step is filled in. Grammar 1. 2. 3. 4. 5. 6. E E T T F F -> -> -> -> -> -> E+T T T*F F (E) id Stack Input Action 0 id*(id+id)*id$ Shift5 6) What is the difference between a type cast and a type coercion? 7) What is short-circuit evaluation? Why is it done? What is the drawback of allowing it in a language? 8) Name a language that always does short –circuit evaluation of boolean expression. Name one that allows the programmer to choose. 9) C++ and Java handle passing by reference to functions/methods much differently. C++ is more powerful, yet more complex. Java is less powerful, but safer and easier to understand. Describe what the differences are. 10) C# built on the previous two languages (C++ and Java) to make passing by reference more powerful. Specifically with the ref keyword. Explain why this is more powerful than what Java allows, but still safe and easier to understand than C++. 11) Class instances (objects) defined on the heap cannot be passed by value in any of contemporary object-oriented languages (C++, Java, C#, etc). There are two primary reasons for this. One, to do with performance. The other to do with compiler design. Explain the two reasons. 12) In contemporary languages such as C++ fixed sized structs can be passed by reference or value. Typically things are passed by value when the procedure should not change the parameters’ values. But why might someone still pass a structure by reference even if the procedure/method is not designed to change it values? 13) Define the two types of abstractions in programming languages. (Make sure to describe each, do not just list them). 14) Describe the 3 characteristic features of object-oriented languages? (Make sure to define/describe each characteristic). 15) What is the difference between a language that supports just Abstract Data Types versus one that supports full object-oriented programming? 16) What is the difference between a class variable/method and an instance variable/method? 17) What is the difference between support for multiple inheritance (for example c++) and support for interfaces (for example, Java or C#)? 18) Why is support for interfaces typically considered better than multiple inheritance? 19) Abstract Classes and Interfaces are similar programming features. Considering how they would be used - What is their primary similarity? What is their primary difference? 20) Describe the characteristics/differences in overriding a method in a derived class for each the following languages: a. C++ b. C# c. Java d. Objective C 21) Objective C and C# both let you extend a class, add methods for example, without subclassing it (creating a derived class). Explain how that is different than deriving from a class and adding those methods in the subclass. 22) What is the purpose of a constructor in C++, Java or C#? 23) What is the purpose of a destructor? And what is the difference between C++ and Java destructors? 24) Describe the difference between how heap memory is reclaimed (de-allocated) in C++ vs. Java or C#. 25) What are the advantages of having support for exception handling built into a language? 26) Why is it useful for a language to have built in exception types (Java, C#, etc) rather than making the programmer define them (c++)? 27) What is the purpose of the finally clause in Java? 28) What is event-driven programming? 29) Explain in words or pseudo code how events and event handlers are used in a language like Java, C#, Visual C++, etc, to handle user interaction with a GUI. 30) When writing code executed in a handler for a GUI event it could be handled synchronously or asynchronously. Compare reasons or give situation where one or the other would be preferable.