Difference Between CPP and Java JVM Bytecode
Difference Between CPP and Java JVM Bytecode
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,
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.
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
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.
Console I/O:
. The
C+t.
method of console input/output is entirely different in java as comparedIto
Cand
1ogram to terminae w
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
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
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.