I need some help. I have to translate a c app into java. Which would be no problem if I knew c. Is there a good uber begginers level tutorial somewhere, that i might be able to figure out what this c code is doing? I mean, i am seeing things like "struct" which I have no idea what that is and pointers which java doesnt use. Anyone have an idea of where i should look.

Recommended Answers

All 5 Replies

I need some help. I have to translate a c app into java. Which would be no problem if I knew c. Is there a good uber begginers level tutorial somewhere, that i might be able to figure out what this c code is doing? I mean, i am seeing things like "struct" which I have no idea what that is and pointers which java doesnt use. Anyone have an idea of where i should look.

I think you'll have a big problem there. Most probably you will be able to make the same program done in C, but in Java. The problem is that it won't be like "translating" english to spanish. Firs of all, C is an imperative language, while Java is an object oriented one. Like you've said, you dont have pointers in java, and thats only one of the "heavy" differences if you've never used them. For instance, in C you don't have objects ( you can try to simulate this concept using ADT's, but thats another subject ), you dont have classes, inheritance or polymorfism and another bunch of difs. So, as you can see, its a very different languaje, from several points of view. I don't know how complex its the code you have to "translate" but you could start by researching a bit about C using your best friend Google. Then you can ask whatever you don't understand about it and if you still cant figure what the purpose of that code is, you can send it to me and I'll try to do my best to help you. Good Luck!

PS: I skipped the explanation about structs because you need to know some previous stuff before getting there. Look for tutorials!! You'll find a lot!

Hey, Thanks for the info. I would take you up on sending you the c code, but it is a homework assignment, and I dont want you to think I am fishing for someone to do it for me. Having said that, if I did send it to you, all I really need is an explanation of what the code is doing. Once I know what the c code is doing, then i can easilly (hopefully) re-write another server / client app in java. I will post the c code if you request, but I really dont want you to think i am looking for an easy out. I want to do it, but I just dont know c code from a hole in the ground. Actually i will attach a text file that has two c classes(if they are called classes), but i put them into one text file.

Hey, Thanks for the info. I would take you up on sending you the c code, but it is a homework assignment, and I dont want you to think I am fishing for someone to do it for me. Having said that, if I did send it to you, all I really need is an explanation of what the code is doing. Once I know what the c code is doing, then i can easilly (hopefully) re-write another server / client app in java. I will post the c code if you request, but I really dont want you to think i am looking for an easy out. I want to do it, but I just dont know c code from a hole in the ground. Actually i will attach a text file that has two c classes(if they are called classes), but i put them into one text file.

Your welcome! Please, don't think I was trying to make you take the easy way. As I told you in my previous post, you should try finding a basic tutorial in order to get some information about how is data representation in C, reading about stuff like: built-in types, arrays, pointers, structs & unions, types definition using typedef, etc. After that I recommend you looking for some information ( know i've seen the code, I can lead you a bit more ) about socket programming in C. I dont pretend you to know how to program this stuff by yourself but if you get an idea of what is the operational insight of some functions like socket I think you will get the main idea of the code. If you have tried with that and you still want my help, I can tell you the "idea" of both client & server. Good Luck!

PS: What you've put in that file are not classes, they are functions. In particular they are the main functions of each program ( client & server ). Each program coded in C, MUST have a main function because thats the entry point of the program( like in java, but in C is just one more function ).

Java provides its own set of libraries for Socket Programming. Refer java.net package. The code provided by you uses C specific libraries for socket programming.

However, the program has two parts Client and Server. The client reads two arguments from command line. They are the program/file name and the host with which you want to connect to. In case of Java, you only require one argument i.e., the host-name.

It then opens a Socket to communicate to the Server.

The program can then uses an infinite loop to get and send messages from and two Server.

The Server part also does some sort of similar stuff. It does not require any host name as it is itself the host.

The Server binds itself to a socket so that it can listen to requests and process them.

The same can be achieved very easily in Java. What you here need to understand is the concept that Java and C uses for Socket programming. You cannot straight away convert a C program to Java because of the differences in them, their architecture and the libraries used by them.

thank you all for the explanations. Currently i have written two small java classes using java.net libraries. I am unsure if i need to create threads to start everything off or not but the client handles reading the input from the command line, puts it into a datagram packet, and sends it off to the server. The server recieves it, gets the data, ip, etc.. In the c code what does it do with the data it recieves? Does it just echo it back to the client? That is what i am assuming from the comments. Again, thank you all for explaining this very simple c stuff to me. I feel kinda retarded having to ask for someone to explain such a thing to me. I will finish the java stuff this weekend and i will post what I have so you guys can critique me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.