C - Vs Java
C - Vs Java
Group members:
1. Rajan Ner - 36
2. Hitashri Patil - 42
3. Rohant Narang - 51
4. Nupur Shinde - 56
5. Srushti Shingade - 57
● The basic syntax and code structure of both C and C++ are the
same.
● Case-sensitive
There are many types of operators in Java which are given below:
● Unary Operator,
● Arithmetic Operator,
● Shift Operator,
● Relational Operator,
● Bitwise Operator,
● Logical Operator,
● Ternary Operator and
● Assignment Operator.
C++ :
● Arithmetic Operators
● Assignment Operators
● Relational Operators
● Logical Operators
● Bitwise Operators
Operator Operation
+ Addition
- Subtraction
* Multiplication
/ Division
= a = b; a = b;
+= a += b; a = a + b;
-= a -= b; a = a - b;
*= a *= b; a = a * b;
/= a /= b; a = a / b;
%= a %= b; a = a % b;
Relational Operators: A relational operator is used to check the
relationship between two operands.
Operator Description
| Binary OR
^ Binary XOR
C++ Java
Pointers, references, and pass- All types (primitive types and reference
by-value are supported for all types) are always passed by value.[2]
types (primitive or user-
defined).
The C++ Standard Library was The standard library has grown with each
designed to have a limited release. By version 1.6, the library included
scope and functions, but support for locales, logging, containers and
includes language support, iterators, algorithms, GUI programming (but
diagnostics, general utilities, not using the system GUI), graphics, multi-
strings, locales, containers, threading, networking, platform security,
algorithms, iterators, introspection, dynamic class loading,
numerics, input/output, blocking and non-blocking I/O. It provided
random number generators, interfaces or support classes for XML, XSLT,
regular expression parsing, MIDI, database connectivity, naming services
threading facilities, type traits (e.g. LDAP), cryptography, security services
(for static type introspection) (e.g. Kerberos), print services, and web
and Standard C Library. The services. SWT offered an abstraction for
Boost library offers more platform-specific GUIs, but was superseded
functions including network by JavaFX in the latest releases, allowing for
I/O. graphics acceleration and CSS-themable UIs.
Although it doesn't support any kind of
A rich amount of third-party "native platform look" support.
libraries exist for GUI and
other functions like: Adaptive
Communication Environment
(ACE), Crypto++, various XMPP
Instant Messaging (IM)
libraries,[4] OpenLDAP, Qt,
gtkmm.
Operator overloading for most Operators are not overridable. The language
operators. Preserving meaning overrides + and += for the String class.
(semantics) is highly
recommended.
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 Compiled into Java bytecode for the JVM.
be cross-platform (can be Byte code is dependent on the Java platform,
compiled for Windows, BSD, but is typically independent of operating
Linux, macOS, Solaris, etc., system specific features.
without modification) and
written to use platform-
specific features. Typically
compiled into native machine
code, must be recompiled for
each target platform.
Language features
Srushti: Syntax
● Java syntax has a context-free grammar that can be parsed by a
simple LALR parser. Parsing C++ is more complicated. For example,
Foo<1>(3); is a sequence of comparisons if Foo is a variable, but
creates an object if Foo is the name of a class template.
● C++ allows namespace-level constants, variables, and functions. In
Java, such entities must belong to some given type, and therefore
must be defined inside a type definition, either a class or an interface.
● In C++, objects are values, while in Java they are not. C++ uses value
semantics by default, while Java always uses reference semantics. To
opt for reference semantics in C++, either a pointer or a reference
can be used.
C++ Java
Foo b = a; // Foo b = a;
// copies the contents of a to a // would declare b to be reference to the
new Foo object b; object pointed to by a
// alternative syntax is "Foo Foo b = a.clone();
b(a)" // copies the contents of the object
pointed to by a
// to a new Foo object;
// sets the reference b to point to this
new object;
// the Foo class must implement the
Cloneable interface
// for this code to compile
c->x = 5; c.x = 5;
// modifies the object pointed to // modifies the object referenced by c
by c
d.bar(5); // invokes Foo::bar() d.bar(5); // invokes Foo.bar() for a
for a c.bar(5); // invokes Foo.bar() for c
c->bar(5); // invokes Foo::bar()
for *c
C++ Java
b->x = 5; b.x = 5;
// LEGAL, the object can still be // LEGAL, the object can still be
modified modified
Resource management
➢ C++ has destructors, while Java has finalizers. Both are invoked
before an object's deallocation, but they differ significantly. A C++
object's destructor must be invoked implicitly (in the case of stack-
bound variables) or explicitly to deallocate an object. The
destructor executes synchronously just before the point in a
program at which an object is deallocated. Synchronous,
coordinated uninitializing and deallocating in C++ thus satisfy the
RAII idiom. In Java, object deallocation is implicitly handled by the
garbage collector. A Java object's finalizer is invoked
asynchronously some time after it has been accessed for the last
time and before it is deallocated. Very few objects need finalizers.
A finalizer is needed by only objects that must guarantee some
cleanup of the object state before deallocating, typically releasing
resources external to the JVM. Additionally, finalizers come with
severe performance penalties and significantly increase the time it
takes for objects to be deallocated, so their use is discouraged and
deprecated in Java 9.
➢ With RAII in C++, one type of resource is typically wrapped inside a
small class that allocates the resource upon construction and
releases the resource upon destruction, and provides access to
the resource in between those points. Any class that contains only
such RAII objects does not need to define a destructor since the
destructors of the RAII objects are called automatically as an
object of this class is destroyed. In Java, safe synchronous
deallocation of resources can be performed deterministically using
the try/catch/finally construct.
➢ In C++, it is possible to have a dangling pointer, a stale reference
to an object that has already been deallocated. Attempting to use
a dangling pointer typically results in program failure. In Java, the
garbage collector will not destroy a referenced object.
➢ In C++, it is possible to have uninitialized primitive objects. Java
enforces default initialization.
➢ In C++, it is possible to have an allocated object to which there is
no valid reference. Such an unreachable object cannot be
destroyed (deallocated), and results in a memory leak. In contrast,
in Java an object will not be deallocated by the garbage collector
until it becomes unreachable (by the user program). (Weak
references are supported, which work with the Java garbage
collector to allow for different strengths of reachability.) Garbage
collection in Java prevents many memory leaks, but leaks are still
possible under some circumstances.
Omkar: Libraries
● C++ provides cross-platform access to many features typically
available in platform-specific libraries. Direct access from Java to
native operating systems and hardware functions requires the use of
the Java Native Interface.
Runtime
C++ Java
/* Miscellaneous
● Java and C++ use different means to divide code into multiple source
files. Java uses a package system that dictates the file name and path
for all program definitions. Its compiler imports the executable class
files. C++ uses a header file source code inclusion system to share
declarations between source files.
● Compiled Java code files are generally smaller than code files in C++
as Java bytecode is usually more compact than native machine code
and Java programs are never statically linked.
● C++ compiling features an added textual preprocessing phase, while
Java does not. Thus some users add a preprocessing phase to their
build process for better support of conditional compiling.
● The sizes of integer types are defined in Java (int is 32-bit, long is 64-
bit), while in C++ the size of integers and pointers is compiler and
application binary interface (ABI) dependent within given constraints.
● Thus a Java program will have consistent behavior across platforms,
whereas a C++ program may require adapting for some platforms,
but may run faster with more natural integer sizes for the local
platform.
Language specification
Trademarks
They also have a similar syntax, meaning the way they are written is
comparable. Think of this like Portuguese and Spanish – different languages
with some similarities. Java and C++ use the same primitive data types and
many of their keywords are the same, too.
Both C++ and Java are object oriented programming languages. This is a
modular approach to programming that supports:
Java can be used for a variety of high-level applications. Java is most popularly
used for games, websites, and apps. Across the globe, Java is powering millions
of mobile phones, televisions, enterprise applications, and more.
● Chatbots
Since Java is more versatile, there are many Java job opportunities including
Software Developer, Android Developer, and Web Developer. With
cybersecurity becoming a major concern, learning Java may also be more
relevant to your career goals. Learning C++ is great if you want to become a
Software Developer.
For these reasons, Java requires a significant amount of memory and requires
a longer runtime. That can mean that it’s slower. However, if it’s used
appropriately with these hindrances in mind, it can run quickly and efficiently.
C++ is not secure; pointers are what makes C++ insecure. Improper use of
pointers can easily result in system failure or memory corruption. Debugging
pointers is one of the most difficult aspects of learning C++.
Rajan: Conclusion
So, in conclusion,we would like to mention that both the languages are used by
a plethora of big Software Companies and therefore, learning both of them
could prove to be extremely useful.
For people looking forward to taking a job in the Software Industry, or already
have a Software Engineering Job, it is better to learn more about Java because
of the diversity and flexibility it provides. However, for people looking to work
on building operating systems, gaming engines, etc. where high performance is
needed, C++ can turn out to be a better programming language than Java as it
is way faster than Java.
Reference
● https://www.softwaretestinghelp.com/cpp-applications/
● https://techvidvan.com/tutorials/applications-of-java/
● https://techwelkin.com/difference-between-java-and-cpp
● https://hackr.io/blog/cpp-vs-java
● https://dare2compete.com/blog/difference-between-cpp-and-java
● https://www.javatpoint.com/java-variables
● https://amplitude.com/blog/data-types
● https://www.javatpoint.com/operators-in-java