0% found this document useful (0 votes)
23 views

Comparison Index C++ Java: Platform-Independent C++ Is Platform-Dependent. Mainly Used For

The document compares C++ and Java programming languages. Some key differences include: C++ supports multiple inheritance, operator overloading, and pointers while Java does not. Java uses both a compiler and interpreter making it platform-independent, while C++ uses only a compiler and is platform-dependent. C++ supports both call by value and call by reference but Java only supports call by value.

Uploaded by

avav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Comparison Index C++ Java: Platform-Independent C++ Is Platform-Dependent. Mainly Used For

The document compares C++ and Java programming languages. Some key differences include: C++ supports multiple inheritance, operator overloading, and pointers while Java does not. Java uses both a compiler and interpreter making it platform-independent, while C++ uses only a compiler and is platform-dependent. C++ supports both call by value and call by reference but Java only supports call by value.

Uploaded by

avav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

C++ vs Java

Comparison Index C++ Java

Platform-independent C++ is platform-dependent. Java is platform-independent.

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

• The new keyword is used to allocate memory at


runtime. All objects get memory in Heap memory area.
Object

• An object is an instance of a class.


• An object is a real-world entity.
• An object is a runtime entity.
• The object is an entity which has state and behavior.
• The object is an instance of a class.
Characteristics of Object
Java Program to illustrate how to 
define a class and fields 
class Student
{
int id; //field or data member or instance variable
String name;
public static void main(String args[])
{
Student s1=new Student(); //creating an object of Student
System.out.println(s1.id); //accessing member through reference
variable
System.out.println(s1.name);
}
}
Object and Class Example: main outside the class

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

Method Overloading Method Overriding


Method overloading is used to Method overriding is used to provide the specific
increase the readability of the implementation of the method that is already
program. provided by its super class.

Method overloading is Method overriding occurs in two classes that


performed within class. have IS-A (inheritance) relationship.
In case of method In case of method overriding, parameter must be
overloading, parameter must be same.
different.
Method overloading is the example Method overriding is the example of run time
of compile time polymorphism. polymorphism.
In java, method overloading can't be Return type must be same or covariant in method
performed by changing return type of overriding.
the method only. Return type can be
same or different in method
overloading. But you must have to
change the parameter.
Method Overloading
• If a class has multiple methods having same name but different
in parameters, it is known as Method Overloading.
• Method overloading is used to increase the readability of the
program.
• Method overloading is performed within class.
t
• In case of method overloading, parameter must be different.
• Method overloading is the example of compile time
polymorphism.
• In java, method overloading can't be performed by changing
return type of the method only. Return type can be same or
different in method overloading. But you must have to change
the parameter.
• https://www.cs.princeton.edu/courses/archive/spr96/cs333/java/t
utorial/java/javaOO/methodaccess.html

You might also like