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

Difference Between CPP and Java JVM Bytecode

cpp and jvm

Uploaded by

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

Difference Between CPP and Java JVM Bytecode

cpp and jvm

Uploaded by

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

FUNDAMENTALS OF JAVA 4.

A1.7 Difference between Java, C and C++

Datatype:
In Java int takes four bytes as compared to C.C++, which take two bytes ot memoy
In Java char takes two bytes as compared to C, C++, which take one byte
memory.
In javanew datatypeboolean is added, it is not available in C, C++t.
Java doesn't supporttypedefand enum

Operators:
Java adds a new operator in bitwise that is right shift operator >>>
in C
which was not supported
% may be applied in Java for dividing float values,

and C++.
which is frequently used in C, Ct+ to
operator sizeofO,
Java doesnot supportspecial
find the memory size bytes of data elements.

Keywords: inaiy
inal,
keywords such as super, try, catch,
Java introduced some new
synchronized,package, interface etc.
that were used in
C and C++ such as typedef, enum,
Java dropped some keywords
delete etc.

Loops: statements
arrays. All other control
for loop used with
Java suPport a special type of
C++.
are same as in C,

Break and Continue: support labeled


continue statements, Java
Inaddition normal use of break and
to the
control over loops.
to provide better
break and continue statements

Pointers: in C
which is very important concept
the conceptof pointers,
Java does not support
and C++.
files:
and header
Preprocessor directives
directives and header
files.

Java does not have preprocessor


to employ inbuilt
java class library.
Java use import keyword
classes.
of packages to organize
Java use the concept

Portability:
is interpreted
intermediate code i.e. Bytecode which
Java programs are compiled to and can be
The byte code is machine independent
by the java run time environment.
executed on any plateform.
dependent executable code.
InC and C++ the source code in compiled to machine
and is not portable.
That is executed on the actual machine
FUNDAMENTALS OF JAVA
4.10

Inheritance:
C.
The concept of inheritance is not supported in is
inheritance directly which
do not support multiple
Java support inheritance but
available in C++.

Operator overloading:
is not supported in C.
overloading
The conceptof operator feature of C++.
which is an important
• Java doesn't support operator overloading

String representation:
terminated array of characters.
and C++ string is represented as null
In C

isan object.
In java every string

Memory management:
mamagement is programmer's responsibility.
In C and C++ memory

without worrying about


deallocation.
In javaprogrammer uses
memory freely

C++ delete() is used to deallocate memory.


InC free() function and in
garbage collection routine.
using
Injava nemory is deallocated

Multithreading:
used in java and not in C and C++.
The concept of multithreaded programming is

Exception handling:
The concept of exception handling is used in java and C++ but not in C.

Java provides better way of exception handling as compared to C++.

Console I/O:
. The
C+t.
method of console input/output is entirely different in java as comparedIto
Cand
1ogram to terminae w

ng an inputmismatch occurs. Por example,if you input 12

insteadoPemN wiCe
3.7 JAVA VIRTUAL MACHINE
machine
Most prgramming languages such as CC#
compile source code directly into
such as
de suitable for
exUion on a particular nmieroprocessor architecture or operating system
neural'. But Javia is
WindowS Or Unix This nnIety does not make these language 'architecural
anvwhere approach, This Teature
an arhitectural neutral languase as it follows Write once execute
the machine lan-
of Java is achieved
as the Java compiler
does not translate the source code into
code
on. Instead the compiler translates source
guage ot the computer that the program is running is needed
into byteade which is not understood
by the underlying operating system. So an application
operating system,
that can convert this bytecode into
nmachine code understood by the underlying

This isaomplished using the Java Vitual Machine.


(JVM) as a hypothetical computer platform
Tou can thìnk of the Java Virtual Machine is an cmulator i.e. a
not really exist as actual hardware. Instead
it

design or a computer that does


the JVM) that can
drive to act like a computer (namely
program thatsets side a part of your hard
CxeCute Java programs, Because of
JVM youcan execute a Java program on any compter hat has
without recompiling the program. This is how Java
provides
a Java runtime environment installed
platforn independence.

0101.e**.
JVM
for Windows

Java
Source Code WINDOWS OS
bytecode
JVM 0101...*
Java Complier bytecode for Unix

(javac)

UNIX OS
bytecode
FirstProg.java
JVM 0101.
for Macintosh

MACINTOSH OS
Fig. 3.13

3.8 BÝTECODE
When youwork with conventional programming languages like Cor C++,the source code is

compiled into an executable form known as primary code or machine code. The machine code is a

pattern of0's and I's understandable by the underlying hardware architecture of the computer on
which the program is intended to run.

On the other hand in Java, source code is not complied into machine code bu rather into a

Learn Programing in Java 54


special intermediate format known as bytecode. Java bytecode is the forn of instructions that the

JVM (Java Virtual Machine) reads and translates them one by one into machine code that the
computer understands. When JVM loads a class file, it gets one stream of byte codes for each
method in the class. The bytecodes for that method will be executed, when the method is invoked
during the course of running the program.

You might also like