Comparison Index C++ Java: Platform-Independent C++ Is Platform-Dependent. Mainly Used For
Comparison Index C++ Java: Platform-Independent C++ Is Platform-Dependent. Mainly Used For
Mainly used for C++ is mainly used for system programming. Java is mainly used for application programming.
It is widely used in Windows-based, web-based,
enterprise, and mobile applications.
Design Goal C++ was designed for systems and applications Java was designed and created as an interpreter for
programming. It was an extension of the C printing systems but later extended as a support
programming language network computing. It was designed to be easy to
. use and accessible to a broader audience.
Goto C++ supports the goto Java doesn't support the goto statement.
statement.
Multiple inheritance C++ supports multiple inheritance. Java doesn't support multiple inheritance through
class. It can be achieved by using interfaces in java
.
Operator Overloading C++ supports operator overloading Java doesn't support operator overloading.
.
Pointers C++ supports pointers Java supports pointer internally. However, you can't write the
. You can write a pointer pointer program in java. It means java has restricted pointer
program in C++. support in java.
Compiler and C++ uses compiler only. C++ is Java uses both compiler and interpreter. Java source code is
Interpreter compiled and run using the converted into bytecode at compilation time. The interpreter
compiler which converts source executes this bytecode at runtime and produces output. Java
code into machine code so, C+ is interpreted that is why it is platform-independent.
+ is platform dependent.
Call by Value C++ supports both call by Java supports call by value only. There is no call by reference
and Call by value and call by reference. in java.
reference
Structure and C++ supports structures and Java doesn't support structures and unions.
Union unions.
Thread C++ doesn't have built-in Java has built-in thread
Support support for threads. It relies on support.
third-party libraries for thread
support.
Class
• A class is a group of objects which have common
properties. It is a template or blueprint from which
objects are created. It is a logical entity. It can't be
physical.
Syntax to declare a class
• class <class_name>
{
field;
method;
}
• A variable which is created inside the class but outside
the method is known as an instance variable. Instance
variable doesn't get memory at compile time. It gets
memory at runtime when an object or instance is
created. That is why it is known as an instance variable.
• In Java, a method is like a function which is used to
expose the behavior of an object.
• Code Reusability
• Code Optimization
class Student
{
int id;
String name;
}
class TestStudent1
{
public static void main(String args[]){
Student s1=new Student();
System.out.println(s1.id);
System.out.println(s1.name);
}
} https://www.slideshare.net/AdilAslam4/access-modifiers-in-java-72656348
Overloading