COSC 150 Final Review
Order place, waiter rings the bell on counter and shouts contents of order to cook to begin making. When made, cook rings small bell and yells items that are ready so waiter can get food and deliver it. Identify: - event which occurs - source of the event -handler of the event -response
- customer orders - customer - waiter handles and rings bell - cook makes food
What are the four elements of deadlock?
-Mutual exclusion -Hold and wait -No preemption -Circular set
Hired at Rolex to design luxury electronic watches with public interface watch{ + displayCurrentTime(); + displayCurrentHR(); +displayTextMessages(); } 1. Name a SOLID principle the interface violates. 2. Propose a modification or replacement for watch to address said principle.
1. Interface segregation 2. public interfaces for CurrentTime, CurrentHR, and TextMessages so that each can be manipulated better and extended without having to implement everything
What is an MVC design pattern?
An MVC pattern (Model-View-Controller) specifies that an application consist of a data model, presentation information, and control information
Chatty-chat uses a "star-shaped" communication pattern, in which client-to-client communication is carried out by a single, centralized server. Give an example of a program and/or application of the internet which uses a different communication pattern
Blockchain doesn't use a centralized server. It has a distributed layout that allows clients to interact without a centralized system. Because of the decentralization, it is easier to use for cryptocurrency, supply chains, etc.
C++ is described as "write once, compile anywhere" while Java is described as "write once, run anywhere". Explain the difference.
C++ can be written and then compiled, but because it is machine oriented, when it is compiled on a certain machine it is tailored to that machine. If someone else wants to run it, they have to compile on their own computer first since it is machine specific. Java on the other hand uses the JVM, so once it is written, if you can access the JVM, you can run it and it will be the same on all machines.
Suppose you are asked to write a computer program which must detect and explicitly interact with a particular hardware of the device it is running on. Would you elect to write this program in C++ or Java? Why?
C++ is more back end and because it is compiled not interpreted, it is read faster by machines. This means that since it it working with a hardware element, C++ is more efficient. Java needs the JVM whereas C++ would detect and explicitly interact with hardware better.
Which of the following programming tools allows you to investigate the behavior of the code during execution? -Compiler - Dissassembler - Debugger - Documentation generator
Debugger
(T/F) A thread must acquire a "lock" on data in memory in order to read of modify that memory value
False
(T/F) The main thread of a process must be the last thread to terminate in the process, waiting for all other threads to terminate first if necessary
False
(T/F) The server side of a network connection must be bound to a port number, while the client side is not bound to one.
False
(T/F) The swing library provides a number of different data structures which you can use to create the Model for your program
False
In the MVC design pattern, the controller is responsible for directly changing the View presented to the user.
False
Suppose you are asked to write a computer program which should look and act on a large group of different devices. Would you use C++ or Java? Why?
I would use Java works best on a large scale with many different devices for things like apps, games, etc. Because of the JVM, it can run anywhere and therefore Java has many more targets than C++
Hired at Gtown Medicine to teach course in clinical diagnostics. Two ways to test students: -Supervise students as they assess patients int he waiting room - Hire a "standardized patient" and have your student assess them. Which of these would you use and why? Incorporate definition of unit testing.
I would use the standardized patient. If there is a random patient, you may not be sure if they are exaggerating symptoms, have a rare disease, or simply don't have what the student diagnosis them with. With the standardized patient, you know the right answer and can be sure to see if the student is right or wrong. This is the same with unit testing. If you input values you know to be true or false, then after the test you can see whether a method works or not.
What does IDE stand for?
Integrated Development Environment
What must be installed to run a Java program? - JVM (Java virtual machine) - JRE (Java runtime environment) - JDK (Java development kit)
JRE- consisting of a JVM and the Java Class Libraries
What does JDK stand for?
Java Development Kit
What does JRE stand for?
Java Runtime Environment
What does JVM stand for?
Java Virtual Machine
Which of the following best describes relationship between C++ and Java? - Java and C++ are two dialects of the same language and are largely interchangeable -Java was inspired by C++ and borrowed some syntax and features from it - C++ was inspired by Java and borrowed some syntax and features from it -Java and C++ were both inspired by and extended from the C programming language
Java was inspired by C++ and borrowed some syntax and features from it
Which of the following is not an advantage of using an event driven programming style to design a program? -Program is responsive to user's desires for program execution -Program executes in the same order in which it is written in the IDE, making debugging straight froward -One piece of event handling code can be replaced with another without changing the source of events -Program can take actions which are asynchronous or long-running and await completion without knowing when they will finish
Program executes in the same order it was written in IDE, WRONG it executed whenever the event completed prompts certain code
What does SOLID stand for?
S- single responsibility O- open (for extension)/ closed (for manipulation) L- Liskov substitution (defines that objects of a superclass shall be replaceable with objects of its subclasses without breaking the application.) I - Interface segregation (multiple public interfaces instead of implementing all together under one) D - Dependency inversion (high-level modules should depend on abstractions rather than concrete implementations)
(T/F) A socket object exists on both the server and the client side of a network connection
True
(T/F) Any thread in a process may interact with data in memory, even if that memory was initially allocated by another thread.
True
(T/F) In an event driven program, code which runs in response to one event can generate a different event
True
(T/F) In the MVC design pattern, the model may contain information which is never-displayed to the user
True
(T/F) The socket API is language-independent, meaning that a network connection between a C++ program on one side and a Java program on the other side is possible.
True
A multi-threaded process with a concurrency bug may display an incorrect behavior when run, but display a different, correct behavior when run a second time
True
Define deadlock
Two (or more) threads have stopped execution or are spinning permanently. For example, a simple deadlock situation: thread 1 locks lock A, thread 2 locks lock B, thread 1 wants lock B and thread 2 wants lock A.
Is it possible to write a compiler (javac) in Java? Why or why not?
Yes, because it is translated into byte code instructions that can then be executed on the JVM. If you write a Java compiler for Java, it only has to be able to interpret byte code and therefore the language of source code doesn't matter. Writing a compiler in the language it compiles is an important step in the development of a language, called "bootstrapping"
Which of the following is an example of a human-computer interface? - Shell running in terminal -point-and-click windowed desktop applicaiton -voice-activated smart-home device - all of the above
all of the above
(T/F) A Java import statement must be included in your source code before you can instantiate objects of another class type
false
(T/F) An event-driven program requires the programmer to specify a particular sequence of events which will occur during program execution
false
(T/F) Comments are only used by novice programmers
false
(T/F) Java programs do not use dynamically allocated memory at all; this is why the language does not contain pointers
false
Wife walking in front, Wife won't exit until umbrella is opened, can't open umbrella until we exit the bus, cannot back up and switch places. Please describe how the above situation incorporates all 4 elements of deadlock.
mutual exclusion- You need to get off to open umbrella, wife needs umbrella to get off hold and wait- you are waiting for your wife to get off the bus, she is waiting for you to open the umbrella no preemption- You can't get off until your wife does, she can't get off until you do. circular set- since you need her to get off and she needs you to get off, it creates a circular set.
Unit Testing
test individual units or pieces of code for a system with code that is either known to be right, or known to be wrong
(T/F) A unit of code is the smallest piece of code which performs a specific action or behavior completely
true
(T/F) Choosing a consistent coding style allows large groups of programmers to write readable, maintainable code
true
(T/F) Java does not directly support the procedural programming paradigm; that is, designing programs which feature functions but not classes
true
(T/F) Java source code files must be named and organized according to the classes and packages they implement
true
Which of the following is NOT one of the goals of applying SOLID design principles to an OOP? - Writing code to execute more efficiently - Writing code that is easier to understand - Writing code which is more flexible and easier to extend - Writing Code which is easier to maintain and repair
writing code which executes more efficiently