Sockets in C++ and Java [closed]
I was wondering whether networking is easier in Java or C++. Because I know in Java networking with sockets and such is incredibly easy, such as doing the following:
Socket s= new Socket();
s.connect(new SocketAddress("localhost",8888));
and if it is significantly harder in C++ that heavily influences my decision. Thanks in advance!
Building working socket code in Java is easier than in C++. Building "good" socket code in either depends more on the developer's experience and skill than on the language. C++ has Boost.Asio that makes this a bit easier.
I would suggest that Java is generally easier for beginners. C++ is easier it you want to do low level programming e.g. with pointers.
In Java I would do
Socket s = new Socket("localhost",8888);
which is even easier.
C++ is conceptually more difficult than java, at least you should deal with pointers.. Most of the people has difficulties to understand pointer concept.. Also, you should allocate and free memory, if you use C++, thanks to Java GC it saves you from this burden. I think this is the most superior future of Java against C++ or C.
And your specific question, Java has built-in socket libraries, you do not need a third party for socket operations..
To sum up, C++ is harder and more difficult than java.
精彩评论