Saturday, May 22, 2010

What are the main differences i should learn between c++ and java?

i know c++, but i wan to learn java. what diffrences should i aware of before i start learning?

What are the main differences i should learn between c++ and java?
The big differences are that in java you don't use pointers any more, so all memory allocation is handled by the java virtual machine. Also in java everything is a class so instead of doing:





int main() {...}





you do





class HelloWorld {


public static void main() {...}


}





There are a lot more than that though, I've posted a site with a bunch more of some of the other differences.
Reply:In C++, class and be created seperately from main function. see the code..





class test


{


public:


};





void main()


{


test t;


}





But in Java, you main program is also a class, with this class has function named "main"; you use this class as main function like C/C++. See the code.








class test


{


public static void main(String a[])


{


......// code here ..


}


}





From the above, the class named "test" has main function in it. It can be use like a main part of your program. See more example:





======= test.java ==============





import java.io.*;





class Factorial


{


Factorial()


{


//


}


void dosomething()


{


///


}


}





class test


{


public static void main(String a[])


{


Factorial f=new Factorial();


f.dosomething();


}


}





From the code test.java, you will see how first mainly difference between C++ you know and Java. Thiis is the frist thing you will learn how difference at the first. In C# also likes this.


No comments:

Post a Comment