Fichas
449 midterm
Fichas del conjunto (133)
- 1Interpreterinterprets line by line and you see the result once the very first line is interpreted.
You have written 10 print statements in python
Syntax error at line 10
Will the first 9 statements be executed in the interpreter? Yes - 2Compilerparsed and then will create an executable file that will be run. If you have any syntax error in your code, you will not see any output
You have written error on the 5th line of your code
You won’t see any output - 3Why is Java considered both compiled & interpreted?its source code is first compiled into a binary byte-code.
This byte-code runs on the Java Virtual Machine (JVM), which is usually a software-based interpreter. - 4c, python, haskell compiled or interpreted?c: compiled
python: interpreted
haskell: both compiled/interpreted
prolog: both ! - 5How do we define a programming language?Syntax: Grammar
Semantics: meaning of elements, done with compiler/interpreter - 6Imperative ProgrammingFocus on "How to do"
sequence important
local variables
modifiable state - 7Functional ProgrammingFunctions are side effect free
Do not include loop
No modifiable global state - 8Logic ProgrammingCollection of facts and rules
Programmer does not specify how to find the solution
Ask questions, end up with a result that satisfies - 9Object Oriented ProgrammingWrite classes, Objects
Main concern: sending messages to objects
Encapsulation and information hiding - 10Can a language have multiple paradigms?Yes
Not mutually exclusive
(ex: recursion) - 11Why is C++ not a pure programming languageSupports multiple inheritance
In real life you can’t have more than 2 parents
You can write code without even creating a class - violates object oriented programming - 12Does python have characters?No
java: yes - 13Primitive Types in Java?Int: 32 bits
Long: 64 bits - 14How does java support multiple inheritance using interfaces?Java does not support multiple inheritance directly
But does support it using interfaces - you can implement more than one class - 15Interface/AbstractAbstract: extends
- can have non abstract methods
- use when you want to share code among closely related classes
Interface: implements
- can only have abstract methods
- use when unrelated classes will use int. - 16Is every variable an object?Java: no
Python: yes - 17When you are comparing objects,it only points to the address not the whole object itself. treat them as pointers
- 18Is + defined for objects?Java: no
c????? - 19Overriding/OverloadingOverloading: when 2+ methods in one class have the same method name but different parameters
Overriding: having 2 methods with the same method name and parameters - 20this/superhuihi
- 21can a constructor return anything?no
- 22is overloading an object oriented feature?No
- 23polymorphismthe ability to present the same interface for differing underlying forms (data types)
ex: integers and floats are implicitly polymorphic since you can add, subtract, multiply .. even though they are different - 24Class person Person p1 is memory allocated to p1?No
- 25class Person Person p1 = new Person() is memory allocated to p1?Yes
- 26How can we determine class level scope and object level scope in java?Class level - static variables
Object level - the variable that you have defined in the class - 27Method overloading Used heavily with primitive data types Java: 2 + 3.5 Uses overloadinghowwwwwwwwwwwwwwww
- 28Shadowed variable Access to variable in superclass is possible byUsing the same name for a variable in the parent and child class
Using the prefix super - 29Java achieves platform independence usingjava virtual machine
- 30Class Templates (l) Type is determined at run-time If classes are dynamically loaded, class template may have to be updated Which classes need to be morphedwht
week 2 - may 9 - 31Do you call a specific exception or general exceptions first?specific first, then general
- 32checked/unchecked exceptionschecked: Must either be caught in a catch block or
declared in a throws clause
unchecked: not required to handle - 33Is throwing an exception an object oriented programming principle?No it has nothing to do with it
Python also supports exception handling - 34What is a binary file?Pictures, audio, video
.bin extension - 35what are object streams?support I/O of objects
directly read/write to objects - 36Internationalizationbased on your location, you are getting the specific feature of your website
Ex: program that shows correct time for people in different time zones - 37writing to binary filesDataOutputStream out = new DataOutputStream(
new FileOutputStream("numbers.bin")); - 38reading from binary filesDataInputStream out = new DataInputStream(
new FileInputStream("numbers.bin")); - 39Does c/c++ support windows programming?Yes
There is a library called windows.h - 40thread/processProcess: each process has its own memory space
OS allocates memory to a specific process
How do processes communicate: Inter process communication (IPC)
Thread: Resides in a process
They don’t have their own memory space - 41thread synchronizationIf thread 1 has access to a method, it is locked for all other threads
In java use keyword synchronize - 42What is a collection and collection framework?Java uses this for Aggregate data
dynamically sized - 43Is haskell strongly typed?Yes bc 3 + “Hi” won’t work
But 2 + 3.5 works in haskell - will give 5.5
however in some situations types can be inferred - 44When the lock is removed, a method called by another thread that is waiting for the object is put into the _____ queue and out of the_____ queueschedular, waiting
- 45haskell type inferencingautomatically deduct the type
Other languages like python do this
You don’t define the types like you do in java -> java is statically typed - 46lazy evaluationExpressions are not evaluated until they have to be
java does support lazy evaluation - 47Unreal Engine 4 software framework (game engine) designed for the creation and development of video gamesHas taken functional programming concepts on board
Purists would disagree, as the engine is written in c++, but functional concepts are applied - 48A variable in Prolog must start witheither an upper-case letter or an underscore ( _ ).
- 49allocating/deallocating is automatically done in java using agarbage collector
- 50Run-time systemis designed based on the designer not the language
Can’t run the same c++ code on apple and window machines b/c runtime environments are different - 51Non-primitive types are maintained onrun-time stackrun-time stack
Objects have their base on the heap
Know stack, run-time stack, heap - 52what is a tuple?allows you to combine different types of data
java: object - 53is haskell side effect free?- yes
- can’t change global state
- can’t change state of parameters either huh - 54arrayarrays should have fixed size and same data type
- 55listlist should also have the same data type but the size is flexible
- 56predecessor of haskell?lisp
- 57Variables are statically typed in Java. What does it mean for variables to be statically typed?That the programmer must specify the type of each variable.
- 58What is the most important reason for maintaining the encapsulation of variables in a class?It allows a class to ensure that all instances are in a valid state at all times.
- 59Which of the following is true about interfaces? I. Interfaces can only contain method headings or class constants. II. Interfaces can be extended. III. Interfaces can be instantiated (you can create an object of the interface type).l && lV
- 60Why should we structure our program?- To make it easier to read
- Reusability
- East to debug as compiler might be able to tell us syntactical and semantically problems early - 61Why is Java considered a compiled languages?It is not possible to run Java code directly.
- 62A strongly typed languagerequires the programmer to explicitly cast when type conversions are required to do an operation
- 63checked exception examplesI/O Exception
FileNotFound Exception - 64unchecked exception examplesArithmeticException
• ArrayIndexOutOfBoundsException
• NullPointerException
• IllegalArgumentException - 65Given that items is a variable of type Collection, what code snippet can be used to print the items in the collection such that each item is printed on a new line?for (Object o : items) { System.out.println(o); }
- 66What does polymorphism mean, when used in object oriented programming?That the same method call results in different behaviour.
- 67a _____ is a collection of values, like the whole numbers or integer.type
- 68Haskell was first defined in1990
- 69Haskell is considered as domain specific language?false
- 70A ____ has a name and will contain a collection of Haskell definition.module
- 71What is the output of the below expression? div 13 52
- 72div vs /div - integer division
/ - for other stuff thats not int - 73Which of the following is FALSE about pattern matching? Pattern matching permits multiple definitions for the same function Each pattern is checked in sequence The first matching pattern executesnone
- 74what does GHCI stand for?Glasgow Haskell Compiler Interactive
- 75error/exceptionerror: an error can never be handled
if it occurs the program will terminate
exception: can be handled by code using try/catch - 76join/sleepsleep: waits for specified amount of time unless interrupted
join: waits for the other thread to finish - 77What are differences between the two threads creation mechanisms in Java?1. by extending the thread class
2. by implementing runnable interface - 78To find a solution, backtracking usesDepth-first search
- 79The empty list in Prolog is represented by the atomic symbol NIL.False
- 80what will the variable L be bound with when the query append(L,[1,2,3],[a,b,1,2,3]) reports a result?[a,b]
- 81Consider the following facts sum(5). sum(3). sum(X + Y). consider the equations ?-sum(2 + 3). Which one of the above fact will unify equation?sum(X + Y).
- 82range(A,A,[A]). range(A,B,[A|R]) :- A < B, X is A + 1, range(X,B,R). What will the variable X be bound with when range(1,4,X) reports a result?[1,2,3,4]
- 83What formal system provides the semantic foundation for Prolog?Predicate Calculus
- 84g m zs= m + length zs What can be inferred about its type?g :: (Int, [b]) -> Int
- 85What is the type of [1 .. ][Int]
- 86Which of following languages use dynamic typing? C, Java, PythonPython
- 87What is the value of the following expression? succ 'd' + max 3 4error since expression is not valid
- 88What would be the output of the following code? data Season = Winter | Summer | Fall | Spring deriving (Enum, Show) succ WinterSummer
- 89the type classes are not describing sets of objects, they are acting more like a Java interface definitiontrue
- 90In order to allow overloading of functions, Haskell has the concept of type classestrue
- 91Which of the following is lazily evaluated in Java? Arithmetic and Boolean expressions. List Elements, Function CallsArithmetic and Boolean expresiions
- 92Which of the following is lazily evaluated in Haskell? Arithmetic and Boolean expressions. List elements Function Calls Components inside a Boolean expressionall of the above
- 93data BST a = Nil | Node (BST a) a (BST a) deriving (Ord, Eq, Show) mystery :: (Ord a) => BST a -> [a] mystery Nil = [] mystery (Node l v r) = [v] ++ mystery l ++ mystery r What's the purpose of mystery function?traverses tree in pre order
- 94Which of the followings is False about lazy evaluation Parameters are passed to the function after being evaluated Repeated uses of the same parameter in the called scope are evaluated every time. Parameters are evaluated in the called scope even if they are not required.all
- 95Consider the following type definitions data MyData = ConstructorOne Int | ConstructorTwo MyData The type would be best described asA recursive algebraic type
- 96Python enumeration types are type safe.false
- 97C++, Java and Python support enumerated types.true
- 98Consider the following type definitions data Shape = Circle Float | Rectangle Float Float deriving(Eq, Show) The type would be best described asproduct type
- 99__ allow restrictions to be placed on variables in polymorphic functionstype classes
- 100Consider a type T that can be compared using operations like <, <=, > and >=. Which type class is T an instance of?Ord
- 101what are the base types?Bool, int, char, float
- 102Composite typeslists, tuples, function
- 103what is an enumerated type?data Color = Red | Blue | Green
- 104are python enumerations type safe?no, comparing enumerations from two different collections returns false
- 105Product Typescan have multiple constructors
each constructor can take a different # of parameters - 106in functional languages can the inputs and outputs be functions?yes, a function can accept a function as a parameter and return a function result
- 107what is uncurried form in haskell?parameters are bundled into a tuple and passed as a group
- 108what is partial applicationa function may be called with fewer arguments than it was called with
result would be function of the remaining arguments - 109operator sectionpartial application of operator
eliminates the need to write a function that already exists(+) - 110is currying and partial application available in python & javajava: yes but syntax isn't as clean as haskell & default is uncurried
python: yes but syntax isnt as clean as haskell &
partial application can be applied to any function - 111function composition2 or more functions can be combined into a single function
- 112function composition in other languages?java: yes use compose
no standard composition function for python, c - 113what if we want to write a function that works on some types and not others?type classes
- 114Eq?==, /=
- 115Num?addition, subtraction, multiplication
- 116type classes in other languagespython: doesn't exist
- 117filter :: (a ‐> Bool) ‐> [a] ‐> [a] result? filter square [1 .. 5]error bc sqaure should return bool
- 118use fold to get the minimum of a listfold min [1,2,3,4,5]
- 119foldl expects:a function, accumulator, list
- 120lambda function to square a number/x->x*x
- 121polymorphic functions in other languages?python
java: by using generics or collections
c: similar to generic or stl (standard template library) - 122map, fold, filtr in other languagesjava, c, python
- 123what languages are eagerpython, java, c
- expressions are fully evaluated before they are passed to the function - 124exception to eager evaluationbuilt in logical operators
- 125what is static typing?- type of variable is known at compile time
- type checking can be performed without running the program - 126what is dynamic typing?- type of variable is not known until the program is running
- usually determined by the value that is stored in it - 127what languages use static/dynamic typing?static: java, c
dynamic: python, javascript - 128what languages support adding character to int?c/c++
no: python, haskell
java: yes if result is stored in an int (char is NOT allowed) - 129adding string to stringjava: yea
python: yea
haskell: yea with ++
c++: yea
c: only with strcat - 130adding integer to floathaskell: no
python: yea
java: yea if result is stored in a float. IN JAVA YOU CANNOT DOWNCAST
c/c++: yea - 131what is explicit typing?programmer is responsible for adding types to variables
- 132what is implicit typing?programmer does not need to specify the type of every variable
- 133—
Información
- Descripción
- Computer Science Fichas sobre 449 midterm, creado por Alisha Lalani el 25/05/2022.
- Creado por
- Alisha Lalani · may 2022
- Actualizado
- 22 jun 2022
- Visitas
- 1
- Valoración