-
Why was the language created?
-
What problems was the language trying to address?
- Java
- Supporting multiple platforms requires compiling a different version for each platform. Sometimes supporting different platforms requires major rewrites. Java instead allows "Write once, Run anywhere".
- C++
- Simula 67's new (at the time) Object Oriented paradigm was very useful for software development, but it was much slower than C and other low level solutions. C++ looked to combine the Object-Orientation of Simula with the speed and capability of C.
- Java
-
Is the language a reaction to a previous language or a replacement for another language?
- Java
- Reaction to Objective-C, C/C++
- Sought to replace C/C++
- C++
- Reaction to Simula, and BCPL
- Sought to replace C
- Java
- Does the language have any particularly unique features?
- Java
- One of a few languages that runs on the Java Virtual Machine and that compiles to Java bytecode.
- C++
- Most features have been copied or done in a new way. C++ most unique feature is Resource acquisition is initialization.
- Java
-
How are name spaces implemented?
- Java
- Java packages
- Creation: Directly mapped to a package directory.
- Use:
using <name_of_namespace>;
- Java packages
- C++
- Creation:
namespace <name_of_namespace> { }
- Use:
using namespace <name_of_namespace>;
- Creation:
- Java
-
How are name spaces used?
- Java
- Name spaces are used to organize code as well as file/file-structure and to prevent name collisions.
- C++
- Name spaces are used to organize code into logical groups and to prevent name collisions.
- Java
-
What types does the language support?
- Java
- Primitives: byte, short, int, long, float, double, boolean, and char
- Also has java.lang.String class as support for character strings.
- C++
- Primitives: bool, char, int, float, double, void, wchar_t
- Also has modifiers signed/unsigned and short/long which can be used as follows:
- unsigned char, signed char, unsigned int, signed int, short int, unsigned short int, signed short int, long int, signed long int, unsigned long int, long double.
- Java
-
Are both reference and value types supported?
- Java
- Supports reference and value types, but is strictly pass-by-value, pass-by-reference isn't supported.
- C++
- Supports both reference and value types.
- Java
-
Can new value types be created?
- Java
- New value types are created via classes.
- C++
- Yes, through classes.
- Java
-
Defining
- Java
class Something {}
- Access modifiers to class are optional
- C++
class Something {}
- classes have no access modifiers
- Java
-
Creating new instances
- Java
Something something = new Something();
- C++
Something something;
orSomething *something = new Something();
- Java
-
Constructing/initializing
- Java
class Something {
public Something() {
//some initialization
}
}
- C++
class Something {
public:
Something();
}
Something::Something() {
//some initialization
}
- Destructing/de-initializing
- Java
- Destructing is handled automatically as part of the Garbage Collection.
- Can override the finalize() method to do extra destructing steps.
- C++
- Java
class Something {
public:
~Something();
}
Something::~Something() {
//some de-initialization
}
- Java
class Something {
string thing;
public Something() {
//some initialization
this.thing = "a thing";
}
}
- C++
class Something {
public:
string thing;
Something();
}
Something::Something() {
//some initialization
this->thing = "a thing";
}
-
Getters and setters...write your own or built in?
- Java
- Write your own
- C++
- Write your own
- Java
-
Backing variables?
- Java
- N/a
- C++
- N/a
- Java
-
Computed properties?
- Java
- N/a
- C++
- N/a
- Java
-
What does the language support?
- Java
- Interfaces
- C++
- No explicit support of interfaces
- Done through abstract classes
- Java
-
What abilities does it have?
- Java
- Forces a class that implements an interface to have certain methods and leaves it up to the class to implement them
- C++
- N/a
- Java
-
How is it used?
- Java
- Runnable is a good example. Requires threaded object to implement the method run by implementing the interface Runnable.
- C++
- N/a
- Java
- Java
class Something {
public void doThing() {}
}
class SomethingElse extends Something {
public void doOtherThing() {}
}
SomethingElse s = new SomethingElse();
s.doThing();
- C++
class Something {
public:
void doThing() {}
};
class SomethingElse: public Something {
void doOtherThing() {}
};
SomethingElse s;
s.doThing();
-
What reflection abilities are supported?
- Java
- All typical reflection capabilities found via java.lang.Class
- C++
- Not officially supported, but solutions can and have been created.
- Java
-
How is reflection used?
- Java
- Can be used to inspect classes at runtime to see their methods, constructors, properties, etc at runtime.
- C++
- N/a
- Java
-
How is it handled?
- Java
- Garbage Collector
- C++
- Manual memory management
- Java
-
How does it work?
- Java
- Objects that pass out of reference are added to the garbage heap to be collected when a new object is created. The memory reclaims the memory as needed.
- C++
- Manual allocation and deallocation. Or variables/objects pass out of scope and are deleted.
- Java
-
Garbage collection?
- Java
- Yes
- C++
- No
- Java
-
Automatic reference counting?
- Java
- No
- C++
- No
- Java
- How are values compared? (i.e. comparing two strings)
- Java
new String("test").equals("test")
- C++
std::string string = "blah"
if(string == "bleh") { . . . }
-
Which does the language use? (null/nil/etc)
- Java
- null
- C++
- NULL
- Java
-
Does the language have features for handling null/nil references?
- Java
- C++
- Nope manually check using an if statement.
- Java and C++ both use try-catch blocks to handle errors and exceptions.
- Java
- Lambda expression: Create an anonymous class that implements a functional interface
- Good Example
interface Sayable{
public String say();
}
public class LambdaExpressionExample{
public static void main(String[] args) {
Sayable s=()->{
return "I have nothing to say.";
};
System.out.println(s.say());
}
}
- C++
- Referred to as a lambda
- Good Example
#include <algorithm>
#include <cmath>
void abssort(float* x, unsigned n) {
std::sort(x, x + n, [](float a, float b) {
return (std::abs(a) < std::abs(b));
});
}
- Java
- C++
- How is a singleton implemented?
- Java
- C++
- Can it be made thread-safe?
- Java
- yes
- C++
- yes
- Java
- Can the singleton instance be lazily instantiated?
- Does the language support procedural programming?
- Java
- Suprisingly debated. Most say no.
- C++
- Yes, C++ is just a superset of C language.
- Java
- Threads or thread-like abilities
- How is multitasking accomplished?
- Both Java and C++ can do process-based multitasking or thread-based multitasking.