GSLC Programming Language Concept 02

name                : Vincensius Adriel

class                 : LH-01

NIM                 : 2101642301

Lesson             : Programming Language Concept

 

GSLC – 2

 

 

  1. What are the similarities of and the differences between Java Packages and C++ Namespace?

 

C++ Java
Extends C with object-oriented programming and generic programming. C code can most properly be used. Strongly influenced by C++/C syntax.
Compatible with C source code, except for a few corner cases. Provides the Java Native Interface and recently Java Native Access as a way to directly call C/C++ code.
Write once, compile anywhere (WOCA). Write once, run anywhere/everywhere (WORA/WORE).
Allows procedural programmingfunctional programmingobject-oriented programminggeneric programming, and template metaprogramming. Favors a mix of paradigms. Allows procedural programmingfunctional programming (since Java 8) and generic programming (since Java 5), but strongly encourages the object-oriented programming paradigm. Includes support for creating scripting languages.
Runs as native executable machine code for the target instruction set(s). Runs on a virtual machine.
Provides object types and type names. Allows reflection via run-time type information (RTTI). Is reflective, allowing metaprogramming and dynamic code generation at runtime.
Has multiple binary compatibility standards (commonly Microsoft (for MSVC compiler) and Itanium/GNU (for almost all other compilers)). Has one binary compatibility standard, cross-platform for OS and compiler.
Optional automated bounds checking (e.g., the at() method in vector and string containers). All operations are required to be bound-checked by all compliant distributions of Java. HotSpot can remove bounds checking.
Native unsigned arithmetic support. Native unsigned arithmetic unsupported. Java 8 changes some of this, but aspects are unclear.[1]
Standardized minimum limits for all numerical types, but the actual sizes are implementation-defined. Standardized types are available via the standard library <cstdint>. Standardized limits and sizes of all primitive types on all platforms.
Pointers, references, and pass-by-value are supported for all types (primitive or user-defined). All types (primitive types and reference types) are always passed by value.[2]
Memory management can be done manually via new / delete, automatically by scope, or by smart pointers. Supports deterministic destruction of objects. Garbage collection ABI standardized in C++11, though compilers are not required to implement garbage collection. Automatic garbage collection. Supports a non-deterministic finalize() method use of which is not recommended.[3]
Resource management can be done manually or by automatic lifetime-based resource management (RAII). Resource management must generally be done manually, or automatically via finalizers, though this is generally discouraged. Has try-with-resources for automatic scope-based resource management (version 7 onwards).

It can also be done using the internal API sun.misc.Unsafe but that usage is highly discouraged and will be replaced by a public API in an upcoming Java version.

Supports classes, structs (passive data structure (PDS) types), and unions, and can allocate them on the heap or the stack. Classes are allocated on the heapJava SE 6 optimizes with escape analysis to allocate some objects on the stack.
Allows explicitly overriding types, and some implicit narrowing conversions (for compatibility with C). Rigid type safety except for widening conversions.
The C++ Standard Library was designed to have a limited scope and functions, but includes language support, diagnostics, general utilities, strings, locales, containers, algorithms, iterators, numerics, input/output, random number generators, regular expression parsing, threading facilities, type traits (for static type introspection) and Standard C Library. The Boost library offers more functions including network I/O.

A rich amount of third-party libraries exist for GUI and other functions like: Adaptive Communication Environment (ACE), Crypto++, various XMPP Instant Messaging (IM) libraries,[4] OpenLDAPQtgtkmm.

The standard library has grown with each release. By version 1.6, the library included support for locales, logging, containers and iterators, algorithms, GUI programming (but not using the system GUI), graphics, multi-threading, networking, platform security, introspection, dynamic class loading, blocking and non-blocking I/O. It provided interfaces or support classes for XMLXSLTMIDI, database connectivity, naming services (e.g. LDAP), cryptography, security services (e.g. Kerberos), print services, and web services. SWT offered an abstraction for platform-specific GUIs, but was superseded by JavaFX in the latest releases ; allowing for graphics acceleration and CSS-themable UIs. It although doesn’t support any kind of “native platform look” support.
Operator overloading for most operators. Preserving meaning (semantics) is highly recommended. Operators are not overridable. The language overrides + and += for the String class.
Single and Multiple inheritance of classes, including virtual inheritance. Single inheritance of classes. Supports multiple inheritance via the Interfaces construct, which is equivalent to a C++ class composed of abstract methods.
Compile-time templates. Allows for Turing complete meta-programming. Generics are used to achieve basic type-parametrization, but they do not translate from source code to byte code due to the use of type erasure by the compiler.
Function pointers, function objects, lambdas (in C++11), and interfaces. Functions references, function objects and lambdas were added in Java 8. Classes (and interfaces, which are classes) can be passed as references as well through SomeClass.class
No standard inline documentation mechanism. Third-party software (e.g. Doxygen) exists. Extensive Javadoc documentation standard on all system classes and methods.
const keyword for defining immutable variables and member functions that do not change the object. Const-ness is propagated as a means to enforce, at compile-time, correctness of the code with respect to mutability of objects (see const-correctness). final provides a version of const, equivalent to type* const pointers for objects and const for primitive types. Immutability of object members achieved via read-only interfaces and object encapsulation.
Supports the goto statement. Supports labels with loops and statement blocks. goto is a reserved keyword but is marked as “unused” in the Java specification.
Source code can be written to be cross-platform (can be compiled for WindowsBSDLinuxmacOSSolaris, etc., without modification) and written to use platform-specific features. Typically compiled into native machine code, must be recompiled for each target platform. Compiled into byte code for the JVM. Byte code is dependent on the Java platform, but is typically independent of operating systemspecific features.

 

 

  1. Explain the dangers of C’s approach to encapsulation.
  • There are two problems with this approach. First, the documentation of the dependence of the client program on the library (and its header file) is lost. Second, the author of the library could change the header file and the implementation file, but the client could attempt to use the new implementation file (not realizing it had changed) but with the old header file, which the user had copied into his or her client program.

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *