Topics for ITEC320 Exam02, 2018fall
Page last generated
- Consider the following roughly-equivalencies:
english metric power power binary
word prefix of ten of two prefix
------ ------ ------- ------- -----
thousand = Kilo = 10^3 ~ 2^10 = Kibi
million = Mega = 10^6 ~ 2^20 = Mebi
billion = Giga = 10^9 ~ 2^30 = Gibi
trillion = Tera = 10^12 ~ 2^40 = Tebi
Exam questions might choose one entry in the table above,
and then ask for one of the other values in that row:
E.g. "2^30 is which metric prefix (approx)?"
or "1K is what power of 2?"
Also good to know:
- exact powers-of-two up to 10;
- able to reason that (e.g.) 2^32 = 2^2 * 2^30 = 4G
- realize that (say) 2^16 is how high you can count, if you have 16 bits
just like 10^16 is how high you can count, if you have 16 decimal-digits.
- These don't apply only to "B" (bytes); you can have
a kilo-meter, a kilo-gram, a kilo-byte, or a kilo-donut (mmmm).
- We won't use the binary-prefixes at all, though it's good to know
how to not to use the metric-prefixes incorrectly,
e.g. "This chip can access 16 GiB of memory" rather than "16GB".]
somewhat-similar concepts in each of: [VERY rough!]
--------------------------------------------------------
Ada C Java
----- --- ------
type-conv. @compile? must be explicit casting circumvents! numeric widening; `toString` often implicit
type-conv. @run? checked(sub-types) not checked cast does run-time check of objects
init.vars no (initially garbage) no yes (fields zero'd; locals must init-before-use)
aggregate types: record struct class
re-name types y; non-interchangeable y; interchangeable no
regluar functions function/procedure function static-method
O.O. functions {not in 320} {C++ only} method (non-static/O.O.)
packages with {only via linking} CLASSPATH
abbr.full names use #include import
aggregates:comparison component-wise = compare bits == reference-equality only ==
aggregates:assignment component-wise := assign bits = reference-assignment only =
immed.mem vs pointer both {ptrs next week!} both references-only
(aka value- vs reference-semantics)
compiling to .o's, then link to .o's, then link to .class; jvm loads other .class at run-time
Observation:
In spirit C and Ada tend to be similar (but Ada enforces type-safety)
Java and Lisps tend to have similar memory-model (but static vs dynamic typing)
value- *and* reference semantics?
Ada: both allowed (though we've only talked about value-semantics)
C: both allowed
C++: both allowed
Java: only reference-semantics for objects (and value-semantics for primitives)
[technically: Java only has pass-by-value, BUT the values are all 'object-reference' (plus a few primitives)]
Note on pass-by-reference in C: the programmer has to wrestle with pointers themselves, to achieve this effect
(referencing (`&`) and de-referencing (`*`) and manually.
(C++ has proper syntax for this, so the compiler can automate this pointer-wrangling or even optimize it away)
In a similar vein, Ada's in/out params might even get optimized to use pass-by-reference when
it can be prove that the results are equivalent to pass-by-value.
The remainder of this file is © Dr
Ned Okie; used by permission.
Any formatting-errors are probably mine. --ib
Material
- Material from class and web page notes since material from last
exam
- From the text: As related to material covered in class and as
mentioned in the web pages, but mostly:
8.7, 2.4 (records) and 11 (packages)
Records
- List and briefly describe similarities and differences between classes and records.
- The term "primitive" can be meant in different ways.
Compare each pair below, w/ regard to Ada records and Java classes:
- Composite type and primitive type
- Reference type and primitive type
- User-defined type and primitive type
- Define and appropriately use the term field (Java) as it relates to records and classes
- Define the term struct (C) as it relates to records.
- Contrast arrays and records with respect to the type of their components and how they access their components.
- Operations with records - describe how each operates, be able to use the operation:
- Declaration of variables and Allocation of memory
- Contrast the declaration of (record or class) type vs declaration and allocation of variable of that type
- Access to fields (ie the dot)
- Assignment (ie field by field)
- Equality test (ie field by field)
- Defining new operations (ie define procedures and functions with record type parameters)
- Contrast default values for fields of Ada records vs those of Java objects (ie what value is in a variable or
object that is not explicitly initialized).
Nested Composite Types:
- Explain what is meant by a nested composite type (ie fields are themselves composite types)
- Declare an Ada record type that is a nested composite types
- Contrast Ada and Java with respect to underlying implementation of records whose fields are record types and classes whose fields are objects
- Draw diagram showing memory allocation of Ada and Java nested composite objects
- Explain Java code that instantiates nested composite object
- Aggregation vs Composition:
- Describe conceptual difference in these two kinds of association, as related to ownership and lifetime
- Describe the natural implementation in Ada vs the less natural Java implementation
- Nested arrays and records (eg Arrays of Records of Arrays):
- Be able to define and use nested arrays and records
- Example: record containing an array of records and a length field
Value vs reference semantics:
- Give Examples
- Define primitive vs composite (ie structured) types in
this context
- Compare with Java as related to creation and allocation of composite values
- Describe, recognize, and explain errors that can occur because of the difference in reference and value semantics:
- Problem: Assign item to a variable and use the variable to modify the item
- Example: Modifying field of nested composite record
- Example: Modifying element of an array
- Benefits and drawbacks
ADTs & Packages
- Definition of abstract and ADT
- Relation to classes, packages, and records
- Define the term package as used in Ada.
- Define the term client
- Package Specification and Body:
- Specification (.ads): describe what it contains (ie public and private
sections), visibility to client and body, relation to body
- Body (.adb): describe what it contains, visibility to client,
relation to specification
- Motivation for packages:
- Explain why we create packages
- Explain the relation of packages to ADT's, including what package features allow creation of an ADT
- Be able to write a simple package
- Be familiar with specification and implementation of and be able to use
bignumpkg,
wordpkg,
and how to implement stacks and queues using arrays.
- Private types :
- Explain what it means for a type to be declared as private
- Describe how to create a private type (or just create one)
- Describe what is public and private about a type used to define and ADT
- Explain the operation of and compare and contrast Ada
with
and use
,
Java import
, and C/C++ #include
(eg what they do; are they transitive?)
- Child packages
- Explain the visibility among the spec and body of the child and parent and a client of both
- Explain several uses for and/or benefits of child packages
- Generic Packages
- Describe the purpose of a generic package
- Describe what a generic package has that a regular package does not
- Instantiation: with but no use, create new package, use new package
- Explain when an instance of a generic package is typically
(ie in the examples in this class) created
- Explain the role of the parameters of a generic package
- Explain what kinds of things can be used as parameters of a generic package
- Create a simple generic package
- Define, recognize, and use the term instantiate as it relates to packages
- Comparison with Java
- Describe what Java language feature is closely related to generic packages
- Explain the type checking problems that occur with Java arrays and other containers of Objects and how this problem is solved with Java
generic types
- Define the term
template
(C++) as it relates to generic procedures and functions.
- Compare and contrast Ada Records and Java Classes in each of these areas:
- Memory allocation template
- Encapsulation
- Access control (Java keyword private vs Ada packages)
- Underlying semantics
- User defined types (Java always has reference semantics)
- Composition of types (Java always has fields that are pointers, Ada can have value sematics record types as fields)
- Some differences Ada records and Java classes:
- Composite types are provided by records and classes in Ada and Java, respectively
- A value of a record type is like a Java object: both have fields, but Ada does no require pointers
- Class contains methods that operations on instances of the class vs Ada defines procedures and functions that operate on a record type
- Draw diagram showing memory allocated for declaration and allocation of record and class variables and objects
- Classes vs packages
- Define the term “conflate”
- Contrast how Ada and Java separate and conflate, respectively, the concepts of type and module.
- Explain several ways in which a class is used:
eg, type for declaring reference variables, template for creating objects,
location for declaring methods that operate on instances of the type, library of methods (eg Math)
- Contrast the above ways a class is used with how similar concepts are implemented in Ada
- Describe and illustrate how OO languages have implicit parameters to procedure vs how Ada programs have explicit parameters
- Explain the role of this in relation to implicit parameters
Enumerated types:
- Define and/or explain what an enumerated type is
- Explain the motivation for them
- Understand and write an appropriate declaration for an enumerated type
- List and use some operations and attributes on enumerated types
- Explain how IO for enumerated types is accomplished (ie generic packages) and why this approach is needed
- Describe approaches taken for enumerated types in Java and C and the pros and cons of these approaches [Not on Spr 18 exam2]
Other topics
- Look_Ahead: parameters, operation, purpose
- Buzz numbers: 2^10, etc
- Signed + Magnitude negative numbers
- 9's Complement
The following are not on this semester's Exam 2 (unless listed above)
- Axiomatic definition of stacks
- Floating point numbers: representation, range and precision
- Exceptions:
- Write an exception handler to handle common, language-defined exceptions
- Use declare and begin-end blocks appropriately to check exceptions within a specified area of code
- Describe and interpret the flow of control associated with exceptions
- Declare exceptions
- Raise exceptions in a package, and handle them in a client.
- ADTs: motivation, kinds of operations
- Variant records
- Motivation
- Basic implementation in Ada
- Security issues and their solutions
- Basic implementation in other languages (concepts, not syntax)
- Parnas Principle
- Deep and shallow copy
- Private types vs limited private types: definition and motivation
- State what operations are not available for limited private types
- Generic Procedures
- Explain what a generic procedure is
- Explain the benefit of having generic procedures
- Describe some example generic procedures
- Structure charts: sequence, loop, if, information passing, procedures
- Use as a design tool
- Sequence, loop, if, information passing, procedures