• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Assistance in conversion of small console C# program to Java

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI All

Please can one assist me in completing converting this console program for C# to Java. I have tried my best to get it as far as I can but still am getting errors.

Here is the C# code and below it the JAva code


Here is what I have so far with the Java code


 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hate the 'convert from one language to another' strategy. What you should do is take the C# application and consider it a specification - a guide line for what your application is supposed to do, but not take the code as a template (i.e. don't think C# can tell you how to do something in Java). Then I would start on the Java application from scratch. I would not try to convert the C# to Java because the languages are too different. They may appear the same, and they may have similar structures, but the act differently that if you simply translate the results will not be the same.

My suggestion would be to get rid of what you have, and start from scratch based on Java, not based on C#. Barring that, if you really want to continue on this path, tell us what errors you get and where they occur so we can address them.
 
John Progton
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Luke wrote:I hate the 'convert from one language to another' strategy. What you should do is take the C# application and consider it a specification - a guide line for what your application is supposed to do, but not take the code as a template (i.e. don't think C# can tell you how to do something in Java). Then I would start on the Java application from scratch. I would not try to convert the C# to Java because the languages are too different. They may appear the same, and they may have similar structures, but the act differently that if you simply translate the results will not be the same.

My suggestion would be to get rid of what you have, and start from scratch based on Java, not based on C#. Barring that, if you really want to continue on this path, tell us what errors you get and where they occur so we can address them.



Hi Steve

I understand what you are saying
Basically the issues I have are in line 26 .This is the C# code


Line 39.I used the HTTPResponse but the compiler is still complaining C# used


And the last is that C# has a class just called Stream but I don't know which one to use in Java for this.


My java one


Basically those are the only three lines I am having issues with.
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Progton wrote:Basically the issues I have are in line 26 .This is the C# code


The C# code isn't relevant. What is the Java code? What is the error? What are you trying to do? How do you do it in Java? Those are the relevant questions. The fact that a line copied from C# to Java doesn't work is of no surprise.

Line 39.I used the HTTPResponse but the compiler is still complaining C# used


Diddo.

And the last is that C# has a class just called Stream but I don't know which one to use in Java for this.


What C# uses is irrelevant. The correct class to use here is... impossible to define. Request is of a type that doesn't exist, GetRequestStream() is a method that doesn't exist, so it doesn't matter what type you define dataStream to be, it will be wrong. You need to write the code in Java and use Java classes and Java methods and Java API to know what and how to call things.

If you want to use just Core Java, you should look at this API: http://docs.oracle.com/javase/7/docs/api/java/net/HttpURLConnection.html, and read this tutorial: http://docs.oracle.com/javase/tutorial/networking/urls/readingWriting.html. If you want to use a library that is a bit easier and more robust then take a look at Apache HttpClient.
 
reply
    Bookmark Topic Watch Topic
  • New Topic