0% found this document useful (0 votes)
16 views3 pages

Differentiate Java With C and C++

Java notes

Uploaded by

Reshmi Gopinath
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)
16 views3 pages

Differentiate Java With C and C++

Java notes

Uploaded by

Reshmi Gopinath
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/ 3

DIFFERENTIATE JAVA WITH C AND C++

Major differences between C and JAVA are

● JAVA is Object-Oriented while C is procedural - Most differences


between the features of the two languages arise due to the use of
different programming paradigms. C is more procedure-oriented while
JAVA is data-oriented.

● Java is an Interpreted language while C is a compiled language- A C


compiler takes your code & translates it into something the machine can
understand. While with JAVA, the code is first transformed to what is
called the bytecode. This bytecode is then executed by the JVM(Java
Virtual Machine). For the same reason, JAVA code is more portable.

● C is a low-level language while JAVA is a high-level language.

● C uses the top-down approach while JAVA uses the bottom-up approach
- In C, formulating the program begins by defining the whole and then
splitting them into smaller elements. JAVA follows the bottom-up
approach where the smaller elements combine together to form the
whole.

● Pointer go backstage in JAVA while C requires explicit handling of


pointers - While in JAVA, we do create references for objects.

● JAVA supports Method Overloading while C does not support overloading


at all - JAVA supports function or method overloading-that is we can have
two or more functions with the same name.

● The standard Input & Output Functions - C uses the printf & scanf
functions as its standard input & output while JAVA uses the System.
out. print & System. In .read functions.

● Exception Handling in JAVA And the errors & crashes in C - When an


error occurs in a Java program it results in an exception being thrown. It
can then be handled using various exception handling techniques. While
in C, if there's an error, there IS an error.

Major differences between C++ and JAVA are

● C++ was mainly designed for systems programming and Java was
created initially to support network computing.
● C++ supports pointers whereas Java does not pointers.

● At compilation time Java Source code converts into byte code


.The interpreter execute this byte code at run time and gives output. C++
run and compile using compiler which converts source code into machine
level languages so C++ is plate from dependents

● Java is platform independent language but C++ is depends upon


operating system machine etc.

● Java uses compiler and interpreter both and in C++ their is only compiler

● C++ supports operator overloading multiple inheritance but java does


not.

● Java does is a similar to C++ but not have all the complicated aspects of
C++ (ex: Pointers, templates, unions, operator overloading, structures
etc..)

● Thread support is built-in Java but not in C++.

● Internet support is built-in Java but not in C++.

● Java does not support header file, include library files just like C++ .Java
use import to include different Classes and methods.

● Java does not support default arguments like C++.

● Exception and Auto Garbage Collector handling in Java is different


because there are no destructors into Java.

● Java has method overloading, but no operator overloading just like C++.

1.0 STRUCTURE

Let us start Java programming with a small example. This program

will show the output “Hello World”

class classname
{
public static void main(String args[])
{
System.out.println(“Hello World”);
}
}
Eg with explanation
class HelloWorld
{
public static void main(String args[])
{
System.out.println(“Hello World”);
}
}

Now let us understand the program line by line.


● Class Declaration – This line declares a class. class is an
object-oriented construct and a keyword which states that the class
declaration follows. HelloWorld is the name of the class.

● Opening and Closing Brace - The entire class definition, including all of
its members, will be between the opening curly brace ({) and the closing
curly brace (}). The use of the curly braces in Java is identical to the way
they are used in C and C++.
● Main Line – The main() function is similar to the the main() in C/C++.
Every Java application program must include the main() method. The
keyword public is an access specifier that declares the main method
accessible to all other classes. The next keyword static states that this
method belongs to the entire class. main() is the method called when a
Java application begins. In main(), there is only one parameter, String
args[ ] declares a parameter named args, which is an array of strings of
the class String. The type modifier void states that the main() method
does not return any value.

● Output Line – This line is similar to the printf() of C or cout << of C++.
The println() method is a member of the out object, which is a static data
member of System class. System is a predefined class that provides
access to the system, and out is the output stream that is connected to
the console.

Output:
Hello World

You might also like