-
Notifications
You must be signed in to change notification settings - Fork 55
/
C++ vs Java
41 lines (30 loc) · 1.79 KB
/
C++ vs Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Question: What are the differences between C++ and Java?
Ans:
IMP POINT:
Java is platform independant whereas c++ is platform dependant.(NOTE: Every different OS has a different JVM)
Please watch this video to clear all doubts: https://www.youtube.com/watch?v=XjNwyXx2os8
1) Java doesnot support pointers. Pointers are tricky to use and troublesome.
2) Java does not support multiple inheritances because it causes more problems than it solves.
Instead Java supports multiple interface inheritance, which allows an object to
inherit many method signatures from different interfaces with the condition
that the inheriting object must implement those inherited methods.
The multiple interface inheritance also allows an object to behave polymorphically on those methods.
3) Java does not include structures or unions.
4) Java does not support destructors but adds a finalize() method.
Finalize methods are invoked by the garbage collector prior to reclaiming
the memory occupied by the object, which has the finalize() method.
This means you do not know when the objects are going to be finalized.
Avoid using finalize() method to release non-memory resources like file
handles, sockets, database connections etc because Java has only a finite
number of these resources and you do not know when the garbage collection is going to kick in
to release these resources through the finalize() method.
5) All the code in Java program is encapsulated within classes therefore Java does not have
global variables or functions.
6) C++ requires explicit memory management, while Java includes automatic garbage collection.
VERY IMPORTANT TO REMEMBER: GG-MS-PhD(h is silent)
G-> Global variables
G-> Garbage Collection(required for memory management)
M-> Multiple Inheritance
S-> Struct and Union
P-> Pointers
D-> Destructors