Why Java is platform-independent but not C++?

Both Java and C++ are efficient programming languages that use object-oriented programming(OOPs) paradigm. Java follows OOPs more than C++. Both support OOPs features like:

  • Classes
  • Objects
  • Polymorphism
  • Encapsulation
  • Abstraction
  • Inheritance, etc.

In this article, we are going to discuss the platform independence of Java and why C++ is not supporting platform independency.

We have heard that java is developed to eliminate the various drawbacks of C, C++. Although Java has mostly inherited its syntax from C++ and some major features as well.

Java is preferred in almost all major organizations because it supports “code once, runs anywhere” made it platform-independent and easy to use and upgrade.

Before knowing why java is platform independent let’s have some brief about compiler phases:

  • Lexical Analyser: Accepts high-level language code and tokenize the input to a valid set of tokens.
  • Syntax Analyser: It checks the syntactical structure of the given input, i.e. whether the given input is in the correct syntax.
  • Semantic Analyser: Interpret symbols, their types, and their relations with each other.
  • Intermediate Code Generation: In the analysis-synthesis model of a compiler, the front end of a compiler translates a source program into an independent intermediate code.
  • Code Optimizer: It transforms the code and tries to improve the code by making it consume fewer resources (i.e. CPU, Memory) and deliver high speed.
  • Target Code Generation: Use the optimized intermediate code and generates target code or machine code on which machine can operate easily.

A Java program whenever compiled, the compiler only generates the intermediate code called bytecode and on runtime, it generates machine code. Hence Java program has lesser compile-time and has higher runtime. Let’s have some elaboration on this:

  • High-level language code (i.e.: java code) goes to java compiler.
  • Java compiler follows the lexical analyzer phase, syntax analyzer phase, semantic analyzer phase and then goes the intermediate code generation phase.
  • On Intermediate code generation, phase Java compiler creates intermediate code i.e. bytecode
  • Bytecode is the machine-independent code ready to run on any environment or platform. This is responsible for java portability.
  • We can run Java bytecode on any machine having JDK installed and running, JVM takes up the bytecode and runs it on the machine.
  • We pass bytecode and run the java program. JDK first converts bytecode to machine code than it runs that code on that machine.

On the contrary, the C++ compiler takes the code, follow all the compiler phases and directly generates the machine code ready to run on a machine. Hence:

  • C++ has higher compile-time and
  • Lesser Runtime

Where do we use Java or C++:

Java:

  • Where you are integrating your application software to multiple platforms use java.
  • Use java where you have a large codebase to handle.
  • Where you have a great extension plan for your application software.

C++:

  • Where you need to interact with memory very often.
  • You need to create the OS for your organization.

SimbaQuartz  
Empowering Businesses With Technology

Mandeep Kaur Sidhu

Chief Executive Officer

Mandeep Kaur Sidhu is the founder and CEO of SimbaQuartz - an IT Consulting & Web Development Service Platform located in Tangra, a rural location in Punjab. Mandeep is an active contributor to the development of society with several initiatives taken to enhance employment in rural India with her other ventures namely SimbaCart, MTrophies, & SimbaCourse.  For her high social spirit and greatly rewarding entrepreneurship, she has appeared as a speaker, twice at TEDx, corporates, the United States, IITs/IIMs and many other elite institutes, delivered topics on Entrepreneurship, Digital Marketing & Philanthropy.She has successfully organized 500+ social campaigns under the mission of 50000 Shoe To Give, Food Sharing, etc. Her venture has been awarded as “The Upcoming Start-up of The Year 2016” by ASSOCHAM India and received an Alumni Award for Social Entrepreneurship in 2019.

Leadership

Mandeep Singh Sidhu

Acting CTO & IT
Advisor

Lorem ipsum dolor sit amet, consectetur adipiscing elit Dcibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Mandeep Kaur Sidhu

Chief Executive Officer

Mandeep Kaur Sidhu is the founder and CEO of SimbaQuartz - an IT Consulting & Web Development Service Platform located in Tangra, a rural location in Punjab. Mandeep is an active contributor to the development of society with several initiatives taken to enhance employment in rural India with her other ventures namely SimbaCart, MTrophies, & SimbaCourse.  For her high social spirit and greatly rewarding entrepreneurship, she has appeared as a speaker, twice at TEDx, corporates, the United States, IITs/IIMs and many other elite institutes, delivered topics on Entrepreneurship, Digital Marketing & Philanthropy.She has successfully organized 500+ social campaigns under the mission of 50000 Shoe To Give, Food Sharing, etc. Her venture has been awarded as “The Upcoming Start-up of The Year 2016” by ASSOCHAM India and received an Alumni Award for Social Entrepreneurship in 2019.

Key Personnel

Dilsher Singh

Sr. Manager Creatives

Pramod Sai Naik
     Megavath

Asst. Project Manager

Jobanjit Singh

Sr. Software Engineer

Vishal Pandey

AGM- Operations & General Management

Manjot Singh

Sr. Software Engineer

From blog

Contact

Web Design
Ecommerce
Development
Others
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.