Differentiate Java With C and C++
Differentiate Java With C and C++
● 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.
● 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.
● C++ was mainly designed for systems programming and Java was
created initially to support network computing.
● C++ supports pointers whereas Java does not pointers.
● Java uses compiler and interpreter both and in C++ their is only compiler
● Java does is a similar to C++ but not have all the complicated aspects of
C++ (ex: Pointers, templates, unions, operator overloading, structures
etc..)
● Java does not support header file, include library files just like C++ .Java
use import to include different Classes and methods.
● Java has method overloading, but no operator overloading just like C++.
1.0 STRUCTURE
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”);
}
}
● 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