GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Karteikarten

449 midterm

Alisha Lalani Computer Science Englisch 133 Karten

Karten in diesem Stapel (133)

  1. 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
  2. 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
  3. 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.
  4. 4c, python, haskell compiled or interpreted?c: compiled
    python: interpreted
    haskell: both compiled/interpreted
    prolog: both !
  5. 5How do we define a programming language?Syntax: Grammar
    Semantics: meaning of elements, done with compiler/interpreter
  6. 6Imperative ProgrammingFocus on "How to do"
    sequence important
    local variables
    modifiable state
  7. 7Functional ProgrammingFunctions are side effect free
    Do not include loop
    No modifiable global state
  8. 8Logic ProgrammingCollection of facts and rules
    Programmer does not specify how to find the solution
    Ask questions, end up with a result that satisfies
  9. 9Object Oriented ProgrammingWrite classes, Objects
    Main concern: sending messages to objects
    Encapsulation and information hiding
  10. 10Can a language have multiple paradigms?Yes
    Not mutually exclusive
    (ex: recursion)
  11. 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
  12. 12Does python have characters?No
    java: yes
  13. 13Primitive Types in Java?Int: 32 bits
    Long: 64 bits
  14. 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
  15. 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.
  16. 16Is every variable an object?Java: no
    Python: yes
  17. 17When you are comparing objects,it only points to the address not the whole object itself. treat them as pointers
  18. 18Is + defined for objects?Java: no
    c?????
  19. 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
  20. 20this/superhuihi
  21. 21can a constructor return anything?no
  22. 22is overloading an object oriented feature?No
  23. 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
  24. 24Class person Person p1 is memory allocated to p1?No
  25. 25class Person Person p1 = new Person() is memory allocated to p1?Yes
  26. 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
  27. 27Method overloading Used heavily with primitive data types Java: 2 + 3.5 Uses overloadinghowwwwwwwwwwwwwwww
  28. 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
  29. 29Java achieves platform independence usingjava virtual machine
  30. 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
  31. 31Do you call a specific exception or general exceptions first?specific first, then general
  32. 32checked/unchecked exceptionschecked: Must either be caught in a catch block or
    declared in a throws clause
    unchecked: not required to handle
  33. 33Is throwing an exception an object oriented programming principle?No it has nothing to do with it
    Python also supports exception handling
  34. 34What is a binary file?Pictures, audio, video
    .bin extension
  35. 35what are object streams?support I/O of objects
    directly read/write to objects
  36. 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
  37. 37writing to binary filesDataOutputStream out = new DataOutputStream(
    new FileOutputStream("numbers.bin"));
  38. 38reading from binary filesDataInputStream out = new DataInputStream(
    new FileInputStream("numbers.bin"));
  39. 39Does c/c++ support windows programming?Yes
    There is a library called windows.h
  40. 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
  41. 41thread synchronizationIf thread 1 has access to a method, it is locked for all other threads
    In java use keyword synchronize
  42. 42What is a collection and collection framework?Java uses this for Aggregate data
    dynamically sized
  43. 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
  44. 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
  45. 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
  46. 46lazy evaluationExpressions are not evaluated until they have to be
    java does support lazy evaluation
  47. 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
  48. 48A variable in Prolog must start witheither an upper-case letter or an underscore ( _ ).
  49. 49allocating/deallocating is automatically done in java using agarbage collector
  50. 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
  51. 51Non-primitive types are maintained onrun-time stackrun-time stack
    Objects have their base on the heap
    Know stack, run-time stack, heap
  52. 52what is a tuple?allows you to combine different types of data
    java: object
  53. 53is haskell side effect free?- yes
    - can’t change global state
    - can’t change state of parameters either huh
  54. 54arrayarrays should have fixed size and same data type
  55. 55listlist should also have the same data type but the size is flexible
  56. 56predecessor of haskell?lisp
  57. 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.
  58. 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.
  59. 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
  60. 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
  61. 61Why is Java considered a compiled languages?It is not possible to run Java code directly.
  62. 62A strongly typed languagerequires the programmer to explicitly cast when type conversions are required to do an operation
  63. 63checked exception examplesI/O Exception
    FileNotFound Exception
  64. 64unchecked exception examplesArithmeticException
    • ArrayIndexOutOfBoundsException
    • NullPointerException
    • IllegalArgumentException
  65. 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); }
  66. 66What does polymorphism mean, when used in object oriented programming?That the same method call results in different behaviour.
  67. 67a _____ is a collection of values, like the whole numbers or integer.type
  68. 68Haskell was first defined in1990
  69. 69Haskell is considered as domain specific language?false
  70. 70A ____ has a name and will contain a collection of Haskell definition.module
  71. 71What is the output of the below expression? div 13 52
  72. 72div vs /div - integer division
    / - for other stuff thats not int
  73. 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
  74. 74what does GHCI stand for?Glasgow Haskell Compiler Interactive
  75. 75error/exceptionerror: an error can never be handled
    if it occurs the program will terminate
    exception: can be handled by code using try/catch
  76. 76join/sleepsleep: waits for specified amount of time unless interrupted
    join: waits for the other thread to finish
  77. 77What are differences between the two threads creation mechanisms in Java?1. by extending the thread class
    2. by implementing runnable interface
  78. 78To find a solution, backtracking usesDepth-first search
  79. 79The empty list in Prolog is represented by the atomic symbol NIL.False
  80. 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]
  81. 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).
  82. 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]
  83. 83What formal system provides the semantic foundation for Prolog?Predicate Calculus
  84. 84g m zs= m + length zs What can be inferred about its type?g :: (Int, [b]) -> Int
  85. 85What is the type of ​[1 .. ][Int]
  86. 86Which of following languages use dynamic typing? C, Java, PythonPython
  87. 87What is the value of the following expression? succ 'd' + max 3 4error since expression is not valid
  88. 88What would be the output of the following code? data Season = Winter | Summer | Fall | Spring deriving (Enum, Show) succ WinterSummer
  89. 89the type classes are not describing sets of objects, they are acting more like a Java interface definitiontrue
  90. 90In order to allow overloading of functions, Haskell has the concept of type classestrue
  91. 91Which of the following is lazily evaluated in Java? Arithmetic and Boolean expressions. List Elements, Function CallsArithmetic and Boolean expresiions
  92. 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
  93. 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
  94. 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
  95. 95Consider the following type definitions data MyData = ConstructorOne Int | ConstructorTwo MyData The type would be best described asA recursive algebraic type
  96. 96Python enumeration types are type safe.false
  97. 97C++, Java and Python support enumerated types.true
  98. 98Consider the following type definitions data Shape = Circle Float | Rectangle Float Float deriving(Eq, Show) The type would be best described asproduct type
  99. 99__ allow restrictions to be placed on variables in polymorphic functionstype classes
  100. 100Consider a type T that can be compared using operations like <, <=, > and >=. Which type class is T an instance of?Ord
  101. 101what are the base types?Bool, int, char, float
  102. 102Composite typeslists, tuples, function
  103. 103what is an enumerated type?data Color = Red | Blue | Green
  104. 104are python enumerations type safe?no, comparing enumerations from two different collections returns false
  105. 105Product Typescan have multiple constructors
    each constructor can take a different # of parameters
  106. 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
  107. 107what is uncurried form in haskell?parameters are bundled into a tuple and passed as a group
  108. 108what is partial applicationa function may be called with fewer arguments than it was called with
    result would be function of the remaining arguments
  109. 109operator sectionpartial application of operator
    eliminates the need to write a function that already exists(+)
  110. 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
  111. 111function composition2 or more functions can be combined into a single function
  112. 112function composition in other languages?java: yes use compose
    no standard composition function for python, c
  113. 113what if we want to write a function that works on some types and not others?type classes
  114. 114Eq?==, /=
  115. 115Num?addition, subtraction, multiplication
  116. 116type classes in other languagespython: doesn't exist
  117. 117filter :: (a ‐> Bool) ‐> [a] ‐> [a] result? filter square [1 .. 5]error bc sqaure should return bool
  118. 118use fold to get the minimum of a listfold min [1,2,3,4,5]
  119. 119foldl expects:a function, accumulator, list
  120. 120lambda function to square a number/x->x*x
  121. 121polymorphic functions in other languages?python
    java: by using generics or collections
    c: similar to generic or stl (standard template library)
  122. 122map, fold, filtr in other languagesjava, c, python
  123. 123what languages are eagerpython, java, c
    - expressions are fully evaluated before they are passed to the function
  124. 124exception to eager evaluationbuilt in logical operators
  125. 125what is static typing?- type of variable is known at compile time
    - type checking can be performed without running the program
  126. 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
  127. 127what languages use static/dynamic typing?static: java, c
    dynamic: python, javascript
  128. 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)
  129. 129adding string to stringjava: yea
    python: yea
    haskell: yea with ++
    c++: yea
    c: only with strcat
  130. 130adding integer to floathaskell: no
    python: yea
    java: yea if result is stored in a float. IN JAVA YOU CANNOT DOWNCAST
    c/c++: yea
  131. 131what is explicit typing?programmer is responsible for adding types to variables
  132. 132what is implicit typing?programmer does not need to specify the type of every variable
  133. 133—

Informationen

Beschreibung
Computer Science Karteikarten am 449 midterm, erstellt von Alisha Lalani am 25/05/2022.
Erstellt von
Alisha Lalani · Mai 2022
Aktualisiert
22 Jun 2022
Aufrufe
1
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck