Question 1
Similarities between Java and C++
Both Java and C++ are known to support method overloading in a similar manner. Java and C++ also lack support of direct higher order functions; instead they provide a way of imitating their behavior. Another notable similarity between java and C++ is that they both provide third level of access control ‘private’ and they both offer ‘static’ members. Furthermore, both Java and C++ are not purely object-oriented, they are hybrid since they fail to satisfy all the specifics of object-oriented languages (Kedar 2008).
Differences between Java and C++
Java provides a mechanism of garbage collection while C++ does not provide any sort of the same. Java language does not allow operator overloading while C++ allows. In addition java lack generic classes and this is a major loophole while C++ templates are more flexible offering many exploits apart from just primary containers though complex. Furthermore, the difference between Java and C++ is that C++ provides full multiple inheritances, including virtual inheritance while Java supports single level inheritance barely from classes as well as multiple interfaces. Unlike C++, the >> operator in java is a signed right bit shift. To add on, unlike java, C++ supports the usage of pre-processor directives such as #if, #warning, and #define (Jana 2005).
Question 2
Interpreted code versus compiled code
The major advantage of interpreted languages is that they are platform independent. JavaScript is perfect example of interpreted language. Instead of depending on installed applications necessary, JavaScript applications can even be executed via a web browser which checks and installs all required files without the user realizing what the browser does. This basically implies that applications can be availed to any OS running a web browser.
Another advantage of using interpreted code is the speed of development. A programmer working with JavaScript for instance can embed a code inside HTML tag, and having JVM installed can develop and run applications very fast. Modification of the code is easily reflected on the browser. Contrastingly, programmer writing in compile mode has to modify the code and then executes it via a compiler that has all the necessities to produce a compiled assembly like DLL. DLL then has to be delivered to the right location whereby in windows deployment of assemblies is done manually to general assembly cache and then the assembly is finally executed by a program. Other advantages of interpreted language include reflective usage of evaluator, dynamic typing, easy debugging, object polymorphism, dynamic scoping, and reduced size of program.
Major drawbacks of using interpreted language are slow execution, loose coupling, late binding, and variant typing. An interpreted language requires compilation every time it is run thus creating unnecessary overheads.
Question 3
1. Machine independence basically refers to programs as well as processes or any other form of software that run in fundamentally the same way despite variance in the machines they are being carried out (Kedar 2008).
2. There are various paradigms of programming, namely:
i. Procedural programming – this is a separation of imperative languages that comprise of routines/subroutines/functions/methods each containing a series of computational stages to be done (Kedar 2008).
ii. Logic programming – is based on pattern-directed invocation of routines from assertions and goals. An action is taken on condition that a set predicate is fully satisfied depending on specifications.
iii. Imperative programming – in this paradigm, computation is done basing on the program state and statements that change the state of a program. Stages necessary to accomplish a task are identified.
iv. Functional programming – this paradigm pictures computation as the assessment of arithmetical functions and circumvents state and mutable data. Function applications are stressed rather than alterations in the universal state and execution of sequence-based commands (Kedar 2008).
3. g(f(x),x) = g(f("abcd"),"abcd")
f is a function that returns the result of reversing the string of input symbols
So f("abcd") = dcba
So g(f("abcd"),"abcd") = g("dcba","abcd")
g is a function that returns the concatenation of the two input strings
so g("dcba","abcd") = dcbaabcd .
4. Machine language is in binary form whereby computer understands 1s and 0s and these are the bits that are used to control the computer’s processor and the language is machine independent while assembly language is a bit closer to the machine language and more readable to human being. Names and labels are used for abstractions instead of fixed memory addresses, and comments.
5.
a. Operator precedence refers to applicable rules in resolving ambiguities emanating from confusion of order of operations in a given arithmetic problem.
b. Expression 6+2 *3 results to
*3 carries addition and multiplication operator. If addition had higher precedence, 6+2*3==> 8*3==> 24. If multiplication is higher on precedence, then: 6+2*3==> 6+6==> 12.
6. Structured programming is a division of procedural programming whereby logical structure of a program being written is of key importance so as to guarantee efficiency and ease of understanding and modification.
7. Strongly typed programming language is a language that put more emphasize on use of types as a means of differentiating variables.
References
Jana, D 2005, C++ and Object-Oriented Programming Paradigm, 2nd edn, PHI Learning Pvt. Ltd, New Delhi.
Kedar, S 2008, Programming paradigms and methodology, Technical Publications, New York.